using Godot; using MaxEffort.Code.Core; using MaxEffort.Code.Data; namespace MaxEffort.Code.Systems; [GlobalClass] public partial class GameManager : Node { [Export] private Godot.Collections.Array _days; [Export] private HazardSystem _hazardSystem; [Export] private Node _minigameContainer; [Export] private Control _winScreen; [Export] private Control _loseScreen; [Export] private Label _dayLabel; private int _currentDayIndex = 0; private Node _currentMiniGame; public override void _Ready() { EventBus.OnLiftCompleted += HandleLiftResult; StartDay(_currentDayIndex); } public override void _ExitTree() { EventBus.OnLiftCompleted -= HandleLiftResult; } private void StartDay(int index) { if (index >= _days.Count) { GD.Print("YOU BEAT THE GYM! ALL DAYS COMPLETE."); // TODO: Show "Game Complete" screen return; } var config = _days[index]; _currentMiniGame?.QueueFree(); _hazardSystem.ClearHazards(); if (config.MiniGameScene != null) { _currentMiniGame = config.MiniGameScene.Instantiate(); _minigameContainer.AddChild(_currentMiniGame); var liftSystem = _currentMiniGame.GetNode("System"); liftSystem?.Initialize(config.TargetWeight, config.Gravity); } _hazardSystem.SetAvailableHazards(config.AvailableHazards); if (_dayLabel != null) _dayLabel.Text = config.DayTitle; if (_winScreen != null) _winScreen.Visible = false; if (_loseScreen != null) _loseScreen.Visible = false; GD.Print($"Started {config.DayTitle}"); } private void HandleLiftResult(bool success) { if (success) { GD.Print("Day Complete! Next day loading..."); if (_winScreen != null) _winScreen.Visible = true; // Wait for player input to proceed, or auto-load after delay // For now, let's auto-advance after 3 seconds for the prototype GetTree().CreateTimer(3.0f).Timeout += () => NextDay(); } else { GD.Print("FAIL! Go home."); if (_loseScreen != null) _loseScreen.Visible = true; // Restart day after delay GetTree().CreateTimer(3.0f).Timeout += () => RestartDay(); } } private void NextDay() { _currentDayIndex++; StartDay(_currentDayIndex); } private void RestartDay() { GetTree().ReloadCurrentScene(); } }