Move save logic out of Game
This commit is contained in:
14
Ma.sln
14
Ma.sln
@@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.11.35222.181
|
VisualStudioVersion = 17.11.35222.181
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Zennysoft.Game.Ma", "Zennysoft.Game.Ma\Zennysoft.Game.Ma.csproj", "{B685AA99-B971-46A7-A708-00546BA0EF55}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Zennysoft.Game.Ma", "Zennysoft.Game.Ma\Ma.csproj", "{B685AA99-B971-46A7-A708-00546BA0EF55}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zennysoft.Game.Ma.Implementation", "Zennysoft.Game.Ma.Implementation\Zennysoft.Game.Ma.Implementation.csproj", "{3C934960-1375-4971-BF3F-C21F5241573A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Zennysoft.Game.Ma.Implementation", "Zennysoft.Game.Ma.Implementation\Zennysoft.Game.Ma.Implementation.csproj", "{3C934960-1375-4971-BF3F-C21F5241573A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E4C0167B-02AB-49E0-B36D-30D0A2479C25}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E4C0167B-02AB-49E0-B36D-30D0A2479C25}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.editorconfig = .editorconfig
|
.editorconfig = .editorconfig
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zennysoft.Game.Abstractions", "Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj", "{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -36,6 +38,14 @@ Global
|
|||||||
{3C934960-1375-4971-BF3F-C21F5241573A}.ExportRelease|Any CPU.Build.0 = Release|Any CPU
|
{3C934960-1375-4971-BF3F-C21F5241573A}.ExportRelease|Any CPU.Build.0 = Release|Any CPU
|
||||||
{3C934960-1375-4971-BF3F-C21F5241573A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3C934960-1375-4971-BF3F-C21F5241573A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{3C934960-1375-4971-BF3F-C21F5241573A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3C934960-1375-4971-BF3F-C21F5241573A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.ExportDebug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.ExportRelease|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.ExportRelease|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EB9A8B79-82E1-4254-B4FB-7F4BCB57BDBF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
10
Zennysoft.Game.Abstractions/Save/ISaveFileManager.cs
Normal file
10
Zennysoft.Game.Abstractions/Save/ISaveFileManager.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Zennysoft.Game.Abstractions;
|
||||||
|
|
||||||
|
public interface ISaveFileManager<T>
|
||||||
|
{
|
||||||
|
public Task WriteToFile(T gameData);
|
||||||
|
|
||||||
|
public Task<T> ReadFromFile();
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Zennysoft.Game.Ma.Implementation;
|
|
||||||
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,36 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
|
public enum WeaponTag
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
SelfDamage,
|
||||||
|
IgnoreAffinity,
|
||||||
|
Knockback,
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(WeaponTag))]
|
||||||
|
public partial class WeaponTagEnumContext : JsonSerializerContext;
|
||||||
|
|
||||||
|
public enum ItemTag
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
BreaksOnChange
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(ItemTag))]
|
||||||
|
public partial class ItemTagEnumContext : JsonSerializerContext;
|
||||||
|
|
||||||
|
public enum AccessoryTag
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
HalfVTConsumption,
|
||||||
|
StatusEffectImmunity
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(AccessoryTag))]
|
||||||
|
public partial class AccessoryTagEnumContext : JsonSerializerContext;
|
||||||
|
|
||||||
public enum ThrowableItemTag
|
public enum ThrowableItemTag
|
||||||
{
|
{
|
||||||
@@ -43,3 +73,16 @@ public enum BoxItemTag
|
|||||||
|
|
||||||
[JsonSerializable(typeof(BoxItemTag))]
|
[JsonSerializable(typeof(BoxItemTag))]
|
||||||
public partial class BoxItemTagEnumContext : JsonSerializerContext;
|
public partial class BoxItemTagEnumContext : JsonSerializerContext;
|
||||||
|
|
||||||
|
public enum ElementType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Aeolic,
|
||||||
|
Telluric,
|
||||||
|
Hydric,
|
||||||
|
Igneous,
|
||||||
|
Ferrum
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSerializable(typeof(ElementType))]
|
||||||
|
public partial class ElementTypeEnumContext : JsonSerializerContext;
|
||||||
56
Zennysoft.Game.Ma.Implementation/Save/SaveFileManager.cs
Normal file
56
Zennysoft.Game.Ma.Implementation/Save/SaveFileManager.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using Chickensoft.Collections;
|
||||||
|
using Chickensoft.Serialization.Godot;
|
||||||
|
using Chickensoft.Serialization;
|
||||||
|
using Godot;
|
||||||
|
using System.IO.Abstractions;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization.Metadata;
|
||||||
|
using Zennysoft.Game.Abstractions;
|
||||||
|
|
||||||
|
namespace Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
|
public class SaveFileManager<T> : ISaveFileManager<T>
|
||||||
|
{
|
||||||
|
private readonly IFileSystem _fileSystem;
|
||||||
|
public const string SAVE_FILE_NAME = "game.json";
|
||||||
|
public JsonSerializerOptions JsonOptions { get; set; } = default!;
|
||||||
|
|
||||||
|
public string SaveFilePath { get; set; } = default!;
|
||||||
|
|
||||||
|
public SaveFileManager(IFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
_fileSystem = fileSystem;
|
||||||
|
SaveFilePath = _fileSystem.Path.Join(OS.GetUserDataDir(), SAVE_FILE_NAME);
|
||||||
|
|
||||||
|
var resolver = new SerializableTypeResolver();
|
||||||
|
GodotSerialization.Setup();
|
||||||
|
Serializer.AddConverter(new Texture2DConverter());
|
||||||
|
|
||||||
|
var upgradeDependencies = new Blackboard();
|
||||||
|
|
||||||
|
JsonOptions = new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
Converters = {
|
||||||
|
new SerializableTypeConverter(upgradeDependencies)
|
||||||
|
},
|
||||||
|
TypeInfoResolver = JsonTypeInfoResolver.Combine(resolver, WeaponTagEnumContext.Default, ItemTagEnumContext.Default, ElementTypeEnumContext.Default, AccessoryTagEnumContext.Default, ThrowableItemTagEnumContext.Default, UsableItemTagEnumContext.Default, BoxItemTagEnumContext.Default),
|
||||||
|
WriteIndented = true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<T> ReadFromFile()
|
||||||
|
{
|
||||||
|
if (!_fileSystem.File.Exists(SaveFilePath))
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
|
||||||
|
var json = await _fileSystem.File.ReadAllTextAsync(SaveFilePath);
|
||||||
|
return JsonSerializer.Deserialize<T>(json, JsonOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task WriteToFile(T gameData)
|
||||||
|
{
|
||||||
|
var json = JsonSerializer.Serialize(gameData, JsonOptions);
|
||||||
|
await _fileSystem.File.WriteAllTextAsync(SaveFilePath, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System;
|
|
||||||
|
|
||||||
/// <summary>Basis JSON converter.</summary>
|
/// <summary>Basis JSON converter.</summary>
|
||||||
public class Texture2DConverter : JsonConverter<Texture2D>
|
public class Texture2DConverter : JsonConverter<Texture2D>
|
||||||
@@ -1,9 +1,26 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Chickensoft.GodotNodeInterfaces" Version="2.4.0" />
|
||||||
|
<PackageReference Include="Chickensoft.Introspection" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Chickensoft.Introspection.Generator" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />
|
||||||
|
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.5.0" />
|
||||||
|
<PackageReference Include="System.IO.Abstractions" Version="21.2.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Enums\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
<!-- Use NativeAOT. -->
|
<!-- Use NativeAOT. -->
|
||||||
<PublishAot>true</PublishAot>
|
<PublishAot>true</PublishAot>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="src\items\weapons\models\**" />
|
||||||
|
<EmbeddedResource Remove="src\items\weapons\models\**" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- Root the assemblies to avoid trimming. -->
|
<!-- Root the assemblies to avoid trimming. -->
|
||||||
<TrimmerRootAssembly Include="GodotSharp" />
|
<TrimmerRootAssembly Include="GodotSharp" />
|
||||||
@@ -20,17 +24,21 @@
|
|||||||
<PackageReference Include="Chickensoft.SaveFileBuilder" Version="1.1.0" />
|
<PackageReference Include="Chickensoft.SaveFileBuilder" Version="1.1.0" />
|
||||||
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />
|
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />
|
||||||
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.5.0" />
|
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.5.0" />
|
||||||
|
<PackageReference Include="SimpleInjector" Version="5.5.0" />
|
||||||
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
<PackageReference Include="SSH.NET" Version="2024.2.0" />
|
||||||
<PackageReference Include="System.IO.Abstractions" Version="21.2.1" />
|
<PackageReference Include="System.IO.Abstractions" Version="21.2.1" />
|
||||||
<PackageReference Include="Zeroconf" Version="3.7.16" />
|
<PackageReference Include="Zeroconf" Version="3.7.16" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="src\items\weapons\models\" />
|
|
||||||
<Folder Include="src\ui\dialogue\" />
|
<Folder Include="src\ui\dialogue\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include=".editorconfig" />
|
<None Include=".editorconfig" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj" />
|
||||||
|
<ProjectReference Include="..\Zennysoft.Game.Ma.Implementation\Zennysoft.Game.Ma.Implementation.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Update="Godot.SourceGenerators" Version="4.4.0-dev.2" />
|
<PackageReference Update="Godot.SourceGenerators" Version="4.4.0-dev.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -6,14 +6,8 @@ using Godot;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This entry-point file is responsible for determining if we should run tests.
|
|
||||||
//
|
|
||||||
// If you want to edit your game's main entry-point, please see Game.tscn and
|
|
||||||
// Game.cs instead.
|
|
||||||
|
|
||||||
public partial class Main : Node
|
public partial class Main : Node
|
||||||
{
|
{
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
// If we don't need to run tests, we can just switch to the game scene.
|
// If we don't need to run tests, we can just switch to the game scene.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Chickensoft.Collections;
|
|||||||
using Chickensoft.GodotNodeInterfaces;
|
using Chickensoft.GodotNodeInterfaces;
|
||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Chickensoft.Collections;
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
|
||||||
|
|
||||||
public enum WeaponTag
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
SelfDamage,
|
|
||||||
IgnoreAffinity,
|
|
||||||
Knockback,
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSerializable(typeof(WeaponTag))]
|
|
||||||
public partial class WeaponTagEnumContext : JsonSerializerContext;
|
|
||||||
|
|
||||||
public enum ItemTag
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
BreaksOnChange
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSerializable(typeof(ItemTag))]
|
|
||||||
public partial class ItemTagEnumContext : JsonSerializerContext;
|
|
||||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Zennysoft.Game.Ma.src.enemy;
|
using Zennysoft.Game.Ma.src.enemy;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Zennysoft.Game.Ma.src.enemy;
|
using Zennysoft.Game.Ma.src.enemy;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Chickensoft.Introspection;
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Chickensoft.Introspection;
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Chickensoft.AutoInject;
|
using Chickensoft.AutoInject;
|
||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Zennysoft.Game.Ma.src.enemy;
|
using Zennysoft.Game.Ma.src.enemy;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Chickensoft.Introspection;
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
|
||||||
|
|
||||||
public enum ElementType
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Aeolic,
|
|
||||||
Telluric,
|
|
||||||
Hydric,
|
|
||||||
Igneous,
|
|
||||||
Ferrum
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSerializable(typeof(ElementType))]
|
|
||||||
public partial class ElementTypeEnumContext : JsonSerializerContext;
|
|
||||||
@@ -14,6 +14,10 @@ using System.IO.Abstractions;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization.Metadata;
|
using System.Text.Json.Serialization.Metadata;
|
||||||
using static Zennysoft.Game.Ma.GameLogic.State;
|
using static Zennysoft.Game.Ma.GameLogic.State;
|
||||||
|
using Zennysoft.Game.Abstractions;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
[Meta(typeof(IAutoNode))]
|
[Meta(typeof(IAutoNode))]
|
||||||
public partial class Game : Node3D, IGame
|
public partial class Game : Node3D, IGame
|
||||||
@@ -28,6 +32,8 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
IGameEventDepot IProvide<IGameEventDepot>.Value() => GameEventDepot;
|
IGameEventDepot IProvide<IGameEventDepot>.Value() => GameEventDepot;
|
||||||
|
|
||||||
|
private static SimpleInjector.Container _container;
|
||||||
|
|
||||||
public IInstantiator Instantiator { get; set; } = default!;
|
public IInstantiator Instantiator { get; set; } = default!;
|
||||||
|
|
||||||
public IGameLogic GameLogic { get; set; } = default!;
|
public IGameLogic GameLogic { get; set; } = default!;
|
||||||
@@ -64,12 +70,6 @@ public partial class Game : Node3D, IGame
|
|||||||
#region Save
|
#region Save
|
||||||
public JsonSerializerOptions JsonOptions { get; set; } = default!;
|
public JsonSerializerOptions JsonOptions { get; set; } = default!;
|
||||||
|
|
||||||
public const string SAVE_FILE_NAME = "game.json";
|
|
||||||
|
|
||||||
public IFileSystem FileSystem { get; set; } = default!;
|
|
||||||
|
|
||||||
public string SaveFilePath { get; set; } = default!;
|
|
||||||
|
|
||||||
public ISaveFile<GameData> SaveFile { get; set; } = default!;
|
public ISaveFile<GameData> SaveFile { get; set; } = default!;
|
||||||
|
|
||||||
public ISaveChunk<GameData> GameChunk { get; set; } = default!;
|
public ISaveChunk<GameData> GameChunk { get; set; } = default!;
|
||||||
@@ -86,9 +86,10 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
FileSystem = new FileSystem();
|
_container = new SimpleInjector.Container();
|
||||||
|
_container.Register<IFileSystem, FileSystem>();
|
||||||
SaveFilePath = FileSystem.Path.Join(OS.GetUserDataDir(), SAVE_FILE_NAME);
|
_container.Register<ISaveFileManager<GameData>, SaveFileManager<GameData>>();
|
||||||
|
_container.Verify();
|
||||||
|
|
||||||
GameRepo = new GameRepo();
|
GameRepo = new GameRepo();
|
||||||
GameLogic = new GameLogic();
|
GameLogic = new GameLogic();
|
||||||
@@ -101,21 +102,6 @@ public partial class Game : Node3D, IGame
|
|||||||
Instantiator = new Instantiator(GetTree());
|
Instantiator = new Instantiator(GetTree());
|
||||||
RescuedItems = new RescuedItemDatabase();
|
RescuedItems = new RescuedItemDatabase();
|
||||||
|
|
||||||
var resolver = new SerializableTypeResolver();
|
|
||||||
GodotSerialization.Setup();
|
|
||||||
Serializer.AddConverter(new Texture2DConverter());
|
|
||||||
|
|
||||||
var upgradeDependencies = new Blackboard();
|
|
||||||
|
|
||||||
JsonOptions = new JsonSerializerOptions
|
|
||||||
{
|
|
||||||
Converters = {
|
|
||||||
new SerializableTypeConverter(upgradeDependencies)
|
|
||||||
},
|
|
||||||
TypeInfoResolver = JsonTypeInfoResolver.Combine(resolver, WeaponTagEnumContext.Default, ItemTagEnumContext.Default, ElementTypeEnumContext.Default, AccessoryTagEnumContext.Default, ThrowableItemTagEnumContext.Default, UsableItemTagEnumContext.Default, BoxItemTagEnumContext.Default),
|
|
||||||
WriteIndented = true
|
|
||||||
};
|
|
||||||
|
|
||||||
GameChunk = new SaveChunk<GameData>(
|
GameChunk = new SaveChunk<GameData>(
|
||||||
(chunk) =>
|
(chunk) =>
|
||||||
{
|
{
|
||||||
@@ -162,25 +148,23 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
public void OnResolved()
|
public void OnResolved()
|
||||||
{
|
{
|
||||||
|
var saveFileManager = _container.GetInstance<ISaveFileManager<GameData>>();
|
||||||
SaveFile = new SaveFile<GameData>(
|
SaveFile = new SaveFile<GameData>(
|
||||||
root: GameChunk,
|
root: GameChunk,
|
||||||
onSave: async (GameData data) =>
|
onSave: saveFileManager.WriteToFile,
|
||||||
{
|
|
||||||
// Save the game data to disk.
|
|
||||||
var json = JsonSerializer.Serialize(data, JsonOptions);
|
|
||||||
await FileSystem.File.WriteAllTextAsync(SaveFilePath, json);
|
|
||||||
},
|
|
||||||
onLoad: async () =>
|
onLoad: async () =>
|
||||||
{
|
{
|
||||||
// Load the game data from disk.
|
try
|
||||||
if (!FileSystem.File.Exists(SaveFilePath))
|
|
||||||
{
|
{
|
||||||
GD.Print("No save file to load");
|
var gameData = await saveFileManager.ReadFromFile();
|
||||||
return null;
|
return gameData;
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
GD.Print("No save file found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = await FileSystem.File.ReadAllTextAsync(SaveFilePath);
|
return null;
|
||||||
return JsonSerializer.Deserialize<GameData>(json, JsonOptions);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma.src.items;
|
namespace Zennysoft.Game.Ma.src.items;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
using Godot;
|
using Godot;
|
||||||
using System.Text.Json.Serialization;
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
@@ -32,13 +32,4 @@ public partial class AccessoryStats : InventoryItemStats
|
|||||||
[Export]
|
[Export]
|
||||||
[Save("accessory_tag")]
|
[Save("accessory_tag")]
|
||||||
public AccessoryTag AccessoryTag { get; set; } = AccessoryTag.None;
|
public AccessoryTag AccessoryTag { get; set; } = AccessoryTag.None;
|
||||||
}
|
}
|
||||||
public enum AccessoryTag
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
HalfVTConsumption,
|
|
||||||
StatusEffectImmunity
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSerializable(typeof(AccessoryTag))]
|
|
||||||
public partial class AccessoryTagEnumContext : JsonSerializerContext;
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Zennysoft.Game.Ma.src.items;
|
using Zennysoft.Game.Ma.src.items;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.Serialization;
|
using Chickensoft.Serialization;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Chickensoft.Collections;
|
using Chickensoft.Collections;
|
||||||
using Chickensoft.SaveFileBuilder;
|
using Chickensoft.SaveFileBuilder;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Godot;
|
|||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
namespace Zennysoft.Game.Ma;
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Zennysoft.Game.Ma;
|
using Zennysoft.Game.Ma.Implementation;
|
||||||
|
|
||||||
|
namespace Zennysoft.Game.Ma;
|
||||||
|
|
||||||
public interface IHasPrimaryAttack
|
public interface IHasPrimaryAttack
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user