|
|
|
@ -1,34 +1,13 @@
|
|
|
|
|
import { equals, Pos, ratioWithinBase } from "../geo/Pos"
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
BallState,
|
|
|
|
|
Player,
|
|
|
|
|
PlayerInfo,
|
|
|
|
|
PlayerLike,
|
|
|
|
|
PlayerPhantom,
|
|
|
|
|
PlayerTeam,
|
|
|
|
|
} from "../model/tactic/Player"
|
|
|
|
|
import {
|
|
|
|
|
Ball,
|
|
|
|
|
BALL_ID,
|
|
|
|
|
BALL_TYPE,
|
|
|
|
|
CourtObject,
|
|
|
|
|
} from "../model/tactic/CourtObjects"
|
|
|
|
|
import {
|
|
|
|
|
ComponentId,
|
|
|
|
|
StepContent,
|
|
|
|
|
TacticComponent,
|
|
|
|
|
} from "../model/tactic/Tactic"
|
|
|
|
|
import { BallState, Player, PlayerInfo, PlayerLike, PlayerPhantom, PlayerTeam } from "../model/tactic/Player"
|
|
|
|
|
import { Ball, BALL_ID, BALL_TYPE, CourtObject } from "../model/tactic/CourtObjects"
|
|
|
|
|
import { ComponentId, StepContent, TacticComponent } from "../model/tactic/Tactic"
|
|
|
|
|
|
|
|
|
|
import { overlaps } from "../geo/Box"
|
|
|
|
|
import { RackedCourtObject, RackedPlayer } from "./RackedItems"
|
|
|
|
|
import {
|
|
|
|
|
getComponent,
|
|
|
|
|
getOrigin,
|
|
|
|
|
getPrecomputedPosition,
|
|
|
|
|
tryGetComponent,
|
|
|
|
|
} from "./PlayerDomains"
|
|
|
|
|
import { ActionKind } from "../model/tactic/Action.ts"
|
|
|
|
|
import { getComponent, getOrigin, getPrecomputedPosition, removePlayer, tryGetComponent } from "./PlayerDomains"
|
|
|
|
|
import { Action, ActionKind } from "../model/tactic/Action.ts"
|
|
|
|
|
import { spreadNewStateFromOriginStateChange } from "./ActionsDomains.ts"
|
|
|
|
|
|
|
|
|
|
export function placePlayerAt(
|
|
|
|
@ -458,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
|
|
|
|
@ -474,14 +451,9 @@ export function drainTerminalStateOnChildContent(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function mapToParentContent(content: StepContent): StepContent {
|
|
|
|
|
return {
|
|
|
|
|
...content,
|
|
|
|
|
components: content.components.map((p) => {
|
|
|
|
|
if (p.type == "ball") return p
|
|
|
|
|
return {
|
|
|
|
|
...p,
|
|
|
|
|
id: p.id + "-parent",
|
|
|
|
|
actions: p.actions.map((a) => ({
|
|
|
|
|
|
|
|
|
|
function mapToParentActions(actions: Action[]): Action[] {
|
|
|
|
|
return actions.map((a) => ({
|
|
|
|
|
...a,
|
|
|
|
|
target: a.target + "-parent",
|
|
|
|
|
segments: a.segments.map((s) => ({
|
|
|
|
@ -491,8 +463,33 @@ export function mapToParentContent(content: StepContent): StepContent {
|
|
|
|
|
? s.next + "-parent"
|
|
|
|
|
: s.next,
|
|
|
|
|
})),
|
|
|
|
|
})),
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...content,
|
|
|
|
|
components: content.components.map((p) => {
|
|
|
|
|
if (p.type == "ball") return p
|
|
|
|
|
if (p.type == "player") {
|
|
|
|
|
return {
|
|
|
|
|
...p,
|
|
|
|
|
id: p.id + "-parent",
|
|
|
|
|
actions: mapToParentActions(p.actions),
|
|
|
|
|
path: p.path && { items: p.path.items.map(p => p + "-parent") },
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
...p,
|
|
|
|
|
pos: p.pos.type == "follows" ? { ...p.pos, attach: p.pos.attach + "-parent" } : p.pos,
|
|
|
|
|
id: p.id + "-parent",
|
|
|
|
|
originPlayerId: p.originPlayerId + "-parent",
|
|
|
|
|
actions: mapToParentActions(p.actions),
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function selectContent(id: string, content: StepContent, parentContent: StepContent | null): StepContent {
|
|
|
|
|
return parentContent && id.endsWith("-parent") ? parentContent : content
|
|
|
|
|
}
|