apply suggestions
continuous-integration/drone/push Build is passing Details

pull/95/head
maxime 1 year ago
parent 9a6103e78a
commit 1b435d4469

@ -1,4 +1,9 @@
import { BallState, Player, PlayerPhantom } from "../model/tactic/Player" import {
BallState,
Player,
PlayerPhantom,
PlayerLike,
} from "../model/tactic/Player"
import { ratioWithinBase } from "../geo/Pos" import { ratioWithinBase } from "../geo/Pos"
import { import {
ComponentId, ComponentId,
@ -44,7 +49,7 @@ export function getActionKind(
} }
export function getActionKindBetween( export function getActionKindBetween(
origin: Player | PlayerPhantom, origin: PlayerLike,
target: TacticComponent | null, target: TacticComponent | null,
state: BallState, state: BallState,
): { kind: ActionKind; nextState: BallState } { ): { kind: ActionKind; nextState: BallState } {
@ -76,7 +81,6 @@ export function isActionValid(
origin.ballState != BallState.HOLDS_ORIGIN && origin.ballState != BallState.HOLDS_ORIGIN &&
origin.actions.find((a) => moves(a.type)) origin.actions.find((a) => moves(a.type))
) { ) {
console.log("a")
return false return false
} }
//Action is valid if the target is null //Action is valid if the target is null
@ -95,7 +99,6 @@ export function isActionValid(
(hasBoundWith(target, origin, components) || (hasBoundWith(target, origin, components) ||
hasBoundWith(origin, target, components)) hasBoundWith(origin, target, components))
) { ) {
console.log("b")
return false return false
} }
@ -104,7 +107,6 @@ export function isActionValid(
origin.actions.find((a) => a.target === target?.id) || origin.actions.find((a) => a.target === target?.id) ||
target?.actions.find((a) => a.target === origin.id) target?.actions.find((a) => a.target === origin.id)
) { ) {
console.log("c")
return false return false
} }
@ -114,7 +116,6 @@ export function isActionValid(
if (areInSamePath(origin, target)) return false if (areInSamePath(origin, target)) return false
if (alreadyHasAnAnteriorActionWith(origin, target, components)) { if (alreadyHasAnAnteriorActionWith(origin, target, components)) {
console.log("e")
return false return false
} }
} }
@ -152,8 +153,8 @@ function hasBoundWith(
} }
function alreadyHasAnAnteriorActionWith( function alreadyHasAnAnteriorActionWith(
origin: Player | PlayerPhantom, origin: PlayerLike,
target: Player | PlayerPhantom, target: PlayerLike,
components: TacticComponent[], components: TacticComponent[],
): boolean { ): boolean {
const targetOrigin = const targetOrigin =
@ -174,7 +175,7 @@ function alreadyHasAnAnteriorActionWith(
for (let i = targetIdx; i < targetOriginPath.length; i++) { for (let i = targetIdx; i < targetOriginPath.length; i++) {
const phantom = components.find( const phantom = components.find(
(c) => c.id === targetOriginPath[i], (c) => c.id === targetOriginPath[i],
)! as Player | PlayerPhantom )! as PlayerLike
if ( if (
phantom.actions.find( phantom.actions.find(
(a) => (a) =>
@ -191,7 +192,7 @@ function alreadyHasAnAnteriorActionWith(
for (let i = 0; i <= originIdx; i++) { for (let i = 0; i <= originIdx; i++) {
const phantom = components.find( const phantom = components.find(
(c) => c.id === originOriginPath[i], (c) => c.id === originOriginPath[i],
)! as Player | PlayerPhantom )! as PlayerLike
if ( if (
phantom.actions.find( phantom.actions.find(
(a) => (a) =>
@ -208,7 +209,7 @@ function alreadyHasAnAnteriorActionWith(
} }
export function createAction( export function createAction(
origin: Player | PlayerPhantom, origin: PlayerLike,
courtBounds: DOMRect, courtBounds: DOMRect,
arrowHead: DOMRect, arrowHead: DOMRect,
content: TacticContent, content: TacticContent,
@ -418,7 +419,7 @@ export function removeAction(
* @param content * @param content
*/ */
export function spreadNewStateFromOriginStateChange( export function spreadNewStateFromOriginStateChange(
origin: Player | PlayerPhantom, origin: PlayerLike,
newState: BallState, newState: BallState,
content: TacticContent, content: TacticContent,
): TacticContent { ): TacticContent {
@ -441,7 +442,7 @@ export function spreadNewStateFromOriginStateChange(
const actionTarget = content.components.find( const actionTarget = content.components.find(
(c) => action.target === c.id, (c) => action.target === c.id,
)! as Player | PlayerPhantom )! as PlayerLike
let targetState: BallState = actionTarget.ballState let targetState: BallState = actionTarget.ballState
let deleteAction = false let deleteAction = false

@ -1,4 +1,9 @@
import { BallState, Player, PlayerPhantom } from "../model/tactic/Player" import {
BallState,
Player,
PlayerLike,
PlayerPhantom,
} from "../model/tactic/Player"
import { TacticComponent, TacticContent } from "../model/tactic/Tactic" import { TacticComponent, TacticContent } from "../model/tactic/Tactic"
import { removeComponent, updateComponent } from "./TacticContentDomains" import { removeComponent, updateComponent } from "./TacticContentDomains"
import { import {
@ -15,10 +20,7 @@ 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 areInSamePath( export function areInSamePath(a: PlayerLike, b: PlayerLike) {
a: Player | PlayerPhantom,
b: Player | PlayerPhantom,
) {
if (a.type === "phantom" && b.type === "phantom") { if (a.type === "phantom" && b.type === "phantom") {
return a.originPlayerId === b.originPlayerId return a.originPlayerId === b.originPlayerId
} }
@ -38,8 +40,8 @@ export function areInSamePath(
* @returns true if the `other` player is the phantom next-to the origin's path. * @returns true if the `other` player is the phantom next-to the origin's path.
*/ */
export function isNextInPath( export function isNextInPath(
origin: Player | PlayerPhantom, origin: PlayerLike,
other: Player | PlayerPhantom, other: PlayerLike,
components: TacticComponent[], components: TacticComponent[],
): boolean { ): boolean {
if (origin.type === "player") { if (origin.type === "player") {
@ -74,7 +76,7 @@ export function removePlayerPath(
} }
export function removePlayer( export function removePlayer(
player: Player | PlayerPhantom, player: PlayerLike,
content: TacticContent, content: TacticContent,
): TacticContent { ): TacticContent {
content = removeAllActionsTargeting(player.id, content) content = removeAllActionsTargeting(player.id, content)
@ -93,7 +95,7 @@ export function removePlayer(
} }
const actionTarget = content.components.find( const actionTarget = content.components.find(
(c) => c.id === action.target, (c) => c.id === action.target,
)! as Player | PlayerPhantom )! as PlayerLike
return spreadNewStateFromOriginStateChange( return spreadNewStateFromOriginStateChange(
actionTarget, actionTarget,
BallState.NONE, BallState.NONE,
@ -139,7 +141,7 @@ export function truncatePlayerPath(
} }
export function changePlayerBallState( export function changePlayerBallState(
player: Player | PlayerPhantom, player: PlayerLike,
newState: BallState, newState: BallState,
content: TacticContent, content: TacticContent,
): TacticContent { ): TacticContent {

@ -188,13 +188,9 @@ export function removeComponent(
componentId: ComponentId, componentId: ComponentId,
content: TacticContent, content: TacticContent,
): TacticContent { ): TacticContent {
const componentIdx = content.components.findIndex(
(c) => c.id == componentId,
)
return { return {
...content, ...content,
components: content.components.toSpliced(componentIdx, 1), components: content.components.filter((c) => c.id !== componentId),
} }
} }
@ -202,12 +198,11 @@ export function updateComponent(
component: TacticComponent, component: TacticComponent,
content: TacticContent, content: TacticContent,
): TacticContent { ): TacticContent {
const componentIdx = content.components.findIndex(
(c) => c.id == component.id,
)
return { return {
...content, ...content,
components: content.components.toSpliced(componentIdx, 1, component), components: content.components.map((c) =>
c.id === component.id ? component : c,
),
} }
} }

@ -2,6 +2,8 @@ import { Component, ComponentId } from "./Tactic"
export type PlayerId = string export type PlayerId = string
export type PlayerLike = Player | PlayerPhantom
export enum PlayerTeam { export enum PlayerTeam {
Allies = "allies", Allies = "allies",
Opponents = "opponents", Opponents = "opponents",

@ -46,7 +46,7 @@ import {
BallState, BallState,
Player, Player,
PlayerInfo, PlayerInfo,
PlayerPhantom, PlayerLike,
PlayerTeam, PlayerTeam,
} from "../model/tactic/Player" } from "../model/tactic/Player"
import { RackedCourtObject, RackedPlayer } from "../editor/RackedItems" import { RackedCourtObject, RackedPlayer } from "../editor/RackedItems"
@ -216,7 +216,7 @@ function EditorView({
} }
const doRemovePlayer = useCallback( const doRemovePlayer = useCallback(
(component: Player | PlayerPhantom) => { (component: PlayerLike) => {
setContent((c) => removePlayer(component, c)) setContent((c) => removePlayer(component, c))
if (component.type == "player") insertRackedPlayer(component) if (component.type == "player") insertRackedPlayer(component)
}, },
@ -224,7 +224,7 @@ function EditorView({
) )
const doMoveBall = useCallback( const doMoveBall = useCallback(
(newBounds: DOMRect, from?: Player | PlayerPhantom) => { (newBounds: DOMRect, from?: PlayerLike) => {
setContent((content) => { setContent((content) => {
if (from) { if (from) {
content = changePlayerBallState( content = changePlayerBallState(
@ -243,7 +243,7 @@ function EditorView({
) )
const validatePlayerPosition = useCallback( const validatePlayerPosition = useCallback(
(player: Player | PlayerPhantom, info: PlayerInfo, newPos: Pos) => { (player: PlayerLike, info: PlayerInfo, newPos: Pos) => {
setContent((content) => setContent((content) =>
moveComponent( moveComponent(
newPos, newPos,
@ -263,7 +263,7 @@ function EditorView({
) )
const renderAvailablePlayerActions = useCallback( const renderAvailablePlayerActions = useCallback(
(info: PlayerInfo, player: Player | PlayerPhantom) => { (info: PlayerInfo, player: PlayerLike) => {
let canPlaceArrows: boolean let canPlaceArrows: boolean
if (player.type == "player") { if (player.type == "player") {
@ -317,7 +317,7 @@ function EditorView({
) )
const renderPlayer = useCallback( const renderPlayer = useCallback(
(component: Player | PlayerPhantom) => { (component: PlayerLike) => {
let info: PlayerInfo let info: PlayerInfo
const isPhantom = component.type == "phantom" const isPhantom = component.type == "phantom"
if (isPhantom) { if (isPhantom) {
@ -579,7 +579,7 @@ function PlayerRack({
interface CourtPlayerArrowActionProps { interface CourtPlayerArrowActionProps {
playerInfo: PlayerInfo playerInfo: PlayerInfo
player: Player | PlayerPhantom player: PlayerLike
isInvalid: boolean isInvalid: boolean
content: TacticContent content: TacticContent
@ -676,7 +676,7 @@ function CourtPlayerArrowAction({
{ {
...(newContent.components.find( ...(newContent.components.find(
(c) => c.id == player.id, (c) => c.id == player.id,
)! as Player | PlayerPhantom), )! as PlayerLike),
ballState, ballState,
}, },
newContent, newContent,

Loading…
Cancel
Save