2023-07-24 12:40:28 -07:00
|
|
|
using Godot;
|
2023-08-12 15:01:22 -07:00
|
|
|
using SupaLidlGame.Utils;
|
2023-07-24 12:40:28 -07:00
|
|
|
|
|
|
|
namespace SupaLidlGame.State.Global;
|
|
|
|
|
|
|
|
public partial class GlobalState : Node
|
|
|
|
{
|
2023-08-05 23:50:08 -07:00
|
|
|
[Export]
|
2023-12-09 16:26:44 -08:00
|
|
|
public Progression Progression { get; set; }
|
2023-08-05 23:50:08 -07:00
|
|
|
|
|
|
|
[Export]
|
2023-12-09 16:26:44 -08:00
|
|
|
public MapState MapState { get; set; }
|
2023-07-25 03:47:31 -07:00
|
|
|
|
2023-08-07 02:38:51 -07:00
|
|
|
[Export]
|
2023-12-09 16:26:44 -08:00
|
|
|
public Stats Stats { get; set; }
|
2023-08-07 02:38:51 -07:00
|
|
|
|
2024-06-04 22:12:01 -07:00
|
|
|
public static GlobalState Instance { get; private set; }
|
|
|
|
|
2023-08-29 22:24:20 -07:00
|
|
|
[Export]
|
2023-12-09 16:26:44 -08:00
|
|
|
public GameSettings Settings { get; set; }
|
2023-08-29 22:24:20 -07:00
|
|
|
|
2023-07-25 03:47:31 -07:00
|
|
|
[Signal]
|
|
|
|
public delegate void SummonBossEventHandler(string bossName);
|
2023-08-07 02:38:51 -07:00
|
|
|
|
2023-12-09 16:26:44 -08:00
|
|
|
public GlobalState()
|
|
|
|
{
|
|
|
|
Progression = new();
|
|
|
|
MapState = new();
|
|
|
|
Stats = new();
|
|
|
|
Settings = new();
|
|
|
|
}
|
|
|
|
|
2023-08-17 00:13:24 -07:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
2024-06-04 22:12:01 -07:00
|
|
|
if (Instance != null)
|
|
|
|
{
|
|
|
|
throw new MultipleSingletonsException();
|
|
|
|
}
|
|
|
|
|
|
|
|
Instance = this;
|
|
|
|
|
2023-08-17 00:13:24 -07:00
|
|
|
ProcessMode = ProcessModeEnum.Always;
|
2023-08-29 22:24:20 -07:00
|
|
|
LoadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Notification(int what)
|
|
|
|
{
|
2023-12-13 18:25:32 -08:00
|
|
|
//if (what == NotificationWMCloseRequest)
|
|
|
|
//{
|
|
|
|
// // TODO: quit prompt
|
|
|
|
// GetTree().Root
|
|
|
|
// .PropagateNotification((int)NotificationWMCloseRequest);
|
|
|
|
// SaveSettings();
|
|
|
|
//}
|
2023-08-29 22:24:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void LoadSettings()
|
|
|
|
{
|
|
|
|
if (ResourceLoader.Exists("user://settings.tres"))
|
|
|
|
{
|
|
|
|
Settings = ResourceLoader.Load<GameSettings>("user://settings.tres");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Settings = new GameSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SaveSettings()
|
|
|
|
{
|
|
|
|
ResourceSaver.Save(Settings, "user://settings.tres");
|
2023-08-17 00:13:24 -07:00
|
|
|
}
|
2023-08-12 15:01:22 -07:00
|
|
|
|
|
|
|
public void ImportFromSave(Save save)
|
|
|
|
{
|
|
|
|
Progression = save.Progression;
|
|
|
|
MapState = save.MapState;
|
|
|
|
Stats = save.Stats;
|
2024-10-05 15:32:26 -07:00
|
|
|
|
|
|
|
var inventory = World.Instance.CurrentPlayer.Inventory;
|
|
|
|
inventory.Items = Stats.Items;
|
|
|
|
|
|
|
|
for (int i = 0; i < Stats.HotbarToItemIndexMap.Count; i++)
|
|
|
|
{
|
|
|
|
int itemIndex = Stats.HotbarToItemIndexMap[i];
|
|
|
|
|
|
|
|
if (itemIndex >= 0)
|
|
|
|
{
|
|
|
|
inventory.SetHotbarIndexToItemIndex(i, itemIndex);
|
|
|
|
}
|
|
|
|
}
|
2023-08-12 15:01:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ExportToSave(Save save)
|
|
|
|
{
|
|
|
|
save.Progression = Progression;
|
|
|
|
save.MapState = MapState;
|
|
|
|
save.Stats = Stats;
|
2024-10-05 15:32:26 -07:00
|
|
|
|
|
|
|
var inventory = World.Instance.CurrentPlayer.Inventory;
|
|
|
|
Stats.Items = inventory.Items;
|
|
|
|
Stats.HotbarToItemIndexMap = inventory.HotbarToItemIndexMap;
|
2023-08-12 15:01:22 -07:00
|
|
|
}
|
2023-07-24 12:40:28 -07:00
|
|
|
}
|