Financial updates and performance updates.

This commit is contained in:
2025-10-04 23:26:27 +02:00
parent 416cc4511b
commit 6a2f94337e
7 changed files with 278 additions and 298 deletions
+15 -17
View File
@@ -15,41 +15,33 @@ export class App {
players: {},
buildings: {}
};
this.selectedBuildingType = null;
this.isPlacingBuilding = false;
}
init() {
console.log('Initializing City Builder...');
// Initialize UI Manager
this.uiManager = new UIManager(this);
this.uiManager.init();
// Show login screen
this.uiManager.showLoginScreen();
}
async startGame(nickname) {
console.log(`Starting game for ${nickname}...`);
// Hide login, show game UI
this.uiManager.hideLoginScreen();
this.uiManager.showGameUI();
// Initialize renderer
this.renderer = new GameRenderer();
this.renderer.init();
// Initialize input handler
this.inputHandler = new InputHandler(this);
this.inputHandler.init();
// Connect to WebSocket
this.wsClient = new WebSocketClient(this);
await this.wsClient.connect(nickname);
// Start render loop
this.renderer.startRenderLoop();
}
@@ -62,21 +54,22 @@ export class App {
// Update UI
this.uiManager.updateStats(this.player);
this.uiManager.updateBuildingToolbox(this.player);
// Render initial state
this.renderer.updateGameState(gameState);
}
onGameStateUpdate(state) {
this.gameState = state;
this.renderer.updateGameState(state);
// Update own player stats
if (this.player && state.players[this.player.player_id]) {
this.player = state.players[this.player.player_id];
onPlayerStatsUpdate(playerData) {
// Update our own player object and UI if the update is for us
if (this.player && this.player.player_id === playerData.player_id) {
this.player = playerData;
this.uiManager.updateStats(this.player);
this.uiManager.updateBuildingToolbox(this.player);
}
// Update the player in the global game state as well
if (this.gameState.players[playerData.player_id]) {
this.gameState.players[playerData.player_id] = playerData;
}
}
onCursorMove(playerId, x, y) {
@@ -86,16 +79,22 @@ export class App {
onBuildingPlaced(building) {
console.log('Building placed:', building);
this.renderer.addBuilding(building);
// Also add to local game state for context menu checks etc.
this.gameState.buildings[`${building.x},${building.y}`] = building;
}
onBuildingRemoved(x, y) {
console.log('Building removed at:', x, y);
this.renderer.removeBuilding(x, y);
delete this.gameState.buildings[`${x},${y}`];
}
onBuildingUpdated(x, y, name) {
console.log('Building updated:', x, y, name);
this.renderer.updateBuildingName(x, y, name);
if (this.gameState.buildings[`${x},${y}`]) {
this.gameState.buildings[`${x},${y}`].name = name;
}
}
onPlayerJoined(playerId, nickname) {
@@ -127,7 +126,6 @@ export class App {
placeBuilding(x, y) {
if (!this.selectedBuildingType) return;
console.log('Placing building:', this.selectedBuildingType, 'at', x, y);
this.wsClient.placeBuilding(this.selectedBuildingType, x, y);
}
+2 -6
View File
@@ -12,7 +12,6 @@ export class WebSocketClient {
try {
this.ws = new WebSocket(wsUrl);
this.ws.onopen = () => {
console.log('WebSocket connected');
this.reconnectAttempts = 0;
@@ -50,10 +49,9 @@ export class WebSocketClient {
this.app.onPlayerInit(data.player, data.game_state);
break;
case 'game_state_update':
this.app.onGameStateUpdate(data.state);
case 'player_stats_update':
this.app.onPlayerStatsUpdate(data.player);
break;
case 'cursor_move':
this.app.onCursorMove(data.player_id, data.x, data.y);
break;
@@ -61,11 +59,9 @@ export class WebSocketClient {
case 'building_placed':
this.app.onBuildingPlaced(data.building);
break;
case 'building_removed':
this.app.onBuildingRemoved(data.x, data.y);
break;
case 'building_updated':
this.app.onBuildingUpdated(data.x, data.y, data.name);
break;