class TimeSystem { constructor(scene) { this.scene = scene; // Konfiguracija this.fullDaySeconds = 300; // 5 minut za cel dan (real-time) this.startTime = 8; // Začetek ob 8:00 // Stanje this.gameTime = this.startTime; // 0 - 24 this.dayCount = 1; // Lighting overlay this.lightOverlay = null; // Ustvarjen bo v GameScene ali tu? Bolje tu če imamo dostop. } create() { // Overlay za temo // Uporabimo velik pravokotnik čez cel ekran, ki je fixiran na kamero // Ampak ker imamo UIScene, je bolje da je overlay v GameScene, ampak nad vsem razen UI. // Najlažje: canvas tinting ali graphics overlay. // Za preprostost: Modificiramo ambient light ali tintamo igralca/teren? // Phaser 3 ima setTint. // Najboljši efekt za 2D: Temno moder rectangle z 'MULTIPLY' blend mode čez GameScene. const width = this.scene.cameras.main.width * 2; // Malo večji za varnost const height = this.scene.cameras.main.height * 2; this.lightOverlay = this.scene.add.rectangle(0, 0, width, height, 0x000022); this.lightOverlay.setScrollFactor(0); this.lightOverlay.setDepth(9000); // Pod UI (UI je v drugi sceni), ampak nad igro this.lightOverlay.setBlendMode(Phaser.BlendModes.MULTIPLY); this.lightOverlay.setAlpha(0); // Začetek dan (0 alpha) } update(delta) { // Povečaj čas // delta je v ms. // fullDaySeconds = 24 game hours. // 1 game hour = fullDaySeconds / 24 seconds. const seconds = delta / 1000; const gameHoursPerRealSecond = 24 / this.fullDaySeconds; this.gameTime += seconds * gameHoursPerRealSecond; if (this.gameTime >= 24) { this.gameTime -= 24; this.dayCount++; console.log(`🌞 Day ${this.dayCount} started!`); } this.updateLighting(); this.updateUI(); } updateLighting() { if (!this.lightOverlay) return; // Izračunaj svetlobo (Alpha vrednost senc) // 0 = Dan (Prozoren overlay) // 0.8 = Polnoč (Temen overlay) let alpha = 0; const t = this.gameTime; // Preprosta logika: // 6:00 - 18:00 = Dan (0 alpha) // 18:00 - 20:00 = Mrak (prehod 0 -> 0.7) // 20:00 - 4:00 = Noč (0.7 alpha) // 4:00 - 6:00 = Jutro (prehod 0.7 -> 0) if (t >= 6 && t < 18) { alpha = 0; // Dan } else if (t >= 18 && t < 20) { alpha = ((t - 18) / 2) * 0.7; // Mrak } else if (t >= 20 || t < 4) { alpha = 0.7; // Noč } else if (t >= 4 && t < 6) { alpha = 0.7 - ((t - 4) / 2) * 0.7; // Jutro } this.lightOverlay.setAlpha(alpha); } updateUI() { const uiScene = this.scene.scene.get('UIScene'); if (uiScene && uiScene.clockText) { const hours = Math.floor(this.gameTime); const minutes = Math.floor((this.gameTime - hours) * 60); const timeString = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; uiScene.clockText.setText(`Day ${this.dayCount} - ${timeString}`); } } getCurrentHour() { return Math.floor(this.gameTime); } getGameTime() { return this.gameTime; } getDayCount() { return this.dayCount; } }