From 95b89d87e45e7c508636ec6852ccd641d6046c38 Mon Sep 17 00:00:00 2001 From: maxime Date: Thu, 21 Mar 2024 23:17:17 +0100 Subject: [PATCH] fix steps bugs --- src/editor/PlayerDomains.ts | 8 +++++--- src/editor/TacticContentDomains.ts | 16 +++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/editor/PlayerDomains.ts b/src/editor/PlayerDomains.ts index 1b3c918..e361f93 100644 --- a/src/editor/PlayerDomains.ts +++ b/src/editor/PlayerDomains.ts @@ -279,9 +279,11 @@ export function removePlayer( if (action.type !== ActionKind.SHOOT) { continue } - const actionTarget = content.components.find( - (c) => c.id === action.target, - )! as PlayerLike + if (typeof action.target !== "string") + continue + const actionTarget = tryGetComponent(action.target, content.components) + if (actionTarget === undefined) + continue //the target was maybe removed return ( spreadNewStateFromOriginStateChange( actionTarget, diff --git a/src/editor/TacticContentDomains.ts b/src/editor/TacticContentDomains.ts index 7ff30fa..e328737 100644 --- a/src/editor/TacticContentDomains.ts +++ b/src/editor/TacticContentDomains.ts @@ -6,7 +6,7 @@ import { ComponentId, StepContent, TacticComponent } from "../model/tactic/Tacti import { overlaps } from "../geo/Box" import { RackedCourtObject, RackedPlayer } from "./RackedItems" -import { getComponent, getOrigin, getPrecomputedPosition, tryGetComponent } from "./PlayerDomains" +import { getComponent, getOrigin, getPrecomputedPosition, removePlayer, tryGetComponent } from "./PlayerDomains" import { Action, ActionKind } from "../model/tactic/Action.ts" import { spreadNewStateFromOriginStateChange } from "./ActionsDomains.ts" @@ -437,14 +437,12 @@ export function drainTerminalStateOnChildContent( const initialChildCompsCount = childContent.components.length - //filter out all frozen components that are not present on the parent's terminal state anymore - childContent = { - components: childContent.components.filter( - (comp) => - comp.type === "phantom" || - !comp.frozen || - tryGetComponent(comp.id, parentTerminalState.components), - ), + for (const component of childContent.components) { + if (component.type !== "phantom" && component.frozen && !tryGetComponent(component.id, parentTerminalState.components)) { + if (component.type === "player") + childContent = removePlayer(component, childContent) + else childContent = {...childContent, components: childContent.components.filter(c => c.id !== component.id)} + } } gotUpdated ||= childContent.components.length !== initialChildCompsCount