project update

This commit is contained in:
h z
2024-06-30 01:52:44 +08:00
parent 117835b503
commit 59d257c06a
67 changed files with 2268 additions and 92 deletions

View File

@@ -0,0 +1,38 @@
using Enigmos.Modules.ControllingModules;
using Enigmos.Ports;
using Enigmos.Ports.DataPorts;
using Godot;
using Nocturnis.Enigmos.Ports;
using TabulaSmaragdina.Constants;
namespace Enigmos.Modules.TerminalModules.TestingModules;
public partial class LightEmittingDiodeModule : TerminalModule
{
private Sprite2D LightEmittingDiode { get; set; }
private DataInPort Input { get; set; }
public override IEnumerable<IBasePort> Ports => new[] { Input };
private static readonly Texture2D TrueTexture =
ResourceLoader.Load<Texture2D>("res://Resources/Circuits/Modules/Terminal/Testing/LEDBubble-T.png");
private static readonly Texture2D FalseTexture =
ResourceLoader.Load<Texture2D>("res://Resources/Circuits/Modules/Terminal/Testing/LEDBubble-F.png");
public override void Init()
{
base.Init();
Finished = true;
LightEmittingDiode = GetNode<Sprite2D>("LightEmittingDiode");
Input = GetPort<DataInPort>("Input");
Input.SetDataType(EnigmosConstant.DataPortTypes.Bit);
PostInit();
}
protected override void Consume(RootModule root)
{
if (Input.GetData(root).Bit)
LightEmittingDiode.Texture = TrueTexture;
else
LightEmittingDiode.Texture = FalseTexture;
Finished = true;
}
}

View File

@@ -0,0 +1,34 @@
using Godot;
using Skeleton.Utils.Helpers;
using R2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVector;
namespace Enigmos.Modules.TerminalModules.TestingModules;
public partial class R2Reader : Control
{
private AnimatedSprite2D Direction { get; set; }
private AnimatedSprite2D Magnitude { get; set; }
public R2 UnderlyingVector { get; set; }
private double TargetPhase() => Math.Atan2(UnderlyingVector[2], UnderlyingVector[1]);
private double TargetLength() => UnderlyingVector.Magnitude;
private int TargetPhaseFrame =>
Mathf.FloorToInt((TargetPhase() % (2d * Math.PI) + 2d * Math.PI) % (2d * Math.PI) * 44d / (2d * Math.PI));
private int TargetLengthFrame =>
Mathf.FloorToInt(TargetLength().DoubleCut() * 9d);
public override void _Process(double delta)
{
Magnitude.SpeedScale = (TargetLengthFrame - Magnitude.Frame) / 7f;
var debug = new[] { TargetPhaseFrame - Direction.Frame, TargetPhaseFrame + 44 - Direction.Frame };
Direction.SpeedScale = debug.MinBy(Math.Abs) / 25f;
}
public void Init()
{
Direction = GetNode<AnimatedSprite2D>("Direction");
Magnitude = GetNode<AnimatedSprite2D>("Magnitude");
Direction.Play();
Magnitude.Play();
}
}

View File

@@ -0,0 +1,29 @@
using Enigmos.Modules.ControllingModules;
using Enigmos.Ports;
using Enigmos.Ports.DataPorts;
using TabulaSmaragdina.Constants;
namespace Enigmos.Modules.TerminalModules.TestingModules;
public partial class R2ReaderModule : TerminalModule
{
private DataInPort DataIn { get; set; }
private R2Reader R2Reader { get; set; }
public override IEnumerable<BasePort> Ports => new[] { DataIn };
public override void Init()
{
base.Init();
DataIn = GetPort<DataInPort>("DataIn");
DataIn.SetDataType(EnigmosConstant.DataPortTypes.R2);
R2Reader = GetNode<R2Reader>("R2Reader");
R2Reader.Init();
PostInit();
}
protected override void Consume(RootModule root)
{
R2Reader.UnderlyingVector = DataIn.GetData(root).R2;
}
}

View File

@@ -0,0 +1,45 @@
using Enigmos.Modules.ControllingModules;
using Enigmos.Ports;
using Enigmos.Ports.DataPorts;
using Godot;
using Skeleton.Utils.Helpers;
using TabulaSmaragdina.Constants;
namespace Enigmos.Modules.TerminalModules.TestingModules;
public partial class RealReaderModule : TerminalModule
{
private DataInPort Input1 { get; set; }
private DataInPort Input2 { get; set; }
private DataInPort Input3 { get; set; }
private AnimatedSprite2D RealReader { get; set; }
public override IEnumerable<BasePort> Ports => new[] { Input1, Input2, Input3 };
public override void Init()
{
base.Init();
Input1 = GetPort<DataInPort>("Input1");
Input2 = GetPort<DataInPort>("Input2");
Input3 = GetPort<DataInPort>("Input3");
Input1.SetDataType(EnigmosConstant.DataPortTypes.Real);
Input2.SetDataType(EnigmosConstant.DataPortTypes.Real);
Input3.SetDataType(EnigmosConstant.DataPortTypes.Real);
RealReader = GetNode<AnimatedSprite2D>("RealReader");
RealReader.SpeedScale = 0;
RealReader.Play();
PostInit();
}
protected override void Consume(RootModule root)
{
double max = Input1.GetData(root).Real;
double min = Input3.GetData(root).Real;
double value = Input2.GetData(root).Real;
//DebugToolWindow.FreeInfo = $"{value}";
double range = max - min;
double percentage = (range == 0 ? 0d : value / range).DoubleCut();
int frame = Mathf.FloorToInt(percentage * 122);
RealReader.SpeedScale = (frame - RealReader.Frame) / 60f;
Finished = true;
}
}