refactor: Replace hardcoded node paths with constants and remove ScoreComponent.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
@@ -8,14 +9,14 @@ public partial class AchievementManager : Node
|
|||||||
{
|
{
|
||||||
[Export] private string AchievementsFolderPath = "res://achievements/";
|
[Export] private string AchievementsFolderPath = "res://achievements/";
|
||||||
[Export] private PackedScene AchievementPopupScene { get; set; }
|
[Export] private PackedScene AchievementPopupScene { get; set; }
|
||||||
|
|
||||||
private System.Collections.Generic.Dictionary<string, AchievementResource> _achievements = new();
|
private System.Collections.Generic.Dictionary<string, AchievementResource> _achievements = new();
|
||||||
private Array<string> _unlockedAchievementIds = [];
|
private Array<string> _unlockedAchievementIds = [];
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
LoadAchievementsFromFolder();
|
LoadAchievementsFromFolder();
|
||||||
LoadUnlockedAchievements();
|
LoadUnlockedAchievements();
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,7 @@ public partial class AchievementManager : Node
|
|||||||
fileName = dir.GetNext();
|
fileName = dir.GetNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnlockAchievement(string achievementId)
|
public void UnlockAchievement(string achievementId)
|
||||||
{
|
{
|
||||||
if (!_achievements.TryGetValue(achievementId, out var achievement))
|
if (!_achievements.TryGetValue(achievementId, out var achievement))
|
||||||
@@ -75,11 +76,11 @@ public partial class AchievementManager : Node
|
|||||||
{
|
{
|
||||||
SteamManager.UnlockAchievement(achievement.Id);
|
SteamManager.UnlockAchievement(achievement.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Save progress
|
// 4. Save progress
|
||||||
SaveUnlockedAchievements();
|
SaveUnlockedAchievements();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LockAchievement(string achievementId)
|
public void LockAchievement(string achievementId)
|
||||||
{
|
{
|
||||||
if (_unlockedAchievementIds.Contains(achievementId))
|
if (_unlockedAchievementIds.Contains(achievementId))
|
||||||
@@ -88,7 +89,7 @@ public partial class AchievementManager : Node
|
|||||||
SaveUnlockedAchievements();
|
SaveUnlockedAchievements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveUnlockedAchievements()
|
private void SaveUnlockedAchievements()
|
||||||
{
|
{
|
||||||
_gameManager.PlayerState["unlocked_achievements"] = _unlockedAchievementIds;
|
_gameManager.PlayerState["unlocked_achievements"] = _unlockedAchievementIds;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
@@ -12,9 +13,9 @@ public partial class ConsoleManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_achievementManager = GetNode<AchievementManager>("/root/AchievementManager");
|
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCoinsCommand(int amount)
|
private void AddCoinsCommand(int amount)
|
||||||
@@ -88,7 +89,7 @@ public partial class ConsoleManager : Node
|
|||||||
|
|
||||||
_skillUnlockerComponent.UnlockAllSkills();
|
_skillUnlockerComponent.UnlockAllSkills();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveSkillCommand(string skillName)
|
private void RemoveSkillCommand(string skillName)
|
||||||
{
|
{
|
||||||
if (!GetSkillManagement()) return;
|
if (!GetSkillManagement()) return;
|
||||||
@@ -102,28 +103,28 @@ public partial class ConsoleManager : Node
|
|||||||
_gameManager.RemoveSkill(skill.Name);
|
_gameManager.RemoveSkill(skill.Name);
|
||||||
_skillManager.DeactivateSkill(skill);
|
_skillManager.DeactivateSkill(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveAllSkillsCommand()
|
private void RemoveAllSkillsCommand()
|
||||||
{
|
{
|
||||||
if (!GetSkillManagement()) return;
|
if (!GetSkillManagement()) return;
|
||||||
|
|
||||||
foreach (var skill in _skillManager.AvailableSkills)
|
foreach (var skill in _skillManager.AvailableSkills)
|
||||||
{
|
{
|
||||||
_gameManager.RemoveSkill(skill.Name);
|
_gameManager.RemoveSkill(skill.Name);
|
||||||
_skillManager.DeactivateSkill(skill);
|
_skillManager.DeactivateSkill(skill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GoToNextLevelCommand()
|
private void GoToNextLevelCommand()
|
||||||
{
|
{
|
||||||
_gameManager.OnLevelComplete();
|
_gameManager.OnLevelComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UnlockAchievementCommand(string achievementId)
|
private void UnlockAchievementCommand(string achievementId)
|
||||||
{
|
{
|
||||||
_achievementManager.UnlockAchievement(achievementId);
|
_achievementManager.UnlockAchievement(achievementId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetAchievementCommand(string achievementId)
|
private void ResetAchievementCommand(string achievementId)
|
||||||
{
|
{
|
||||||
_achievementManager.LockAchievement(achievementId);
|
_achievementManager.LockAchievement(achievementId);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
using Double = System.Double;
|
using Double = System.Double;
|
||||||
@@ -55,7 +56,7 @@ public partial class GameManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_speedRunManager = GetNode<SpeedRunManager>("/root/SpeedRunManager");
|
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +187,7 @@ public partial class GameManager : Node
|
|||||||
ResetPlayerState();
|
ResetPlayerState();
|
||||||
ResetCurrentSessionState();
|
ResetCurrentSessionState();
|
||||||
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
||||||
GetNode<SaveSystem>("/root/SaveSystem").SaveGame();
|
GetNode<SaveSystem>(Constants.SaveSystemPath).SaveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QuitGame() => GetTree().Quit();
|
public void QuitGame() => GetTree().Quit();
|
||||||
@@ -202,12 +203,12 @@ public partial class GameManager : Node
|
|||||||
_speedRunManager?.StartTimer();
|
_speedRunManager?.StartTimer();
|
||||||
|
|
||||||
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
GetTree().ChangeSceneToPacked(LevelScenes[0]);
|
||||||
GetNode<SaveSystem>("/root/SaveSystem").SaveGame();
|
GetNode<SaveSystem>(Constants.SaveSystemPath).SaveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ContinueGame()
|
public void ContinueGame()
|
||||||
{
|
{
|
||||||
var save = GetNode<SaveSystem>("/root/SaveSystem");
|
var save = GetNode<SaveSystem>(Constants.SaveSystemPath);
|
||||||
if (!save.LoadGame())
|
if (!save.LoadGame())
|
||||||
{
|
{
|
||||||
GD.PrintErr("Failed to load game. Starting a new game instead.");
|
GD.PrintErr("Failed to load game. Starting a new game instead.");
|
||||||
@@ -236,7 +237,7 @@ public partial class GameManager : Node
|
|||||||
|
|
||||||
ResetCurrentSessionState();
|
ResetCurrentSessionState();
|
||||||
TryToGoToNextLevel();
|
TryToGoToNextLevel();
|
||||||
GetNode<SaveSystem>("/root/SaveSystem").SaveGame();
|
GetNode<SaveSystem>(Constants.SaveSystemPath).SaveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<SkillData> GetUnlockedSkills()
|
public Array<SkillData> GetUnlockedSkills()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
@@ -13,7 +14,7 @@ public partial class SaveSystem : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveGame()
|
public void SaveGame()
|
||||||
@@ -46,16 +47,16 @@ public partial class SaveSystem : Node
|
|||||||
GD.Print("Game state loaded from: ", SavePath);
|
GD.Print("Game state loaded from: ", SavePath);
|
||||||
GD.Print("Player state: ", saveDataObj["player_state"]);
|
GD.Print("Player state: ", saveDataObj["player_state"]);
|
||||||
_gameManager.PlayerState = (Dictionary)saveDataObj["player_state"];
|
_gameManager.PlayerState = (Dictionary)saveDataObj["player_state"];
|
||||||
|
|
||||||
var skills = new Array<SkillData>();
|
var skills = new Array<SkillData>();
|
||||||
foreach (var skill in (Array<SkillData>)_gameManager.PlayerState["unlocked_skills"])
|
foreach (var skill in (Array<SkillData>)_gameManager.PlayerState["unlocked_skills"])
|
||||||
{
|
{
|
||||||
skills.Add(skill);
|
skills.Add(skill);
|
||||||
}
|
}
|
||||||
|
|
||||||
_gameManager.UnlockSkills(skills);
|
_gameManager.UnlockSkills(skills);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckSaveExists() => FileAccess.FileExists(SavePath);
|
public bool CheckSaveExists() => FileAccess.FileExists(SavePath);
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -14,19 +15,19 @@ public partial class SkillManager : Node
|
|||||||
private PlayerController _player;
|
private PlayerController _player;
|
||||||
|
|
||||||
[Export] public Array<SkillData> AvailableSkills { get; set; } = [];
|
[Export] public Array<SkillData> AvailableSkills { get; set; } = [];
|
||||||
|
|
||||||
public Dictionary ActiveComponents { get; private set; } = new();
|
public Dictionary ActiveComponents { get; private set; } = new();
|
||||||
|
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void ActiveThrowSkillChangedEventHandler(BrickThrowComponent throwComponent);
|
public delegate void ActiveThrowSkillChangedEventHandler(BrickThrowComponent throwComponent);
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void SkillRemovedEventHandler(SkillData skillData);
|
public delegate void SkillRemovedEventHandler(SkillData skillData);
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called by the PlayerController from its _Ready method to register itself with the manager.
|
/// Called by the PlayerController from its _Ready method to register itself with the manager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,7 +40,7 @@ public partial class SkillManager : Node
|
|||||||
{
|
{
|
||||||
UnregisterPlayer();
|
UnregisterPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
_player = player;
|
_player = player;
|
||||||
if (_player != null)
|
if (_player != null)
|
||||||
{
|
{
|
||||||
@@ -61,7 +62,7 @@ public partial class SkillManager : Node
|
|||||||
}
|
}
|
||||||
_player = null;
|
_player = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddSkill(SkillData skillData)
|
public void AddSkill(SkillData skillData)
|
||||||
{
|
{
|
||||||
// Ensure a valid player is registered before adding a skill.
|
// 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.");
|
GD.Print("SkillManager: Player not available to add skill.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ActiveComponents.ContainsKey(skillData.Name))
|
if (ActiveComponents.ContainsKey(skillData.Name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -98,9 +99,9 @@ public partial class SkillManager : Node
|
|||||||
if (instance is ISkill skill)
|
if (instance is ISkill skill)
|
||||||
{
|
{
|
||||||
// Initialize the skill with the registered player instance.
|
// Initialize the skill with the registered player instance.
|
||||||
skill.Initialize(_player, skillData);
|
skill.Initialize(_player, skillData);
|
||||||
skill.Activate();
|
skill.Activate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GD.PrintErr($"Skill scene for '{skillData.Name}' does not implement ISkill!");
|
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.
|
// Add the skill node as a child of the player.
|
||||||
_player.AddChild(instance);
|
_player.AddChild(instance);
|
||||||
ActiveComponents[skillData.Name] = instance;
|
ActiveComponents[skillData.Name] = instance;
|
||||||
|
|
||||||
if (instance is BrickThrowComponent btc)
|
if (instance is BrickThrowComponent btc)
|
||||||
{
|
{
|
||||||
EmitSignalActiveThrowSkillChanged(btc);
|
EmitSignalActiveThrowSkillChanged(btc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveSkill(string skillName)
|
public void RemoveSkill(string skillName)
|
||||||
{
|
{
|
||||||
if (!ActiveComponents.TryGetValue(skillName, out var component))
|
if (!ActiveComponents.TryGetValue(skillName, out var component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (component.AsGodotObject() is BrickThrowComponent)
|
if (component.AsGodotObject() is BrickThrowComponent)
|
||||||
{
|
{
|
||||||
EmitSignalActiveThrowSkillChanged(null);
|
EmitSignalActiveThrowSkillChanged(null);
|
||||||
@@ -133,7 +134,7 @@ public partial class SkillManager : Node
|
|||||||
{
|
{
|
||||||
skill.Deactivate();
|
skill.Deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsInstanceValid(inst))
|
if (IsInstanceValid(inst))
|
||||||
inst.QueueFree();
|
inst.QueueFree();
|
||||||
|
|
||||||
@@ -150,7 +151,7 @@ public partial class SkillManager : Node
|
|||||||
var sd = GetSkillByName(skillName);
|
var sd = GetSkillByName(skillName);
|
||||||
if (sd != null) EmitSignalSkillRemoved(sd);
|
if (sd != null) EmitSignalSkillRemoved(sd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveAllActiveSkills()
|
private void RemoveAllActiveSkills()
|
||||||
{
|
{
|
||||||
// Create a copy of keys to avoid modification during iteration
|
// Create a copy of keys to avoid modification during iteration
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.Autoloads;
|
namespace Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ public partial class StatisticsManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_achievementManager = GetNode<AchievementManager>("/root/AchievementManager");
|
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||||
LoadStatistics();
|
LoadStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ public partial class StatisticsManager : Node
|
|||||||
_gameManager.PlayerState["statistics"] = _stats;
|
_gameManager.PlayerState["statistics"] = _stats;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Increases a numerical statistic by a given amount.
|
/// Increases a numerical statistic by a given amount.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ public static class Constants
|
|||||||
public const string FloatingTextManagerPath = "/root/FloatingTextManager";
|
public const string FloatingTextManagerPath = "/root/FloatingTextManager";
|
||||||
public const string UIManagerPath = "/root/UIManager";
|
public const string UIManagerPath = "/root/UIManager";
|
||||||
public const string ConsoleManagerPath = "/root/ConsoleManager";
|
public const string ConsoleManagerPath = "/root/ConsoleManager";
|
||||||
|
public const string ConfigFileHandlerPath = "/root/ConfigFileHandler";
|
||||||
|
|
||||||
// Group names
|
// Group names
|
||||||
public const string CoinsGroup = "coins";
|
public const string CoinsGroup = "coins";
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -10,19 +11,19 @@ public partial class AudioSettings : Control
|
|||||||
[Export] public Slider SfxVolumeSlider { get; set; }
|
[Export] public Slider SfxVolumeSlider { get; set; }
|
||||||
[Export] public Control AudioSettingsControl { get; set; }
|
[Export] public Control AudioSettingsControl { get; set; }
|
||||||
[Export] public float MuteThreshold { get; set; } = -20f;
|
[Export] public float MuteThreshold { get; set; } = -20f;
|
||||||
|
|
||||||
private UIManager _uiManager;
|
private UIManager _uiManager;
|
||||||
private ConfigFileHandler _configFileHandler;
|
private ConfigFileHandler _configFileHandler;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
_configFileHandler = GetNode<ConfigFileHandler>("/root/ConfigFileHandler");
|
_configFileHandler = GetNode<ConfigFileHandler>(Constants.ConfigFileHandlerPath);
|
||||||
Initialize();
|
Initialize();
|
||||||
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
|
MasterVolumeSlider.ValueChanged += OnMasterVolumeChanged;
|
||||||
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
|
MusicVolumeSlider.ValueChanged += OnMusicVolumeChanged;
|
||||||
SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged;
|
SfxVolumeSlider.ValueChanged += OnSfxVolumeChanged;
|
||||||
|
|
||||||
LoadSettings();
|
LoadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ public partial class AudioSettings : Control
|
|||||||
{
|
{
|
||||||
if (!@event.IsActionReleased("ui_cancel")) return;
|
if (!@event.IsActionReleased("ui_cancel")) return;
|
||||||
if (!_uiManager.IsScreenOnTop(AudioSettingsControl)) return;
|
if (!_uiManager.IsScreenOnTop(AudioSettingsControl)) return;
|
||||||
|
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
_uiManager.PopScreen();
|
_uiManager.PopScreen();
|
||||||
}
|
}
|
||||||
@@ -64,12 +65,12 @@ public partial class AudioSettings : Control
|
|||||||
MasterVolumeSlider.Value = volumeDb;
|
MasterVolumeSlider.Value = volumeDb;
|
||||||
MasterVolumeSlider.MinValue = MuteThreshold;
|
MasterVolumeSlider.MinValue = MuteThreshold;
|
||||||
MasterVolumeSlider.MaxValue = 0f;
|
MasterVolumeSlider.MaxValue = 0f;
|
||||||
|
|
||||||
var musicVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("music"));
|
var musicVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("music"));
|
||||||
MusicVolumeSlider.Value = musicVolumeDb;
|
MusicVolumeSlider.Value = musicVolumeDb;
|
||||||
MusicVolumeSlider.MinValue = MuteThreshold;
|
MusicVolumeSlider.MinValue = MuteThreshold;
|
||||||
MusicVolumeSlider.MaxValue = 0f;
|
MusicVolumeSlider.MaxValue = 0f;
|
||||||
|
|
||||||
var sfxVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("sfx"));
|
var sfxVolumeDb = AudioServer.GetBusVolumeDb(AudioServer.GetBusIndex("sfx"));
|
||||||
SfxVolumeSlider.Value = sfxVolumeDb;
|
SfxVolumeSlider.Value = sfxVolumeDb;
|
||||||
SfxVolumeSlider.MinValue = MuteThreshold;
|
SfxVolumeSlider.MinValue = MuteThreshold;
|
||||||
@@ -95,12 +96,12 @@ public partial class AudioSettings : Control
|
|||||||
{
|
{
|
||||||
var settingsConfig = _configFileHandler.SettingsConfig;
|
var settingsConfig = _configFileHandler.SettingsConfig;
|
||||||
if (!settingsConfig.HasSection("audio_settings")) return;
|
if (!settingsConfig.HasSection("audio_settings")) return;
|
||||||
|
|
||||||
var masterVolume = (float)settingsConfig.GetValue("audio_settings", "master_volume", MasterVolumeSlider.Value);
|
var masterVolume = (float)settingsConfig.GetValue("audio_settings", "master_volume", MasterVolumeSlider.Value);
|
||||||
var musicVolume = (float)settingsConfig.GetValue("audio_settings", "music_volume", MusicVolumeSlider.Value);
|
var musicVolume = (float)settingsConfig.GetValue("audio_settings", "music_volume", MusicVolumeSlider.Value);
|
||||||
var sfxVolume = (float)settingsConfig.GetValue("audio_settings", "sfx_volume", SfxVolumeSlider.Value);
|
var sfxVolume = (float)settingsConfig.GetValue("audio_settings", "sfx_volume", SfxVolumeSlider.Value);
|
||||||
var muteThreshold = (float)settingsConfig.GetValue("audio_settings", "mute_threshold", MuteThreshold);
|
var muteThreshold = (float)settingsConfig.GetValue("audio_settings", "mute_threshold", MuteThreshold);
|
||||||
|
|
||||||
MasterVolumeSlider.Value = masterVolume;
|
MasterVolumeSlider.Value = masterVolume;
|
||||||
MusicVolumeSlider.Value = musicVolume;
|
MusicVolumeSlider.Value = musicVolume;
|
||||||
SfxVolumeSlider.Value = sfxVolume;
|
SfxVolumeSlider.Value = sfxVolume;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -17,15 +18,15 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
{
|
{
|
||||||
ProgressBar.Hide();
|
ProgressBar.Hide();
|
||||||
|
|
||||||
_skillManager = GetNodeOrNull<SkillManager>("/root/SkillManager");
|
_skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
|
||||||
if (_skillManager == null)
|
if (_skillManager == null)
|
||||||
{
|
{
|
||||||
GD.PrintErr("ChargeProgressBar: SkillManager autoload not found.");
|
GD.PrintErr("ChargeProgressBar: SkillManager autoload not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_skillManager.ActiveThrowSkillChanged += OnActiveThrowSkillChanged;
|
_skillManager.ActiveThrowSkillChanged += OnActiveThrowSkillChanged;
|
||||||
|
|
||||||
SetupDependencies();
|
SetupDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
OnOwnerExiting();
|
OnOwnerExiting();
|
||||||
|
|
||||||
if (throwComponent == null || !IsInstanceValid(throwComponent)) return;
|
if (throwComponent == null || !IsInstanceValid(throwComponent)) return;
|
||||||
|
|
||||||
_throwComponent = throwComponent;
|
_throwComponent = throwComponent;
|
||||||
_throwComponent.TreeExiting += OnOwnerExiting;
|
_throwComponent.TreeExiting += OnOwnerExiting;
|
||||||
SetupDependencies();
|
SetupDependencies();
|
||||||
@@ -60,7 +61,7 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
}
|
}
|
||||||
_throwComponent = null;
|
_throwComponent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void SetupDependencies()
|
private void SetupDependencies()
|
||||||
{
|
{
|
||||||
@@ -68,7 +69,7 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_throwComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput)
|
if (_throwComponent.ThrowInputBehavior is ChargeThrowInputResource throwInput)
|
||||||
{
|
{
|
||||||
_throwInput = throwInput;
|
_throwInput = throwInput;
|
||||||
@@ -77,7 +78,7 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
{
|
{
|
||||||
_throwInput = null;
|
_throwInput = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_throwInput == null)
|
if (_throwInput == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@@ -88,9 +89,9 @@ public partial class ChargeProgressBar : ProgressBar
|
|||||||
ProgressBar.Hide();
|
ProgressBar.Hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupProgressBar();
|
SetupProgressBar();
|
||||||
|
|
||||||
_throwInput.ChargeStarted += OnChargeStarted;
|
_throwInput.ChargeStarted += OnChargeStarted;
|
||||||
_throwInput.ChargeStopped += OnChargeStopped;
|
_throwInput.ChargeStopped += OnChargeStopped;
|
||||||
_throwInput.ChargeUpdated += OnChargeUpdated;
|
_throwInput.ChargeUpdated += OnChargeUpdated;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -9,7 +10,7 @@ public partial class Credits : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _UnhandledInput(InputEvent @event)
|
public override void _UnhandledInput(InputEvent @event)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
|
|
||||||
@@ -12,27 +13,27 @@ public partial class DeathScreen : Control
|
|||||||
[Export] public Label LivesLeftLabel { get; set; }
|
[Export] public Label LivesLeftLabel { get; set; }
|
||||||
[Export] public float TimeoutTime { get; set; } = 2.0f;
|
[Export] public float TimeoutTime { get; set; } = 2.0f;
|
||||||
[Export] public Godot.Collections.Array<Node> NodesToDisable { get; set; } = new();
|
[Export] public Godot.Collections.Array<Node> NodesToDisable { get; set; } = new();
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
SetLabels();
|
SetLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetLabels()
|
private void SetLabels()
|
||||||
{
|
{
|
||||||
if (_gameManager == null) return;
|
if (_gameManager == null) return;
|
||||||
|
|
||||||
if (CurrentLevel != null)
|
if (CurrentLevel != null)
|
||||||
{
|
{
|
||||||
CurrentLevelLabel.Text = CurrentLevel.LevelName;
|
CurrentLevelLabel.Text = CurrentLevel.LevelName;
|
||||||
}
|
}
|
||||||
LivesLeftLabel.Text = $" x {_gameManager.GetLives()}";
|
LivesLeftLabel.Text = $" x {_gameManager.GetLives()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupTimer()
|
private void SetupTimer()
|
||||||
{
|
{
|
||||||
_timer = new Timer();
|
_timer = new Timer();
|
||||||
@@ -42,31 +43,31 @@ public partial class DeathScreen : Control
|
|||||||
AddChild(_timer);
|
AddChild(_timer);
|
||||||
_timer.Start();
|
_timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToggleNodes()
|
private void ToggleNodes()
|
||||||
{
|
{
|
||||||
foreach (var node in NodesToDisable)
|
foreach (var node in NodesToDisable)
|
||||||
{
|
{
|
||||||
node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled
|
node.ProcessMode = node.ProcessMode == ProcessModeEnum.Disabled
|
||||||
? ProcessModeEnum.Inherit
|
? ProcessModeEnum.Inherit
|
||||||
: ProcessModeEnum.Disabled;
|
: ProcessModeEnum.Disabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPlayerDeath()
|
public void OnPlayerDeath()
|
||||||
{
|
{
|
||||||
if (_gameManager == null) return;
|
if (_gameManager == null) return;
|
||||||
|
|
||||||
ToggleNodes();
|
ToggleNodes();
|
||||||
SetLabels();
|
SetLabels();
|
||||||
Show();
|
Show();
|
||||||
SetupTimer();
|
SetupTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTimeout()
|
private void OnTimeout()
|
||||||
{
|
{
|
||||||
if (_gameManager == null || _gameManager.GetLives() == 0) return;
|
if (_gameManager == null || _gameManager.GetLives() == 0) return;
|
||||||
|
|
||||||
GetTree().ReloadCurrentScene();
|
GetTree().ReloadCurrentScene();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -9,14 +10,14 @@ public partial class GameOverScreen : Control
|
|||||||
[Export] public Button RestartButton { get; set; }
|
[Export] public Button RestartButton { get; set; }
|
||||||
[Export] public Button MainMenuButton { get; set; }
|
[Export] public Button MainMenuButton { get; set; }
|
||||||
[Export] public PackedScene MainMenuScene { get; set; }
|
[Export] public PackedScene MainMenuScene { get; set; }
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
RestartButton.Pressed += OnRestartClicked;
|
RestartButton.Pressed += OnRestartClicked;
|
||||||
MainMenuButton.Pressed += OnMainMenuClicked;
|
MainMenuButton.Pressed += OnMainMenuClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMainMenuClicked()
|
private void OnMainMenuClicked()
|
||||||
@@ -33,7 +34,7 @@ public partial class GameOverScreen : Control
|
|||||||
public void OnPlayerDeath()
|
public void OnPlayerDeath()
|
||||||
{
|
{
|
||||||
if (_gameManager == null || _gameManager.GetLives() != 0) return;
|
if (_gameManager == null || _gameManager.GetLives() != 0) return;
|
||||||
|
|
||||||
GameOverPanel.Show();
|
GameOverPanel.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ public partial class Hud : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -14,16 +15,16 @@ public partial class MainMenu : Control
|
|||||||
[Export] public Label VersionLabel { get; set; }
|
[Export] public Label VersionLabel { get; set; }
|
||||||
[Export] public Control SettingsControl { get; set; }
|
[Export] public Control SettingsControl { get; set; }
|
||||||
[Export] public Control CreditsControl { get; set; }
|
[Export] public Control CreditsControl { get; set; }
|
||||||
|
|
||||||
private SaveSystem _saveSystem;
|
private SaveSystem _saveSystem;
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
private UIManager _uiManager;
|
private UIManager _uiManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_saveSystem = GetNode<SaveSystem>("/root/SaveSystem");
|
_saveSystem = GetNode<SaveSystem>(Constants.SaveSystemPath);
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
|
|
||||||
NewGameButton.Pressed += OnNewGamePressed;
|
NewGameButton.Pressed += OnNewGamePressed;
|
||||||
ContinueButton.Pressed += OnContinuePressed;
|
ContinueButton.Pressed += OnContinuePressed;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -17,7 +18,7 @@ public partial class Marketplace : Control
|
|||||||
[Export] public Array<Node> ComponentsToDisable { get; set; } = [];
|
[Export] public Array<Node> ComponentsToDisable { get; set; } = [];
|
||||||
[Export] public PackedScene MarketplaceButtonScene { get; set; }
|
[Export] public PackedScene MarketplaceButtonScene { get; set; }
|
||||||
[Export] public PackedScene SkillButtonScene { get; set; }
|
[Export] public PackedScene SkillButtonScene { get; set; }
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
private SkillManager _skillManager;
|
private SkillManager _skillManager;
|
||||||
private readonly List<Button> _unlockButtons = [];
|
private readonly List<Button> _unlockButtons = [];
|
||||||
@@ -25,21 +26,21 @@ public partial class Marketplace : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
_skillManager.SkillRemoved += OnSkillRemoved;
|
_skillManager.SkillRemoved += OnSkillRemoved;
|
||||||
|
|
||||||
Skills = _skillManager.AvailableSkills;
|
Skills = _skillManager.AvailableSkills;
|
||||||
|
|
||||||
var skillsToUnlock = new List<SkillData>();
|
var skillsToUnlock = new List<SkillData>();
|
||||||
|
|
||||||
foreach (var skill in Skills) skillsToUnlock.Add(skill);
|
foreach (var skill in Skills) skillsToUnlock.Add(skill);
|
||||||
|
|
||||||
foreach (var skill in skillsToUnlock) CreateUpgradeButton(skill);
|
foreach (var skill in skillsToUnlock) CreateUpgradeButton(skill);
|
||||||
|
|
||||||
var unlockedSkills = _gameManager.GetUnlockedSkills();
|
var unlockedSkills = _gameManager.GetUnlockedSkills();
|
||||||
foreach (var skill in unlockedSkills) CreateSkillButton(skill);
|
foreach (var skill in unlockedSkills) CreateSkillButton(skill);
|
||||||
|
|
||||||
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
|
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ public partial class Marketplace : Control
|
|||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (!@event.IsActionPressed("show_marketplace")) return;
|
if (!@event.IsActionPressed("show_marketplace")) return;
|
||||||
|
|
||||||
if (IsVisible())
|
if (IsVisible())
|
||||||
{
|
{
|
||||||
Hide();
|
Hide();
|
||||||
@@ -75,7 +76,7 @@ public partial class Marketplace : Control
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buttonExists) CreateSkillButton(skill);
|
if (!buttonExists) CreateSkillButton(skill);
|
||||||
|
|
||||||
foreach (var btn in _skillButtons)
|
foreach (var btn in _skillButtons)
|
||||||
@@ -92,7 +93,7 @@ public partial class Marketplace : Control
|
|||||||
button.Setup();
|
button.Setup();
|
||||||
button.Pressed += () => OnSkillButtonPressed(button);
|
button.Pressed += () => OnSkillButtonPressed(button);
|
||||||
button.Activate();
|
button.Activate();
|
||||||
|
|
||||||
_skillButtons.Add(button);
|
_skillButtons.Add(button);
|
||||||
UnlockedGrid.AddChild(button);
|
UnlockedGrid.AddChild(button);
|
||||||
UnlockedGrid.QueueSort();
|
UnlockedGrid.QueueSort();
|
||||||
@@ -104,7 +105,7 @@ public partial class Marketplace : Control
|
|||||||
button.Data = skill;
|
button.Data = skill;
|
||||||
button.Icon = skill.Icon;
|
button.Icon = skill.Icon;
|
||||||
button.Pressed += () => OnUpgradeButtonPressed(skill);
|
button.Pressed += () => OnUpgradeButtonPressed(skill);
|
||||||
|
|
||||||
_unlockButtons.Add(button);
|
_unlockButtons.Add(button);
|
||||||
ToUnlockGrid.AddChild(button);
|
ToUnlockGrid.AddChild(button);
|
||||||
ToUnlockGrid.QueueSort();
|
ToUnlockGrid.QueueSort();
|
||||||
@@ -133,7 +134,7 @@ public partial class Marketplace : Control
|
|||||||
private void OnSkillButtonPressed(SkillButton button)
|
private void OnSkillButtonPressed(SkillButton button)
|
||||||
{
|
{
|
||||||
SkillUnlockerComponent.SkillManager.ToggleSkillActivation(button.Data);
|
SkillUnlockerComponent.SkillManager.ToggleSkillActivation(button.Data);
|
||||||
|
|
||||||
foreach (var btn in _skillButtons)
|
foreach (var btn in _skillButtons)
|
||||||
{
|
{
|
||||||
if (btn.Data.IsActive)
|
if (btn.Data.IsActive)
|
||||||
@@ -142,7 +143,7 @@ public partial class Marketplace : Control
|
|||||||
btn.Deactivate();
|
btn.Deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSkillRemoved(SkillData skill)
|
private void OnSkillRemoved(SkillData skill)
|
||||||
{
|
{
|
||||||
SkillButton buttonToRemove = null;
|
SkillButton buttonToRemove = null;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.components;
|
using Mr.BrickAdventures.scripts.components;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -11,26 +12,26 @@ public partial class MarketplaceButton : Button
|
|||||||
[Export] public Texture2D UnlockedSkillIcon { get; set; }
|
[Export] public Texture2D UnlockedSkillIcon { get; set; }
|
||||||
[Export] public Texture2D LockedSkillIcon { get; set; }
|
[Export] public Texture2D LockedSkillIcon { get; set; }
|
||||||
[Export] public Container SkillLevelContainer { get; set; }
|
[Export] public Container SkillLevelContainer { get; set; }
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
private SkillUnlockerComponent _skillUnlockerComponent;
|
private SkillUnlockerComponent _skillUnlockerComponent;
|
||||||
private SkillManager _skillManager;
|
private SkillManager _skillManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
var player = _gameManager.Player;
|
var player = _gameManager.Player;
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
_skillUnlockerComponent = player.GetNodeOrNull<SkillUnlockerComponent>("SkillUnlockerComponent");
|
_skillUnlockerComponent = player.GetNodeOrNull<SkillUnlockerComponent>("SkillUnlockerComponent");
|
||||||
if (_skillUnlockerComponent != null)
|
if (_skillUnlockerComponent != null)
|
||||||
{
|
{
|
||||||
_skillUnlockerComponent.SkillUnlocked += OnSkillStateChanged;
|
_skillUnlockerComponent.SkillUnlocked += OnSkillStateChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
_skillManager.SkillRemoved += OnSkillStateChanged;
|
_skillManager.SkillRemoved += OnSkillStateChanged;
|
||||||
|
|
||||||
UpdateButtonState();
|
UpdateButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ public partial class MarketplaceButton : Button
|
|||||||
_skillUnlockerComponent.SkillUnlocked -= OnSkillStateChanged;
|
_skillUnlockerComponent.SkillUnlocked -= OnSkillStateChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSkillStateChanged(SkillData skill)
|
private void OnSkillStateChanged(SkillData skill)
|
||||||
{
|
{
|
||||||
if (skill.Name == Data.Name)
|
if (skill.Name == Data.Name)
|
||||||
@@ -59,7 +60,7 @@ public partial class MarketplaceButton : Button
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isUnlocked = _gameManager.IsSkillUnlocked(Data);
|
var isUnlocked = _gameManager.IsSkillUnlocked(Data);
|
||||||
|
|
||||||
for (var i = 0; i < SkillLevelContainer.GetChildCount(); i++)
|
for (var i = 0; i < SkillLevelContainer.GetChildCount(); i++)
|
||||||
{
|
{
|
||||||
SkillLevelContainer.GetChild(i).QueueFree();
|
SkillLevelContainer.GetChild(i).QueueFree();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -18,8 +19,8 @@ public partial class PauseMenu : Control
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
|
|
||||||
ResumeButton.Pressed += OnResumePressed;
|
ResumeButton.Pressed += OnResumePressed;
|
||||||
MainMenuButton.Pressed += OnMainMenuPressed;
|
MainMenuButton.Pressed += OnMainMenuPressed;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -14,18 +15,18 @@ public partial class SettingsMenu : Control
|
|||||||
[Export] public Button AudioSettingsButton { get; set; }
|
[Export] public Button AudioSettingsButton { get; set; }
|
||||||
[Export] public Button DisplaySettingsButton { get; set; }
|
[Export] public Button DisplaySettingsButton { get; set; }
|
||||||
[Export] public Button GameplaySettingsButton { get; set; }
|
[Export] public Button GameplaySettingsButton { get; set; }
|
||||||
|
|
||||||
private UIManager _uiManager;
|
private UIManager _uiManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_uiManager = GetNode<UIManager>("/root/UIManager");
|
_uiManager = GetNode<UIManager>(Constants.UIManagerPath);
|
||||||
|
|
||||||
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
InputSettingsButton.Pressed += OnInputSettingsPressed;
|
||||||
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
AudioSettingsButton.Pressed += OnAudioSettingsPressed;
|
||||||
DisplaySettingsButton.Pressed += OnDisplaySettingsPressed;
|
DisplaySettingsButton.Pressed += OnDisplaySettingsPressed;
|
||||||
GameplaySettingsButton.Pressed += OnGameplaySettingsPressed;
|
GameplaySettingsButton.Pressed += OnGameplaySettingsPressed;
|
||||||
|
|
||||||
InputSettingsControl?.Hide();
|
InputSettingsControl?.Hide();
|
||||||
AudioSettingsControl?.Hide();
|
AudioSettingsControl?.Hide();
|
||||||
DisplaySettingsControl?.Hide();
|
DisplaySettingsControl?.Hide();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.UI;
|
namespace Mr.BrickAdventures.scripts.UI;
|
||||||
@@ -7,15 +8,15 @@ namespace Mr.BrickAdventures.scripts.UI;
|
|||||||
public partial class SpeedRunHud : Control
|
public partial class SpeedRunHud : Control
|
||||||
{
|
{
|
||||||
[Export] private Label _timerLabel;
|
[Export] private Label _timerLabel;
|
||||||
|
|
||||||
private SpeedRunManager _speedRunManager;
|
private SpeedRunManager _speedRunManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_speedRunManager = GetNode<SpeedRunManager>("/root/SpeedRunManager");
|
_speedRunManager = GetNode<SpeedRunManager>(Constants.SpeedRunManagerPath);
|
||||||
|
|
||||||
_speedRunManager.TimeUpdated += OnTimerUpdated;
|
_speedRunManager.TimeUpdated += OnTimerUpdated;
|
||||||
|
|
||||||
Visible = _speedRunManager.IsVisible;
|
Visible = _speedRunManager.IsVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -9,7 +10,7 @@ namespace Mr.BrickAdventures.scripts.components;
|
|||||||
public partial class BrickShieldSkillComponent : Node, ISkill
|
public partial class BrickShieldSkillComponent : Node, ISkill
|
||||||
{
|
{
|
||||||
[Export] public PackedScene ShieldScene { get; set; }
|
[Export] public PackedScene ShieldScene { get; set; }
|
||||||
|
|
||||||
private PlayerController _player;
|
private PlayerController _player;
|
||||||
private Node2D _shieldInstance;
|
private Node2D _shieldInstance;
|
||||||
private SkillData _skillData;
|
private SkillData _skillData;
|
||||||
@@ -19,8 +20,8 @@ public partial class BrickShieldSkillComponent : Node, ISkill
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_skillManager = GetNode<SkillManager>("/root/SkillManager");
|
_skillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Initialize(Node owner, SkillData data)
|
public void Initialize(Node owner, SkillData data)
|
||||||
@@ -59,7 +60,7 @@ public partial class BrickShieldSkillComponent : Node, ISkill
|
|||||||
_shieldHealth.MaxHealth = (float)newHealth;
|
_shieldHealth.MaxHealth = (float)newHealth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnShieldDestroyed()
|
private void OnShieldDestroyed()
|
||||||
{
|
{
|
||||||
if (_gameManager != null && _skillData != null && _skillManager != null)
|
if (_gameManager != null && _skillData != null && _skillManager != null)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
|
|
||||||
@@ -12,25 +13,25 @@ public partial class ExitDoorComponent : Area2D, IUnlockable
|
|||||||
[Export] public AudioStreamPlayer2D OpenDoorSfx { get; set; }
|
[Export] public AudioStreamPlayer2D OpenDoorSfx { get; set; }
|
||||||
[Export] public int OpenedDoorFrame { get; set; } = 0;
|
[Export] public int OpenedDoorFrame { get; set; } = 0;
|
||||||
[Export] public string AchievementId = "level_complete_1";
|
[Export] public string AchievementId = "level_complete_1";
|
||||||
|
|
||||||
[Signal] public delegate void ExitTriggeredEventHandler();
|
[Signal] public delegate void ExitTriggeredEventHandler();
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
private AchievementManager _achievementManager;
|
private AchievementManager _achievementManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
_achievementManager = GetNode<AchievementManager>("/root/AchievementManager");
|
_achievementManager = GetNode<AchievementManager>(Constants.AchievementManagerPath);
|
||||||
|
|
||||||
BodyEntered += OnExitAreaBodyEntered;
|
BodyEntered += OnExitAreaBodyEntered;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExitAreaBodyEntered(Node2D body)
|
private void OnExitAreaBodyEntered(Node2D body)
|
||||||
{
|
{
|
||||||
if (Locked) return;
|
if (Locked) return;
|
||||||
|
|
||||||
EmitSignalExitTriggered();
|
EmitSignalExitTriggered();
|
||||||
_achievementManager.UnlockAchievement(AchievementId);
|
_achievementManager.UnlockAchievement(AchievementId);
|
||||||
_gameManager.UnlockLevel((int)_gameManager.PlayerState["current_level"] + 1);
|
_gameManager.UnlockLevel((int)_gameManager.PlayerState["current_level"] + 1);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -15,25 +16,25 @@ public partial class LeverComponent : Node
|
|||||||
|
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void ActivatedEventHandler();
|
public delegate void ActivatedEventHandler();
|
||||||
|
|
||||||
private FloatingTextManager _floatingTextManager;
|
private FloatingTextManager _floatingTextManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_floatingTextManager = GetNode<FloatingTextManager>("/root/FloatingTextManager");
|
_floatingTextManager = GetNode<FloatingTextManager>(Constants.FloatingTextManagerPath);
|
||||||
|
|
||||||
if (Area == null)
|
if (Area == null)
|
||||||
{
|
{
|
||||||
GD.PushError("LeverComponent: Area is not set.");
|
GD.PushError("LeverComponent: Area is not set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Sprite == null)
|
if (Sprite == null)
|
||||||
{
|
{
|
||||||
GD.PushError("LeverComponent: Sprite is not set.");
|
GD.PushError("LeverComponent: Sprite is not set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Area.BodyEntered += OnBodyEntered;
|
Area.BodyEntered += OnBodyEntered;
|
||||||
Area.AreaEntered += OnAreaEntered;
|
Area.AreaEntered += OnAreaEntered;
|
||||||
}
|
}
|
||||||
@@ -58,7 +59,7 @@ public partial class LeverComponent : Node
|
|||||||
await timer.ToSignal(timer, Timer.SignalName.Timeout);
|
await timer.ToSignal(timer, Timer.SignalName.Timeout);
|
||||||
Sprite.Frame = StartAnimationIndex;
|
Sprite.Frame = StartAnimationIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleTriggerLogic(Node2D obj)
|
private void HandleTriggerLogic(Node2D obj)
|
||||||
{
|
{
|
||||||
var triggerLever = obj.GetNodeOrNull<TriggerLeverComponent>("TriggerLeverComponent");
|
var triggerLever = obj.GetNodeOrNull<TriggerLeverComponent>("TriggerLeverComponent");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -10,7 +11,7 @@ namespace Mr.BrickAdventures.scripts.components;
|
|||||||
public partial class PlayerController : CharacterBody2D
|
public partial class PlayerController : CharacterBody2D
|
||||||
{
|
{
|
||||||
[Export] private Node MovementAbilitiesContainer { get; set; }
|
[Export] private Node MovementAbilitiesContainer { get; set; }
|
||||||
|
|
||||||
[ExportGroup("Movement Ability Scenes")]
|
[ExportGroup("Movement Ability Scenes")]
|
||||||
[Export] public PackedScene GroundMovementScene { get; set; }
|
[Export] public PackedScene GroundMovementScene { get; set; }
|
||||||
[Export] public PackedScene JumpMovementScene { get; set; }
|
[Export] public PackedScene JumpMovementScene { get; set; }
|
||||||
@@ -19,23 +20,23 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
[Export] public PackedScene SpaceshipMovementScene { get; set; }
|
[Export] public PackedScene SpaceshipMovementScene { get; set; }
|
||||||
[Export] public PackedScene WallJumpScene { get; set; }
|
[Export] public PackedScene WallJumpScene { get; set; }
|
||||||
[Export] public PackedScene GridMovementScene { get; set; }
|
[Export] public PackedScene GridMovementScene { get; set; }
|
||||||
|
|
||||||
[Signal] public delegate void JumpInitiatedEventHandler();
|
[Signal] public delegate void JumpInitiatedEventHandler();
|
||||||
[Signal] public delegate void MovementAbilitiesChangedEventHandler();
|
[Signal] public delegate void MovementAbilitiesChangedEventHandler();
|
||||||
|
|
||||||
public Vector2 LastDirection { get; private set; } = Vector2.Right;
|
public Vector2 LastDirection { get; private set; } = Vector2.Right;
|
||||||
public Vector2 PreviousVelocity { get; private set; } = Vector2.Zero;
|
public Vector2 PreviousVelocity { get; private set; } = Vector2.Zero;
|
||||||
|
|
||||||
private List<MovementAbility> _abilities = [];
|
private List<MovementAbility> _abilities = [];
|
||||||
private PlayerInputHandler _inputHandler;
|
private PlayerInputHandler _inputHandler;
|
||||||
|
|
||||||
public IReadOnlyList<MovementAbility> GetActiveAbilities() => _abilities;
|
public IReadOnlyList<MovementAbility> GetActiveAbilities() => _abilities;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
var skillManager = GetNodeOrNull<SkillManager>("/root/SkillManager");
|
var skillManager = GetNodeOrNull<SkillManager>(Constants.SkillManagerPath);
|
||||||
skillManager?.RegisterPlayer(this);
|
skillManager?.RegisterPlayer(this);
|
||||||
|
|
||||||
_inputHandler = GetNode<PlayerInputHandler>("PlayerInputHandler");
|
_inputHandler = GetNode<PlayerInputHandler>("PlayerInputHandler");
|
||||||
foreach (var child in MovementAbilitiesContainer.GetChildren())
|
foreach (var child in MovementAbilitiesContainer.GetChildren())
|
||||||
{
|
{
|
||||||
@@ -45,20 +46,20 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
_abilities.Add(ability);
|
_abilities.Add(ability);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = ConnectJumpAndGravityAbilities();
|
_ = ConnectJumpAndGravityAbilities();
|
||||||
EmitSignalMovementAbilitiesChanged();
|
EmitSignalMovementAbilitiesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
var velocity = Velocity;
|
var velocity = Velocity;
|
||||||
|
|
||||||
foreach (var ability in _abilities)
|
foreach (var ability in _abilities)
|
||||||
{
|
{
|
||||||
velocity = ability.ProcessMovement(velocity, delta);
|
velocity = ability.ProcessMovement(velocity, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_inputHandler.MoveDirection.X != 0)
|
if (_inputHandler.MoveDirection.X != 0)
|
||||||
{
|
{
|
||||||
LastDirection = new Vector2(_inputHandler.MoveDirection.X > 0 ? 1 : -1, 0);
|
LastDirection = new Vector2(_inputHandler.MoveDirection.X > 0 ? 1 : -1, 0);
|
||||||
@@ -68,14 +69,14 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
Velocity = velocity;
|
Velocity = velocity;
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddAbility(MovementAbility ability)
|
public void AddAbility(MovementAbility ability)
|
||||||
{
|
{
|
||||||
MovementAbilitiesContainer.AddChild(ability);
|
MovementAbilitiesContainer.AddChild(ability);
|
||||||
ability.Initialize(this);
|
ability.Initialize(this);
|
||||||
_abilities.Add(ability);
|
_abilities.Add(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearMovementAbilities()
|
public void ClearMovementAbilities()
|
||||||
{
|
{
|
||||||
foreach (var ability in _abilities)
|
foreach (var ability in _abilities)
|
||||||
@@ -84,7 +85,7 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
}
|
}
|
||||||
_abilities.Clear();
|
_abilities.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAbility<T>() where T : MovementAbility
|
public void RemoveAbility<T>() where T : MovementAbility
|
||||||
{
|
{
|
||||||
for (var i = _abilities.Count - 1; i >= 0; i--)
|
for (var i = _abilities.Count - 1; i >= 0; i--)
|
||||||
@@ -102,20 +103,20 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
public void SetPlatformMovement()
|
public void SetPlatformMovement()
|
||||||
{
|
{
|
||||||
ClearMovementAbilities();
|
ClearMovementAbilities();
|
||||||
|
|
||||||
if (GroundMovementScene != null) AddAbility(GroundMovementScene.Instantiate<MovementAbility>());
|
if (GroundMovementScene != null) AddAbility(GroundMovementScene.Instantiate<MovementAbility>());
|
||||||
if (JumpMovementScene != null) AddAbility(JumpMovementScene.Instantiate<MovementAbility>());
|
if (JumpMovementScene != null) AddAbility(JumpMovementScene.Instantiate<MovementAbility>());
|
||||||
if (GravityScene != null) AddAbility(GravityScene.Instantiate<MovementAbility>());
|
if (GravityScene != null) AddAbility(GravityScene.Instantiate<MovementAbility>());
|
||||||
if (OneWayPlatformScene != null) AddAbility(OneWayPlatformScene.Instantiate<MovementAbility>());
|
if (OneWayPlatformScene != null) AddAbility(OneWayPlatformScene.Instantiate<MovementAbility>());
|
||||||
|
|
||||||
_ = ConnectJumpAndGravityAbilities();
|
_ = ConnectJumpAndGravityAbilities();
|
||||||
EmitSignalMovementAbilitiesChanged();
|
EmitSignalMovementAbilitiesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetSpaceshipMovement()
|
public void SetSpaceshipMovement()
|
||||||
{
|
{
|
||||||
ClearMovementAbilities();
|
ClearMovementAbilities();
|
||||||
|
|
||||||
if (SpaceshipMovementScene != null) AddAbility(SpaceshipMovementScene.Instantiate<MovementAbility>());
|
if (SpaceshipMovementScene != null) AddAbility(SpaceshipMovementScene.Instantiate<MovementAbility>());
|
||||||
EmitSignalMovementAbilitiesChanged();
|
EmitSignalMovementAbilitiesChanged();
|
||||||
}
|
}
|
||||||
@@ -130,10 +131,10 @@ public partial class PlayerController : CharacterBody2D
|
|||||||
private async Task ConnectJumpAndGravityAbilities()
|
private async Task ConnectJumpAndGravityAbilities()
|
||||||
{
|
{
|
||||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||||
|
|
||||||
var jumpAbility = _abilities.OfType<VariableJumpAbility>().FirstOrDefault();
|
var jumpAbility = _abilities.OfType<VariableJumpAbility>().FirstOrDefault();
|
||||||
var gravityAbility = _abilities.OfType<GravityAbility>().FirstOrDefault();
|
var gravityAbility = _abilities.OfType<GravityAbility>().FirstOrDefault();
|
||||||
|
|
||||||
if (jumpAbility != null && gravityAbility != null)
|
if (jumpAbility != null && gravityAbility != null)
|
||||||
{
|
{
|
||||||
gravityAbility.AscendGravity = jumpAbility.AscendGravity;
|
gravityAbility.AscendGravity = jumpAbility.AscendGravity;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
namespace Mr.BrickAdventures.scripts.components;
|
||||||
@@ -10,12 +11,12 @@ public partial class PlayerDeathComponent : Node2D
|
|||||||
[Export] public PackedScene DeathEffect { get; set; }
|
[Export] public PackedScene DeathEffect { get; set; }
|
||||||
[Export] public HealthComponent HealthComponent { get; set; }
|
[Export] public HealthComponent HealthComponent { get; set; }
|
||||||
[Export] public Vector2 EffectScale { get; set; } = new Vector2(1.5f, 1.5f);
|
[Export] public Vector2 EffectScale { get; set; } = new Vector2(1.5f, 1.5f);
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
HealthComponent.Death += OnDeath;
|
HealthComponent.Death += OnDeath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ public partial class PlayerDeathComponent : Node2D
|
|||||||
effect.GlobalPosition = GlobalPosition;
|
effect.GlobalPosition = GlobalPosition;
|
||||||
effect.Scale = EffectScale;
|
effect.Scale = EffectScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
_gameManager.RemoveLives(1);
|
_gameManager.RemoveLives(1);
|
||||||
_gameManager.ResetCurrentSessionState();
|
_gameManager.ResetCurrentSessionState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
using Mr.BrickAdventures.Autoloads;
|
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
|
||||||
|
|
||||||
namespace Mr.BrickAdventures.scripts.components;
|
|
||||||
|
|
||||||
[GlobalClass]
|
|
||||||
public partial class ScoreComponent : Node
|
|
||||||
{
|
|
||||||
private GameManager _gameManager;
|
|
||||||
private const string CoinsGroupName = "coins";
|
|
||||||
|
|
||||||
public override async void _Ready()
|
|
||||||
{
|
|
||||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
|
||||||
|
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
|
||||||
if (_gameManager == null)
|
|
||||||
{
|
|
||||||
GD.PrintErr("GameManager not found in the scene tree.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var coins = GetTree().GetNodesInGroup(CoinsGroupName);
|
|
||||||
foreach (var coin in coins)
|
|
||||||
{
|
|
||||||
var c = coin.GetNodeOrNull<CollectableComponent>("CollectableComponent");
|
|
||||||
if (c != null)
|
|
||||||
{
|
|
||||||
c.Collected += OnCollected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnCollected(float amount, CollectableType type, Node2D body)
|
|
||||||
{
|
|
||||||
if (type != CollectableType.Coin) return;
|
|
||||||
|
|
||||||
var coinAmount = (int)amount;
|
|
||||||
var currentCoins = (int)_gameManager.CurrentSessionState["coins_collected"];
|
|
||||||
_gameManager.CurrentSessionState["coins_collected"] = currentCoins + coinAmount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
uid://ccqb8kd5m0eh7
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
using Mr.BrickAdventures;
|
||||||
using Mr.BrickAdventures.Autoloads;
|
using Mr.BrickAdventures.Autoloads;
|
||||||
using Mr.BrickAdventures.scripts.interfaces;
|
using Mr.BrickAdventures.scripts.interfaces;
|
||||||
using Mr.BrickAdventures.scripts.Resources;
|
using Mr.BrickAdventures.scripts.Resources;
|
||||||
@@ -18,8 +19,8 @@ public partial class SkillUnlockerComponent : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_gameManager = GetNode<GameManager>("/root/GameManager");
|
_gameManager = GetNode<GameManager>(Constants.GameManagerPath);
|
||||||
SkillManager = GetNode<SkillManager>("/root/SkillManager");
|
SkillManager = GetNode<SkillManager>(Constants.SkillManagerPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HasEnoughCoins(int amount)
|
private bool HasEnoughCoins(int amount)
|
||||||
|
|||||||
Reference in New Issue
Block a user