diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 00000000..ddb6ff85 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "visualstudiotoolsforunity.vstuc" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..da60e25a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,10 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Attach to Unity", + "type": "vstuc", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..0a8271c7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,70 @@ +{ + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.vs": true, + "**/.gitmodules": true, + "**/.vsconfig": true, + "**/*.booproj": true, + "**/*.pidb": true, + "**/*.suo": true, + "**/*.user": true, + "**/*.userprefs": true, + "**/*.unityproj": true, + "**/*.dll": true, + "**/*.exe": true, + "**/*.pdf": true, + "**/*.mid": true, + "**/*.midi": true, + "**/*.wav": true, + "**/*.gif": true, + "**/*.ico": true, + "**/*.jpg": true, + "**/*.jpeg": true, + "**/*.png": true, + "**/*.psd": true, + "**/*.tga": true, + "**/*.tif": true, + "**/*.tiff": true, + "**/*.3ds": true, + "**/*.3DS": true, + "**/*.fbx": true, + "**/*.FBX": true, + "**/*.lxo": true, + "**/*.LXO": true, + "**/*.ma": true, + "**/*.MA": true, + "**/*.obj": true, + "**/*.OBJ": true, + "**/*.asset": true, + "**/*.cubemap": true, + "**/*.flare": true, + "**/*.mat": true, + "**/*.meta": true, + "**/*.prefab": true, + "**/*.unity": true, + "build/": true, + "Build/": true, + "Library/": true, + "library/": true, + "obj/": true, + "Obj/": true, + "Logs/": true, + "logs/": true, + "ProjectSettings/": true, + "UserSettings/": true, + "temp/": true, + "Temp/": true + }, + "files.associations": { + "*.asset": "yaml", + "*.meta": "yaml", + "*.prefab": "yaml", + "*.unity": "yaml", + }, + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + "*.sln": "*.csproj", + }, + "dotnet.defaultSolution": "Digital-Logic-Sim-Tests.sln" +} \ No newline at end of file diff --git a/Assets/Scripts/Description/Types/ProjectDescription.cs b/Assets/Scripts/Description/Types/ProjectDescription.cs index a8dc0f33..bc4b2cfb 100644 --- a/Assets/Scripts/Description/Types/ProjectDescription.cs +++ b/Assets/Scripts/Description/Types/ProjectDescription.cs @@ -21,6 +21,10 @@ public struct ProjectDescription public bool Prefs_SimPaused; public int Prefs_SimTargetStepsPerSecond; public int Prefs_SimStepsPerClockTick; + public int Prefs_WireRouting; + public int Prefs_WireStyle; + + // List of all player-created chips (in order of creation -- oldest first) public string[] AllCustomChipNames; diff --git a/Assets/Scripts/Game/Elements/WireInstance.cs b/Assets/Scripts/Game/Elements/WireInstance.cs index afe28ec4..ea79104e 100644 --- a/Assets/Scripts/Game/Elements/WireInstance.cs +++ b/Assets/Scripts/Game/Elements/WireInstance.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using DLS.Description; using DLS.Graphics; using UnityEngine; @@ -63,7 +64,15 @@ public WireInstance(ConnectionInfo firstConnectionInfo, int spawnOrder) bitCount = firstPin.bitCount; originalWireConnectionPoint = firstConnectionInfo.connectionPoint; WirePoints.Add(GetAttachmentPoint(firstConnectionInfo)); - WirePoints.Add(WirePoints[0]); // end point to be controlled by mouse during placement mode + + if (Project.ActiveProject.ShouldRouteWires) + { + WirePoints.Add(WirePoints[0]); // add second point to allow routing wires + WirePoints.Add(WirePoints[0]); // add third point to allow routing wires + //WirePoints.Add(WirePoints[0]); // add fourth point to allow routing wires + } + + WirePoints.Add(WirePoints[^1]); // end point to be controlled by mouse during placement mode BitWires = new BitWire[(int)bitCount]; this.spawnOrder = spawnOrder; @@ -117,12 +126,21 @@ public void FinishPlacingWire(ConnectionInfo connection) PinInstance endPin = connection.pin; WirePoints[^1] = endPin.GetWorldPos(); + if (Project.ActiveProject.ShouldRouteWires) + { + // If routing wires, we need to reroute the second last point to account for the end pin snapping to the grid or chip pin + Vector2[] points = GridHelper.RouteWire(GetWirePoint(WirePoints.Count - 3), endPin.GetWorldPos(), Project.ActiveProject.WireRoutingMode, GetWireLength()); + SetWirePoint(points[0], WirePoints.Count - 3); + SetWirePoint(points[1], WirePoints.Count - 2); + + } + // If wire connection started out at another wire, it is not known (until now when we have the end pin) whether that - // initial connection should be to the source or target pin of that wire (so correct if needed) - ConnectionInfo correctedFirstConnection = FirstConnectionInfo; + // initial connection should be to the source or target pin of that wire (so correct if needed) + ConnectionInfo correctedFirstConnection = FirstConnectionInfo; if (FirstConnectionInfo.pin.IsSourcePin == endPin.IsSourcePin) // same type, must fix { - Debug.Assert(FirstConnectionInfo.IsConnectedAtWire, "Connection is source->source or target->target, but connection didn't start from wire?!"); + System.Diagnostics.Debug.Assert(FirstConnectionInfo.IsConnectedAtWire, "Connection is source->source or target->target, but connection didn't start from wire?!"); if (endPin.IsSourcePin) correctedFirstConnection.pin = GetBusCorrectedTargetPin(FirstConnectionInfo.connectedWire); else correctedFirstConnection.pin = FirstConnectionInfo.connectedWire.SourcePin; } @@ -207,17 +225,69 @@ public void SetWirePoint(Vector2 p, int i) public void SetWirePointWithSnapping(Vector2 p, int i, Vector2 straightLineRefPoint) { if (Project.ActiveProject.ShouldSnapToGrid) p = GridHelper.SnapToGrid(p, true, true); - if (Project.ActiveProject.ForceStraightWires) p = GridHelper.ForceStraightLine(straightLineRefPoint, p); - + if (Project.ActiveProject.ForceStraightWires && (!Project.ActiveProject.ShouldRouteWires || IsFullyConnected)) p = GridHelper.ForceStraightLine(straightLineRefPoint, p); + if (Project.ActiveProject.ForceStraightWires && Project.ActiveProject.ShouldRouteWires /*&& WirePoints.Count > 3*/ && !IsFullyConnected) + { + // If routing wires, we need to route the wire to the new point + int refPointIndex = 0; + if (WirePoints.Count > 4) + { + refPointIndex = WirePoints.Count - 4; // use the point before the last two points + } + + + Vector2[] points = GridHelper.RouteWire(GetWirePoint(refPointIndex), p, Project.ActiveProject.WireRoutingMode, GetWireLength()); + p = points[2]; + SetWirePoint(points[0], WirePoints.Count - 3); + SetWirePoint(points[1], WirePoints.Count - 2); + //SetWirePoint(points[2], WirePoints.Count - 2); + } + else if (Project.ActiveProject.ShouldRouteWires) + { + // If button to route wires is not pressed (or released), set the last two points to be the same (overlapping points can be removed later) + if (WirePoints.Count > 2) WirePoints[^2] = p; + if (WirePoints.Count > 3) WirePoints[^3] = p; + if (WirePoints.Count > 4) WirePoints[^4] = p; + + } + SetWirePoint(p, i); } + /* + public void SetWirePointWithSnapping(Vector2 p, int i, Vector2 straightLineRefPoint, ChipInteractionController.RotationTarget r) + { + if (Project.ActiveProject.ShouldSnapToGrid) p = GridHelper.SnapToGrid(p, true, true); + if (Project.ActiveProject.ForceStraightWires && (!Project.ActiveProject.ShouldRouteWires || IsFullyConnected)) p = GridHelper.ForceStraightLine(straightLineRefPoint, p); + if (Project.ActiveProject.ForceStraightWires && Project.ActiveProject.ShouldRouteWires && WirePoints.Count > 3 && !IsFullyConnected) + { + // If routing wires, we need to route the wire to the new point + Vector2[] points = GridHelper.RouteWire(GetWirePoint(WirePoints.Count - 4), p, Project.ActiveProject.WireRoutingMode, GetWireLength()); + p = points[2]; + SetWirePoint(points[0], WirePoints.Count - 3); + SetWirePoint(points[1], WirePoints.Count - 2); + } + else + { + // If button to route wires is not pressed (or released), set the last two points to be the same (overlapping points can be removed later) + if (WirePoints.Count > 2) WirePoints[^2] = p; + } + + SetWirePoint(p, i); + }*/ public void SetLastWirePoint(Vector2 p) { SetWirePointWithSnapping(p, WirePoints.Count - 1, GetWirePoint(WirePoints.Count - 2)); } - public void AddWirePoint(Vector2 p) => WirePoints.Add(p); + public void AddWirePoint(Vector2 p) + { + WirePoints.Add(p); + if (!Project.ActiveProject.ShouldRouteWires) return; + WirePoints.Add(p); + WirePoints.Add(p); + //WirePoints.Add(p); // add 3 extra points to allow routing wires + } public void DeleteWirePoint(int i) { @@ -245,7 +315,7 @@ public bool RemoveLastPoint() // Connection info for the end of this wire that connects to another wire public ref ConnectionInfo GetWireConnectionInfo() { - Debug.Assert(ConnectedWire != null, "No connected wire?"); + System.Diagnostics.Debug.Assert(ConnectedWire != null, "No connected wire?"); return ref SourceConnectionInfo.IsConnectedAtWire ? ref SourceConnectionInfo : ref TargetConnectionInfo; } @@ -323,6 +393,17 @@ public Color GetColour(int bitIndex) return col; } + + public float GetWireLength() + { + float length = 0f; + for (int i = 0; i < WirePoints.Count - 1; i++) + { + length += Vector2.Distance(WirePoints[i], WirePoints[i + 1]); + } + + return length; + } public static Vector2 ClosestPointOnLineSegment(Vector2 p, Vector2 a1, Vector2 a2) { diff --git a/Assets/Scripts/Game/Helpers/GridHelper.cs b/Assets/Scripts/Game/Helpers/GridHelper.cs index 63df3ee2..15be05cb 100644 --- a/Assets/Scripts/Game/Helpers/GridHelper.cs +++ b/Assets/Scripts/Game/Helpers/GridHelper.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; using static DLS.Graphics.DrawSettings; namespace DLS.Game @@ -52,5 +53,164 @@ public static Vector2 ForceStraightLine(Vector2 prev, Vector2 curr) return prev + offset; } + + + public static Vector2[] RouteWire(Vector2 prev, Vector2 curr, int mode) + { + Vector2[] points = new Vector2[2]; + Vector2 offset = curr - prev; + + + if (mode == 1) + { + if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y)) + { + + // Horizontal mode: move horizontally, then 45-degree diagonal to curr + float diagLen = Mathf.Min(Mathf.Abs(offset.x), Mathf.Abs(offset.y)); + float signX = Mathf.Sign(offset.x); + Vector2 bend = new Vector2(curr.x - diagLen * signX, prev.y); + points[0] = bend; + points[1] = curr; + } + else + { + // Vertical mode: move vertically, then 45-degree diagonal to curr + float diagLen = Mathf.Min(Mathf.Abs(offset.x), Mathf.Abs(offset.y)); + float signY = Mathf.Sign(offset.y); + Vector2 bend = new Vector2(prev.x, curr.y - diagLen * signY); + points[0] = bend; + points[1] = curr; + } + } + else if (mode == 2) + { + if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y)) + { + // Horizontal mode: move horizontally, then vertically to curr + Vector2 bend = new Vector2(curr.x, prev.y); + points[0] = bend; + points[1] = curr; + } + else + { + // Vertical mode: move vertically, then horizontally to curr + Vector2 bend = new Vector2(prev.x, curr.y); + points[0] = bend; + points[1] = curr; + } + } + + return points; + } + + public static Vector2[] RouteWire(Vector2 prev, Vector2 curr, int mode, float length) + { + Vector2[] points = new Vector2[4]; + Vector2 offset = curr - prev; + float endLength = Project.ActiveProject.WireTerminationLength; + + if (mode == 1) + { + if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y)) + { + // Horizontal mode: move horizontally, then 45-degree diagonal to bend2 then horizontally to curr + float signX = MathF.Sign(offset.x); + Vector2 bend0 = new(prev.x + endLength * signX, prev.y); + Vector2 bend2 = new(curr.x - endLength * signX, curr.y); + + float diagLen = Mathf.Abs(offset.y); + + Vector2 bend1 = new(bend2.x - diagLen * signX, prev.y); + /*points[0] = bend0; + points[1] = bend1; + points[2] = bend2; + points[3] = curr;*/ + + points[0] = bend1; + points[1] = bend2; + points[2] = curr; + } + else + { + // Vertical mode: move vertically, then 45-degree diagonal to bend2 then vertically to curr + float signY = Mathf.Sign(offset.y); + Vector2 bend0 = new(prev.x, prev.y + endLength * signY); + Vector2 bend2 = new(curr.x, curr.y - endLength * signY); + + float diagLen = Mathf.Abs(offset.x); + + Vector2 bend1 = new(prev.x, bend2.y - diagLen * signY); + /*points[0] = bend0; + points[1] = bend1; + points[2] = bend2; + points[3] = curr;*/ + points[0] = bend1; + points[1] = bend2; + points[2] = curr; + } + } + else if (mode == 2) + { + if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y)) + { + float signX = Mathf.Sign(offset.x); + Vector2 bend0 = new(prev.x + endLength * signX, prev.y); + Vector2 bend2 = new(curr.x - endLength * signX, curr.y); + // Horizontal mode: move horizontally, then vertically to curr + Vector2 bend1 = new(bend2.x, prev.y); + /*points[0] = bend0; + points[1] = bend1; + points[2] = bend2; + points[3] = curr;*/ + points[0] = bend1; + points[1] = bend2; + points[2] = curr; + } + else + { + float signY = Mathf.Sign(offset.y); + Vector2 bend0 = new(prev.x, prev.y + endLength * signY); + Vector2 bend2 = new(curr.x, curr.y - endLength * signY); + // Vertical mode: move vertically, then horizontally to curr + Vector2 bend1 = new(prev.x, bend2.y); + /*points[0] = bend0; + points[1] = bend1; + points[2] = bend2; + points[3] = curr;*/ + points[0] = bend1; + points[1] = bend2; + points[2] = curr; + } + } + + return points; + } + + public static Vector2[] RouteWire(Vector2 prev, Vector2 curr, int mode, ChipInteractionController.RotationTarget r) + { + return null; // Placeholder for future implementation + + if (mode == 1) + { + //Mode 1: 45-degree bend + if (r == ChipInteractionController.RotationTarget.Left || r == ChipInteractionController.RotationTarget.Right) + { + //Wire must end on a horizontal line + Vector2[] points = new Vector2[2]; + Vector2 offset = curr - prev; + + if (Mathf.Abs(offset.x) > Mathf.Abs(offset.y)) + { + + } + } + + } + else if (mode == 2) + { + + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/Game/Interaction/ChipInteractionController.cs b/Assets/Scripts/Game/Interaction/ChipInteractionController.cs index da9491d3..1bba2755 100644 --- a/Assets/Scripts/Game/Interaction/ChipInteractionController.cs +++ b/Assets/Scripts/Game/Interaction/ChipInteractionController.cs @@ -23,6 +23,7 @@ public class ChipInteractionController IMoveable[] Obstacles; // Obstacles are the non-selected items when a group of elements is being moved public Vector2 SelectionBoxStartPos; StraightLineMoveState straightLineMoveState; + RotationTarget wireRotationTarget = RotationTarget.Right; // Determines how wires are routed by attempting to terminate the wire in the specified direction bool hasExittedMultiModeSincePlacementStart; // ---- Wire edit state ---- @@ -113,7 +114,7 @@ public bool CanCompleteWireConnection(PinInstance endPin, WireInstance wireToCon } public static bool IsSelected(IMoveable element) => element.IsSelected; - + public void Delete(IMoveable element) { DeleteElements(new List(new[] { element })); @@ -190,6 +191,17 @@ void HandleKeyboardInput() if (KeyboardShortcuts.UndoShortcutTriggered) ActiveDevChip.UndoController.TryUndo(); else if (KeyboardShortcuts.RedoShortcutTriggered) ActiveDevChip.UndoController.TryRedo(); + if (KeyboardShortcuts.RotateShortcutTriggered) + { + if (IsCreatingWire) + { + wireRotationTarget = NextRotationTarget(wireRotationTarget); + } + else + { + wireRotationTarget = RotationTarget.Right; // Reset rotation target to right when not placing wire + } + } if (!KeyboardShortcuts.StraightLineModeHeld) straightLineMoveState = StraightLineMoveState.None; @@ -1062,5 +1074,26 @@ enum StraightLineMoveState Horizontal, Vertical } + + + public enum RotationTarget + { + Right, + Down, + Left, + Up + } + + static RotationTarget NextRotationTarget(RotationTarget current) + { + return current switch + { + RotationTarget.Right => RotationTarget.Down, + RotationTarget.Down => RotationTarget.Left, + RotationTarget.Left => RotationTarget.Up, + RotationTarget.Up => RotationTarget.Right, + _ => RotationTarget.Right, + }; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Game/Interaction/KeyboardShortcuts.cs b/Assets/Scripts/Game/Interaction/KeyboardShortcuts.cs index 21f9dbd0..516563f7 100644 --- a/Assets/Scripts/Game/Interaction/KeyboardShortcuts.cs +++ b/Assets/Scripts/Game/Interaction/KeyboardShortcuts.cs @@ -33,6 +33,7 @@ public static class KeyboardShortcuts public static bool DeleteShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.Backspace) || InputHelper.IsKeyDownThisFrame(KeyCode.Delete); public static bool SimNextStepShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.Space) && !InputHelper.CtrlIsHeld; public static bool SimPauseToggleShortcutTriggered => CtrlShortcutTriggered(KeyCode.Space); + public static bool RotateShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.R); // ---- Dev shortcuts ---- public static bool OpenSaveDataFolderShortcutTriggered => InputHelper.IsKeyDownThisFrame(KeyCode.O) && InputHelper.CtrlIsHeld && InputHelper.ShiftIsHeld && InputHelper.AltIsHeld; diff --git a/Assets/Scripts/Game/Project/Project.cs b/Assets/Scripts/Game/Project/Project.cs index e2a5be6e..0a3cff28 100644 --- a/Assets/Scripts/Game/Project/Project.cs +++ b/Assets/Scripts/Game/Project/Project.cs @@ -480,6 +480,24 @@ public void ToggleGridDisplay() public bool ShouldSnapToGrid => KeyboardShortcuts.SnapModeHeld || (description.Prefs_Snapping == 1 && ShowGrid) || description.Prefs_Snapping == 2; public bool ForceStraightWires => KeyboardShortcuts.StraightLineModeHeld || (description.Prefs_StraightWires == 1 && ShowGrid) || description.Prefs_StraightWires == 2; + public bool ShouldRouteWires => description.Prefs_WireRouting == 1 || description.Prefs_WireRouting == 2; + + public float WireTerminationLength = 0.5f; //Terminate Wires at 20% of its length when routing + + public int WireRoutingMode => description.Prefs_WireRouting switch + { + 0 => 0, // No routing + 1 => 1, // 45-degree routing + 2 => 2, // 90-degree routing + _ => 0 // Default to no routing + }; + + public int WireStyle => description.Prefs_WireStyle switch + { + 0 => 0, // Stright wires + 1 => 1, // Curved wires + _ => 0 // Default to normal wires + }; public void NotifyExit() { diff --git a/Assets/Scripts/Graphics/UI/Menus/PreferencesMenu.cs b/Assets/Scripts/Graphics/UI/Menus/PreferencesMenu.cs index 13909b2b..97395c7e 100644 --- a/Assets/Scripts/Graphics/UI/Menus/PreferencesMenu.cs +++ b/Assets/Scripts/Graphics/UI/Menus/PreferencesMenu.cs @@ -45,6 +45,19 @@ public static class PreferencesMenu "Always" }; + static readonly string[] WireRoutingOptions = + { + "Off", + "45°", + "90°", + }; + + static readonly string[] WireStyleOptions = + { + "Straight", + "Curved" + }; + static readonly string[] SimulationStatusOptions = { "Active", @@ -60,6 +73,8 @@ public static class PreferencesMenu static readonly UIHandle ID_GridDisplay = new("PREFS_GridDisplay"); static readonly UIHandle ID_Snapping = new("PREFS_Snapping"); static readonly UIHandle ID_StraightWires = new("PREFS_StraightWires"); + static readonly UIHandle ID_WireRouting = new("PREFS_WireRouting"); + static readonly UIHandle ID_WireStyle = new("PREFS_WireStyle"); static readonly UIHandle ID_SimStatus = new("PREFS_SimStatus"); static readonly UIHandle ID_SimFrequencyField = new("PREFS_SimTickTarget"); static readonly UIHandle ID_ClockSpeedInput = new("PREFS_ClockSpeed"); @@ -99,9 +114,11 @@ public static void DrawMenu(Project project) int mainPinNamesMode = DrawNextWheel("Show I/O pin names", PinDisplayOptions, ID_MainPinNames); int chipPinNamesMode = DrawNextWheel("Show chip pin names", PinDisplayOptions, ID_ChipPinNames); int gridDisplayMode = DrawNextWheel(showGridLabel, GridDisplayOptions, ID_GridDisplay); + int wireStyleMode = DrawNextWheel("Wire style", WireStyleOptions, ID_WireStyle); DrawHeader("EDITING:"); int snappingMode = DrawNextWheel("Snap to grid", SnappingOptions, ID_Snapping); int straightWireMode = DrawNextWheel("Straight wires", StraightWireOptions, ID_StraightWires); + int wireRoutingMode = DrawNextWheel("Wire routing", WireRoutingOptions, ID_WireRouting); DrawHeader("SIMULATION:"); bool pauseSim = MenuHelper.LabeledOptionsWheel(simStatusLabel, labelCol, labelPosCurr, entrySize, ID_SimStatus, SimulationStatusOptions, settingFieldSize.x, true) == 1; @@ -136,7 +153,9 @@ public static void DrawMenu(Project project) project.description.Prefs_ChipPinNamesDisplayMode = chipPinNamesMode; project.description.Prefs_GridDisplayMode = gridDisplayMode; project.description.Prefs_Snapping = snappingMode; + project.description.Prefs_WireRouting = wireRoutingMode; project.description.Prefs_StraightWires = straightWireMode; + project.description.Prefs_WireStyle = wireStyleMode; project.description.Prefs_SimTargetStepsPerSecond = targetSimTicksPerSecond; project.description.Prefs_SimStepsPerClockTick = clockSpeed; project.description.Prefs_SimPaused = pauseSim; @@ -206,6 +225,8 @@ static void UpdateUIFromDescription() UI.GetWheelSelectorState(ID_GridDisplay).index = projDesc.Prefs_GridDisplayMode; UI.GetWheelSelectorState(ID_Snapping).index = projDesc.Prefs_Snapping; UI.GetWheelSelectorState(ID_StraightWires).index = projDesc.Prefs_StraightWires; + UI.GetWheelSelectorState(ID_WireRouting).index = projDesc.Prefs_WireRouting; + UI.GetWheelSelectorState(ID_WireStyle).index = projDesc.Prefs_WireStyle; UI.GetWheelSelectorState(ID_SimStatus).index = projDesc.Prefs_SimPaused ? 1 : 0; // -- Input fields UI.GetInputFieldState(ID_SimFrequencyField).SetText(projDesc.Prefs_SimTargetStepsPerSecond + "", false); diff --git a/Assets/Scripts/Graphics/World/DevSceneDrawer.cs b/Assets/Scripts/Graphics/World/DevSceneDrawer.cs index eefb8307..66f601d0 100644 --- a/Assets/Scripts/Graphics/World/DevSceneDrawer.cs +++ b/Assets/Scripts/Graphics/World/DevSceneDrawer.cs @@ -749,7 +749,7 @@ static void DrawSingleBitWire(WireInstance wire) // Draw Color col = wire.GetColour(0); - float interactSqrDst = WireDrawer.DrawWireStraight(wire.BitWires[0].Points, thickness, col, mousePos); + float interactSqrDst = WireDrawer.DrawWire(wire.BitWires[0].Points, thickness, col, mousePos); // Draw connection point (if connects to wire) if (wire.ConnectedWire != null) @@ -782,7 +782,7 @@ static void DrawMultiBitWire(WireInstance wire) { WireInstance.BitWire bitWire = wire.BitWires[bitIndex]; Color col = wire.GetColour(bitIndex); - float sqrInteractDst = WireDrawer.DrawWireStraight(bitWire.Points, thickness, col, mousePos); + float sqrInteractDst = WireDrawer.DrawWire(bitWire.Points, thickness, col, mousePos); if (canInteract && sqrInteractDst < sqrDstThreshold) InteractionState.NotifyElementUnderMouse(wire); } } diff --git a/Assets/Scripts/Graphics/World/WireDrawer.cs b/Assets/Scripts/Graphics/World/WireDrawer.cs index a136ea4e..830c355a 100644 --- a/Assets/Scripts/Graphics/World/WireDrawer.cs +++ b/Assets/Scripts/Graphics/World/WireDrawer.cs @@ -1,3 +1,4 @@ +using DLS.Game; using Seb.Helpers; using Seb.Vis; using UnityEngine; @@ -5,7 +6,20 @@ namespace DLS.Graphics { public static class WireDrawer - { + { + + public static float DrawWire(Vector2[] points, float thickness, Color col, Vector2 interactPos) + { + if (Project.ActiveProject.WireStyle == 0) // 0 = straight, 1 = curved + { + return DrawWireStraight(points, thickness, col, interactPos); + } + else + { + return DrawWireCurved(points, thickness, col, interactPos); + } + } + public static float DrawWireStraight(Vector2[] points, float thickness, Color col, Vector2 interactPos) { float interactSqrDst = float.MaxValue; diff --git a/TestData/Projects/MainTest/ProjectDescription.json b/TestData/Projects/MainTest/ProjectDescription.json index 6d1823ff..4fdc01a5 100644 --- a/TestData/Projects/MainTest/ProjectDescription.json +++ b/TestData/Projects/MainTest/ProjectDescription.json @@ -1,17 +1,18 @@ { "ProjectName": "MainTest", - "DLSVersion_LastSaved": "2.1.5", + "DLSVersion_LastSaved": "2.1.6", "DLSVersion_EarliestCompatible": "2.0.0", - "CreationTime": "2025-03-14T18:23:30.404+01:00", - "LastSaveTime": "2025-05-04T09:15:41.061+02:00", + "CreationTime": "2025-03-14T19:23:30.404+02:00", + "LastSaveTime": "2025-05-23T21:01:50.361+02:00", "Prefs_MainPinNamesDisplayMode": 2, "Prefs_ChipPinNamesDisplayMode": 1, "Prefs_GridDisplayMode": 1, - "Prefs_Snapping": 0, - "Prefs_StraightWires": 0, + "Prefs_Snapping": 2, + "Prefs_StraightWires": 2, "Prefs_SimPaused": false, "Prefs_SimTargetStepsPerSecond": 150, "Prefs_SimStepsPerClockTick": 6, + "Prefs_WireRouting": 1, "AllCustomChipNames":[ "AND", "D-LATCH",