diff --git a/Autoloads/AchievementManager.cs b/Autoloads/AchievementManager.cs index 5b275e9..38105e8 100644 --- a/Autoloads/AchievementManager.cs +++ b/Autoloads/AchievementManager.cs @@ -1,5 +1,6 @@ using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.Autoloads; @@ -8,14 +9,14 @@ public partial class AchievementManager : Node { [Export] private string AchievementsFolderPath = "res://achievements/"; [Export] private PackedScene AchievementPopupScene { get; set; } - + private System.Collections.Generic.Dictionary _achievements = new(); private Array _unlockedAchievementIds = []; private GameManager _gameManager; - + public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); LoadAchievementsFromFolder(); LoadUnlockedAchievements(); } @@ -44,7 +45,7 @@ public partial class AchievementManager : Node fileName = dir.GetNext(); } } - + public void UnlockAchievement(string achievementId) { if (!_achievements.TryGetValue(achievementId, out var achievement)) @@ -75,11 +76,11 @@ public partial class AchievementManager : Node { SteamManager.UnlockAchievement(achievement.Id); } - + // 4. Save progress SaveUnlockedAchievements(); } - + public void LockAchievement(string achievementId) { if (_unlockedAchievementIds.Contains(achievementId)) @@ -88,7 +89,7 @@ public partial class AchievementManager : Node SaveUnlockedAchievements(); } } - + private void SaveUnlockedAchievements() { _gameManager.PlayerState["unlocked_achievements"] = _unlockedAchievementIds; diff --git a/Autoloads/ConsoleManager.cs b/Autoloads/ConsoleManager.cs index bd7ef9c..a55b84e 100644 --- a/Autoloads/ConsoleManager.cs +++ b/Autoloads/ConsoleManager.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.components; namespace Mr.BrickAdventures.Autoloads; @@ -12,9 +13,9 @@ public partial class ConsoleManager : Node public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); - _achievementManager = GetNode("/root/AchievementManager"); - _skillManager = GetNode("/root/SkillManager"); + _gameManager = GetNode(Constants.GameManagerPath); + _achievementManager = GetNode(Constants.AchievementManagerPath); + _skillManager = GetNode(Constants.SkillManagerPath); } private void AddCoinsCommand(int amount) @@ -88,7 +89,7 @@ public partial class ConsoleManager : Node _skillUnlockerComponent.UnlockAllSkills(); } - + private void RemoveSkillCommand(string skillName) { if (!GetSkillManagement()) return; @@ -102,28 +103,28 @@ public partial class ConsoleManager : Node _gameManager.RemoveSkill(skill.Name); _skillManager.DeactivateSkill(skill); } - + private void RemoveAllSkillsCommand() { if (!GetSkillManagement()) return; - + foreach (var skill in _skillManager.AvailableSkills) { _gameManager.RemoveSkill(skill.Name); _skillManager.DeactivateSkill(skill); } } - + private void GoToNextLevelCommand() { _gameManager.OnLevelComplete(); } - + private void UnlockAchievementCommand(string achievementId) { _achievementManager.UnlockAchievement(achievementId); } - + private void ResetAchievementCommand(string achievementId) { _achievementManager.LockAchievement(achievementId); diff --git a/Autoloads/GameManager.cs b/Autoloads/GameManager.cs index 6997c1a..b7bfc9f 100644 --- a/Autoloads/GameManager.cs +++ b/Autoloads/GameManager.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; using Double = System.Double; @@ -55,7 +56,7 @@ public partial class GameManager : Node public override void _Ready() { - _speedRunManager = GetNode("/root/SpeedRunManager"); + _speedRunManager = GetNode(Constants.SpeedRunManagerPath); } @@ -186,7 +187,7 @@ public partial class GameManager : Node ResetPlayerState(); ResetCurrentSessionState(); GetTree().ChangeSceneToPacked(LevelScenes[0]); - GetNode("/root/SaveSystem").SaveGame(); + GetNode(Constants.SaveSystemPath).SaveGame(); } public void QuitGame() => GetTree().Quit(); @@ -202,12 +203,12 @@ public partial class GameManager : Node _speedRunManager?.StartTimer(); GetTree().ChangeSceneToPacked(LevelScenes[0]); - GetNode("/root/SaveSystem").SaveGame(); + GetNode(Constants.SaveSystemPath).SaveGame(); } public void ContinueGame() { - var save = GetNode("/root/SaveSystem"); + var save = GetNode(Constants.SaveSystemPath); if (!save.LoadGame()) { GD.PrintErr("Failed to load game. Starting a new game instead."); @@ -236,7 +237,7 @@ public partial class GameManager : Node ResetCurrentSessionState(); TryToGoToNextLevel(); - GetNode("/root/SaveSystem").SaveGame(); + GetNode(Constants.SaveSystemPath).SaveGame(); } public Array GetUnlockedSkills() diff --git a/Autoloads/SaveSystem.cs b/Autoloads/SaveSystem.cs index d5ce18a..0eeda5f 100644 --- a/Autoloads/SaveSystem.cs +++ b/Autoloads/SaveSystem.cs @@ -1,5 +1,6 @@ using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.Resources; namespace Mr.BrickAdventures.Autoloads; @@ -13,7 +14,7 @@ public partial class SaveSystem : Node public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); } public void SaveGame() @@ -46,16 +47,16 @@ public partial class SaveSystem : Node GD.Print("Game state loaded from: ", SavePath); GD.Print("Player state: ", saveDataObj["player_state"]); _gameManager.PlayerState = (Dictionary)saveDataObj["player_state"]; - + var skills = new Array(); foreach (var skill in (Array)_gameManager.PlayerState["unlocked_skills"]) { skills.Add(skill); } - + _gameManager.UnlockSkills(skills); return true; } - + public bool CheckSaveExists() => FileAccess.FileExists(SavePath); } \ No newline at end of file diff --git a/Autoloads/SkillManager.cs b/Autoloads/SkillManager.cs index d499789..ae525f4 100644 --- a/Autoloads/SkillManager.cs +++ b/Autoloads/SkillManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.interfaces; using Mr.BrickAdventures.scripts.Resources; @@ -14,19 +15,19 @@ public partial class SkillManager : Node private PlayerController _player; [Export] public Array AvailableSkills { get; set; } = []; - + public Dictionary ActiveComponents { get; private set; } = new(); [Signal] public delegate void ActiveThrowSkillChangedEventHandler(BrickThrowComponent throwComponent); [Signal] public delegate void SkillRemovedEventHandler(SkillData skillData); - + public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); } - + /// /// Called by the PlayerController from its _Ready method to register itself with the manager. /// @@ -39,7 +40,7 @@ public partial class SkillManager : Node { UnregisterPlayer(); } - + _player = player; if (_player != null) { @@ -61,7 +62,7 @@ public partial class SkillManager : Node } _player = null; } - + public void AddSkill(SkillData skillData) { // Ensure a valid player is registered before adding a skill. @@ -70,7 +71,7 @@ public partial class SkillManager : Node GD.Print("SkillManager: Player not available to add skill."); return; } - + if (ActiveComponents.ContainsKey(skillData.Name)) return; @@ -98,9 +99,9 @@ public partial class SkillManager : Node if (instance is ISkill skill) { // Initialize the skill with the registered player instance. - skill.Initialize(_player, skillData); + skill.Initialize(_player, skillData); skill.Activate(); - } + } else { GD.PrintErr($"Skill scene for '{skillData.Name}' does not implement ISkill!"); @@ -111,18 +112,18 @@ public partial class SkillManager : Node // Add the skill node as a child of the player. _player.AddChild(instance); ActiveComponents[skillData.Name] = instance; - + if (instance is BrickThrowComponent btc) { - EmitSignalActiveThrowSkillChanged(btc); + EmitSignalActiveThrowSkillChanged(btc); } } - + public void RemoveSkill(string skillName) { if (!ActiveComponents.TryGetValue(skillName, out var component)) return; - + if (component.AsGodotObject() is BrickThrowComponent) { EmitSignalActiveThrowSkillChanged(null); @@ -133,7 +134,7 @@ public partial class SkillManager : Node { skill.Deactivate(); } - + if (IsInstanceValid(inst)) inst.QueueFree(); @@ -150,7 +151,7 @@ public partial class SkillManager : Node var sd = GetSkillByName(skillName); if (sd != null) EmitSignalSkillRemoved(sd); } - + private void RemoveAllActiveSkills() { // Create a copy of keys to avoid modification during iteration diff --git a/Autoloads/StatisticsManager.cs b/Autoloads/StatisticsManager.cs index a9c9ccf..f8406bd 100644 --- a/Autoloads/StatisticsManager.cs +++ b/Autoloads/StatisticsManager.cs @@ -1,5 +1,6 @@ using Godot; using Godot.Collections; +using Mr.BrickAdventures; namespace Mr.BrickAdventures.Autoloads; @@ -11,8 +12,8 @@ public partial class StatisticsManager : Node public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); - _achievementManager = GetNode("/root/AchievementManager"); + _gameManager = GetNode(Constants.GameManagerPath); + _achievementManager = GetNode(Constants.AchievementManagerPath); LoadStatistics(); } @@ -28,7 +29,7 @@ public partial class StatisticsManager : Node _gameManager.PlayerState["statistics"] = _stats; } } - + /// /// Increases a numerical statistic by a given amount. /// diff --git a/scripts/Constants.cs b/scripts/Constants.cs index 6dab51b..a5b064b 100644 --- a/scripts/Constants.cs +++ b/scripts/Constants.cs @@ -17,6 +17,7 @@ public static class Constants public const string FloatingTextManagerPath = "/root/FloatingTextManager"; public const string UIManagerPath = "/root/UIManager"; public const string ConsoleManagerPath = "/root/ConsoleManager"; + public const string ConfigFileHandlerPath = "/root/ConfigFileHandler"; // Group names public const string CoinsGroup = "coins"; diff --git a/scripts/UI/AudioSettings.cs b/scripts/UI/AudioSettings.cs index b9acc6f..96eeebb 100644 --- a/scripts/UI/AudioSettings.cs +++ b/scripts/UI/AudioSettings.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -10,19 +11,19 @@ public partial class AudioSettings : Control [Export] public Slider SfxVolumeSlider { get; set; } [Export] public Control AudioSettingsControl { get; set; } [Export] public float MuteThreshold { get; set; } = -20f; - + private UIManager _uiManager; private ConfigFileHandler _configFileHandler; public override void _Ready() { - _uiManager = GetNode("/root/UIManager"); - _configFileHandler = GetNode("/root/ConfigFileHandler"); + _uiManager = GetNode(Constants.UIManagerPath); + _configFileHandler = GetNode(Constants.ConfigFileHandlerPath); Initialize(); MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged; MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged; SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged; - + LoadSettings(); } @@ -35,7 +36,7 @@ public partial class AudioSettings : Control { if (!@event.IsActionReleased("ui_cancel")) return; if (!_uiManager.IsScreenOnTop(AudioSettingsControl)) return; - + SaveSettings(); _uiManager.PopScreen(); } @@ -64,12 +65,12 @@ public partial class AudioSettings : Control MasterVolumeSlider.Value = volumeDb; MasterVolumeSlider.MinValue = MuteThreshold; MasterVolumeSlider.MaxValue = 0f; - + var musicVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("music")); MusicVolumeSlider.Value = musicVolumeDb; MusicVolumeSlider.MinValue = MuteThreshold; MusicVolumeSlider.MaxValue = 0f; - + var sfxVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("sfx")); SfxVolumeSlider.Value = sfxVolumeDb; SfxVolumeSlider.MinValue = MuteThreshold; @@ -95,12 +96,12 @@ public partial class AudioSettings : Control { var settingsConfig = _configFileHandler.SettingsConfig; if (!settingsConfig.HasSection("audio_settings")) return; - + var masterVolume = (float)settingsConfig.GetValue("audio_settings", "master_volume", MasterVolumeSlider.Value); var musicVolume = (float)settingsConfig.GetValue("audio_settings", "music_volume", MusicVolumeSlider.Value); var sfxVolume = (float)settingsConfig.GetValue("audio_settings", "sfx_volume", SfxVolumeSlider.Value); var muteThreshold = (float)settingsConfig.GetValue("audio_settings", "mute_threshold", MuteThreshold); - + MasterVolumeSlider.Value = masterVolume; MusicVolumeSlider.Value = musicVolume; SfxVolumeSlider.Value = sfxVolume; diff --git a/scripts/UI/ChargeProgressBar.cs b/scripts/UI/ChargeProgressBar.cs index 91654ef..286295f 100644 --- a/scripts/UI/ChargeProgressBar.cs +++ b/scripts/UI/ChargeProgressBar.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; @@ -17,15 +18,15 @@ public partial class ChargeProgressBar : ProgressBar { ProgressBar.Hide(); - _skillManager = GetNodeOrNull("/root/SkillManager"); + _skillManager = GetNodeOrNull(Constants.SkillManagerPath); if (_skillManager == null) { GD.PrintErr("ChargeProgressBar: SkillManager autoload not found."); return; } - + _skillManager.ActiveThrowSkillChanged += OnActiveThrowSkillChanged; - + SetupDependencies(); } @@ -43,7 +44,7 @@ public partial class ChargeProgressBar : ProgressBar OnOwnerExiting(); if (throwComponent == null || !IsInstanceValid(throwComponent)) return; - + _throwComponent = throwComponent; _throwComponent.TreeExiting += OnOwnerExiting; SetupDependencies(); @@ -60,7 +61,7 @@ public partial class ChargeProgressBar : ProgressBar } _throwComponent = null; } - + private void SetupDependencies() { @@ -68,7 +69,7 @@ public partial class ChargeProgressBar : ProgressBar { return; } - + if (_throwComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput) { _throwInput = throwInput; @@ -77,7 +78,7 @@ public partial class ChargeProgressBar : ProgressBar { _throwInput = null; } - + if (_throwInput == null) { return; @@ -88,9 +89,9 @@ public partial class ChargeProgressBar : ProgressBar ProgressBar.Hide(); return; } - + SetupProgressBar(); - + _throwInput.ChargeStarted += OnChargeStarted; _throwInput.ChargeStopped += OnChargeStopped; _throwInput.ChargeUpdated += OnChargeUpdated; diff --git a/scripts/UI/Credits.cs b/scripts/UI/Credits.cs index b0d2d0f..d26b114 100644 --- a/scripts/UI/Credits.cs +++ b/scripts/UI/Credits.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -9,7 +10,7 @@ public partial class Credits : Control public override void _Ready() { - _uiManager = GetNode("/root/UIManager"); + _uiManager = GetNode(Constants.UIManagerPath); } public override void _UnhandledInput(InputEvent @event) diff --git a/scripts/UI/DeathScreen.cs b/scripts/UI/DeathScreen.cs index ce03d99..31f0d2a 100644 --- a/scripts/UI/DeathScreen.cs +++ b/scripts/UI/DeathScreen.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.Resources; @@ -12,27 +13,27 @@ public partial class DeathScreen : Control [Export] public Label LivesLeftLabel { get; set; } [Export] public float TimeoutTime { get; set; } = 2.0f; [Export] public Godot.Collections.Array NodesToDisable { get; set; } = new(); - + private GameManager _gameManager; private Timer _timer; public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); SetLabels(); } - + private void SetLabels() { if (_gameManager == null) return; - + if (CurrentLevel != null) { CurrentLevelLabel.Text = CurrentLevel.LevelName; } LivesLeftLabel.Text = $" x {_gameManager.GetLives()}"; } - + private void SetupTimer() { _timer = new Timer(); @@ -42,31 +43,31 @@ public partial class DeathScreen : Control AddChild(_timer); _timer.Start(); } - + private void ToggleNodes() { foreach (var node in NodesToDisable) { - node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled - ? ProcessModeEnum.Inherit + node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled + ? ProcessModeEnum.Inherit : ProcessModeEnum.Disabled; } } - + public void OnPlayerDeath() { if (_gameManager == null) return; - + ToggleNodes(); SetLabels(); Show(); SetupTimer(); } - + private void OnTimeout() { if (_gameManager == null || _gameManager.GetLives() == 0) return; - + GetTree().ReloadCurrentScene(); } } \ No newline at end of file diff --git a/scripts/UI/GameOverScreen.cs b/scripts/UI/GameOverScreen.cs index 6cb17a1..514c728 100644 --- a/scripts/UI/GameOverScreen.cs +++ b/scripts/UI/GameOverScreen.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -9,14 +10,14 @@ public partial class GameOverScreen : Control [Export] public Button RestartButton { get; set; } [Export] public Button MainMenuButton { get; set; } [Export] public PackedScene MainMenuScene { get; set; } - + private GameManager _gameManager; public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); RestartButton.Pressed += OnRestartClicked; - MainMenuButton.Pressed += OnMainMenuClicked; + MainMenuButton.Pressed += OnMainMenuClicked; } private void OnMainMenuClicked() @@ -33,7 +34,7 @@ public partial class GameOverScreen : Control public void OnPlayerDeath() { if (_gameManager == null || _gameManager.GetLives() != 0) return; - + GameOverPanel.Show(); } } \ No newline at end of file diff --git a/scripts/UI/Hud.cs b/scripts/UI/Hud.cs index 9f584ce..cc021a5 100644 --- a/scripts/UI/Hud.cs +++ b/scripts/UI/Hud.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; @@ -15,7 +16,7 @@ public partial class Hud : Control public override void _Ready() { - _gameManager = GetNode("/root/GameManager"); + _gameManager = GetNode(Constants.GameManagerPath); } public override void _Process(double delta) diff --git a/scripts/UI/MainMenu.cs b/scripts/UI/MainMenu.cs index b3aa727..bf6810f 100644 --- a/scripts/UI/MainMenu.cs +++ b/scripts/UI/MainMenu.cs @@ -1,4 +1,5 @@ using Godot; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; @@ -14,16 +15,16 @@ public partial class MainMenu : Control [Export] public Label VersionLabel { get; set; } [Export] public Control SettingsControl { get; set; } [Export] public Control CreditsControl { get; set; } - + private SaveSystem _saveSystem; private GameManager _gameManager; private UIManager _uiManager; public override void _Ready() { - _saveSystem = GetNode("/root/SaveSystem"); - _gameManager = GetNode("/root/GameManager"); - _uiManager = GetNode("/root/UIManager"); + _saveSystem = GetNode(Constants.SaveSystemPath); + _gameManager = GetNode(Constants.GameManagerPath); + _uiManager = GetNode(Constants.UIManagerPath); NewGameButton.Pressed += OnNewGamePressed; ContinueButton.Pressed += OnContinuePressed; diff --git a/scripts/UI/Marketplace.cs b/scripts/UI/Marketplace.cs index 4b801c7..7cefe6f 100644 --- a/scripts/UI/Marketplace.cs +++ b/scripts/UI/Marketplace.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using Godot; using Godot.Collections; +using Mr.BrickAdventures; using Mr.BrickAdventures.Autoloads; using Mr.BrickAdventures.scripts.components; using Mr.BrickAdventures.scripts.Resources; @@ -17,7 +18,7 @@ public partial class Marketplace : Control [Export] public Array ComponentsToDisable { get; set; } = []; [Export] public PackedScene MarketplaceButtonScene { get; set; } [Export] public PackedScene SkillButtonScene { get; set; } - + private GameManager _gameManager; private SkillManager _skillManager; private readonly List