Apply suggestions and format
continuous-integration/drone/push Build is passing Details

pull/117/head
maxime 1 year ago
parent 882e45f328
commit bef196e09e

@ -40,11 +40,9 @@ export function BasketCourt({
{courtImage} {courtImage}
{courtRef.current && {courtRef.current &&
parentComponents && parentComponents?.map((i) => renderComponent(i, true))}
parentComponents.map((i) => renderComponent(i, true))}
{courtRef.current && {courtRef.current &&
parentComponents && parentComponents?.flatMap((i) => renderActions(i, true))}
parentComponents.flatMap((i) => renderActions(i, true))}
{courtRef.current && {courtRef.current &&
components.map((i) => renderComponent(i, false))} components.map((i) => renderComponent(i, false))}

@ -279,11 +279,12 @@ export function removePlayer(
if (action.type !== ActionKind.SHOOT) { if (action.type !== ActionKind.SHOOT) {
continue continue
} }
if (typeof action.target !== "string") if (typeof action.target !== "string") continue
continue const actionTarget = tryGetComponent<PlayerLike>(
const actionTarget = tryGetComponent<PlayerLike>(action.target, content.components) action.target,
if (actionTarget === undefined) content.components,
continue //the target was maybe removed )
if (actionTarget === undefined) continue //the target was maybe removed
return ( return (
spreadNewStateFromOriginStateChange( spreadNewStateFromOriginStateChange(
actionTarget, actionTarget,

@ -1,12 +1,34 @@
import { equals, Pos, ratioWithinBase } from "../geo/Pos" import { equals, Pos, ratioWithinBase } from "../geo/Pos"
import { BallState, Player, PlayerInfo, PlayerLike, PlayerPhantom, PlayerTeam } from "../model/tactic/Player" import {
import { Ball, BALL_ID, BALL_TYPE, CourtObject } from "../model/tactic/CourtObjects" BallState,
import { ComponentId, StepContent, TacticComponent } from "../model/tactic/Tactic" 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 { overlaps } from "../geo/Box"
import { RackedCourtObject, RackedPlayer } from "./RackedItems" import { RackedCourtObject, RackedPlayer } from "./RackedItems"
import { getComponent, getOrigin, getPrecomputedPosition, removePlayer, tryGetComponent } from "./PlayerDomains" import {
getComponent,
getOrigin,
getPrecomputedPosition,
removePlayer,
tryGetComponent,
} from "./PlayerDomains"
import { Action, ActionKind } from "../model/tactic/Action.ts" import { Action, ActionKind } from "../model/tactic/Action.ts"
import { spreadNewStateFromOriginStateChange } from "./ActionsDomains.ts" import { spreadNewStateFromOriginStateChange } from "./ActionsDomains.ts"
@ -179,9 +201,9 @@ export function moveComponent(
phantomIdx == 0 phantomIdx == 0
? origin ? origin
: getComponent( : getComponent(
originPathItems[phantomIdx - 1], originPathItems[phantomIdx - 1],
content.components, content.components,
) )
// detach the action from the screen target and transform it to a regular move action to the phantom. // detach the action from the screen target and transform it to a regular move action to the phantom.
content = updateComponent( content = updateComponent(
{ {
@ -189,18 +211,18 @@ export function moveComponent(
actions: playerBeforePhantom.actions.map((a) => actions: playerBeforePhantom.actions.map((a) =>
a.target === referent a.target === referent
? { ? {
...a, ...a,
segments: a.segments.toSpliced( segments: a.segments.toSpliced(
a.segments.length - 2, a.segments.length - 2,
1, 1,
{ {
...a.segments[a.segments.length - 1], ...a.segments[a.segments.length - 1],
next: component.id, next: component.id,
}, },
), ),
target: component.id, target: component.id,
type: ActionKind.MOVE, type: ActionKind.MOVE,
} }
: a, : a,
), ),
}, },
@ -213,9 +235,9 @@ export function moveComponent(
...component, ...component,
pos: isPhantom pos: isPhantom
? { ? {
type: "fixed", type: "fixed",
...newPos, ...newPos,
} }
: newPos, : newPos,
}, },
content, content,
@ -300,9 +322,9 @@ export function computeTerminalState(
comp.type === "player" comp.type === "player"
? getPlayerTerminalState(comp, content, computedPositions) ? getPlayerTerminalState(comp, content, computedPositions)
: { : {
...comp, ...comp,
frozen: true, frozen: true,
}, },
) )
return { return {
@ -438,10 +460,20 @@ export function drainTerminalStateOnChildContent(
const initialChildCompsCount = childContent.components.length const initialChildCompsCount = childContent.components.length
for (const component of childContent.components) { for (const component of childContent.components) {
if (component.type !== "phantom" && component.frozen && !tryGetComponent(component.id, parentTerminalState.components)) { if (
component.type !== "phantom" &&
component.frozen &&
!tryGetComponent(component.id, parentTerminalState.components)
) {
if (component.type === "player") if (component.type === "player")
childContent = removePlayer(component, childContent) childContent = removePlayer(component, childContent)
else childContent = {...childContent, components: childContent.components.filter(c => c.id !== component.id)} else
childContent = {
...childContent,
components: childContent.components.filter(
(c) => c.id !== component.id,
),
}
} }
} }
@ -451,17 +483,13 @@ export function drainTerminalStateOnChildContent(
} }
export function mapToParentContent(content: StepContent): StepContent { export function mapToParentContent(content: StepContent): StepContent {
function mapToParentActions(actions: Action[]): Action[] { function mapToParentActions(actions: Action[]): Action[] {
return actions.map((a) => ({ return actions.map((a) => ({
...a, ...a,
target: a.target + "-parent", target: a.target + "-parent",
segments: a.segments.map((s) => ({ segments: a.segments.map((s) => ({
...s, ...s,
next: next: typeof s.next === "string" ? s.next + "-parent" : s.next,
typeof s.next === "string"
? s.next + "-parent"
: s.next,
})), })),
})) }))
} }
@ -475,12 +503,17 @@ export function mapToParentContent(content: StepContent): StepContent {
...p, ...p,
id: p.id + "-parent", id: p.id + "-parent",
actions: mapToParentActions(p.actions), actions: mapToParentActions(p.actions),
path: p.path && { items: p.path.items.map(p => p + "-parent") }, path: p.path && {
items: p.path.items.map((p) => p + "-parent"),
},
} }
} }
return { return {
...p, ...p,
pos: p.pos.type == "follows" ? { ...p.pos, attach: p.pos.attach + "-parent" } : p.pos, pos:
p.pos.type == "follows"
? { ...p.pos, attach: p.pos.attach + "-parent" }
: p.pos,
id: p.id + "-parent", id: p.id + "-parent",
originPlayerId: p.originPlayerId + "-parent", originPlayerId: p.originPlayerId + "-parent",
actions: mapToParentActions(p.actions), actions: mapToParentActions(p.actions),
@ -489,7 +522,10 @@ export function mapToParentContent(content: StepContent): StepContent {
} }
} }
export function selectContent(
export function selectContent(id: string, content: StepContent, parentContent: StepContent | null): StepContent { id: string,
content: StepContent,
parentContent: StepContent | null,
): StepContent {
return parentContent && id.endsWith("-parent") ? parentContent : content return parentContent && id.endsWith("-parent") ? parentContent : content
} }

@ -47,7 +47,8 @@ import {
placeBallAt, placeBallAt,
placeObjectAt, placeObjectAt,
placePlayerAt, placePlayerAt,
removeBall, selectContent, removeBall,
selectContent,
updateComponent, updateComponent,
} from "../editor/TacticContentDomains" } from "../editor/TacticContentDomains"
@ -488,7 +489,10 @@ function EditorPage({
) == -1 ) == -1
isFrozen = player.frozen isFrozen = player.frozen
} else { } else {
const origin = getOrigin(player, selectContent(player.id, content, parentContent).components) const origin = getOrigin(
player,
selectContent(player.id, content, parentContent).components,
)
const path = origin.path! const path = origin.path!
// phantoms can only place other arrows if they are the head of the path // phantoms can only place other arrows if they are the head of the path
canPlaceArrows = canPlaceArrows =

@ -46,7 +46,7 @@
} }
.player-piece-has-no-ball { .player-piece-has-no-ball {
padding: 2px padding: 2px;
} }
.player-actions { .player-actions {

Loading…
Cancel
Save