Upgrade structure of code base
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
using Enigmos.Cables;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Cables;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using Nocturnis.Inventories.Items.Items;
|
||||
using VirtualChemistry.Chemistry.Mixtures.Implements;
|
||||
|
||||
namespace Enigmos.Ports;
|
||||
|
||||
public abstract partial class BasePort : TextureButton, IBasePort
|
||||
{
|
||||
public virtual Vector2 PositionToBoard() => Position + PivotOffset + Module?.PositionToBoard ?? Vector2.Zero;
|
||||
public virtual Vector2 PositionToBoard => Position + PivotOffset + Module?.PositionToBoard ?? Vector2.Zero;
|
||||
/// <summary>
|
||||
/// When Condition is Equal to 0, Port is Disabled
|
||||
/// </summary>
|
||||
@@ -20,77 +17,10 @@ public abstract partial class BasePort : TextureButton, IBasePort
|
||||
/// </summary>
|
||||
public int Quality { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Increase Condition
|
||||
/// Modify Quality base on property of material
|
||||
/// </summary>
|
||||
public void FixWith(IBaseChemicalItem c)
|
||||
{
|
||||
if (c.ContentMaterial.Amount == 0)
|
||||
return;
|
||||
HeterogeneousMixture material = c.ContentMaterial;
|
||||
double s = 1; //material.LayerOrder.Last.Value.CayleyValue();
|
||||
double u = 1;//material.LayerOrder.Last.Value.EuclidValue();
|
||||
double usedAmount = Math.Min(1d, material.LayerOrder.Last.Value.Amount);
|
||||
double dCond = usedAmount * (Module.MaintenanceAlpha * s - Module.MaintenanceBeta * u);
|
||||
double dQuality = usedAmount * (Math.Pow(Module.MaintenanceBeta, 2) * s - Module.MaintenanceAlpha * u);
|
||||
c.ConsumeFromBottom(usedAmount);
|
||||
Condition = Mathf.FloorToInt(Math.Max(0, Math.Min(100, Condition + dCond)));
|
||||
Quality = Mathf.FloorToInt(Math.Max(0, Math.Min(20000, Quality + dQuality)));
|
||||
}
|
||||
|
||||
public IBaseModule? Module { get; set; }
|
||||
public abstract bool IsMatch(IBasePort oth);
|
||||
public IBasePort? ConnectedPort { get; set; }
|
||||
public bool Connected => ConnectedPort != null;
|
||||
/// <summary>
|
||||
/// Try to Connect two Ports
|
||||
/// if this port is Connected already, it will disconnect first
|
||||
/// </summary>
|
||||
public void Connect()
|
||||
{
|
||||
if(Connected)
|
||||
Disconnect();
|
||||
if (Module.Board.ConnectPending == null)
|
||||
{
|
||||
SetStatusPending();
|
||||
Module.Board.ConnectPending = this;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Module.Board.ConnectPending.IsMatch(this))
|
||||
{
|
||||
ConnectedPort = Module.Board.ConnectPending;
|
||||
Module.Board.ConnectPending.ConnectedPort = this;
|
||||
BaseCable cable = MakeCable(Module.Board.ConnectPending);
|
||||
Module.Board.CablePairing[this] = cable;
|
||||
Module.Board.CablePairing[Module.Board.ConnectPending] = cable;
|
||||
Module.Board.AddCable(cable);
|
||||
cable.LineUpdate();
|
||||
SetStatusConnected();
|
||||
Module.Board.ConnectPending.SetStatusConnected();
|
||||
Module.Board.ConnectPending = null;
|
||||
return;
|
||||
}
|
||||
Module.Board.ConnectPending.SetStatusNormal();
|
||||
Module.Board.ConnectPending = null;
|
||||
}
|
||||
|
||||
protected virtual void Disconnect()
|
||||
{
|
||||
if (!Connected)
|
||||
return;
|
||||
IBaseCable cable = Module.Board.CablePairing[this];
|
||||
Module.Board.CablePairing.Remove(ConnectedPort);
|
||||
Module.Board.FocusedCables.Remove(Module.Board.CablePairing[this]);
|
||||
Module.Board.CablePairing.Remove(this);
|
||||
|
||||
cable.Free();
|
||||
ConnectedPort.SetStatusNormal();
|
||||
ConnectedPort.ConnectedPort = null;
|
||||
SetStatusNormal();
|
||||
ConnectedPort = null;
|
||||
}
|
||||
|
||||
public abstract void SetStatusPending();
|
||||
public abstract void SetStatusConnected();
|
||||
@@ -98,7 +28,7 @@ public abstract partial class BasePort : TextureButton, IBasePort
|
||||
/// <summary>
|
||||
/// Determine whether this port can be connected with given port
|
||||
/// </summary>
|
||||
public abstract BaseCable MakeCable(IBasePort other);
|
||||
public abstract IBaseCable MakeCable(IBasePort other);
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
using Enigmos.Cables;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Cables;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using Nocturnis.Enigmos.Ports.DataPorts.Directions;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
|
||||
namespace Enigmos.Ports.DataPorts;
|
||||
public partial class DataInPort : DataPort, IDataInPort
|
||||
{
|
||||
public new DataOutPort ConnectedPort
|
||||
public new IDataOutPort? ConnectedPort
|
||||
{
|
||||
get => base.ConnectedPort as DataOutPort;
|
||||
get => (base.ConnectedPort as IDataOutPort)!;
|
||||
set => base.ConnectedPort = value;
|
||||
}
|
||||
|
||||
public override bool IsMatch(IBasePort other) =>
|
||||
other is DataOutPort dataOut &&
|
||||
GlobalProvider.DataPackageTypeProvider.DataPortTypeCompatible(DataType, dataOut.DataType);
|
||||
|
||||
GlobalProvider.DataPackageTypeProvider!.DataPortTypeCompatible(DataType!, dataOut.DataType!);
|
||||
|
||||
public IDataPackage GetData(IRootModule root)
|
||||
public DataCache GetData => Connected ? ConnectedPort!.OutData : DataCache.Null;
|
||||
|
||||
/*public IDataPackage GetData(IRootModule root)
|
||||
{
|
||||
if (!Connected)
|
||||
return GlobalProvider.DataStructureProvider.DefaultDataPackage;
|
||||
return GlobalProvider.DataStructureProvider!.DefaultDataPackage;
|
||||
if(!ConnectedPort.DataUpdated)
|
||||
ConnectedPort.DataUpdateRequest(root);
|
||||
return ConnectedPort.ResultData;
|
||||
}
|
||||
return ConnectedPort!.ResultData;
|
||||
}*/
|
||||
|
||||
public override BaseCable MakeCable(IBasePort other)
|
||||
public override IBaseCable MakeCable(IBasePort other)
|
||||
{
|
||||
BaseCable res = base.MakeCable(other);
|
||||
IBaseCable res = base.MakeCable(other);
|
||||
res.PortFrom = this;
|
||||
res.PortTo = other;
|
||||
return res;
|
||||
|
||||
@@ -1,47 +1,40 @@
|
||||
using Enigmos.Cables;
|
||||
using Enigmos.Modules.ComputationalModules;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Nocturnis.DataStructures;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Cables;
|
||||
using Nocturnis.Enigmos.Modules.ComputationalModules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using Nocturnis.Enigmos.Ports.DataPorts.Directions;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
|
||||
namespace Enigmos.Ports.DataPorts;
|
||||
|
||||
public partial class DataOutPort : DataPort, IDataOutPort
|
||||
{
|
||||
public bool DataUpdated { get; set; }
|
||||
|
||||
public new ComputationalModule Module
|
||||
public new IComputationalModule Module
|
||||
{
|
||||
get => base.Module as ComputationalModule;
|
||||
get => (base.Module as IComputationalModule)!;
|
||||
set => base.Module = value;
|
||||
}
|
||||
|
||||
public void DataUpdateRequest(IRootModule root) => Module.ComputeWithTimeoutHandle(root);
|
||||
//public void DataUpdateRequest(IRootModule root) => Module.ComputeWithTimeoutHandle(root);
|
||||
|
||||
|
||||
public DataOutPort()
|
||||
public new IDataInPort? ConnectedPort
|
||||
{
|
||||
DataUpdated = false;
|
||||
ResultData = GlobalProvider.DataStructureProvider.NewDataPackage();
|
||||
}
|
||||
|
||||
public new DataInPort ConnectedPort
|
||||
{
|
||||
get => base.ConnectedPort as DataInPort;
|
||||
get => (base.ConnectedPort as IDataInPort)!;
|
||||
set => base.ConnectedPort = value;
|
||||
}
|
||||
|
||||
public override bool IsMatch(IBasePort other) =>
|
||||
other is DataInPort inPort &&
|
||||
GlobalProvider.DataPackageTypeProvider.DataPortTypeCompatible(inPort.DataType, DataType);
|
||||
public IDataPackage ResultData { get; set; }
|
||||
GlobalProvider.DataPackageTypeProvider!.DataPortTypeCompatible(inPort.DataType!, DataType!);
|
||||
|
||||
public override BaseCable MakeCable(IBasePort other)
|
||||
public override IBaseCable MakeCable(IBasePort other)
|
||||
{
|
||||
BaseCable res = base.MakeCable(other);
|
||||
IBaseCable res = base.MakeCable(other);
|
||||
res.PortFrom = other;
|
||||
res.PortTo = this;
|
||||
return res;
|
||||
}
|
||||
|
||||
public DataCache OutData { get; set; } = new(x => (0, ""));
|
||||
}
|
||||
|
||||
@@ -1,54 +1,53 @@
|
||||
using Enigmos.Cables;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Cables;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using Nocturnis.Enigmos.Ports.DataPorts;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
|
||||
namespace Enigmos.Ports.DataPorts;
|
||||
|
||||
public abstract partial class DataPort : BasePort, IDataPort
|
||||
{
|
||||
public new DataPort ConnectedPort
|
||||
public new IDataPort? ConnectedPort
|
||||
{
|
||||
get => base.ConnectedPort as DataPort;
|
||||
get => (base.ConnectedPort as IDataPort)!;
|
||||
set => base.ConnectedPort = value;
|
||||
}
|
||||
protected Sprite2D DataTypeTexture { get; set; }
|
||||
public StringName DataType { get; set; }
|
||||
protected Sprite2D? DataTypeTexture { get; set; }
|
||||
public StringName? DataType { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
Console.WriteLine("XY");
|
||||
DataTypeTexture = GetNode<Sprite2D>("DataTypeTexture");
|
||||
DataTypeTexture.Visible = false;
|
||||
base.Init();
|
||||
}
|
||||
|
||||
|
||||
public void SetDataType(StringName val)
|
||||
{
|
||||
if(Connected && val != ConnectedPort.DataType)
|
||||
Disconnect();
|
||||
if(Connected && val != ConnectedPort!.DataType)
|
||||
this.Disconnect();
|
||||
DataType = val;
|
||||
DataTypeTexture.Texture = GlobalProvider.EnigmosProvider.DataPortTypeMap[val];
|
||||
DataTypeTexture!.Texture = GlobalProvider.EnigmosProvider!.DataPortTypeMap[val];
|
||||
}
|
||||
|
||||
private void MouseEnterHandler() => DataTypeTexture.Visible = true;
|
||||
private void MouseExitHandler() => DataTypeTexture.Visible = false;
|
||||
private void MouseEnterHandler() => DataTypeTexture!.Visible = true;
|
||||
private void MouseExitHandler() => DataTypeTexture!.Visible = false;
|
||||
|
||||
public override BaseCable MakeCable(IBasePort other)
|
||||
public override IBaseCable MakeCable(IBasePort other)
|
||||
{
|
||||
BaseCable res = GlobalProvider.EnigmosProvider.DataCableScene.Instantiate<BaseCable>();
|
||||
BaseCable res = GlobalProvider.EnigmosProvider!.DataCableScene.Instantiate<BaseCable>();
|
||||
res.Init();
|
||||
return res;
|
||||
}
|
||||
|
||||
public override void SetStatusNormal() =>
|
||||
TextureNormal = GlobalProvider.EnigmosProvider.DataPortStatusNormal;
|
||||
TextureNormal = GlobalProvider.EnigmosProvider!.DataPortStatusNormal;
|
||||
|
||||
public override void SetStatusPending() =>
|
||||
TextureNormal = GlobalProvider.EnigmosProvider.DataPortStatusPending;
|
||||
TextureNormal = GlobalProvider.EnigmosProvider!.DataPortStatusPending;
|
||||
|
||||
public override void SetStatusConnected() =>
|
||||
TextureNormal = GlobalProvider.EnigmosProvider.DataPortStatusConnected;
|
||||
TextureNormal = GlobalProvider.EnigmosProvider!.DataPortStatusConnected;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,20 @@ using Enigmos.Cables;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using Nocturnis.Enigmos.Ports.SignalPorts.Directions;
|
||||
|
||||
namespace Enigmos.Ports.SignalPorts;
|
||||
public partial class SignalInPort : SignalPort, ISignalInPort
|
||||
{
|
||||
public new IControllingModule Module
|
||||
{
|
||||
get => (base.Module as ControllingModule)!;
|
||||
get => (base.Module as PiplineModule)!;
|
||||
set => base.Module = value;
|
||||
}
|
||||
|
||||
public new SignalOutPort? ConnectedPort
|
||||
public new ISignalOutPort? ConnectedPort
|
||||
{
|
||||
get => base.ConnectedPort as SignalOutPort;
|
||||
get => base.ConnectedPort as ISignalOutPort;
|
||||
set => base.ConnectedPort = value;
|
||||
}
|
||||
|
||||
@@ -27,4 +28,5 @@ public partial class SignalInPort : SignalPort, ISignalInPort
|
||||
res.PortTo = other;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
using Enigmos.Cables;
|
||||
using Enigmos.Modules.ControllingModules;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using Nocturnis.Enigmos.Ports.SignalPorts.Directions;
|
||||
|
||||
namespace Enigmos.Ports.SignalPorts;
|
||||
|
||||
public partial class SignalOutPort : SignalPort, ISignalOutPort
|
||||
{
|
||||
public new IControllingModule Module
|
||||
public new IRoutingModule Module
|
||||
{
|
||||
get => (base.Module as ControllingModule)!;
|
||||
get => (base.Module as IRoutingModule)!;
|
||||
set => base.Module = value;
|
||||
}
|
||||
|
||||
|
||||
public new ISignalInPort? ConnectedPort
|
||||
{
|
||||
get => base.ConnectedPort as SignalInPort;
|
||||
get => base.ConnectedPort as ISignalInPort;
|
||||
set => base.ConnectedPort = value;
|
||||
}
|
||||
|
||||
@@ -29,4 +29,12 @@ public partial class SignalOutPort : SignalPort, ISignalOutPort
|
||||
res.PortTo = this;
|
||||
return res;
|
||||
}
|
||||
|
||||
public void Route()
|
||||
{
|
||||
if (!Connected)
|
||||
return;
|
||||
ConnectedPort!.Module.Execute();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
using Enigmos.Cables;
|
||||
using Godot;
|
||||
using Nocturnis.Enigmos.Modules;
|
||||
using Nocturnis.Enigmos.Ports;
|
||||
using TabulaSmaragdina;
|
||||
using Nocturnis.Enigmos.Ports.SignalPorts;
|
||||
using Nocturnis.GlobalManagement.Providers;
|
||||
|
||||
namespace Enigmos.Ports.SignalPorts;
|
||||
|
||||
public abstract partial class SignalPort : BasePort, ISignalInPort
|
||||
public abstract partial class SignalPort : BasePort, ISignalPort
|
||||
{
|
||||
public new IControllingModule Module
|
||||
{
|
||||
get => (base.Module as IControllingModule)!;
|
||||
set => base.Module = value;
|
||||
}
|
||||
protected AnimatedSprite2D SignalDirection { get; set; }
|
||||
|
||||
protected AnimatedSprite2D? SignalDirection { get; set; }
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
@@ -21,8 +17,8 @@ public abstract partial class SignalPort : BasePort, ISignalInPort
|
||||
SignalDirection.Visible = false;
|
||||
}
|
||||
|
||||
private void MouseEnteredHandler() => SignalDirection.Visible = true;
|
||||
private void MouseExitedHandler() => SignalDirection.Visible = false;
|
||||
private void MouseEnteredHandler() => SignalDirection!.Visible = true;
|
||||
private void MouseExitedHandler() => SignalDirection!.Visible = false;
|
||||
|
||||
public override void SetStatusConnected() =>
|
||||
TextureNormal = GlobalProvider.EnigmosProvider!.SignalPortStatusConnected;
|
||||
@@ -39,4 +35,10 @@ public abstract partial class SignalPort : BasePort, ISignalInPort
|
||||
res.Init();
|
||||
return res;
|
||||
}
|
||||
|
||||
public new ISignalPort? ConnectedPort
|
||||
{
|
||||
get => (base.ConnectedPort as ISignalPort)!;
|
||||
set => base.ConnectedPort = value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user