Skip to content

Commit

Permalink
Merge pull request #132 from Akhetonics/feature/externalPortSwitching
Browse files Browse the repository at this point in the history
Feature/external port switching
  • Loading branch information
aignermax committed Apr 3, 2024
2 parents 5e860da + 393c135 commit 0a41773
Show file tree
Hide file tree
Showing 49 changed files with 1,369 additions and 637 deletions.
38 changes: 37 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,40 @@ dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, protec
dotnet_naming_style.first_word_upper.capitalization = pascal_case

# Code quality rules
dotnet_diagnostic.CA1822.severity = warning
dotnet_diagnostic.CA1822.severity = warning
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_indent_labels = one_less_than_current
csharp_space_around_binary_operators = before_and_after
[*.{cs,vb}]
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
22 changes: 20 additions & 2 deletions Connect-A-Pic-Core/ExternalPorts/ExternalInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,26 @@ namespace CAP_Core.ExternalPorts
{
public class ExternalInput : ExternalPort
{
public LaserType LaserType { get; }
public Complex InFlowPower { get; set; }
private LaserType _laserType;
public LaserType LaserType
{
get => _laserType;
set
{
_laserType = value;
OnPropertyChanged();
}
}
public Complex _inFlowPower;
public Complex InFlowPower
{
get => _inFlowPower;
set
{
_inFlowPower = value;
OnPropertyChanged();
}
}
public Complex InFlowField => Complex.FromPolarCoordinates(Math.Sqrt(InFlowPower.Magnitude), InFlowPower.Phase);
public ExternalInput(string pinName, LaserType inputLaserType, int tilePositionY, Complex inflowPower) : base(pinName, tilePositionY)
{
Expand Down
17 changes: 14 additions & 3 deletions Connect-A-Pic-Core/ExternalPorts/ExternalPort.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
namespace CAP_Core.ExternalPorts
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace CAP_Core.ExternalPorts
{
public abstract class ExternalPort
public abstract class ExternalPort: INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public ExternalPort(string pinName, int tilePositionY)
{
PinName = pinName;
Expand All @@ -10,5 +19,7 @@ public ExternalPort(string pinName, int tilePositionY)

public string PinName { get; }
public int TilePositionY { get; }


}
}
}
5 changes: 4 additions & 1 deletion Connect-A-Pic-Core/Grid/GridManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class GridManager
public IExternalPortManager ExternalPortManager { get; }
public IComponentRotator ComponentRotator { get; }
public IComponentRelationshipManager ComponentRelationshipManager { get; }
public LightManager LightManager { get; }

public GridManager(ITileManager tileManager, IComponentMover componentMover, IExternalPortManager externalPortManager, IComponentRotator componentRotator, IComponentRelationshipManager componentRelationshipManager)
public GridManager(ITileManager tileManager, IComponentMover componentMover, IExternalPortManager externalPortManager, IComponentRotator componentRotator, IComponentRelationshipManager componentRelationshipManager, LightManager lightManager)
{
TileManager = tileManager;
ComponentMover = componentMover;
ExternalPortManager = externalPortManager;
ComponentRotator = componentRotator;
ComponentRelationshipManager = componentRelationshipManager;
LightManager = lightManager;
}
public GridManager (int width , int height)
{
Expand All @@ -28,6 +30,7 @@ public GridManager (int width , int height)
ExternalPortManager = new ExternalPortManager(TileManager);
ComponentRotator = new ComponentRotator(TileManager,ComponentMover);
ComponentRelationshipManager = new ComponentRelationshipManager(TileManager);
LightManager = new LightManager();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CAP_Core.ExternalPorts;
using CAP_Core.ExternalPorts;
using System.Numerics;

namespace CAP_Core.LightCalculation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public class LightCalculationService

private SemaphoreSlim Semaphore = new (1, 1);

public LightCalculationService(GridManager grid, LightManager lightManager, ILightCalculator gridSMatrixAnalyzer)
public LightCalculationService(GridManager grid, ILightCalculator gridSMatrixAnalyzer)
{
LightInputs = grid.ExternalPortManager.GetAllExternalInputs();

grid.ExternalPortManager.ExternalPorts.CollectionChanged += async (object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) => {
LightInputs = grid.ExternalPortManager.GetAllExternalInputs();
if (lightManager.IsLightOn)
if (grid.LightManager.IsLightOn)
{
await ShowLightPropagationAsync();
}
Expand Down
74 changes: 41 additions & 33 deletions Scenes/ExternalPortContainer/PortsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,68 @@
using CAP_Core.ExternalPorts;
using System.Diagnostics;
using CAP_Core.LightCalculation;
using System.ComponentModel;
using ConnectAPIC.Scripts.ViewModel;
using ConnectAPIC.LayoutWindow.ViewModel.Commands;
using ConnectAPIC.Scripts.ViewModel.Commands;
using ConnectAPic.LayoutWindow;
using ConnectAPIC.Scenes.RightClickMenu;




[SuperNode(typeof(Dependent))]
public partial class PortsContainer : Node2D
{
public override partial void _Notification(int what);
[Dependency] public GridManager GridManager => DependOn<GridManager>();
[Dependency] public LightManager LightManager => DependOn<LightManager>();
[Dependency] public GridManager Grid => DependOn<GridManager>();
[Dependency] public LightCalculationService LightCalculator => DependOn<LightCalculationService>();

[Export] public PackedScene ExternalPortViewTemplate { get; set; }
[Export] public PackedScene RightClickMenu { get; set; }
[Export] public PackedScene RightClickMenuTemplate { get; set; }

public SimpleControlMenu ControlMenu { get; set; }
public ExternalPortViewFactory PortViewFactory { get; set; }
public List<ExternalPortView> Views { get; set; } = new();
public List<ExternalPortViewModel> PortViewModels { get; set; } = new();

//Commands
public static InputPowerAdjustCommand inputPowerAdjustCommand;
public static InputColorChangeCommand inputColorChangeCommand;
public static InputOutputChangeCommand inputOutputChangeCommand;

public void OnResolved()
{
PortViewFactory = new ExternalPortViewFactory(this, GridManager, LightCalculator, LightManager);
InitializeCommands();
InitializePortsAndPortsFactory();
InitializeControlMenuAndConnectToPorts();
}

GridManager.ExternalPortManager.ExternalPorts.CollectionChanged += (object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) =>
private void InitializeControlMenuAndConnectToPorts()
{
foreach (ExternalPortViewModel viewModel in PortViewModels)
{
ExternalPortView tmpView;
foreach (ExternalPort port in e.OldItems)
{
tmpView = Views.Find((view) => port.TilePositionY == view.ViewModel.TilePositionY);
Views.Remove(tmpView);
tmpView.RightClicked -= View_RightClicked;
tmpView.QueueFree();
}
foreach (ExternalPort port in e.NewItems)
{
tmpView = PortViewFactory?.InitializeExternalPortView(port);
tmpView.RightClicked += View_RightClicked;
Views.Add(tmpView);
}
};

Views = PortViewFactory?.InitializeExternalPortViewList(GridManager.ExternalPortManager.ExternalPorts);

foreach (ExternalPortView view in Views) {
view.RightClicked += View_RightClicked;
viewModel.Clicked += ViewModel_Clicked;
}
ControlMenu = RightClickMenuTemplate.Instantiate<SimpleControlMenu>();
ControlMenu.SetPortContainer(this);
this.AddChild(ControlMenu);
}

private void View_RightClicked(object sender, EventArgs e)
private void InitializePortsAndPortsFactory()
{
PortViewFactory = new ExternalPortViewFactory(this, Grid, LightCalculator);
PortViewModels = PortViewFactory?.InitializeExternalPortViewList(Grid.ExternalPortManager.ExternalPorts);
}
private void InitializeCommands()
{
ExternalPortView view = sender as ExternalPortView;
if (view == null) return;
inputPowerAdjustCommand = new InputPowerAdjustCommand(Grid);
inputColorChangeCommand = new InputColorChangeCommand(Grid);
inputOutputChangeCommand = new InputOutputChangeCommand(Grid);
}

//TODO: find out if view is input or output
//TODO: build right click menu accordingly (if haven't done it already)
//TODO: open right click menu on that ports position (with some offset)
private void ViewModel_Clicked(object sender, EventArgs e)
{
ExternalPortViewModel viewModel = sender as ExternalPortViewModel;
if (viewModel == null) return;
ControlMenu.ConnectToPort(viewModel);
}
}
7 changes: 6 additions & 1 deletion Scenes/PICEditor/PICEditor.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://cu6wqy6xwjfo1"]
[gd_scene load_steps=24 format=3 uid="uid://cu6wqy6xwjfo1"]

[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="1_c0scx"]
[ext_resource type="Script" path="res://Scripts/View/ComponentFactory/ComponentViewFactory.cs" id="2_7hjmy"]
Expand All @@ -11,6 +11,7 @@
[ext_resource type="Script" path="res://Scripts/View/DragDropProxy.cs" id="8_h35r3"]
[ext_resource type="Script" path="res://Scripts/View/StandardDialogs/NotificationManager.cs" id="9_gj54m"]
[ext_resource type="PackedScene" uid="uid://bscqmaslppyt8" path="res://Scenes/NotificationBox.tscn" id="10_06t00"]
[ext_resource type="PackedScene" uid="uid://dx13abdux2230" path="res://Scenes/RightClickMenu/ControlMenu.tscn" id="11_ylcdl"]
[ext_resource type="PackedScene" uid="uid://bd8isg4mddv21" path="res://Scenes/InGameConsole/InGameConsole.tscn" id="16_7rcst"]
[ext_resource type="Texture2D" uid="uid://djdwbxfnvfvfb" path="res://Scenes/MenuBar/SaveIcon.png" id="17_q4e7w"]
[ext_resource type="Texture2D" uid="uid://qtdana7kc4y" path="res://Scenes/MenuBar/LoadIcon.png" id="18_17x6l"]
Expand Down Expand Up @@ -57,6 +58,7 @@ metadata/_edit_use_anchors_ = true

[node name="PortContainer" parent="GridView" instance=ExtResource("22_75h2p")]
ExternalPortViewTemplate = ExtResource("2_dn85u")
RightClickMenuTemplate = ExtResource("11_ylcdl")

[node name="Control" type="Control" parent="."]
layout_mode = 3
Expand Down Expand Up @@ -199,3 +201,6 @@ NotificationBoxScene = ExtResource("10_06t00")
[connection signal="toggled" from="GUILayer/MenuBar/HBoxContainer/btnShowLightPropagation" to="GridView" method="_on_btn_show_light_propagation_toggled"]
[connection signal="pressed" from="GUILayer/MenuBar/HBoxContainer/btnExportNazca" to="GridView" method="_on_btn_export_nazca_pressed"]
[connection signal="toggled" from="GUILayer/ToolboxControl/MarginContainer/VBoxContainer/HideToggle" to="GUILayer/ToolboxControl" method="OnToggleButtonPressed"]
[connection signal="WindowClosed" from="GUILayer/HelpWindow" to="MainCamera" method="OnMouseExitedTutorialWindow"]
[connection signal="mouse_entered" from="GUILayer/HelpWindow" to="MainCamera" method="OnMouseEnteredTutorialWindow"]
[connection signal="mouse_exited" from="GUILayer/HelpWindow" to="MainCamera" method="OnMouseExitedTutorialWindow"]
Binary file added Scenes/PopUpWindow/ComponentPlacement.ogv
Binary file not shown.
Binary file added Scenes/PopUpWindow/ExitButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://cxa7n5a2grbq6"
path="res://.godot/imported/TopBar.png-ec389bda0865d131c0b24dbb29cb3ea5.ctex"
uid="uid://bwofnv3cggxhh"
path="res://.godot/imported/ExitButton.png-fc507b5e0a2c39f38b65afe60146ead0.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Scenes/RightClickMenu/TopBar.png"
dest_files=["res://.godot/imported/TopBar.png-ec389bda0865d131c0b24dbb29cb3ea5.ctex"]
source_file="res://Scenes/PopUpWindow/ExitButton.png"
dest_files=["res://.godot/imported/ExitButton.png-fc507b5e0a2c39f38b65afe60146ead0.ctex"]

[params]

Expand Down
4 changes: 4 additions & 0 deletions Scenes/PopUpWindow/PopUpWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public partial class PopUpWindow : Control
{
[Export] public Button ToggleButton { get; set; }

//Godot signal for easier handling from gui
[Signal] public delegate void WindowClosedEventHandler();

public override void _Ready()
{
Expand All @@ -23,12 +25,14 @@ public override void _Ready()
private void OnToggleButtonPressed(bool toggledOn)
{
Visible = toggledOn;
if (!Visible) EmitSignal(SignalName.WindowClosed);
}

private void OnCloseButtonPressed()
{
Visible = false;
ToggleButton.ButtonPressed = false;
EmitSignal(SignalName.WindowClosed);
}

}
Expand Down
Loading

0 comments on commit 0a41773

Please sign in to comment.