53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { type GameObjectRegister } from "."
|
|
import type { Card } from "./Card"
|
|
import type { GameObjectNetcode } from "./GameObject"
|
|
import { type Team } from "./Team"
|
|
import { type Turn } from "./Turn"
|
|
export interface PlayerNetcode extends GameObjectNetcode {
|
|
stack_pile: Array<string>
|
|
discard_pile: Array<string>
|
|
hand: Array<string>
|
|
board: Array<string>
|
|
team: string
|
|
username: string
|
|
turn: string
|
|
}
|
|
|
|
|
|
export type Player = Omit<PlayerNetcode, 'discard_pile' | 'stack_pile' | 'hand' | 'board' | 'team' | 'turn'> & {
|
|
stack_pile: Array<Card | null>
|
|
discard_pile: Array<Card>
|
|
hand: Array<Card | null>
|
|
board: Array<Card>
|
|
team: Team
|
|
turn: Turn
|
|
}
|
|
export function create_player(input: PlayerNetcode, register: GameObjectRegister) {
|
|
return new Proxy<any>(input, {
|
|
get(target: PlayerNetcode, prop, reciever) {
|
|
if (prop == "stack_pile") {
|
|
return target.stack_pile.map(e => register.cards.get(e))
|
|
}
|
|
if (prop == "discard_pile") {
|
|
return target.discard_pile.map(e => register.cards.get(e))
|
|
}
|
|
if (prop == "hand") {
|
|
return target.hand.map(e => register.cards.get(e))
|
|
}
|
|
if (prop == "board") {
|
|
return target.board.map(e => register.cards.get(e))
|
|
}
|
|
if (prop == "team") {
|
|
return register.teams.get(target.team)
|
|
}
|
|
if (prop == "turn") {
|
|
return register.turns.get(target.turn)
|
|
}
|
|
return Reflect.get(target, prop, reciever);
|
|
},
|
|
set(target, prop, val, receiver) {
|
|
return Reflect.set(target, prop, val, receiver);
|
|
}
|
|
}) as Player
|
|
}
|