Move save logic out of Game
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma.src.items;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using Godot;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using System.Text.Json;
|
||||
using System;
|
||||
|
||||
/// <summary>Basis JSON converter.</summary>
|
||||
public class Texture2DConverter : JsonConverter<Texture2D>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeToConvert == typeof(Texture2D);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Texture2D Read(
|
||||
ref Utf8JsonReader reader,
|
||||
Type typeToConvert,
|
||||
JsonSerializerOptions options)
|
||||
{
|
||||
var texture2D = new Texture2D();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
return texture2D;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyName = reader.GetString();
|
||||
reader.Read();
|
||||
|
||||
switch (propertyName)
|
||||
{
|
||||
case "resource_path":
|
||||
var resourcePath = JsonSerializer.Deserialize<string>(ref reader, options);
|
||||
texture2D = GD.Load<Texture2D>(resourcePath);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonException("Unexpected end when reading Texture2D.");
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(
|
||||
Utf8JsonWriter writer,
|
||||
Texture2D value,
|
||||
JsonSerializerOptions options
|
||||
)
|
||||
{
|
||||
var resolver = options.TypeInfoResolver;
|
||||
var resourcePathType = resolver!.GetTypeInfo(typeof(string), options)!;
|
||||
|
||||
writer.WriteStartObject();
|
||||
writer.WritePropertyName("resource_path");
|
||||
JsonSerializer.Serialize(writer, value.ResourcePath, resourcePathType);
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using System.Text.Json.Serialization;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -32,13 +32,4 @@ public partial class AccessoryStats : InventoryItemStats
|
||||
[Export]
|
||||
[Save("accessory_tag")]
|
||||
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 Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public enum ThrowableItemTag
|
||||
{
|
||||
None,
|
||||
LowerTargetTo1HP,
|
||||
CanChangeAffinity,
|
||||
TeleportToRandomLocation,
|
||||
WarpToExitIfFound
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(ThrowableItemTag))]
|
||||
public partial class ThrowableItemTagEnumContext : JsonSerializerContext;
|
||||
|
||||
public enum UsableItemTag
|
||||
{
|
||||
None,
|
||||
DoubleEXP,
|
||||
IdentifyAllItemsCostHP,
|
||||
BriefImmunity,
|
||||
SwapHPAndVT,
|
||||
TeleportAllEnemiesToRoom,
|
||||
TurnAllEnemiesIntoHealingItem,
|
||||
KillHalfEnemiesInRoom,
|
||||
AbsorbHPFromAllEnemiesInRoom,
|
||||
HealsAllInRoomToMaxHP,
|
||||
DealElementalDamageToAllEnemiesInRoom,
|
||||
RaiseCurrentWeaponAttack,
|
||||
RaiseCurrentDefenseArmor,
|
||||
RaiseLevel,
|
||||
RandomEffect,
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(UsableItemTag))]
|
||||
public partial class UsableItemTagEnumContext : JsonSerializerContext;
|
||||
|
||||
public enum BoxItemTag
|
||||
{
|
||||
RandomNewItem,
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(BoxItemTag))]
|
||||
public partial class BoxItemTagEnumContext : JsonSerializerContext;
|
||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Zennysoft.Game.Ma.src.items;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user