game save class
parent
f3452f7d3e
commit
1b80fa54a7
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using SupaLidlGame.Utils;
|
||||
|
||||
namespace SupaLidlGame.State.Global;
|
||||
|
||||
|
@ -17,4 +18,18 @@ public partial class GlobalState : Node
|
|||
public delegate void SummonBossEventHandler(string bossName);
|
||||
|
||||
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.Collections;
|
||||
|
||||
namespace SupaLidlGame.State.Global;
|
||||
|
||||
public partial class MapState : Resource
|
||||
{
|
||||
[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);
|
||||
|
||||
// TODO: create a single save resource file
|
||||
ResourceSaver.Save(GlobalState.Progression, "user://progression.tres");
|
||||
ResourceSaver.Save(GlobalState.MapState, "user://map-state.tres");
|
||||
ResourceSaver.Save(GlobalState.Stats, "user://stats.tres");
|
||||
var save = GetSave();
|
||||
GlobalState.ExportToSave(save);
|
||||
ResourceSaver.Save(save, "user://save.tres");
|
||||
}
|
||||
|
||||
private Save GetSave()
|
||||
{
|
||||
if (ResourceLoader.Exists("user://save.tres"))
|
||||
{
|
||||
return ResourceLoader.Load<Save>("user://save.tres");
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Save();
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadGame()
|
||||
{
|
||||
var prog = ResourceLoader.Load<Progression>("user://progression.tres");
|
||||
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();
|
||||
GlobalState.ImportFromSave(GetSave());
|
||||
|
||||
// load the player scene
|
||||
// TODO: implement
|
||||
|
|
Loading…
Reference in New Issue