class TownSquareScene extends Phaser.Scene { constructor() { super({ key: 'TownSquareScene' }); this.buildingsSprites = new Map(); } create() { console.log('šŸ˜ļø TownSquareScene: Initialized!'); this.cameras.main.setBackgroundColor('#8B4513'); // Access the global TownRestorationSystem this.townRestorationSystem = window.townRestorationSystem || new TownRestorationSystem(this); this.add.text(512, 50, 'TOWN SQUARE', { fontSize: '48px', color: '#FFD700', fontFamily: 'Courier New', fontStyle: 'bold' }).setOrigin(0.5); this.add.text(512, 100, 'Press M to go back to Farm', { fontSize: '18px', color: '#ffffff', fontFamily: 'Courier New' }).setOrigin(0.5); // Transition back this.input.keyboard.on('keydown-M', () => { this.scene.start('GameScene'); }); // Create Ruins this.createBuilding(400, 300, 'jakob_shop', 'Jakob\'s Shop'); this.createBuilding(650, 300, 'lena_bakery', 'Lena\'s Bakery'); this.createBuilding(512, 500, 'dr_chen_clinic', 'Dr. Chen\'s Clinic'); } createBuilding(x, y, id, name) { if (!this.townRestorationSystem) return; const buildingData = this.townRestorationSystem.buildings.get(id); const isRestored = buildingData ? buildingData.isRestored : false; const color = isRestored ? 0x44aa44 : 0x666666; const base = this.add.rectangle(x, y, 150, 150, color, 0.8); base.setStrokeStyle(3, 0xffffff); const label = this.add.text(x, y, `${name}\n${isRestored ? 'āœ… RESTORED' : 'šŸšļø RUIN'}`, { fontSize: '16px', color: '#ffffff', align: 'center', fontFamily: 'Courier New', fontStyle: 'bold' }).setOrigin(0.5); base.setInteractive(); base.on('pointerdown', () => { const currentData = this.townRestorationSystem.buildings.get(id); if (!currentData || !currentData.isRestored) { this.interactWithRuin(id); } else { const ui = this.scene.scene.get('UIScene'); if (ui && ui.showNotification) { ui.showNotification({ text: `${name} is functional!`, icon: 'šŸŖ' }); } } }); this.buildingsSprites.set(id, { base, label, name }); } interactWithRuin(id) { const building = this.townRestorationSystem.buildings.get(id); if (!building) return; if (this.townRestorationSystem.hasMaterials(building.materials)) { this.townRestorationSystem.startRestoration(id); } else { const ui = this.scene.scene.get('UIScene'); if (ui && ui.showNotification) { ui.showNotification({ title: 'Resources Needed', text: `Wood: ${building.materials.wood}, Stone: ${building.materials.stone}`, icon: 'šŸ“¦' }); } } } updateBuildingVisuals(id) { const sprite = this.buildingsSprites.get(id); if (sprite) { sprite.base.setFillStyle(0x44aa44); sprite.label.setText(`${sprite.name}\nāœ… RESTORED`); // Celebration effect this.cameras.main.shake(500, 0.01); console.log(`✨ Visuals updated for ${id}`); } } }