|
|
@ -14,6 +14,21 @@ export function getOrigin(
|
|
|
|
return components.find((c) => c.id == pathItem.originPlayerId)! as Player
|
|
|
|
return components.find((c) => c.id == pathItem.originPlayerId)! as Player
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getPlayerNextTo(player: PlayerLike, n: number, components: TacticComponent[]): PlayerLike | undefined {
|
|
|
|
|
|
|
|
const playerOrigin = player.type === "player" ? player : getOrigin(player, components)
|
|
|
|
|
|
|
|
const pathItems = playerOrigin.path?.items!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add one as there is a shifting because a Player is never at the head of its own path
|
|
|
|
|
|
|
|
const idx = pathItems.indexOf(player.id) + 1 // is 0 if the player is the origin
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const targetIdx = idx + n
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove the screen phantom
|
|
|
|
|
|
|
|
const result = targetIdx == 0 ? playerOrigin : getComponent<PlayerLike>(pathItems[targetIdx - 1], components)
|
|
|
|
|
|
|
|
console.log(result, targetIdx, idx, n)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//FIXME this function can be a bottleneck if the phantom's position is
|
|
|
|
//FIXME this function can be a bottleneck if the phantom's position is
|
|
|
|
// following another phantom and / or the origin of the phantom is another
|
|
|
|
// following another phantom and / or the origin of the phantom is another
|
|
|
|
export function computePhantomPositioning(phantom: PlayerPhantom,
|
|
|
|
export function computePhantomPositioning(phantom: PlayerPhantom,
|
|
|
@ -151,6 +166,19 @@ export function removePlayer(
|
|
|
|
content = removeAllPhantomsAttached(player.id, content)
|
|
|
|
content = removeAllPhantomsAttached(player.id, content)
|
|
|
|
|
|
|
|
|
|
|
|
if (player.type === "phantom") {
|
|
|
|
if (player.type === "phantom") {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pos = player.pos
|
|
|
|
|
|
|
|
// if the phantom was attached to another player, remove the action that symbolizes the attachment
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
}, content)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const origin = getOrigin(player, content.components)
|
|
|
|
const origin = getOrigin(player, content.components)
|
|
|
|
return truncatePlayerPath(origin, player, content)
|
|
|
|
return truncatePlayerPath(origin, player, content)
|
|
|
|
}
|
|
|
|
}
|
|
|
|