Added a RTS camera, and some assorted changes.
This commit is contained in:
@@ -2,17 +2,24 @@ namespace FoodFactory.Voxel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Arch.Core;
|
||||
using Arch.LowLevel;
|
||||
using Arch.System;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Chickensoft.Serialization;
|
||||
using Chickensoft.Serialization.Godot;
|
||||
using FoodFactory;
|
||||
using FoodFactory.Blueprints;
|
||||
using FoodFactory.Conveyors;
|
||||
using FoodFactory.Math;
|
||||
using FoodFactory.Recipes;
|
||||
using Godot;
|
||||
using SharpYaml;
|
||||
|
||||
public class BacterialSystem : BaseSystem<World, float>
|
||||
{
|
||||
private QueryDescription _desc = new QueryDescription().WithAll<Bacteria, Temperature>();
|
||||
@@ -44,7 +51,14 @@ public class BacterialSystem : BaseSystem<World, float>
|
||||
|
||||
//Will Liklely be the game instead of a node like this
|
||||
[Meta(typeof(IAutoNode))]// [Tool]
|
||||
public partial class VoxelGridNode : Node3D, IProvide<IVoxelGridRegistry>, IProvide<IItemRenderer>, IProvide<IRecipes>, IProvide<IBlueprintManger>, IProvide<World>, IProvide<IFoodFactoryApi>
|
||||
public partial class VoxelGridNode : Node3D,
|
||||
IProvide<IVoxelGridRegistry>,
|
||||
IProvide<IItemRenderer>,
|
||||
IProvide<IRecipes>,
|
||||
IProvide<IBlueprintManger>,
|
||||
IProvide<World>,
|
||||
IProvide<IFoodFactoryApi>,
|
||||
IProvide<ISaveChunk<GameData>>
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
@@ -60,6 +74,62 @@ public partial class VoxelGridNode : Node3D, IProvide<IVoxelGridRegistry>, IProv
|
||||
IRecipes IProvide<IRecipes>.Value() => _recipes;
|
||||
private IItemRenderer _itemRenderer = default!;
|
||||
IItemRenderer IProvide<IItemRenderer>.Value() => _itemRenderer;
|
||||
public ISaveChunk<GameData> Value() => SaveFile.Root;
|
||||
public static string SavePath => $"{OS.GetUserDataDir()}/SaveFile.json";
|
||||
JsonSerializerOptions _options;
|
||||
public void Setup()
|
||||
{
|
||||
GodotSerialization.Setup();
|
||||
_options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
TypeInfoResolver = new SerializableTypeResolver(),
|
||||
Converters = { new SerializableTypeConverter() }
|
||||
};
|
||||
|
||||
var test = "gg";
|
||||
GD.Print(SavePath);
|
||||
SaveFile = new SaveFile<GameData>(
|
||||
new SaveChunk<GameData>(
|
||||
onSave: (chunk) =>
|
||||
{
|
||||
|
||||
var gameData = new GameData()
|
||||
{
|
||||
World = _world,
|
||||
// Equipments = chunk.GetChunkSaveData<EquipmentsData>()
|
||||
};
|
||||
return gameData;
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
World.Destroy(_world);
|
||||
_world = data.World;
|
||||
// chunk.LoadChunkSaveData(data.Equipments);
|
||||
}
|
||||
),
|
||||
onSave: async data =>
|
||||
{
|
||||
|
||||
var yaml = JsonSerializer.Serialize(data, _options);
|
||||
|
||||
GD.Print(SavePath);
|
||||
await File.WriteAllTextAsync(SavePath, yaml);
|
||||
},
|
||||
onLoad: async () =>
|
||||
{
|
||||
if (!File.Exists(SavePath))
|
||||
{
|
||||
GD.PushWarning("Save does nto exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
var data = JsonSerializer.Deserialize<GameData>(await File.ReadAllTextAsync(SavePath), _options);
|
||||
return data;
|
||||
}
|
||||
);
|
||||
}
|
||||
public ISaveFile<GameData> SaveFile { get; set; } = default!;
|
||||
Group<float> _systems;
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -118,6 +188,15 @@ public partial class VoxelGridNode : Node3D, IProvide<IVoxelGridRegistry>, IProv
|
||||
}
|
||||
}
|
||||
}
|
||||
if (@event.IsActionPressed("ui_right"))
|
||||
{
|
||||
SaveFile.Save();
|
||||
|
||||
}
|
||||
if (@event.IsActionPressed("ui_left"))
|
||||
{
|
||||
SaveFile.Load();
|
||||
}
|
||||
}
|
||||
public override void _ExitTree()
|
||||
{
|
||||
@@ -125,6 +204,7 @@ public partial class VoxelGridNode : Node3D, IProvide<IVoxelGridRegistry>, IProv
|
||||
_systems.Dispose();
|
||||
_world.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
public static class BacteriaModel
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user