diff --git a/src/editor/ActionsDomains.ts b/src/editor/ActionsDomains.ts index d0d42b6..0530e68 100644 --- a/src/editor/ActionsDomains.ts +++ b/src/editor/ActionsDomains.ts @@ -7,6 +7,7 @@ import {removeBall, updateComponent} from "./TacticContentDomains" import { areInSamePath, changePlayerBallState, + getComponent, getOrigin, getPlayerNextTo, isNextInPath, @@ -165,11 +166,9 @@ function alreadyHasAnAnteriorActionWith( const targetIdx = targetOriginPath.indexOf(target.id) for (let i = targetIdx; i < targetOriginPath.length; i++) { - const phantom = components.find( - (c) => c.id === targetOriginPath[i], - )! as PlayerLike + const component = getComponent(targetOriginPath[i], components) if ( - phantom.actions.find( + component.actions.find( (a) => typeof a.target === "string" && moves(a.type) && @@ -467,9 +466,7 @@ export function spreadNewStateFromOriginStateChange( continue } - const actionTarget = content.components.find( - (c) => action.target === c.id, - )! as PlayerLike + const actionTarget: PlayerLike = getComponent(action.target, content.components) let targetState: BallState = actionTarget.ballState let deleteAction = false @@ -499,13 +496,16 @@ export function spreadNewStateFromOriginStateChange( action.type === ActionKind.SCREEN ) { targetState = BallState.HOLDS_BY_PASS + const screenPhantom = getPlayerNextTo(origin, 1, content.components)! + if (screenPhantom.type === "phantom" && screenPhantom.pos.type === "follows") { + content = removePlayer(screenPhantom, content) + origin = getComponent(origin.id, content.components) + } } if (deleteAction) { content = removeAction(origin, i, content) - origin = content.components.find((c) => c.id === origin.id)! as - | Player - | PlayerPhantom + origin = getComponent(origin.id, content.components) i-- // step back } else { // do not change the action type if it is a shoot action diff --git a/src/editor/PlayerDomains.ts b/src/editor/PlayerDomains.ts index add77a1..03aa898 100644 --- a/src/editor/PlayerDomains.ts +++ b/src/editor/PlayerDomains.ts @@ -25,7 +25,6 @@ export function getPlayerNextTo(player: PlayerLike, n: number, components: Tacti // remove the screen phantom const result = targetIdx == 0 ? playerOrigin : getComponent(pathItems[targetIdx - 1], components) - console.log(result, targetIdx, idx, n) return result } @@ -172,7 +171,6 @@ export function removePlayer( if (pos.type === "follows") { const playerBefore = getPlayerNextTo(player, -1, content.components)! const actionIdx = playerBefore.actions.findIndex(a => a.target === pos.attach) - console.log(actionIdx, playerBefore) content = updateComponent({ ...playerBefore, actions: playerBefore.actions.toSpliced(actionIdx, 1) @@ -180,7 +178,9 @@ export function removePlayer( } const origin = getOrigin(player, content.components) - return truncatePlayerPath(origin, player, content) + content = truncatePlayerPath(origin, player, content) + console.log(content) + return content } content = clearPlayerPath(player, content) diff --git a/src/pages/Editor.tsx b/src/pages/Editor.tsx index 776623a..cc51abb 100644 --- a/src/pages/Editor.tsx +++ b/src/pages/Editor.tsx @@ -67,7 +67,8 @@ import { middlePos, Pos, ratioWithinBase } from "../geo/Pos" import { Action, ActionKind } from "../model/tactic/Action" import BallAction from "../components/actions/BallAction" import { - changePlayerBallState, computePhantomPositioning, + changePlayerBallState, + computePhantomPositioning, getOrigin, removePlayer, } from "../editor/PlayerDomains"