diff --git a/.gitignore b/.gitignore index d1e66cf..40bb742 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules -/out \ No newline at end of file +/out +copy.cmd \ No newline at end of file diff --git a/aftman.toml b/aftman.toml new file mode 100644 index 0000000..159fdf4 --- /dev/null +++ b/aftman.toml @@ -0,0 +1,7 @@ +# This file lists tools managed by Aftman, a cross-platform toolchain manager. +# For more information, see https://github.com/LPGhatguy/aftman + +# To add a new tool, add an entry to this table. +[tools] +rojo = "rojo-rbx/rojo@7.5.1" +# rojo = "rojo-rbx/rojo@6.2.0" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 13a88d3..1f91b78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "next_station_plugin", "version": "1.0.0", "license": "ISC", + "dependencies": { + "@rbxts/signal": "^1.1.1" + }, "devDependencies": { "@rbxts/compiler-types": "^3.0.0-types.0", "@rbxts/types": "^1.0.881", @@ -318,6 +321,12 @@ "dev": true, "license": "MIT" }, + "node_modules/@rbxts/signal": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@rbxts/signal/-/signal-1.1.1.tgz", + "integrity": "sha512-WX+ONE+ld4pG9PvRkR8OgDld9NpaV1RfXyUIw+Q2oXP/5rehkYzvt20NWtrLAP3NhMc5inYInLd+hnufey6nFw==", + "license": "ISC" + }, "node_modules/@rbxts/types": { "version": "1.0.881", "resolved": "https://registry.npmjs.org/@rbxts/types/-/types-1.0.881.tgz", diff --git a/package.json b/package.json index f16753a..8e081f7 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "build": "rbxtsc", - "watch": "rbxtsc -w" + "watch": "rbxtsc -w", + "build-to-roblox": "rbxtsc && rojo build --plugin \"next-station.rbxm\"" }, "keywords": [], "author": "", @@ -23,5 +24,8 @@ "prettier": "^3.6.2", "roblox-ts": "^3.0.0", "typescript": "^5.8.3" + }, + "dependencies": { + "@rbxts/signal": "^1.1.1" } } diff --git a/src/Adornment/Handles.ts b/src/Adornment/Handles.ts index 0f2b0ec..c1d8ff8 100644 --- a/src/Adornment/Handles.ts +++ b/src/Adornment/Handles.ts @@ -1,5 +1,6 @@ import Signal from "@rbxts/signal"; import { createAnchor } from "Utils/Gui"; +import { roundVector } from "Utils/Math"; export class Handles { currentVector: Vector3 = new Vector3(); @@ -40,7 +41,7 @@ export class Handles { break; } - this.anchor.Position = this.currentVector.add(offset); + this.anchor.Position = roundVector(this.currentVector.add(offset)); }); handles.MouseButton1Up.Connect(() => { diff --git a/src/Toolbar/Buttons.ts b/src/Toolbar/Buttons.ts new file mode 100644 index 0000000..7b90c15 --- /dev/null +++ b/src/Toolbar/Buttons.ts @@ -0,0 +1,35 @@ +const Selection = game.GetService("Selection"); +const ChangeHistoryService = game.GetService("ChangeHistoryService"); + +export function createNewRoomButton(toolbar: PluginToolbar) { + const newRoomButton = toolbar.CreateButton("New Room", "New Room", "rbxassetid://14978048121"); + newRoomButton.Click.Connect(function () { + const selectedObjects = Selection.Get(); + if (selectedObjects.isEmpty()) return; + const room = selectedObjects[0]; + if (!room.IsA("Model")) return; + const config = new Instance("Configuration"); + config.Name = "RoomConfig"; + config.Parent = room; + + const origin = new Instance("Vector3Value"); + origin.Name = "Origin"; + origin.Parent = config; + origin.Value = room.GetPivot().Position; + + const endvalue = new Instance("Vector3Value"); + endvalue.Name = "End"; + endvalue.Parent = config; + endvalue.Value = room.GetPivot().Position; + + const roomtype = new Instance("StringValue"); + roomtype.Name = "RoomType"; + roomtype.Parent = config; + + const roomId = new Instance("IntValue"); + roomId.Name = "RoomId"; + roomId.Parent = config; + + ChangeHistoryService.SetWaypoint("Added new room config"); + }); +} diff --git a/src/Utils/Math.ts b/src/Utils/Math.ts new file mode 100644 index 0000000..25b5cc6 --- /dev/null +++ b/src/Utils/Math.ts @@ -0,0 +1,3 @@ +export function roundVector(vector: Vector3) { + return new Vector3(math.round(vector.X * 4) / 4, math.round(vector.Y * 4) / 4, math.round(vector.Z * 4) / 4); +} diff --git a/src/Utils/Room.ts b/src/Utils/Room.ts index bda1bd0..4aea761 100644 --- a/src/Utils/Room.ts +++ b/src/Utils/Room.ts @@ -1,4 +1,4 @@ -type RoomConfig = Configuration & { +export type RoomConfig = Configuration & { RoomId: IntValue; RoomType: StringValue; Origin: Vector3Value; diff --git a/src/Widget/RoomWidget.ts b/src/Widget/RoomWidget.ts index e16594a..b66c51e 100644 --- a/src/Widget/RoomWidget.ts +++ b/src/Widget/RoomWidget.ts @@ -3,6 +3,7 @@ import LabeledTextInput from "Lualibs/LabeledTextInput"; import VerticallyScalingListFrame from "Lualibs/VerticallyScalingListFrame"; import VerticalScrollingFrame from "Lualibs/VerticalScrollingFrame"; import { syncGuiColors } from "Utils/Gui"; +import { RoomConfig } from "Utils/Room"; export class RoomWidget { plugin: Plugin; @@ -64,7 +65,11 @@ export class RoomWidget { // Setup Widget this.roomIdInput.GetFrame().Parent = this.roomCollapse.GetContentsFrame(); + const textbox = this.roomIdInput.GetFrame().FindFirstChildOfClass("TextBox")!; + textbox.ClearTextOnFocus = false; this.roomTypeInput.GetFrame().Parent = this.roomCollapse.GetContentsFrame(); + const textboxf = this.roomTypeInput.GetFrame().FindFirstChildOfClass("TextBox")!; + textboxf.ClearTextOnFocus = false; this.listFrame.AddChild(this.roomCollapse.GetSectionFrame()); this.listFrame.AddChild(this.exitCollapse.GetSectionFrame()); @@ -74,8 +79,11 @@ export class RoomWidget { this.scrollFrame.GetSectionFrame().Parent = this.widget; this.noRoomLabel.Parent = this.widget; } - UpdateValue() { - + UpdateValue(config: RoomConfig) { + this.roomIdValue = config.RoomId; + this.roomIdInput.SetValue(tostring(config.RoomId.Value)); + this.roomTypeValue = config.RoomType; + this.roomTypeInput.SetValue(config.RoomType.Value); } SetActive(active: boolean) { this.noRoomLabel.Visible = !active; diff --git a/src/Widget/RoomWidget.lua b/src/Widget/RoomWidget_legacy.lua similarity index 100% rename from src/Widget/RoomWidget.lua rename to src/Widget/RoomWidget_legacy.lua diff --git a/src/index.server.ts b/src/index.server.ts index 363c8ed..3294c50 100644 --- a/src/index.server.ts +++ b/src/index.server.ts @@ -1,37 +1,33 @@ import Signal from "@rbxts/signal"; import { HandlesArea } from "Adornment/Area"; +import { createNewRoomButton } from "Toolbar/Buttons"; import { WidgetButton } from "Toolbar/WidgetButton"; import { checkRoomConfig } from "Utils/Room"; +import { RoomWidget } from "Widget/RoomWidget"; // Services const Selection = game.GetService("Selection"); const CoreGui = game.GetService("CoreGui"); -// Module -// const UseLessModule = require(script.Parent.Tools.Useless) -// const RoomWidget = require(script.Parent.Widget.Room.Main) -// const WidgetButton = require(script.Parent.Widget.WidgetTogger) -// const ToolsButtons = require(script.Parent.Buttons.ToolsButtons) - -// Create Widget -// const roomWidget = RoomWidget.new(plugin) - -// Create Toolbar -const toolbar = plugin.CreateToolbar("Next Station Plugin"); - -// Create Buttons -// const roomWidgetButton = new WidgetButton(toolbar, roomWidget.widget, "Room Info", "rbxassetid.//14978048121"); -// const createRoomButton = ToolsButtons.createNewRoomButton(toolbar) - // Create CoreGui Folders const pluginModel = new Instance("Folder"); -pluginModel.Name = "_constGizmoContainer"; +pluginModel.Name = "_Model"; pluginModel.Parent = CoreGui; plugin.Unloading.Connect(() => { pluginModel.Destroy(); }); +// Create Widget +const roomWidget = new RoomWidget(plugin, pluginModel); + +// Create Toolbar +const toolbar = plugin.CreateToolbar("Next Station Plugin"); + +// Create Buttons +new WidgetButton(toolbar, roomWidget.widget, "Room Info", "rbxassetid//14978048121"); +createNewRoomButton(toolbar); + // Selection Room Config Controller function clearAdornment() { pluginModel.ClearAllChildren(); @@ -42,14 +38,17 @@ function clearAdornment() { const selectedObjects = Selection.Get(); // Reset Adornments clearAdornment(); + roomWidget.SetActive(false); // roomWidget.SetActive(false) if (!selectedObjects.isEmpty()) { const selected = selectedObjects[0]; const config = selected.FindFirstChild("RoomConfig"); if (selected.IsA("Model") && config && checkRoomConfig(config)) { + roomWidget.UpdateValue(config); + roomWidget.SetActive(true); const roomArea = new HandlesArea(pluginModel, config.Origin.Value, config.End.Value); - roomArea.originValueChanged.Connect((value) => (config.Origin.Value = value)); - roomArea.tipValueChanged.Connect((value) => (config.End.Value = value)); + roomArea.originValueChanged.Connect((value: Vector3) => (config.Origin.Value = value)); + roomArea.tipValueChanged.Connect((value: Vector3) => (config.End.Value = value)); } } });