game save class
parent
f3452f7d3e
commit
1b80fa54a7
|
@ -1,4 +1,5 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using SupaLidlGame.Utils;
|
||||||
|
|
||||||
namespace SupaLidlGame.State.Global;
|
namespace SupaLidlGame.State.Global;
|
||||||
|
|
||||||
|
@ -17,4 +18,18 @@ public partial class GlobalState : Node
|
||||||
public delegate void SummonBossEventHandler(string bossName);
|
public delegate void SummonBossEventHandler(string bossName);
|
||||||
|
|
||||||
public void Print(string str) => GD.Print(str);
|
public void Print(string str) => GD.Print(str);
|
||||||
|
|
||||||
|
public void ImportFromSave(Save save)
|
||||||
|
{
|
||||||
|
Progression = save.Progression;
|
||||||
|
MapState = save.MapState;
|
||||||
|
Stats = save.Stats;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExportToSave(Save save)
|
||||||
|
{
|
||||||
|
save.Progression = Progression;
|
||||||
|
save.MapState = MapState;
|
||||||
|
save.Stats = Stats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
|
|
||||||
|
namespace SupaLidlGame.State.Global;
|
||||||
|
|
||||||
public partial class MapState : Resource
|
public partial class MapState : Resource
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace SupaLidlGame.Utils;
|
||||||
|
|
||||||
|
public partial class Save : Resource
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public State.Global.Progression Progression { get; set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public State.Global.MapState MapState { get; set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public State.Global.Stats Stats { get; set; }
|
||||||
|
|
||||||
|
public Save()
|
||||||
|
{
|
||||||
|
Progression = new();
|
||||||
|
MapState = new();
|
||||||
|
Stats = new();
|
||||||
|
}
|
||||||
|
}
|
|
@ -282,21 +282,26 @@ public partial class World : Node
|
||||||
{
|
{
|
||||||
SetSpawn(CurrentPlayer.GlobalPosition);
|
SetSpawn(CurrentPlayer.GlobalPosition);
|
||||||
|
|
||||||
// TODO: create a single save resource file
|
var save = GetSave();
|
||||||
ResourceSaver.Save(GlobalState.Progression, "user://progression.tres");
|
GlobalState.ExportToSave(save);
|
||||||
ResourceSaver.Save(GlobalState.MapState, "user://map-state.tres");
|
ResourceSaver.Save(save, "user://save.tres");
|
||||||
ResourceSaver.Save(GlobalState.Stats, "user://stats.tres");
|
}
|
||||||
|
|
||||||
|
private Save GetSave()
|
||||||
|
{
|
||||||
|
if (ResourceLoader.Exists("user://save.tres"))
|
||||||
|
{
|
||||||
|
return ResourceLoader.Load<Save>("user://save.tres");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadGame()
|
public void LoadGame()
|
||||||
{
|
{
|
||||||
var prog = ResourceLoader.Load<Progression>("user://progression.tres");
|
GlobalState.ImportFromSave(GetSave());
|
||||||
var mapState = ResourceLoader.Load<MapState>("user://map-state.tres");
|
|
||||||
var stats = ResourceLoader.Load<Stats>("user://stats.tres");
|
|
||||||
|
|
||||||
GlobalState.Progression = prog ?? new Progression();
|
|
||||||
GlobalState.MapState = mapState ?? new MapState();
|
|
||||||
GlobalState.Stats = stats ?? new Stats();
|
|
||||||
|
|
||||||
// load the player scene
|
// load the player scene
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
|
|
Loading…
Reference in New Issue