From ac74639453d116f7a5db58d0724599f7788cd2df Mon Sep 17 00:00:00 2001
From: spherallic <spherallic@gmail.com>
Date: Tue, 7 May 2024 01:30:01 +0200
Subject: [PATCH] Add 2 new scripts

---
 .../Scripts/Examples/NiGHTS/modifyorder.js    | 48 +++++++++++++++
 .../Examples/copyplanepropertiestoopposite.js | 59 +++++++++++++++++++
 2 files changed, 107 insertions(+)
 create mode 100644 Build/UDBScript/Scripts/Examples/NiGHTS/modifyorder.js
 create mode 100644 Build/UDBScript/Scripts/Examples/copyplanepropertiestoopposite.js

diff --git a/Build/UDBScript/Scripts/Examples/NiGHTS/modifyorder.js b/Build/UDBScript/Scripts/Examples/NiGHTS/modifyorder.js
new file mode 100644
index 000000000..126425e88
--- /dev/null
+++ b/Build/UDBScript/Scripts/Examples/NiGHTS/modifyorder.js
@@ -0,0 +1,48 @@
+/// <reference path="../../udbscript.d.ts" />
+
+`#version 4`;
+
+`#name Modify NiGHTS track order`;
+
+`#description Inserts or removes an order index from the selected thing's mare`;
+
+`#scriptoptions
+
+operation
+{
+	description = "Insert/remove?";
+	default = 0;
+	type = 11; // Enum
+	enumvalues {
+		0 = "Insert";
+		1 = "Remove";
+	}
+}
+`;
+
+// Get the selected things
+let selected = UDB.Map.getSelectedThings();
+
+if (selected.length != 1)
+    UDB.die('More than one thing selected, aborting script.');
+
+if (selected[0].type < 1700 || selected[0].type > 1702)
+	UDB.die('Thing is not a track element, aborting script.');
+
+let mare = selected[0].args[0];
+let order = selected[0].args[1];
+let operation = UDB.ScriptOptions.operation;
+
+UDB.Map.getThings().filter(o => o.type >= 1700 && o.type <= 1702).forEach(thing => {
+
+	if (thing.args[0] == mare)
+	{
+		if (operation == 0 && thing.args[1] > order)
+			thing.args[1] = thing.args[1] + 1;
+		else if (operation == 1 && thing.args[1] > order)
+			thing.args[1] = thing.args[1] - 1;
+		else if (operation == 1 && thing.args[1] == order)
+			thing.delete();
+	}
+
+});
\ No newline at end of file
diff --git a/Build/UDBScript/Scripts/Examples/copyplanepropertiestoopposite.js b/Build/UDBScript/Scripts/Examples/copyplanepropertiestoopposite.js
new file mode 100644
index 000000000..14dc75355
--- /dev/null
+++ b/Build/UDBScript/Scripts/Examples/copyplanepropertiestoopposite.js
@@ -0,0 +1,59 @@
+/// <reference path="../../udbscript.d.ts" />
+
+`#version 4`;
+
+`#name Copy plane texture properties to opposite plane`;
+
+`#description Copies plane texture properties (rotation, offsets) of all selected sectors to its opposite plane.`;
+
+`#scriptoptions
+
+direction
+{
+	description = "Copy direction";
+	default = 0;
+	type = 11; // Enum
+	enumvalues {
+		0 = "Floor to ceiling";
+		1 = "Ceiling to floor";
+	}
+}
+
+copytexture
+{
+	description = "Copy texture?";
+	default = 0;
+	type = 11; // Enum
+	enumvalues {
+		0 = "No";
+		1 = "Yes";
+	}
+}
+`;
+
+// Get the selected things
+let selected = UDB.Map.getSelectedSectors();
+
+if (selected.length == 0)
+    UDB.die('This script requires a selection!');
+
+let direction = UDB.ScriptOptions.direction;
+let copytexture = UDB.ScriptOptions.copytexture;
+
+UDB.Map.getSelectedSectors().forEach(sector => {
+	if (direction == 0)
+	{
+		sector.fields.xpanningceiling = sector.fields.xpanningfloor;
+		sector.fields.ypanningceiling = sector.fields.ypanningfloor;
+		sector.fields.rotationceiling = sector.fields.rotationfloor;
+		if (copytexture == 1) sector.ceilingTexture = sector.floorTexture;
+	}
+	else
+	{
+		sector.fields.xpanningfloor = sector.fields.xpanningceiling;
+		sector.fields.ypanningfloor = sector.fields.ypanningceiling;
+		sector.fields.rotationfloor = sector.fields.rotationceiling;
+		if (copytexture == 1) sector.floorTexture = sector.ceilingTexture;
+	}
+
+});
\ No newline at end of file
-- 
GitLab