Fix texture stuff
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public class AppRepo : IAppRepo
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IAppLogic : ILogicBlock<AppLogic.State>;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
18
Zennysoft.Game.Ma.Implementation/Game/GameData.cs
Normal file
18
Zennysoft.Game.Ma.Implementation/Game/GameData.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Zennysoft.Game.Ma;
|
||||
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
[Meta, Id("game_data")]
|
||||
public partial record GameData
|
||||
{
|
||||
[Save("player_data")]
|
||||
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,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IGameLogic : ILogicBlock<GameLogic.State>;
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
using Chickensoft.Collections;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IGameRepo : IDisposable
|
||||
{
|
||||
@@ -18,7 +17,7 @@ public interface IGameRepo : IDisposable
|
||||
|
||||
event Action? DoubleExpTimeEnd;
|
||||
|
||||
event Action<IInventoryItem>? RemoveItemFromInventoryEvent;
|
||||
event Action<InventoryItem>? RemoveItemFromInventoryEvent;
|
||||
|
||||
void Pause();
|
||||
|
||||
@@ -34,7 +33,7 @@ public interface IGameRepo : IDisposable
|
||||
|
||||
public void AnnounceMessageInInventory(string message);
|
||||
|
||||
public void RemoveItemFromInventory(IInventoryItem item);
|
||||
public void RemoveItemFromInventory(InventoryItem item);
|
||||
|
||||
public void CloseInventory();
|
||||
|
||||
@@ -51,7 +50,7 @@ public class GameRepo : IGameRepo
|
||||
public event Action<string>? AnnounceMessageInInventoryEvent;
|
||||
public event Action<int>? DoubleExpTimeStart;
|
||||
public event Action? DoubleExpTimeEnd;
|
||||
public event Action<IInventoryItem>? RemoveItemFromInventoryEvent;
|
||||
public event Action<InventoryItem>? RemoveItemFromInventoryEvent;
|
||||
|
||||
public IAutoProp<bool> IsPaused => _isPaused;
|
||||
private readonly AutoProp<bool> _isPaused;
|
||||
@@ -101,7 +100,7 @@ public class GameRepo : IGameRepo
|
||||
AnnounceMessageInInventoryEvent?.Invoke(message);
|
||||
}
|
||||
|
||||
public void RemoveItemFromInventory(IInventoryItem item)
|
||||
public void RemoveItemFromInventory(InventoryItem item)
|
||||
{
|
||||
RemoveItemFromInventoryEvent?.Invoke(item);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class GameLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
12
Zennysoft.Game.Ma.Implementation/Item/IInventory.cs
Normal file
12
Zennysoft.Game.Ma.Implementation/Item/IInventory.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IInventory
|
||||
{
|
||||
public List<InventoryItem> Items { get; }
|
||||
|
||||
public bool TryAdd(InventoryItem inventoryItem);
|
||||
|
||||
public void Remove(InventoryItem inventoryItem);
|
||||
|
||||
public void Sort();
|
||||
}
|
||||
24
Zennysoft.Game.Ma.Implementation/Item/InventoryItem.cs
Normal file
24
Zennysoft.Game.Ma.Implementation/Item/InventoryItem.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
[Meta, Id("inventory_item")]
|
||||
public abstract partial class InventoryItem : Node3D
|
||||
{
|
||||
[Save("inventory_item_id")]
|
||||
public Guid ID => Guid.NewGuid();
|
||||
[Save("inventory_item_name")]
|
||||
public abstract string ItemName { get; }
|
||||
[Save("inventory_item_description")]
|
||||
public abstract string Description { get; }
|
||||
[Save("inventory_item_spawn_rate")]
|
||||
public abstract float SpawnRate { get; }
|
||||
[Save("inventory_item_throw_damage")]
|
||||
public abstract double ThrowDamage { get; }
|
||||
[Save("inventory_item_throw_speed")]
|
||||
public abstract float ThrowSpeed { get; }
|
||||
|
||||
public abstract Texture2D GetTexture();
|
||||
}
|
||||
17
Zennysoft.Game.Ma.Implementation/Item/RescuedItemDatabase.cs
Normal file
17
Zennysoft.Game.Ma.Implementation/Item/RescuedItemDatabase.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
[Meta, Id("rescued_items")]
|
||||
public partial class RescuedItemDatabase
|
||||
{
|
||||
[Save("rescued_item_list")]
|
||||
public List<InventoryItem> Items { get; init; }
|
||||
|
||||
public RescuedItemDatabase()
|
||||
{
|
||||
Items = new List<InventoryItem>();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum AccessoryTag
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum BoxItemTag
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum ElementType
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum ItemTag
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum ThrowableItemTag
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum UsableItemTag
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public enum WeaponTag
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
[JsonSerializable(typeof(WeaponTag))]
|
||||
public partial class WeaponTagEnumContext : JsonSerializerContext;
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
using Godot;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using System.Text.Json;
|
||||
|
||||
/// <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();
|
||||
}
|
||||
}
|
||||
18
Zennysoft.Game.Ma.Implementation/Module/Module.cs
Normal file
18
Zennysoft.Game.Ma.Implementation/Module/Module.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using SimpleInjector;
|
||||
using System.IO.Abstractions;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Game.Implementation;
|
||||
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public class Module
|
||||
{
|
||||
public static void Bootstrap(Container container)
|
||||
{
|
||||
container.RegisterSingleton<IFileSystem, FileSystem>();
|
||||
container.RegisterSingleton<ISaveFileManager<GameData>, SaveFileManager<GameData>>();
|
||||
container.RegisterSingleton<IMaSaveFileManager<GameData>, MaSaveFileManager<GameData>>();
|
||||
container.Register<IGameRepo, GameRepo>(Lifestyle.Singleton);
|
||||
container.Register<IGameLogic, GameLogic>(Lifestyle.Singleton);
|
||||
}
|
||||
}
|
||||
22
Zennysoft.Game.Ma.Implementation/Player/PlayerData.cs
Normal file
22
Zennysoft.Game.Ma.Implementation/Player/PlayerData.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta, Id("player_data")]
|
||||
public partial record PlayerData
|
||||
{
|
||||
[Save("player_stats")]
|
||||
public required PlayerStats PlayerStats { get; init; }
|
||||
|
||||
[Save("player_inventory")]
|
||||
public required IInventory Inventory { get; init; }
|
||||
}
|
||||
|
||||
[Meta, Id("map_data")]
|
||||
public partial record MapData
|
||||
{
|
||||
[Save("floor_list")]
|
||||
public required List<string> FloorScenes { get; init; }
|
||||
}
|
||||
152
Zennysoft.Game.Ma.Implementation/Player/PlayerStats.cs
Normal file
152
Zennysoft.Game.Ma.Implementation/Player/PlayerStats.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta, Id("player_stats")]
|
||||
public partial record PlayerStats
|
||||
{
|
||||
[Save("currentHP")]
|
||||
public int CurrentHP { get; init; }
|
||||
[Save("maximumHP")]
|
||||
public int MaximumHP { get; init; }
|
||||
[Save("currentVT")]
|
||||
public int CurrentVT { get; init; }
|
||||
[Save("maximumVT")]
|
||||
public int MaximumVT { get; init; }
|
||||
[Save("currentExp")]
|
||||
public double CurrentExp { get; init; }
|
||||
[Save("currentLevel")]
|
||||
public int CurrentLevel { get; init; }
|
||||
[Save("currentAttack")]
|
||||
public int CurrentAttack { get; init; }
|
||||
[Save("bonusAttack")]
|
||||
public int BonusAttack { get; init; }
|
||||
[Save("maxAttack")]
|
||||
public int MaxAttack { get; init; }
|
||||
[Save("currentDefense")]
|
||||
public int CurrentDefense { get; init; }
|
||||
[Save("bonusDefense")]
|
||||
public int BonusDefense { get; init; }
|
||||
[Save("maxDefense")]
|
||||
public int MaxDefense { get; init; }
|
||||
[Save("expToNextLevel")]
|
||||
public int ExpToNextLevel { get; init; }
|
||||
[Save("luck")]
|
||||
public double Luck { get; init; }
|
||||
}
|
||||
|
||||
public class PlayerStatController
|
||||
{
|
||||
public void Init(PlayerStats playerStats)
|
||||
{
|
||||
_currentHP.OnNext(playerStats.CurrentHP);
|
||||
_maximumHP.OnNext(playerStats.MaximumHP);
|
||||
_currentVT.OnNext(playerStats.CurrentVT);
|
||||
_maximumVT.OnNext(playerStats.MaximumVT);
|
||||
_currentExp.OnNext(playerStats.CurrentExp);
|
||||
_currentLevel.OnNext(playerStats.CurrentLevel);
|
||||
_currentAttack.OnNext(playerStats.CurrentAttack);
|
||||
_bonusAttack.OnNext(playerStats.BonusAttack);
|
||||
_maxAttack.OnNext(playerStats.MaxAttack);
|
||||
_currentDefense.OnNext(playerStats.CurrentDefense);
|
||||
_bonusDefense.OnNext(playerStats.BonusDefense);
|
||||
_maxDefense.OnNext(playerStats.MaxDefense);
|
||||
_expToNextLevel.OnNext(playerStats.ExpToNextLevel);
|
||||
_luck.OnNext(playerStats.Luck);
|
||||
}
|
||||
|
||||
public IAutoProp<int> CurrentHP => _currentHP;
|
||||
public IAutoProp<int> MaximumHP => _maximumHP;
|
||||
public IAutoProp<int> CurrentVT => _currentVT;
|
||||
public IAutoProp<int> MaximumVT => _maximumVT;
|
||||
public IAutoProp<int> CurrentAttack => _currentAttack;
|
||||
public IAutoProp<int> MaxAttack => _maxAttack;
|
||||
public IAutoProp<int> BonusAttack => _bonusAttack;
|
||||
public IAutoProp<int> CurrentDefense => _currentDefense;
|
||||
public IAutoProp<int> MaxDefense => _maxDefense;
|
||||
public IAutoProp<int> BonusDefense => _bonusDefense;
|
||||
public IAutoProp<double> CurrentExp => _currentExp;
|
||||
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
|
||||
public IAutoProp<int> CurrentLevel => _currentLevel;
|
||||
public IAutoProp<double> Luck => _luck;
|
||||
|
||||
public void SetCurrentHP(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
|
||||
_currentHP.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaximumHP(int newValue)
|
||||
{
|
||||
_maximumHP.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentVT(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
|
||||
_currentVT.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaximumVT(int newValue)
|
||||
{
|
||||
_maximumVT.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentExp(double newValue)
|
||||
{
|
||||
_currentExp.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentLevel(int newValue)
|
||||
{
|
||||
_currentLevel.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentAttack(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
|
||||
_currentAttack.OnNext(clampedValue);
|
||||
}
|
||||
public void SetBonusAttack(int newValue)
|
||||
{
|
||||
_bonusAttack.OnNext(newValue);
|
||||
}
|
||||
public void SetMaxAttack(int newValue)
|
||||
{
|
||||
_maxAttack.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentDefense(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
|
||||
_currentDefense.OnNext(clampedValue);
|
||||
}
|
||||
public void SetBonusDefense(int newValue)
|
||||
{
|
||||
_bonusDefense.OnNext(newValue);
|
||||
}
|
||||
public void SetMaxDefense(int newValue)
|
||||
{
|
||||
_maxDefense.OnNext(newValue);
|
||||
}
|
||||
public void SetExpToNextLevel(int newValue)
|
||||
{
|
||||
_expToNextLevel.OnNext(newValue);
|
||||
}
|
||||
public void SetLuck(double newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
|
||||
_luck.OnNext(clampedValue);
|
||||
}
|
||||
|
||||
private readonly AutoProp<int> _currentHP = new(-1);
|
||||
private readonly AutoProp<int> _maximumHP = new(-1);
|
||||
private readonly AutoProp<int> _currentVT = new(-1);
|
||||
private readonly AutoProp<int> _maximumVT = new(-1);
|
||||
private readonly AutoProp<double> _currentExp = new(-1);
|
||||
private readonly AutoProp<int> _currentLevel = new(-1);
|
||||
private readonly AutoProp<int> _currentAttack = new(-1);
|
||||
private readonly AutoProp<int> _bonusAttack = new(-1);
|
||||
private readonly AutoProp<int> _maxAttack = new(-1);
|
||||
private readonly AutoProp<int> _currentDefense = new(-1);
|
||||
private readonly AutoProp<int> _bonusDefense = new(-1);
|
||||
private readonly AutoProp<int> _maxDefense = new(-1);
|
||||
private readonly AutoProp<int> _expToNextLevel = new(-1);
|
||||
private readonly AutoProp<double> _luck = new(-1);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IPlayerLogic : ILogicBlock<PlayerLogic.State>;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class PlayerLogic
|
||||
{
|
||||
|
||||
31
Zennysoft.Game.Ma.Implementation/Save/MaSaveFileManager.cs
Normal file
31
Zennysoft.Game.Ma.Implementation/Save/MaSaveFileManager.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IMaSaveFileManager<T>
|
||||
{
|
||||
Task Save(T gameData);
|
||||
|
||||
Task<T?> Load();
|
||||
}
|
||||
|
||||
public sealed class MaSaveFileManager<T> : IMaSaveFileManager<T>
|
||||
{
|
||||
private readonly ISaveFileManager<T> _saveFileManager;
|
||||
private ImmutableList<IJsonTypeInfoResolver> _converters;
|
||||
|
||||
public MaSaveFileManager(ISaveFileManager<T> saveFileManager)
|
||||
{
|
||||
_saveFileManager = saveFileManager;
|
||||
_converters = [WeaponTagEnumContext.Default, ItemTagEnumContext.Default, ElementTypeEnumContext.Default, AccessoryTagEnumContext.Default, ThrowableItemTagEnumContext.Default, UsableItemTagEnumContext.Default, BoxItemTagEnumContext.Default];
|
||||
}
|
||||
|
||||
public async Task Save(T gameData)
|
||||
{
|
||||
await _saveFileManager.WriteToFile(gameData, [.. _converters]);
|
||||
}
|
||||
|
||||
public async Task<T?> Load() => await _saveFileManager.ReadFromFile([.. _converters]);
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
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.Ma.Godot.Adapter;
|
||||
|
||||
public class SaveFileManager<T> : ISaveFileManager<T>
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private JsonSerializerOptions _jsonOptions;
|
||||
private string _defaultSaveLocation;
|
||||
public const string DEFAULT_SAVE_FILE_NAME = "game.json";
|
||||
|
||||
public SaveFileManager(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_defaultSaveLocation = _fileSystem.Path.Join(OS.GetUserDataDir(), DEFAULT_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 Task<T?> ReadFromFile()
|
||||
{
|
||||
if (!_fileSystem.File.Exists(_defaultSaveLocation))
|
||||
throw new FileNotFoundException();
|
||||
return ReadFromFile(_defaultSaveLocation);
|
||||
}
|
||||
|
||||
public async Task<T?> ReadFromFile(string filePath)
|
||||
{
|
||||
if (!_fileSystem.File.Exists(filePath))
|
||||
throw new FileNotFoundException();
|
||||
|
||||
var json = await _fileSystem.File.ReadAllTextAsync(filePath);
|
||||
|
||||
return JsonSerializer.Deserialize<T?>(json, _jsonOptions);
|
||||
}
|
||||
|
||||
public Task WriteToFile(T gameData)
|
||||
{
|
||||
return WriteToFile(gameData, _defaultSaveLocation, _jsonOptions);
|
||||
}
|
||||
|
||||
public Task WriteToFile(T gameData, string filePath)
|
||||
{
|
||||
return WriteToFile(gameData, filePath, _jsonOptions);
|
||||
}
|
||||
|
||||
public async Task WriteToFile(T gameData, string filePath, JsonSerializerOptions jsonOptions)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(gameData, jsonOptions);
|
||||
await _fileSystem.File.WriteAllTextAsync(filePath, json);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
@@ -38,7 +37,7 @@ public partial class InGameUILogic
|
||||
Output(new Output.AnnounceMessageInInventory(message));
|
||||
}
|
||||
|
||||
private void OnRemoveItemFromInventory(IInventoryItem item) => Output(new Output.RemoveItemFromInventory(item));
|
||||
private void OnRemoveItemFromInventory(InventoryItem item) => Output(new Output.RemoveItemFromInventory(item));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public interface IInGameUILogic : ILogicBlock<InGameUILogic.State>;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
public static class Input
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Game.Ma;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
public static class Output
|
||||
{
|
||||
public readonly record struct AnnounceMessageOnMainScreen(string Message);
|
||||
public readonly record struct AnnounceMessageInInventory(string Message);
|
||||
public readonly record struct RemoveItemFromInventory(IInventoryItem Item);
|
||||
public readonly record struct RemoveItemFromInventory(InventoryItem Item);
|
||||
public readonly record struct DisplayMinimap;
|
||||
public readonly record struct HideMinimap;
|
||||
public readonly record struct ShowInventory;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Ma.Godot.Adapter;
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public partial class InGameUILogic
|
||||
{
|
||||
|
||||
@@ -13,11 +13,13 @@
|
||||
<PackageReference Include="Chickensoft.LogicBlocks" Version="5.16.0" />
|
||||
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />
|
||||
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.6.0-250131-2115.Release" />
|
||||
<PackageReference Include="SimpleInjector" Version="5.5.0" />
|
||||
<PackageReference Include="System.IO.Abstractions" Version="22.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\Zennysoft.Game.Godot.Implementation\Zennysoft.Game.Implementation.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
70
Zennysoft.Game.Ma.Implementation/cspell.json
Normal file
70
Zennysoft.Game.Ma.Implementation/cspell.json
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"files": [
|
||||
"**/*.*"
|
||||
],
|
||||
"ignorePaths": [
|
||||
"**/*.tscn",
|
||||
"**/*.import",
|
||||
"**/badges/**/*.*",
|
||||
"**/coverage/**/*.*",
|
||||
"**/.godot/**/*.*",
|
||||
"**/obj/**/*.*",
|
||||
"**/bin/**/*.*",
|
||||
"**/nupkg/**/*.*"
|
||||
],
|
||||
"words": [
|
||||
"assemblyfilters",
|
||||
"automerge",
|
||||
"branchcoverage",
|
||||
"brandedoutcast",
|
||||
"buildtransitive",
|
||||
"camelcase",
|
||||
"chickenpackage",
|
||||
"Chickensoft",
|
||||
"classfilters",
|
||||
"contentfiles",
|
||||
"CYGWIN",
|
||||
"devbuild",
|
||||
"endregion",
|
||||
"Finalizer",
|
||||
"Finalizers",
|
||||
"globaltool",
|
||||
"godotengine",
|
||||
"godotpackage",
|
||||
"issuecomment",
|
||||
"justalemon",
|
||||
"lcov",
|
||||
"lihop",
|
||||
"linecoverage",
|
||||
"methodcoverage",
|
||||
"missingall",
|
||||
"msbuild",
|
||||
"MSYS",
|
||||
"nameof",
|
||||
"Nerdbank",
|
||||
"netstandard",
|
||||
"NOLOGO",
|
||||
"nupkg",
|
||||
"Omnisharp",
|
||||
"opencover",
|
||||
"OPTOUT",
|
||||
"paramref",
|
||||
"pascalcase",
|
||||
"Postinitialize",
|
||||
"Predelete",
|
||||
"renovatebot",
|
||||
"reportgenerator",
|
||||
"reporttypes",
|
||||
"Shouldly",
|
||||
"subfolders",
|
||||
"targetargs",
|
||||
"targetdir",
|
||||
"tscn",
|
||||
"typeof",
|
||||
"typeparam",
|
||||
"typeparamref",
|
||||
"ulong",
|
||||
"Unparented",
|
||||
"Xunit"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user