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 totalPlayers = 0;
|
||||||
let activeGames = 0;
|
let activeGames = 0;
|
||||||
const gameRooms = [];
|
const gameRooms = [];
|
||||||
const allPlayers = [];
|
const allPlayers: any[] = [];
|
||||||
|
|
||||||
for (const room of rooms) {
|
for (const room of rooms) {
|
||||||
if (room.name === 'game') {
|
if (room.name === 'game') {
|
||||||
@@ -88,7 +88,7 @@ export default config({
|
|||||||
// Extract player information with their tokens
|
// Extract player information with their tokens
|
||||||
if (roomData.state && roomData.state.players) {
|
if (roomData.state && roomData.state.players) {
|
||||||
// Use forEach to iterate over MapSchema properly
|
// 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
|
// Skip internal MapSchema properties
|
||||||
if (playerId.startsWith('$') || playerId === 'deletedItems') {
|
if (playerId.startsWith('$') || playerId === 'deletedItems') {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,17 +13,17 @@ export class TokenInventory extends Schema {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class TradeOffer extends Schema {
|
export class TradeOffer extends Schema {
|
||||||
@type("string") id: string;
|
@type("string") id: string = "";
|
||||||
@type("string") offererId: string;
|
@type("string") offererId: string = "";
|
||||||
@type("string") targetId: string;
|
@type("string") targetId: string = "";
|
||||||
@type(TokenInventory) offering = new TokenInventory();
|
@type(TokenInventory) offering = new TokenInventory();
|
||||||
@type(TokenInventory) requesting = new TokenInventory();
|
@type(TokenInventory) requesting = new TokenInventory();
|
||||||
@type("string") status: string = "pending"; // "pending" | "accepted" | "rejected" | "snatched" | "cancelled"
|
@type("string") status: string = "pending"; // "pending" | "accepted" | "rejected" | "snatched" | "cancelled"
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Player extends Schema {
|
export class Player extends Schema {
|
||||||
@type("string") id: string;
|
@type("string") id: string = "";
|
||||||
@type("string") name: string;
|
@type("string") name: string = "";
|
||||||
@type("string") producerRole: string = "turkey"; // "turkey" | "coffee" | "corn"
|
@type("string") producerRole: string = "turkey"; // "turkey" | "coffee" | "corn"
|
||||||
@type(TokenInventory) tokens = new TokenInventory();
|
@type(TokenInventory) tokens = new TokenInventory();
|
||||||
@type("number") points: number = 0;
|
@type("number") points: number = 0;
|
||||||
@@ -101,7 +101,7 @@ export class GameRoom extends Room<GameState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private calculatePoints(player: Player): number {
|
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;
|
const otherTokens = (player.tokens.turkey + player.tokens.coffee + player.tokens.corn) - ownTokens;
|
||||||
return ownTokens * 1 + otherTokens * 2;
|
return ownTokens * 1 + otherTokens * 2;
|
||||||
}
|
}
|
||||||
@@ -284,7 +284,7 @@ export class GameRoom extends Room<GameState> {
|
|||||||
return {
|
return {
|
||||||
roomId: this.roomId,
|
roomId: this.roomId,
|
||||||
name: 'game',
|
name: 'game',
|
||||||
clients: clients.length,
|
clientCount: clients.length,
|
||||||
maxClients: this.maxClients,
|
maxClients: this.maxClients,
|
||||||
locked: this.locked,
|
locked: this.locked,
|
||||||
state: this.state,
|
state: this.state,
|
||||||
|
|||||||
Reference in New Issue
Block a user