Save and load map data
This commit is contained in:
@@ -94,6 +94,7 @@ public partial class Game : Node3D, IGame
|
|||||||
GameLogic.Set(AppRepo);
|
GameLogic.Set(AppRepo);
|
||||||
GameLogic.Set(GameEventDepot);
|
GameLogic.Set(GameEventDepot);
|
||||||
GameLogic.Set(Player);
|
GameLogic.Set(Player);
|
||||||
|
GameLogic.Set(Map);
|
||||||
Instantiator = new Instantiator(GetTree());
|
Instantiator = new Instantiator(GetTree());
|
||||||
RescuedItems = new RescuedItemDatabase();
|
RescuedItems = new RescuedItemDatabase();
|
||||||
|
|
||||||
@@ -137,14 +138,21 @@ public partial class Game : Node3D, IGame
|
|||||||
Luck = Player.Stats.Luck.Value
|
Luck = Player.Stats.Luck.Value
|
||||||
},
|
},
|
||||||
Inventory = Player.Inventory
|
Inventory = Player.Inventory
|
||||||
}
|
},
|
||||||
|
MapData = new MapData()
|
||||||
|
{
|
||||||
|
FloorScenes = Map.FloorScenes
|
||||||
|
},
|
||||||
|
RescuedItems = new RescuedItemDatabase() { Items = RescuedItems.Items }
|
||||||
};
|
};
|
||||||
|
|
||||||
return gameData;
|
return gameData;
|
||||||
},
|
},
|
||||||
onLoad: (chunk, data) =>
|
onLoad: (chunk, data) =>
|
||||||
{
|
{
|
||||||
|
RescuedItems = data.RescuedItems;
|
||||||
chunk.LoadChunkSaveData(data.PlayerData);
|
chunk.LoadChunkSaveData(data.PlayerData);
|
||||||
|
chunk.LoadChunkSaveData(data.MapData);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,10 @@ public partial record GameData
|
|||||||
{
|
{
|
||||||
[Save("player_data")]
|
[Save("player_data")]
|
||||||
public required PlayerData PlayerData { get; init; }
|
public required PlayerData PlayerData { get; init; }
|
||||||
|
|
||||||
|
[Save("map_data")]
|
||||||
|
public required MapData MapData { get; init; }
|
||||||
|
|
||||||
|
[Save("rescued_items")]
|
||||||
|
public required RescuedItemDatabase RescuedItems { get; init; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using Chickensoft.AutoInject;
|
using Chickensoft.AutoInject;
|
||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using GameJamDungeon;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace GameJamDungeon;
|
namespace GameJamDungeon;
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
using System.Collections.Generic;
|
using Chickensoft.Introspection;
|
||||||
|
using Chickensoft.Serialization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace GameJamDungeon;
|
namespace GameJamDungeon;
|
||||||
|
|
||||||
public class RescuedItemDatabase
|
[Meta, Id("rescued_items")]
|
||||||
|
public partial class RescuedItemDatabase
|
||||||
{
|
{
|
||||||
public List<InventoryItem> Items;
|
[Save("rescued_item_list")]
|
||||||
|
public List<InventoryItem> Items { get; init; }
|
||||||
|
|
||||||
public RescuedItemDatabase()
|
public RescuedItemDatabase()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
using Chickensoft.AutoInject;
|
using Chickensoft.AutoInject;
|
||||||
using Chickensoft.GodotNodeInterfaces;
|
using Chickensoft.GodotNodeInterfaces;
|
||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
|
using Chickensoft.SaveFileBuilder;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace GameJamDungeon;
|
namespace GameJamDungeon;
|
||||||
|
|
||||||
public interface IMap : INode3D
|
public interface IMap : INode3D, IProvide<ISaveChunk<MapData>>
|
||||||
{
|
{
|
||||||
public Godot.Collections.Array<PackedScene> Floors { get; }
|
public List<string> FloorScenes { get; }
|
||||||
|
|
||||||
public IDungeonFloor CurrentFloor { get; }
|
public IDungeonFloor CurrentFloor { get; }
|
||||||
|
|
||||||
@@ -29,13 +31,44 @@ public partial class Map : Node3D, IMap
|
|||||||
[Dependency]
|
[Dependency]
|
||||||
public IPlayer Player => this.DependOn<IPlayer>();
|
public IPlayer Player => this.DependOn<IPlayer>();
|
||||||
|
|
||||||
|
#region Save
|
||||||
|
public ISaveChunk<MapData> MapChunk { get; set; } = default!;
|
||||||
|
|
||||||
|
ISaveChunk<MapData> IProvide<ISaveChunk<MapData>>.Value() => MapChunk;
|
||||||
|
|
||||||
|
[Dependency]
|
||||||
|
public ISaveChunk<GameData> GameChunk => this.DependOn<ISaveChunk<GameData>>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public Godot.Collections.Array<PackedScene> Floors { get; set; } = default!;
|
private Godot.Collections.Array<PackedScene> _floors { get; set; } = default!;
|
||||||
|
|
||||||
|
public List<string> FloorScenes { get; private set; }
|
||||||
|
|
||||||
public IDungeonFloor CurrentFloor { get; private set; }
|
public IDungeonFloor CurrentFloor { get; private set; }
|
||||||
|
|
||||||
public void Setup()
|
public void OnResolved()
|
||||||
{
|
{
|
||||||
|
FloorScenes = new List<string>();
|
||||||
|
|
||||||
|
MapChunk = new SaveChunk<MapData>(
|
||||||
|
onSave: (chunk) => new MapData()
|
||||||
|
{
|
||||||
|
FloorScenes = FloorScenes,
|
||||||
|
},
|
||||||
|
onLoad: (chunk, data) =>
|
||||||
|
{
|
||||||
|
FloorScenes = data.FloorScenes;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
GameChunk.AddChunk(MapChunk);
|
||||||
|
|
||||||
|
this.Provide();
|
||||||
|
|
||||||
|
foreach (var floor in _floors)
|
||||||
|
FloorScenes.Add(floor.ResourcePath);
|
||||||
|
|
||||||
LoadFloor();
|
LoadFloor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,11 +88,12 @@ public partial class Map : Node3D, IMap
|
|||||||
|
|
||||||
private void LoadFloor()
|
private void LoadFloor()
|
||||||
{
|
{
|
||||||
var currentFloorScene = Floors.First();
|
var currentFloorScene = _floors.First();
|
||||||
var instantiator = new Instantiator(GetTree());
|
var instantiator = new Instantiator(GetTree());
|
||||||
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene.ResourcePath);
|
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene.ResourcePath);
|
||||||
AddChild(loadedScene);
|
AddChild(loadedScene);
|
||||||
CurrentFloor = (IDungeonFloor)loadedScene;
|
CurrentFloor = (IDungeonFloor)loadedScene;
|
||||||
Floors.Remove(currentFloorScene);
|
_floors.Remove(currentFloorScene);
|
||||||
|
FloorScenes.Remove(currentFloorScene.ResourcePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,13 @@
|
|||||||
[gd_scene load_steps=25 format=3 uid="uid://by67pn7fdsg1m"]
|
[gd_scene load_steps=6 format=3 uid="uid://by67pn7fdsg1m"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://14e8mu48ed4" path="res://src/map/Map.cs" id="1_bw70o"]
|
[ext_resource type="Script" uid="uid://14e8mu48ed4" path="res://src/map/Map.cs" id="1_bw70o"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dl6h1djc27ddl" path="res://src/map/dungeon/floors/Floor00.tscn" id="2_0m8h8"]
|
[ext_resource type="PackedScene" uid="uid://dl6h1djc27ddl" path="res://src/map/dungeon/floors/Floor00.tscn" id="2_0m8h8"]
|
||||||
[ext_resource type="PackedScene" uid="uid://bc1sp6xwe0j65" path="res://src/map/dungeon/floors/Floor01.tscn" id="2_merfv"]
|
[ext_resource type="PackedScene" uid="uid://bc1sp6xwe0j65" path="res://src/map/dungeon/floors/Floor01.tscn" id="2_merfv"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dmiqwmivkjgmq" path="res://src/map/dungeon/floors/Floor02.tscn" id="4_8y0oy"]
|
[ext_resource type="PackedScene" uid="uid://dmiqwmivkjgmq" path="res://src/map/dungeon/floors/Floor02.tscn" id="4_8y0oy"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dl1scvkp8r5sw" path="res://src/map/dungeon/floors/Floor03.tscn" id="5_uag72"]
|
[ext_resource type="PackedScene" uid="uid://dl1scvkp8r5sw" path="res://src/map/dungeon/floors/Floor03.tscn" id="5_uag72"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cikq7vuorlpbl" path="res://src/map/dungeon/floors/Floor04.tscn" id="6_1ny7u"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://t7cac7801bnk" path="res://src/map/dungeon/floors/Floor05.tscn" id="7_abpbr"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://da107mywg18x1" path="res://src/map/dungeon/floors/Floor06.tscn" id="8_caf7v"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cgtqjgh1f5fqi" path="res://src/map/dungeon/floors/Floor07.tscn" id="9_y74f3"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dg20ovvj2m2lp" path="res://src/map/dungeon/floors/Floor08.tscn" id="10_dbqu2"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://b5jk743ng6fqg" path="res://src/map/dungeon/floors/Floor09.tscn" id="11_xcm54"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://g28xmp6cn16h" path="res://src/map/dungeon/floors/Floor10.tscn" id="12_caf7v"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dl2x3l7a3an65" path="res://src/map/dungeon/floors/Floor11.tscn" id="13_3vg2e"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://drvjw06wbi2qh" path="res://src/map/dungeon/floors/Floor12.tscn" id="14_tx34j"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://fellg2owwe64" path="res://src/map/dungeon/floors/Floor13.tscn" id="15_8npfy"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://vhqwff12y7wn" path="res://src/map/dungeon/floors/Floor14.tscn" id="16_pids3"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://h8tc1uohuqx2" path="res://src/map/dungeon/floors/Floor15.tscn" id="17_u3fsa"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cyfp0p38w2yfr" path="res://src/map/dungeon/floors/Floor16.tscn" id="18_io2ww"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dnrbqkv438tjx" path="res://src/map/dungeon/floors/Floor17.tscn" id="19_rb6u5"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cgoogenmugoti" path="res://src/map/dungeon/floors/Floor18.tscn" id="20_31a0u"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://33lvido1dkbu" path="res://src/map/dungeon/floors/Floor19.tscn" id="21_sbsee"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://w2peiubnalof" path="res://src/map/dungeon/floors/Floor20.tscn" id="22_qamtw"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://ds5dbs3wdko8j" path="res://src/map/dungeon/floors/Floor21.tscn" id="23_j54h1"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://fvemjkxfoxlw" path="res://src/map/dungeon/floors/Floor22.tscn" id="24_41t83"]
|
|
||||||
|
|
||||||
[node name="Map" type="Node3D"]
|
[node name="Map" type="Node3D"]
|
||||||
script = ExtResource("1_bw70o")
|
script = ExtResource("1_bw70o")
|
||||||
Floors = Array[PackedScene]([ExtResource("2_0m8h8"), ExtResource("2_merfv"), ExtResource("4_8y0oy"), ExtResource("5_uag72"), ExtResource("6_1ny7u"), ExtResource("7_abpbr"), ExtResource("8_caf7v"), ExtResource("9_y74f3"), ExtResource("10_dbqu2"), ExtResource("11_xcm54"), ExtResource("12_caf7v"), ExtResource("13_3vg2e"), ExtResource("14_tx34j"), ExtResource("15_8npfy"), ExtResource("16_pids3"), ExtResource("17_u3fsa"), ExtResource("18_io2ww"), ExtResource("19_rb6u5"), ExtResource("20_31a0u"), ExtResource("21_sbsee"), ExtResource("22_qamtw"), ExtResource("23_j54h1"), ExtResource("24_41t83")])
|
_floors = Array[PackedScene]([ExtResource("2_0m8h8"), ExtResource("2_merfv"), ExtResource("4_8y0oy"), ExtResource("5_uag72")])
|
||||||
|
|
||||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace GameJamDungeon;
|
namespace GameJamDungeon;
|
||||||
|
|
||||||
@@ -12,3 +13,10 @@ public partial record PlayerData
|
|||||||
[Save("player_inventory")]
|
[Save("player_inventory")]
|
||||||
public required Inventory Inventory { get; init; }
|
public required Inventory Inventory { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Meta, Id("map_data")]
|
||||||
|
public partial record MapData
|
||||||
|
{
|
||||||
|
[Save("floor_list")]
|
||||||
|
public required List<string> FloorScenes { get; init; }
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user