Files
Next_Station_Plugin/src/Adornment/Handles.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-09-14 13:34:16 +02:00
import Signal from "@rbxts/signal";
import { createAnchor } from "Utils/Gui";
2025-09-17 21:37:53 +02:00
import { roundVector } from "Utils/Math";
2025-09-14 13:34:16 +02:00
export class Handles {
currentVector: Vector3 = new Vector3();
anchor: Part;
valueChanged = new Signal<(newValue: Vector3) => void>();
constructor(model: Folder, startPosition: Vector3 = Vector3.zero, anchor = createAnchor(model, startPosition)) {
this.anchor = anchor;
const handles = new Instance("Handles");
handles.Adornee = this.anchor;
handles.Parent = model;
handles.MouseButton1Down.Connect(() => {
this.currentVector = this.anchor.Position;
});
handles.MouseDrag.Connect((face, distance) => {
// Apply the changes to the anchor's position
let offset = Vector3.zero;
switch (face) {
case Enum.NormalId.Right:
offset = new Vector3(distance, 0, 0);
break;
case Enum.NormalId.Left:
offset = new Vector3(-distance, 0, 0);
break;
case Enum.NormalId.Top:
offset = new Vector3(0, distance, 0);
break;
case Enum.NormalId.Bottom:
offset = new Vector3(0, -distance, 0);
break;
case Enum.NormalId.Front:
offset = new Vector3(0, 0, -distance);
break;
case Enum.NormalId.Back:
offset = new Vector3(0, 0, distance);
break;
}
2025-09-17 21:37:53 +02:00
this.anchor.Position = roundVector(this.currentVector.add(offset));
2025-09-14 13:34:16 +02:00
});
handles.MouseButton1Up.Connect(() => {
const newpos = this.anchor.Position;
this.valueChanged.Fire(newpos);
});
}
}