diff --git a/src/backend/autobeerpong/match.py b/src/backend/autobeerpong/match.py index 3543911..39c35e4 100644 --- a/src/backend/autobeerpong/match.py +++ b/src/backend/autobeerpong/match.py @@ -1,9 +1,15 @@ +import random + from autobeerpong.types.raw import MessageRaw_T +champions = ["berset", "lucas"] + +def randomChampion() -> str: + return random.choice(champions) class Team: def __init__(self) -> None: - self.formation = [1, 2, 3] + self.formation = [randomChampion(), randomChampion(), randomChampion()] self.cups = [True, True, True] def rotate(self) -> None: diff --git a/src/frontend/src/GameElements/Champion.ts b/src/frontend/src/GameElements/Champion.ts index 8aababb..e58464b 100644 --- a/src/frontend/src/GameElements/Champion.ts +++ b/src/frontend/src/GameElements/Champion.ts @@ -4,15 +4,16 @@ import { randomInteger } from "../utils/randomUtils"; import { getImage } from "../imageLoader"; import { Clock } from "../Timers/Clock"; import { BaseActor } from "./BaseActor"; -import { ChampionName, champions } from "./champions"; +import { champions } from "./champions"; +import { ChampionId } from "../jsonTypes"; type Facing = "left" | "right"; export class Champion extends BaseActor { facing: Facing; - championName: ChampionName; + championName: ChampionId; - constructor(actorArgs: ActorArgs, facing: Facing, name: ChampionName) { + constructor(actorArgs: ActorArgs, facing: Facing, name: ChampionId) { super(actorArgs); this.facing = facing; this.championName = name; diff --git a/src/frontend/src/GameElements/champions.ts b/src/frontend/src/GameElements/champions.ts index 2148383..d256f9f 100644 --- a/src/frontend/src/GameElements/champions.ts +++ b/src/frontend/src/GameElements/champions.ts @@ -1,7 +1,7 @@ -export type ChampionName = "lucas" | "berset"; +import { ChampionId } from "../jsonTypes"; export interface ChampionConfig { - name: ChampionName; + name: ChampionId; height: number; } @@ -15,7 +15,7 @@ const berset: ChampionConfig = { height: 1.5, }; -export const champions: Record = { +export const champions: Record = { lucas, berset, }; diff --git a/src/frontend/src/Scenes/MatchScene.ts b/src/frontend/src/Scenes/MatchScene.ts index 51c4576..4221d5f 100644 --- a/src/frontend/src/Scenes/MatchScene.ts +++ b/src/frontend/src/Scenes/MatchScene.ts @@ -12,7 +12,7 @@ import { import { Action, Table } from "../jsonTypes"; import { assertNotNull, assertNull } from "../utils/assertUtils"; import { colorDistance } from "../utils/colorUtils"; -import { randomColor, randomInteger } from "../utils/randomUtils"; +import { randomColor } from "../utils/randomUtils"; import { BaseScene } from "./BaseScene"; import { Parabola } from "../GameElements/Parabola"; import { Engine, vec, Color } from "excalibur"; @@ -83,20 +83,6 @@ export class MatchScene extends BaseScene { this._cups.push(cup); }); - championPositions.forEach((offsetX, index) => { - const facing = index < 3 ? "right" : "left"; - const champion = new Champion( - { - color: randomNonGroundColor(), - pos: vec(offsetX, groundHeight), - }, - facing, - randomInteger(0, 2) === 0 ? "berset" : "lucas", - ); - this.add(champion); - this._champions.push(champion); - }); - this._ball = new Ball({}, defaultBallConfiguration); } @@ -150,6 +136,30 @@ export class MatchScene extends BaseScene { assertNotNull(cup); this.updateActorVisibility(cup, visible); }); + + this._updateChampions(table); + } + + private _updateChampions(table: Table): void { + this._champions.forEach((champion) => this.remove(champion)); + this._champions = []; + + championPositions.forEach((offsetX, index) => { + const facing = index < 3 ? "right" : "left"; + const championName = + index < 3 ? table.teamA[index] : table.teamB[index - 3]; + + const champion = new Champion( + { + color: randomNonGroundColor(), + pos: vec(offsetX, groundHeight), + }, + facing, + championName, + ); + this.add(champion); + this._champions.push(champion); + }); } private _updateFromActionState(action: Action): void { diff --git a/src/frontend/src/jsonTypes.ts b/src/frontend/src/jsonTypes.ts index 426e120..e17ff0c 100644 --- a/src/frontend/src/jsonTypes.ts +++ b/src/frontend/src/jsonTypes.ts @@ -1,4 +1,5 @@ export type Id = number; +export type ChampionId = "lucas" | "berset"; export type MessageRaw = LobbyStateRaw | MatchStateRaw; @@ -32,8 +33,8 @@ export interface MatchStateRaw { export interface Table { cupsA: [boolean, boolean, boolean]; cupsB: [boolean, boolean, boolean]; - teamA: [Id, Id, Id]; - teamB: [Id, Id, Id]; + teamA: [ChampionId, ChampionId, ChampionId]; + teamB: [ChampionId, ChampionId, ChampionId]; } export interface Action { diff --git a/src/schema/match/table.json b/src/schema/match/table.json index aae6c80..b39839e 100644 --- a/src/schema/match/table.json +++ b/src/schema/match/table.json @@ -35,7 +35,11 @@ "team": { "type": "array", "items": { - "type": "number" + "type": "string", + "enum": [ + "berset", + "lucas" + ] }, "minItems": 3, "maxItems": 3