feat(champions): use champions sent from server (#54)

This commit is contained in:
lucas authored and GitHub committed 2026-07-07 21:08:03 +02:00
1 parent 710d3ec041
commit bf6abfb2fa
6 files changed
+47 -25

No files matched your search

+7 -1
View File
@@ -1,9 +1,15 @@
import random
from autobeerpong.types.raw import MessageRaw_T from autobeerpong.types.raw import MessageRaw_T
champions = ["berset", "lucas"]
def randomChampion() -> str:
return random.choice(champions)
class Team: class Team:
def __init__(self) -> None: def __init__(self) -> None:
self.formation = [1, 2, 3] self.formation = [randomChampion(), randomChampion(), randomChampion()]
self.cups = [True, True, True] self.cups = [True, True, True]
def rotate(self) -> None: def rotate(self) -> None:
+4 -3
View File
@@ -4,15 +4,16 @@ import { randomInteger } from "../utils/randomUtils";
import { getImage } from "../imageLoader"; import { getImage } from "../imageLoader";
import { Clock } from "../Timers/Clock"; import { Clock } from "../Timers/Clock";
import { BaseActor } from "./BaseActor"; import { BaseActor } from "./BaseActor";
import { ChampionName, champions } from "./champions"; import { champions } from "./champions";
import { ChampionId } from "../jsonTypes";
type Facing = "left" | "right"; type Facing = "left" | "right";
export class Champion extends BaseActor { export class Champion extends BaseActor {
facing: Facing; facing: Facing;
championName: ChampionName; championName: ChampionId;
constructor(actorArgs: ActorArgs, facing: Facing, name: ChampionName) { constructor(actorArgs: ActorArgs, facing: Facing, name: ChampionId) {
super(actorArgs); super(actorArgs);
this.facing = facing; this.facing = facing;
this.championName = name; this.championName = name;
+3 -3
View File
@@ -1,7 +1,7 @@
export type ChampionName = "lucas" | "berset"; import { ChampionId } from "../jsonTypes";
export interface ChampionConfig { export interface ChampionConfig {
name: ChampionName; name: ChampionId;
height: number; height: number;
} }
@@ -15,7 +15,7 @@ const berset: ChampionConfig = {
height: 1.5, height: 1.5,
}; };
export const champions: Record<ChampionName, ChampionConfig> = { export const champions: Record<ChampionId, ChampionConfig> = {
lucas, lucas,
berset, berset,
}; };
+25 -15
View File
@@ -12,7 +12,7 @@ import {
import { Action, Table } from "../jsonTypes"; import { Action, Table } from "../jsonTypes";
import { assertNotNull, assertNull } from "../utils/assertUtils"; import { assertNotNull, assertNull } from "../utils/assertUtils";
import { colorDistance } from "../utils/colorUtils"; import { colorDistance } from "../utils/colorUtils";
import { randomColor, randomInteger } from "../utils/randomUtils"; import { randomColor } from "../utils/randomUtils";
import { BaseScene } from "./BaseScene"; import { BaseScene } from "./BaseScene";
import { Parabola } from "../GameElements/Parabola"; import { Parabola } from "../GameElements/Parabola";
import { Engine, vec, Color } from "excalibur"; import { Engine, vec, Color } from "excalibur";
@@ -83,20 +83,6 @@ export class MatchScene extends BaseScene {
this._cups.push(cup); 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); this._ball = new Ball({}, defaultBallConfiguration);
} }
@@ -150,6 +136,30 @@ export class MatchScene extends BaseScene {
assertNotNull(cup); assertNotNull(cup);
this.updateActorVisibility(cup, visible); 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 { private _updateFromActionState(action: Action): void {
+3 -2
View File
@@ -1,4 +1,5 @@
export type Id = number; export type Id = number;
export type ChampionId = "lucas" | "berset";
export type MessageRaw = LobbyStateRaw | MatchStateRaw; export type MessageRaw = LobbyStateRaw | MatchStateRaw;
@@ -32,8 +33,8 @@ export interface MatchStateRaw {
export interface Table { export interface Table {
cupsA: [boolean, boolean, boolean]; cupsA: [boolean, boolean, boolean];
cupsB: [boolean, boolean, boolean]; cupsB: [boolean, boolean, boolean];
teamA: [Id, Id, Id]; teamA: [ChampionId, ChampionId, ChampionId];
teamB: [Id, Id, Id]; teamB: [ChampionId, ChampionId, ChampionId];
} }
export interface Action { export interface Action {
+5 -1
View File
@@ -35,7 +35,11 @@
"team": { "team": {
"type": "array", "type": "array",
"items": { "items": {
"type": "number" "type": "string",
"enum": [
"berset",
"lucas"
]
}, },
"minItems": 3, "minItems": 3,
"maxItems": 3 "maxItems": 3