Bracket System
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="GodotSharp" Version="4.3.0-beta.3" />
|
<PackageReference Include="GodotSharp" Version="4.4.0-dev.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
11
src/Controls/IStateControl.cs
Normal file
11
src/Controls/IStateControl.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using Nocturnis.DataStructures.States;
|
||||||
|
|
||||||
|
namespace Nocturnis.Controls;
|
||||||
|
|
||||||
|
public interface IStateControl
|
||||||
|
{
|
||||||
|
string this[string path] { get; set; }
|
||||||
|
void Load();
|
||||||
|
void Save();
|
||||||
|
public void AddRule(string path, StateTransferRule rule);
|
||||||
|
}
|
||||||
35
src/DataStructures/DoubleKeyDictionary.cs
Normal file
35
src/DataStructures/DoubleKeyDictionary.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
namespace Nocturnis.DataStructures;
|
||||||
|
|
||||||
|
public class DoubleKeyDictionary<TKey, TValue> : Dictionary<TKey, Dictionary<TKey, TValue>>
|
||||||
|
{
|
||||||
|
public DoubleKeyDictionary(TValue defaultValue)
|
||||||
|
{
|
||||||
|
DefaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TValue DefaultValue { get; set; }
|
||||||
|
|
||||||
|
public TValue this[TKey pk1, TKey pk2]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return this[pk1][pk2];
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException)
|
||||||
|
{
|
||||||
|
return DefaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if(!ContainsKey(pk1))
|
||||||
|
this[pk1] = new Dictionary<TKey, TValue>();
|
||||||
|
this[pk1][pk2] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsKey(TKey pk1, TKey pk2) => ContainsKey(pk1) && this[pk1].ContainsKey(pk2);
|
||||||
|
|
||||||
|
}
|
||||||
3
src/DataStructures/States/StateTransferRule.cs
Normal file
3
src/DataStructures/States/StateTransferRule.cs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Nocturnis.DataStructures.States;
|
||||||
|
|
||||||
|
public delegate bool StateTransferRule (string path, string fromState, string toState);
|
||||||
@@ -37,7 +37,7 @@ public class EnigmosControl
|
|||||||
EngineUp = true;
|
EngineUp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double Energy { get; set; } = 0d;
|
public double Energy { get; set; } = 1d;
|
||||||
public bool EngineUp { get; private set; }
|
public bool EngineUp { get; private set; }
|
||||||
public double IdlePower => CreatureControl.Instance.CurrentCharacter.MotherBoard.IdlePower + VoidPower;
|
public double IdlePower => CreatureControl.Instance.CurrentCharacter.MotherBoard.IdlePower + VoidPower;
|
||||||
public double VoidPower { get; set; } = 0;
|
public double VoidPower { get; set; } = 0;
|
||||||
|
|||||||
76
src/GlobalManagement/Controls/StateControl.cs
Normal file
76
src/GlobalManagement/Controls/StateControl.cs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Nocturnis.Controls;
|
||||||
|
using Nocturnis.DataStructures.States;
|
||||||
|
using FileAccess = Godot.FileAccess;
|
||||||
|
|
||||||
|
namespace Nocturnis.GlobalManagement.Controls;
|
||||||
|
|
||||||
|
public sealed class StateControl
|
||||||
|
{
|
||||||
|
public const string NullState = "NullState";
|
||||||
|
|
||||||
|
private HashSet<StateTransferRule> Rules { get; set; }
|
||||||
|
public Dictionary<string, string> States { get; set; }
|
||||||
|
|
||||||
|
private StateControl()
|
||||||
|
{
|
||||||
|
States = new Dictionary<string, string>();
|
||||||
|
Rules = new HashSet<StateTransferRule>();
|
||||||
|
}
|
||||||
|
private static StateControl _instance = null;
|
||||||
|
public static StateControl Instance => _instance ??= new StateControl();
|
||||||
|
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
if (!FileAccess.FileExists("States.json"))
|
||||||
|
return;
|
||||||
|
using FileAccess file = FileAccess.Open("States.json", FileAccess.ModeFlags.Read);
|
||||||
|
string jsonData = file.GetAsText();
|
||||||
|
States = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
string jsonData = JsonSerializer.Serialize(States);
|
||||||
|
using FileAccess file = FileAccess.Open("States.json", FileAccess.ModeFlags.Write);
|
||||||
|
file.StoreString(jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Transfer(string path, string state)
|
||||||
|
{
|
||||||
|
foreach (var rule in Rules)
|
||||||
|
if (rule(path, States[path], state))
|
||||||
|
{
|
||||||
|
States[path] = state;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string this[string path]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return States[path];
|
||||||
|
}
|
||||||
|
catch (KeyNotFoundException)
|
||||||
|
{
|
||||||
|
return NullState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if(!States.ContainsKey(path))
|
||||||
|
States[path] = NullState;
|
||||||
|
Transfer(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void AddRule(StateTransferRule rule)
|
||||||
|
{
|
||||||
|
Rules.Add(rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
70
src/GlobalManagement/Controls/TopicControl.cs
Normal file
70
src/GlobalManagement/Controls/TopicControl.cs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Nocturnis.GlobalManagement.Providers;
|
||||||
|
using Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
|
||||||
|
namespace Nocturnis.GlobalManagement.Controls;
|
||||||
|
|
||||||
|
public class TopicControl
|
||||||
|
{
|
||||||
|
private static TopicControl _instance;
|
||||||
|
public static TopicControl Instance => _instance ??= new TopicControl();
|
||||||
|
public HashSet<IBracketTopic> ActiveTopics { get; set; }
|
||||||
|
public Dictionary<string, IBracketTopic> Topics { get; set; }
|
||||||
|
private TopicControl()
|
||||||
|
{
|
||||||
|
ActiveTopics = new HashSet<IBracketTopic>();
|
||||||
|
Topics = new Dictionary<string, IBracketTopic>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Load(string topicName)
|
||||||
|
{
|
||||||
|
string jsonContent = GlobalProvider.FileAccessProvider.Read($"res://Resources/Topics/{topicName}.json");
|
||||||
|
TopicData topicData = JsonSerializer.Deserialize<TopicData>(jsonContent);
|
||||||
|
IBracketTopic topic = GlobalProvider.ConstructorProvider.NewBracketTopic();
|
||||||
|
topic.Topic = topicData.topic;
|
||||||
|
topic.Reusable = topicData.reusable;
|
||||||
|
topic.Finished = false;
|
||||||
|
topic.LineMap = new Dictionary<string, IBracketLine>();
|
||||||
|
foreach (var lineData in topicData.lines)
|
||||||
|
{
|
||||||
|
IBracketLine line = GlobalProvider.ConstructorProvider.NewBracketLine();
|
||||||
|
line.Conditions = lineData.conditions;
|
||||||
|
line.Line = lineData.line;
|
||||||
|
line.Successors = new HashSet<IBracketLine>();
|
||||||
|
topic.LineMap[lineData.line] = line;
|
||||||
|
line.BraLines = lineData.braLines;
|
||||||
|
line.KetLines = lineData.ketLines;
|
||||||
|
line.ArrowMarkers = lineData.arrows;
|
||||||
|
line.CleanPrevious = lineData.cleanPrevious;
|
||||||
|
line.Topic = topicData.topic;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (LineData lineData in topicData.lines)
|
||||||
|
{
|
||||||
|
IBracketLine line = topic.LineMap[lineData.line];
|
||||||
|
foreach (string successorId in lineData.successors)
|
||||||
|
line.Successors.Add(topic.LineMap[successorId]);
|
||||||
|
}
|
||||||
|
topic.Root = topic.LineMap[topicData.lines[0].line];
|
||||||
|
topic.CurrentLine = topic.Root;
|
||||||
|
Topics.Add(topic.Topic, topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TopicData
|
||||||
|
{
|
||||||
|
public bool reusable { get; set; }
|
||||||
|
public string topic { get; set; }
|
||||||
|
public LineData[] lines { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LineData
|
||||||
|
{
|
||||||
|
public bool cleanPrevious { get; set; }
|
||||||
|
public string line { get; set; }
|
||||||
|
public string[] conditions { get; set; }
|
||||||
|
public string[] successors { get; set; }
|
||||||
|
public string[] braLines { get; set; }
|
||||||
|
public string[] ketLines { get; set; }
|
||||||
|
public string[] arrows { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Nocturnis.DataStructures.DataTypes;
|
|
||||||
using Nocturnis.Enigmos.Modules;
|
using Nocturnis.Enigmos.Modules;
|
||||||
using Nocturnis.Inventories.Items;
|
using Nocturnis.Inventories.Items;
|
||||||
|
|
||||||
@@ -15,6 +14,10 @@ public static class GlobalProvider
|
|||||||
public static IDataTypeProvider DataTypeProvider { get; set; }
|
public static IDataTypeProvider DataTypeProvider { get; set; }
|
||||||
public static IProcessProvider ProcessProvider { get; set; }
|
public static IProcessProvider ProcessProvider { get; set; }
|
||||||
public static ITextureProvider TextureProvider { get; set; }
|
public static ITextureProvider TextureProvider { get; set; }
|
||||||
|
|
||||||
|
public static IConstructorProvider ConstructorProvider { get; set; }
|
||||||
|
|
||||||
|
public static IFileAccessProvider FileAccessProvider { get; set; }
|
||||||
|
|
||||||
public static class ModulePreviewMapper<TModule>
|
public static class ModulePreviewMapper<TModule>
|
||||||
where TModule : IBaseModule
|
where TModule : IBaseModule
|
||||||
|
|||||||
9
src/GlobalManagement/Providers/IConstructorProvider.cs
Normal file
9
src/GlobalManagement/Providers/IConstructorProvider.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
|
||||||
|
namespace Nocturnis.GlobalManagement.Providers;
|
||||||
|
|
||||||
|
public interface IConstructorProvider
|
||||||
|
{
|
||||||
|
IBracketTopic NewBracketTopic();
|
||||||
|
IBracketLine NewBracketLine();
|
||||||
|
}
|
||||||
10
src/GlobalManagement/Providers/IDataAccessProvider.cs
Normal file
10
src/GlobalManagement/Providers/IDataAccessProvider.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using FileAccess = Godot.FileAccess;
|
||||||
|
|
||||||
|
namespace Nocturnis.GlobalManagement.Providers;
|
||||||
|
|
||||||
|
public interface IFileAccessProvider
|
||||||
|
{
|
||||||
|
public string Read(string path);
|
||||||
|
public void Write(string path, string content);
|
||||||
|
public string ResRead(string path);
|
||||||
|
}
|
||||||
15
src/Hermeteus/BracketSystem/IBracketLine.cs
Normal file
15
src/Hermeteus/BracketSystem/IBracketLine.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
|
||||||
|
public interface IBracketLine
|
||||||
|
{
|
||||||
|
string Topic { get; set; }
|
||||||
|
string Line { get; set; }
|
||||||
|
bool CleanPrevious { get; set; }
|
||||||
|
string[] BraLines { get; set; }
|
||||||
|
string[] KetLines { get; set; }
|
||||||
|
string[] ArrowMarkers { get; set; }
|
||||||
|
string[] Conditions { get; set; }
|
||||||
|
HashSet<IBracketLine> Successors { get; set; }
|
||||||
|
bool IsReady { get; }
|
||||||
|
}
|
||||||
|
|
||||||
13
src/Hermeteus/BracketSystem/IBracketTopic.cs
Normal file
13
src/Hermeteus/BracketSystem/IBracketTopic.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
|
||||||
|
public interface IBracketTopic
|
||||||
|
{
|
||||||
|
bool Reusable { get; set; }
|
||||||
|
string Topic { get; set; }
|
||||||
|
bool Finished { get; set; }
|
||||||
|
IBracketLine Root { get; set; }
|
||||||
|
IBracketLine CurrentLine { get; set; }
|
||||||
|
void Activate();
|
||||||
|
void Finish();
|
||||||
|
Dictionary<string, IBracketLine> LineMap { get; set; }
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace Nocturnis.Hermeteus;
|
namespace Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
|
||||||
public interface ICondition
|
public interface ICondition
|
||||||
{
|
{
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using Nocturnis.UIElements.Layers;
|
using Nocturnis.UIElements.Layers;
|
||||||
|
|
||||||
namespace Nocturnis.Hermeteus;
|
namespace Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
|
||||||
public interface IInstructionAgent : INodeInterface
|
public interface IInstructionAgent : INodeInterface
|
||||||
{
|
{
|
||||||
void Load(string content, Action callBack);
|
void Load(string content, Action callBack);
|
||||||
void Clean(Action callBack);
|
void Clean(Action callBack);
|
||||||
void LoadArrows(Vector2[] ends);
|
void LoadArrows(string[] ends);
|
||||||
void CleanArrows();
|
void CleanArrows();
|
||||||
void Init(IInstructionLayer insLayer);
|
void Init(IInstructionLayer insLayer);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
using Nocturnis.UIElements;
|
namespace Nocturnis.Hermeteus.BracketSystem.Processors;
|
||||||
|
|
||||||
namespace Nocturnis.Hermeteus.Processors;
|
|
||||||
|
|
||||||
public interface IBracketProcessor
|
public interface IBracketProcessor
|
||||||
{
|
{
|
||||||
@@ -13,5 +11,5 @@ public interface IBracketProcessor
|
|||||||
double BracketEsc { get; set; }
|
double BracketEsc { get; set; }
|
||||||
string Status { get; set; }
|
string Status { get; set; }
|
||||||
void Init(IInstructionAgent bra, IInstructionAgent pointer, IInstructionAgent ket);
|
void Init(IInstructionAgent bra, IInstructionAgent pointer, IInstructionAgent ket);
|
||||||
void SyncLoad(IBracketTalk talk);
|
void SyncLoad(IBracketLine talk);
|
||||||
}
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
namespace Nocturnis.Hermeteus;
|
|
||||||
|
|
||||||
public static class EBracketRouter
|
|
||||||
{
|
|
||||||
public static IBracketRouter RouteAndSkip(this IBracketRouter router)
|
|
||||||
{
|
|
||||||
IBracketRouter pr = router.Route();
|
|
||||||
while (pr is IBracketTalk { CanSkip: true } prt)
|
|
||||||
{
|
|
||||||
prt.Finished = true;
|
|
||||||
pr = pr.RouteAndSkip();
|
|
||||||
}
|
|
||||||
return pr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using Skeleton.DataStructure.Tree;
|
|
||||||
|
|
||||||
namespace Nocturnis.Hermeteus;
|
|
||||||
|
|
||||||
public interface IBracketChapter : IBracketRouter
|
|
||||||
{
|
|
||||||
IBracketStory Story { get; set; }
|
|
||||||
string State { get; set; }
|
|
||||||
bool Finished { get; set; }
|
|
||||||
string Chapter { get; set; }
|
|
||||||
IBracketTopic CurrentTopic { get; set; }
|
|
||||||
HashSet<IBracketTopic> Children { get; set; }
|
|
||||||
HashSet<ICondition> Conditions { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Nocturnis.Hermeteus;
|
|
||||||
|
|
||||||
public interface IBracketRouter
|
|
||||||
{
|
|
||||||
IBracketRouter Route();
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using Nocturnis.Hermeteus.Processors;
|
|
||||||
using Skeleton.DataStructure.Tree;
|
|
||||||
|
|
||||||
namespace Nocturnis.Hermeteus;
|
|
||||||
|
|
||||||
public interface IBracketStory : IBracketRouter
|
|
||||||
{
|
|
||||||
IBracketChapter CurrentChapter { get; set; }
|
|
||||||
IBracketChapter[] Children { get; set; }
|
|
||||||
IBracketRouter CurrentRouter { get; set; }
|
|
||||||
bool Process(IBracketProcessor processor);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
|
|
||||||
namespace Nocturnis.Hermeteus;
|
|
||||||
|
|
||||||
public interface IBracketTalk : IBracketRouter
|
|
||||||
{
|
|
||||||
IBracketTopic Topic { get; set; }
|
|
||||||
string TriggerStatus { get; set; }
|
|
||||||
string EnterStatus { get; set; }
|
|
||||||
double TriggerEsc { get; set; }
|
|
||||||
bool CleanPrevious { get; set; }
|
|
||||||
string[] BraLines { get; set; }
|
|
||||||
string[] KetLines { get; set; }
|
|
||||||
HashSet<ICondition> Conditions { get; set; }
|
|
||||||
Vector2[] ArrowMarkers { get; set; }
|
|
||||||
bool Finished { get; set; }
|
|
||||||
bool CanSkip { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using Skeleton.DataStructure.Tree;
|
|
||||||
|
|
||||||
namespace Nocturnis.Hermeteus;
|
|
||||||
|
|
||||||
public interface IBracketTopic : IBracketRouter
|
|
||||||
{
|
|
||||||
IBracketChapter Chapter { get; set; }
|
|
||||||
string Topic { get; set; }
|
|
||||||
bool Finished { get; set; }
|
|
||||||
HashSet<IBracketTalk> Children { get; set; }
|
|
||||||
IBracketTalk CurrentTalk { get; set; }
|
|
||||||
HashSet<ICondition> Conditions { get; set; }
|
|
||||||
}
|
|
||||||
8
src/Hermeteus/QuerySystem/IQueryEngine.cs
Normal file
8
src/Hermeteus/QuerySystem/IQueryEngine.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Nocturnis.Hermeteus.QuerySystem;
|
||||||
|
|
||||||
|
public interface IQueryEngine
|
||||||
|
{
|
||||||
|
bool Check(string query);
|
||||||
|
}
|
||||||
@@ -7,4 +7,5 @@ public interface INodeInterface
|
|||||||
void RemoveChild(Node node);
|
void RemoveChild(Node node);
|
||||||
void AddChild(Node node, bool forceReadableName = false, Node.InternalMode @internal = (Node.InternalMode)(0));
|
void AddChild(Node node, bool forceReadableName = false, Node.InternalMode @internal = (Node.InternalMode)(0));
|
||||||
bool Visible { get; set; }
|
bool Visible { get; set; }
|
||||||
|
Node GetNode(NodePath path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Nocturnis.UIElements.Layers;
|
|||||||
|
|
||||||
namespace Nocturnis.Scenes;
|
namespace Nocturnis.Scenes;
|
||||||
|
|
||||||
public interface IRootScene
|
public interface IRootScene : INodeInterface
|
||||||
{
|
{
|
||||||
void ChangeScene(Node scene);
|
void ChangeScene(Node scene);
|
||||||
IKeyListener KeyListener { get; set; }
|
IKeyListener KeyListener { get; set; }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Nocturnis.Hermeteus;
|
using Nocturnis.Hermeteus;
|
||||||
using Nocturnis.Hermeteus.Processors;
|
using Nocturnis.Hermeteus.BracketSystem;
|
||||||
|
using Nocturnis.Hermeteus.BracketSystem.Processors;
|
||||||
|
|
||||||
namespace Nocturnis.UIElements.Layers;
|
namespace Nocturnis.UIElements.Layers;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user