Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
1.0.5
Browse files Browse the repository at this point in the history
- Enforce minimum spacing distance to prevent overlapping of multiple invisible items.
  • Loading branch information
algernon-A committed Dec 3, 2023
1 parent 24482a4 commit 0cd1578
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion BepInEx/manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 4 additions & 1 deletion Code/Systems/LineToolSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace LineTool
{
using System;
using System.Reflection;
using Colossal.Entities;
using Colossal.Logging;
Expand Down Expand Up @@ -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<LineToolUISystem>().UpdateSpacing();
_dirty = true;
}
}
Expand Down
15 changes: 13 additions & 2 deletions Code/Systems/LineToolUISystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public sealed partial class LineToolUISystem : UISystemBase
private string _injectedJS;
private string _injectedCSS;

/// <summary>
/// Updates the displayed spacing amount.
/// </summary>
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();}}");
}

/// <summary>
/// Called when the system is created.
/// </summary>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<float>)SetSpacing));
_eventHandles.Add(_uiView.RegisterForEvent("SetLineToolFenceMode", (Action<bool>)SetFenceMode));
Expand Down
2 changes: 1 addition & 1 deletion LineToolLite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Authors>algernon</Authors>
<Copyright>Copyright © 2023 algernon (github.com/algernon-A). All rights reserved.</Copyright>
<Product>$(Title)</Product>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<LangVersion>9.0</LangVersion>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
Expand Down
14 changes: 14 additions & 0 deletions UI/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0cd1578

Please sign in to comment.