source generator
This commit is contained in:
@@ -19,17 +19,18 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
[Export] protected bool UsingPreset { get; set; }
|
||||
[Export] public IPresetModuleConnection[] PresetConnections { get; set; } = Array.Empty<IPresetModuleConnection>();
|
||||
[Export] public string LabelString { get; set; } = "";
|
||||
|
||||
|
||||
public virtual Vector2 PositionToBoard => Position;
|
||||
protected virtual bool Draggable => true;
|
||||
protected virtual bool HasManual => true;
|
||||
public bool HasLabel => HasManual;
|
||||
public virtual IEnumerable<IBasePort> Ports => Array.Empty<BasePort>();
|
||||
|
||||
public virtual IEnumerable<IBasePort> Ports => GetChildren().OfType<IBasePort>();
|
||||
|
||||
public IBaseBoard? Board { get; set; }
|
||||
private ModuleManual? Manual { get; set; }
|
||||
public ISimpleLabel? Label { get; set; }
|
||||
public Label? Label { get; set; }
|
||||
public Node AsNode => this;
|
||||
|
||||
public virtual void PresetValueInit()
|
||||
{
|
||||
foreach (IBasePort port in Ports)
|
||||
@@ -38,19 +39,18 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
port.Quality = PresetPortQuality;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public virtual void Init()
|
||||
{
|
||||
if (HasLabel)
|
||||
{
|
||||
Label = GlobalProvider.SceneProvider!
|
||||
.AssetMapper<ISimpleLabel>()
|
||||
.Instantiate<ISimpleLabel>();
|
||||
Label = new Label();
|
||||
Label.AddThemeFontOverride("font", GlobalProvider.Font);
|
||||
Label.Position = new Vector2(0, -25);
|
||||
Label.Text = LabelString;
|
||||
AddChild(Label.AsNode);
|
||||
AddChild(Label);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
{
|
||||
foreach (IBasePort port in Ports)
|
||||
{
|
||||
if(!Board!.CablePairing.ContainsKey(port))
|
||||
if (!Board!.CablePairing.ContainsKey(port))
|
||||
continue;
|
||||
Board.CablePairing[port].LineUpdate();
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
{
|
||||
foreach (IBasePort port in Ports)
|
||||
port.Module = this;
|
||||
if(UsingPreset)
|
||||
if (UsingPreset)
|
||||
PresetValueInit();
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
}
|
||||
|
||||
protected virtual void TimeoutHandler(ModuleExecutionTimeout timeout) => throw timeout;
|
||||
|
||||
|
||||
public override Variant _GetDragData(Vector2 atPosition)
|
||||
{
|
||||
if (!Draggable)
|
||||
@@ -102,20 +102,12 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
return GlobalProvider.DataStructureProvider!.NewVariantWithType("Module", this);
|
||||
}
|
||||
|
||||
|
||||
/*protected T GetPort<T>(string path) where T : BasePort
|
||||
{
|
||||
T res = GetNode<T>(path);
|
||||
res.Init();
|
||||
return res;
|
||||
}*/
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton eventMouseButton)
|
||||
{
|
||||
Vector2 mousePosition = GetLocalMousePosition();
|
||||
if(mousePosition.X > 0 && mousePosition.X < Size.X && mousePosition.Y > 0 && mousePosition.Y < Size.Y)
|
||||
if (mousePosition.X > 0 && mousePosition.X < Size.X && mousePosition.Y > 0 && mousePosition.Y < Size.Y)
|
||||
{
|
||||
if (eventMouseButton.ButtonIndex == MouseButton.Right && eventMouseButton.Pressed)
|
||||
{
|
||||
@@ -125,8 +117,8 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
return;
|
||||
if (Manual == null)
|
||||
{
|
||||
Manual = GlobalProvider.SceneProvider!
|
||||
.AssetMapper<ModuleManual>()
|
||||
Manual = GlobalProvider
|
||||
.AssetMapper<ModuleManual>.Scene
|
||||
.Instantiate<ModuleManual>();
|
||||
Manual.Init(this);
|
||||
}
|
||||
@@ -148,7 +140,8 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
.Select(p => Board.CablePairing[p])
|
||||
.ToHashSet();
|
||||
if (this is ICompositeModule thisCompositeModule)
|
||||
foreach (IBasePort port in thisCompositeModule.SubModules.SelectMany(module => module.Ports).Where(Board.CablePairing.ContainsKey))
|
||||
foreach (IBasePort port in thisCompositeModule.SubModules.SelectMany(module => module.Ports)
|
||||
.Where(Board.CablePairing.ContainsKey))
|
||||
Board.FocusedCables.Add(Board.CablePairing[port]);
|
||||
foreach (IBaseCable cable in Board.FocusedCables)
|
||||
cable.Modulate = Color.Color8(255, 255, 255, 255);
|
||||
@@ -159,4 +152,7 @@ public abstract partial class BaseModule : TextureRect, IBaseModule
|
||||
|
||||
base._Input(@event);
|
||||
}
|
||||
|
||||
public Texture2D PreviewTexture => GlobalProvider.TextureProvider.ModuleTextureMapper(this);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user