fix: Resolve TypeScript compilation errors
- Add explicit types for allPlayers array and forEach parameters - Initialize Schema properties with default values - Fix arithmetic operation types with null coalescing - Resolve duplicate 'clients' property in object literal
This commit is contained in:
@@ -65,7 +65,7 @@ export default config({
|
||||
let totalPlayers = 0;
|
||||
let activeGames = 0;
|
||||
const gameRooms = [];
|
||||
const allPlayers = [];
|
||||
const allPlayers: any[] = [];
|
||||
|
||||
for (const room of rooms) {
|
||||
if (room.name === 'game') {
|
||||
@@ -88,7 +88,7 @@ export default config({
|
||||
// Extract player information with their tokens
|
||||
if (roomData.state && roomData.state.players) {
|
||||
// Use forEach to iterate over MapSchema properly
|
||||
roomData.state.players.forEach((player, playerId) => {
|
||||
roomData.state.players.forEach((player: any, playerId: string) => {
|
||||
// Skip internal MapSchema properties
|
||||
if (playerId.startsWith('$') || playerId === 'deletedItems') {
|
||||
return;
|
||||
|
||||
@@ -13,17 +13,17 @@ export class TokenInventory extends Schema {
|
||||
}
|
||||
|
||||
export class TradeOffer extends Schema {
|
||||
@type("string") id: string;
|
||||
@type("string") offererId: string;
|
||||
@type("string") targetId: string;
|
||||
@type("string") id: string = "";
|
||||
@type("string") offererId: string = "";
|
||||
@type("string") targetId: string = "";
|
||||
@type(TokenInventory) offering = new TokenInventory();
|
||||
@type(TokenInventory) requesting = new TokenInventory();
|
||||
@type("string") status: string = "pending"; // "pending" | "accepted" | "rejected" | "snatched" | "cancelled"
|
||||
}
|
||||
|
||||
export class Player extends Schema {
|
||||
@type("string") id: string;
|
||||
@type("string") name: string;
|
||||
@type("string") id: string = "";
|
||||
@type("string") name: string = "";
|
||||
@type("string") producerRole: string = "turkey"; // "turkey" | "coffee" | "corn"
|
||||
@type(TokenInventory) tokens = new TokenInventory();
|
||||
@type("number") points: number = 0;
|
||||
@@ -101,7 +101,7 @@ export class GameRoom extends Room<GameState> {
|
||||
}
|
||||
|
||||
private calculatePoints(player: Player): number {
|
||||
const ownTokens = player.tokens[player.producerRole as keyof TokenInventory];
|
||||
const ownTokens = player.tokens[player.producerRole as keyof TokenInventory] || 0;
|
||||
const otherTokens = (player.tokens.turkey + player.tokens.coffee + player.tokens.corn) - ownTokens;
|
||||
return ownTokens * 1 + otherTokens * 2;
|
||||
}
|
||||
@@ -284,7 +284,7 @@ export class GameRoom extends Room<GameState> {
|
||||
return {
|
||||
roomId: this.roomId,
|
||||
name: 'game',
|
||||
clients: clients.length,
|
||||
clientCount: clients.length,
|
||||
maxClients: this.maxClients,
|
||||
locked: this.locked,
|
||||
state: this.state,
|
||||
|
||||
Reference in New Issue
Block a user