project update
This commit is contained in:
54
Modules/ComputationalModules/Nullary/ConstantModule.cs
Normal file
54
Modules/ComputationalModules/Nullary/ConstantModule.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class ConstantModule : NullaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
|
||||
[Export] private double PresetConstantValue { get; set; }
|
||||
|
||||
private HashSet<DataOutPort> OutputGroup { get; set; } = new();
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
private IDoubleParameter ConstValue { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
ConstValue =
|
||||
GlobalProvider.DataStructureProvider.NewDoubleParameter(
|
||||
"Constant Value",
|
||||
-1,
|
||||
1,
|
||||
UsingPreset ? PresetConstantValue : 0
|
||||
);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { ConstValue };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.ResultData.Real = ConstValue.ParameterValue;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
51
Modules/ComputationalModules/Nullary/KeyListenerModule.cs
Normal file
51
Modules/ComputationalModules/Nullary/KeyListenerModule.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Godot;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
public partial class KeyListenerModule : NullaryComputationalModule, IParameterizedModule, IKeyListenerModule
|
||||
{
|
||||
[Export] private StringName? PresetActionName { get; set; }
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
public IKeyParameter? ListeningKey { get; set; }
|
||||
public bool Pressed { get; set; }
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
public override IEnumerable<BasePort> Ports => new[] { Output1, Output2, Output3 }!;
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
Output1!.ResultData.Bit = Pressed;
|
||||
Output2!.ResultData.Bit = Pressed;
|
||||
Output3!.ResultData.Bit = Pressed;
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output1.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output2.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
Output3.SetDataType(EnigmosConstant.DataPortTypes.Bit);
|
||||
ListeningKey = GlobalProvider.DataStructureProvider!.NewKeyParameter(
|
||||
"Listening Key",
|
||||
UsingPreset && (PresetActionName != null) ? PresetActionName : "KeyListenAction"
|
||||
);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { ListeningKey };
|
||||
int i = 0;
|
||||
while (InputMap.HasAction($"{ListeningKey.ParameterValue}{i}") && !UsingPreset)
|
||||
i++;
|
||||
ListeningKey.ParameterValue = $"{ListeningKey.ParameterValue}{i}";
|
||||
if(!UsingPreset)
|
||||
InputMap.AddAction(ListeningKey.ParameterValue);
|
||||
GlobalProvider.SceneProvider!.RootScene.KeyListener.Register(this);
|
||||
PostInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Enigmos.Ports;
|
||||
using Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.DataStructures.ConfigurableParameters;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Skeleton.Utils.RandomEngines;
|
||||
using TabulaSmaragdina;
|
||||
using TabulaSmaragdina.Constants;
|
||||
|
||||
|
||||
namespace Enigmos.Modules.ComputationalModules.Nullary;
|
||||
|
||||
public partial class NormalDistributionModule : NullaryComputationalModule, IParameterizedModule
|
||||
{
|
||||
private HashSet<DataOutPort> OutputGroup { get; set; } = new();
|
||||
private DataOutPort? Output1 { get; set; }
|
||||
private DataOutPort? Output2 { get; set; }
|
||||
private DataOutPort? Output3 { get; set; }
|
||||
private DataOutPort? Output4 { get; set; }
|
||||
public override IEnumerable<BasePort> Ports => base.Ports.Union(new[] { Output1, Output2, Output3, Output4 })!;
|
||||
private IDoubleParameter? Mu { get; set; }
|
||||
private IDoubleParameter? Sigma { get; set; }
|
||||
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
Output1 = GetPort<DataOutPort>("Output1");
|
||||
Output2 = GetPort<DataOutPort>("Output2");
|
||||
Output3 = GetPort<DataOutPort>("Output3");
|
||||
Output4 = GetPort<DataOutPort>("Output4");
|
||||
|
||||
OutputGroup = new HashSet<DataOutPort>(new[] { Output1, Output2, Output3, Output4 });
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
port.SetDataType(EnigmosConstant.DataPortTypes.Real);
|
||||
Mu = GlobalProvider.DataStructureProvider!.NewDoubleParameter("mu", -1, 1, 0);
|
||||
Sigma = GlobalProvider.DataStructureProvider.NewDoubleParameter("sigma", 0, 2, 1);
|
||||
ConfigurableParameters = new HashSet<IConfigurableParameter> { Mu, Sigma };
|
||||
PostInit();
|
||||
}
|
||||
|
||||
protected override void Compute(IRootModule root)
|
||||
{
|
||||
foreach (DataOutPort port in OutputGroup)
|
||||
{
|
||||
port.ResultData.Real = Normal.Get() * Sigma.ParameterValue - Mu.ParameterValue;
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<IConfigurableParameter> ConfigurableParameters { get; set; } = new();
|
||||
}
|
||||
Reference in New Issue
Block a user