From 0cd1578bcdcb7fc0be4333292db48d8b3de92585 Mon Sep 17 00:00:00 2001 From: algernon-A Date: Sun, 3 Dec 2023 13:42:09 +1100 Subject: [PATCH] 1.0.5 - Enforce minimum spacing distance to prevent overlapping of multiple invisible items. --- BepInEx/manifest.json | 2 +- Changelog.txt | 3 +++ Code/Systems/LineToolSystem.cs | 5 ++++- Code/Systems/LineToolUISystem.cs | 15 +++++++++++++-- LineToolLite.csproj | 2 +- UI/ui.js | 14 ++++++++++++++ 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/BepInEx/manifest.json b/BepInEx/manifest.json index 4fc9518..45937db 100644 --- a/BepInEx/manifest.json +++ b/BepInEx/manifest.json @@ -1,6 +1,6 @@ { "name": "Line_Tool_Lite", - "version_number": "1.0.4", + "version_number": "1.0.5", "website_url": "https://github.com/algernon-A/LineToolLite", "description": "Place objects in lines, curves, or circles", "dependencies": [ diff --git a/Changelog.txt b/Changelog.txt index 52243ba..f4545b3 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,3 +1,6 @@ +1.0.5 +- Enforce minimum spacing distance to prevent overlapping of multiple invisible items. + 1.0.4 - Improve previewing and cursor handling. - Fix spacing setting not being reset after re-activating tool when fence mode is set. diff --git a/Code/Systems/LineToolSystem.cs b/Code/Systems/LineToolSystem.cs index 956a3bb..edc9c7b 100644 --- a/Code/Systems/LineToolSystem.cs +++ b/Code/Systems/LineToolSystem.cs @@ -4,6 +4,7 @@ namespace LineTool { + using System; using System.Reflection; using Colossal.Entities; using Colossal.Logging; @@ -107,7 +108,9 @@ internal float Spacing set { - _spacing = value; + // Don't allow spacing to be set smaller than the smallest side of zBounds. + _spacing = (float)Math.Round(math.max(value, math.max(math.abs(_zBounds.max), math.abs(_zBounds.min) + 0.1f)), 1); + World.GetOrCreateSystemManaged().UpdateSpacing(); _dirty = true; } } diff --git a/Code/Systems/LineToolUISystem.cs b/Code/Systems/LineToolUISystem.cs index a004953..c42290c 100644 --- a/Code/Systems/LineToolUISystem.cs +++ b/Code/Systems/LineToolUISystem.cs @@ -39,6 +39,15 @@ public sealed partial class LineToolUISystem : UISystemBase private string _injectedJS; private string _injectedCSS; + /// + /// Updates the displayed spacing amount. + /// + internal void UpdateSpacing() + { + // Multiply spacing by 10 for accuracy conversion) + ExecuteScript(_uiView, $"if (lineTool != null) {{ lineTool.spacing = {_lineToolSystem.RawSpacing * 10}; if (lineTool.refreshSpacing != null) lineTool.refreshSpacing();}}"); + } + /// /// Called when the system is created. /// @@ -78,8 +87,7 @@ protected override void OnUpdate() // Tool is now active but previously wasn't; ensure namespace. ExecuteScript(_uiView, "if (lineTool == null) var lineTool = {};"); - // Set initial variables in UI (multiply spacing by 10 for accuracy conversion). - ExecuteScript(_uiView, $"lineTool.spacing = {_lineToolSystem.RawSpacing * 10};"); + // Set initial rotation variable in UI (multiply spacing by 10 for accuracy conversion). ExecuteScript(_uiView, $"lineTool.rotation = {_lineToolSystem.Rotation};"); // Attach our custom controls. @@ -124,6 +132,9 @@ protected override void OnUpdate() ExecuteScript(_uiView, "lineTool.addTreeControl();"); } + // Set initial spacing. + UpdateSpacing(); + // Register event callbacks. _eventHandles.Add(_uiView.RegisterForEvent("SetLineToolSpacing", (Action)SetSpacing)); _eventHandles.Add(_uiView.RegisterForEvent("SetLineToolFenceMode", (Action)SetFenceMode)); diff --git a/LineToolLite.csproj b/LineToolLite.csproj index 82aa8d2..124dd13 100644 --- a/LineToolLite.csproj +++ b/LineToolLite.csproj @@ -6,7 +6,7 @@ algernon Copyright © 2023 algernon (github.com/algernon-A). All rights reserved. $(Title) - 1.0.4 + 1.0.5 9.0 True diff --git a/UI/ui.js b/UI/ui.js index 6893be5..b9aa61d 100644 --- a/UI/ui.js +++ b/UI/ui.js @@ -26,6 +26,20 @@ if (typeof lineTool.adjustSpacing !== 'function') { } } +// Function to update displayed spacing. +if (typeof lineTool.refreshSpacing !== 'function') { + lineTool.refreshSpacing = function () { + if (lineTool.spacing == null) { + return; + } + + var spacingField = document.getElementById("line-tool-spacing-field"); + if (spacingField != null) { + document.getElementById("line-tool-spacing-field").innerHTML = (lineTool.spacing / 10) + " m"; + } + } +} + // Function to adjust rotation. if (typeof lineTool.adjustRotation !== 'function') { lineTool.adjustRotation = function(event, adjustment) {