Skip to content

Commit

Permalink
mapeditor Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlinaNova21 committed Jul 23, 2024
1 parent e0d0a31 commit 0f3c80d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 42 deletions.
1 change: 1 addition & 0 deletions MapEditor/Definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Map Editor",
"version": "$(AssemblyVersion)",
"assemblies": [ "MapEditor" ],
"updateUrl": "https://railroader.alinanova.dev/update.json",
"requires": [
"Zamu.StrangeCustoms"
],
Expand Down
2 changes: 1 addition & 1 deletion MapEditor/Dialogs/TrackNodeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void BuildNodeEditor(UIPanelBuilder builder)
builder.AddField("Flip Switch Stand", builder.AddToggle(() => NodeManager.GetFlipSwitchStand(), val => NodeManager.FlipSwitchStand(val))!);
builder.HStack(stack =>
{
stack.AddButtonCompact("Add", NodeManager.AddNode);
stack.AddButtonCompact("Add", () => NodeManager.AddNode());
stack.AddButtonCompact("Split", () => NodeManager.SplitNode());
stack.AddButtonCompact("Remove", () => NodeManager.RemoveNode(Input.GetKey(KeyCode.LeftShift)));
stack.AddButtonCompact("Show", EditorContext.MoveCameraToSelectedNode);
Expand Down
35 changes: 29 additions & 6 deletions MapEditor/EditorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,22 +250,23 @@ public static void MoveCameraToSelectedNode()
}
}

public static void UpdateUiHelpers()
{
CreateUiHelpers();
}

#region UI helpers

private static void CreateUiHelpers()
{
foreach (var trackNode in Graph.Shared.Nodes!)
{
var gameObject = new GameObject("TrackNodeHelper");
gameObject.transform.SetParent(trackNode.transform);
gameObject.AddComponent<TrackNodeHelper>();
AttachUiHelper(trackNode);
}

foreach (var trackSegment in Graph.Shared.Segments!)
{
var gameObject = new GameObject("TrackSegmentHelper");
gameObject.transform.SetParent(trackSegment.transform);
gameObject.AddComponent<TrackSegmentHelper>();
AttachUiHelper(trackSegment);
}
}

Expand All @@ -290,6 +291,28 @@ private static void DestroyUiHelpers()
}

}

internal static void AttachUiHelper(TrackNode node)
{
if (node.transform.Find("TrackNodeHelper") != null)
{
return;
}
var gameObject = new GameObject("TrackNodeHelper");
gameObject.transform.SetParent(node.transform);
gameObject.AddComponent<TrackNodeHelper>();
}

internal static void AttachUiHelper(TrackSegment segment)
{
if (segment.transform.Find("TrackSegmentHelper") != null)
{
return;
}
var gameObject = new GameObject("TrackSegmentHelper");
gameObject.transform.SetParent(segment.transform);
gameObject.AddComponent<TrackSegmentHelper>();
}
#endregion

}
Expand Down
26 changes: 0 additions & 26 deletions MapEditor/HarmonyPatches/TrackSegmentAwake.cs

This file was deleted.

4 changes: 2 additions & 2 deletions MapEditor/Managers/NodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public static void DivideScaling()

#endregion

public static void AddNode()
public static void AddNode(TrackNode? node = null)
{
var node = EditorContext.SelectedNode!;
node ??= EditorContext.SelectedNode!;
var nid = EditorContext.TrackNodeIdGenerator.Next()!;
var sid = EditorContext.TrackSegmentIdGenerator.Next()!;
EditorContext.ChangeManager.AddChange(new CompoundChange(
Expand Down
1 change: 1 addition & 0 deletions MapEditor/StateTracker/Node/TrackNodeGhost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void CreateNode()
gameObject.SetActive(true);
Graph.Shared.AddNode(node);
EditorContext.PatchEditor!.AddOrUpdateNode(node);
EditorContext.AttachUiHelper(node);
}

public void DestroyNode()
Expand Down
10 changes: 3 additions & 7 deletions MapEditor/StateTracker/Segment/TrackSegmentGhost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,15 @@ public void UpdateSegment(TrackSegment segment)
public void CreateSegment()
{
var gameObject = new GameObject($"Segment {id}");
gameObject.SetActive(true);
gameObject.SetActive(false);
var segment = gameObject.AddComponent<TrackSegment>();
segment.id = id;
segment.transform.SetParent(Graph.Shared.transform);
UpdateSegment(segment);
gameObject.SetActive(false);
gameObject.SetActive(true);
Graph.Shared.AddSegment(segment);
// var helper = new GameObject("TrackSegmentHelper");
// helper.transform.SetParent(segment.transform);
// var sh = helper.AddComponent<TrackSegmentHelper>();
// sh.Rebuild();

EditorContext.PatchEditor!.AddOrUpdateSegment(segment);
EditorContext.AttachUiHelper(segment);
}

public void DestroySegment()
Expand Down
1 change: 1 addition & 0 deletions MapEditor/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name: Map Editor
desc: |-
A Map Editor for manipulating track mods.
WARNING: Extremely WIP. I will not be providing support. Use at your own risk.
downloadUrl: https://github.com/AlinaNova21/Railroader-Mods/releases/download/v1.4.24204.650/MapEditor_1.1.24204.650.zip
version: '1.1.24204.650'
changelog:
- version: '1.1.24204.650'
Expand Down

0 comments on commit 0f3c80d

Please sign in to comment.