2026-04-14 17:41:39 +02:00

94 lines
2.6 KiB
Lua

gizmo = {}
gizmo.utils = {}
function gizmo.handleCameraUpdate(self)
CreateThread(function()
while decorate.active and decorate.mode == "gizmo" do
SendNUIMessage({
action = "set_camera_position",
data = {
position = GetFinalRenderedCamCoord(),
rotation = GetFinalRenderedCamRot(2)
}
})
Wait(0)
end
end)
end
function gizmo.selectEntity(self, entityHandle)
local entityCoords = GetEntityCoords(entityHandle)
local entityRotation = GetEntityRotation(entityHandle)
SendReactMessage("set_gizmo_entity", {
handle = entityHandle,
position = entityCoords,
rotation = entityRotation
})
self.entity = entityHandle
self.maxZ = entityCoords.z + 10.0
CreateThread(function()
while self.entity and DoesEntityExist(self.entity) do
Wait(0)
end
SendReactMessage("set_gizmo_entity", nil)
end)
end
function gizmo.deselectEntity(self)
self.entity = nil
end
RegisterNUICallback("select_decorate_entity", function(data, cb)
cb(1)
if decorate.mode ~= "gizmo" then
return Debug("gizmo:selectEntity gizmo mode is not enabled, so we do not select entity")
end
decorate:selectEntity()
end)
function gizmo.setEditorMode(self, editorMode)
SendReactMessage("set_gizmo_editor_mode", editorMode)
end
RegisterNUICallback("set_gizmo_editor_mode", function(data, cb)
cb(1)
gizmo:setEditorMode(data)
end)
function gizmo.updateGizmoEntity(self)
if not self.entity or not DoesEntityExist(self.entity) then
return Error("updateGizmoEntity", "Entity does not exist", self.entity)
end
local entityCoords = GetEntityCoords(self.entity)
local entityRotation = GetEntityRotation(self.entity)
SendReactMessage("set_gizmo_entity", {
handle = self.entity,
position = entityCoords,
rotation = entityRotation
})
end
RegisterNUICallback("move_entity", function(data, cb)
cb(1)
if not data.handle or not DoesEntityExist(data.handle) then
return Error("move_entity", "Entity does not exist", data.handle)
end
if data.position then
data.position.z = math.min(data.position.z, gizmo.maxZ)
SetEntityCoordsNoOffset(data.handle, data.position.x, data.position.y, data.position.z, false, false, false)
end
if data.rotation then
SetEntityRotation(data.handle, data.rotation.x, data.rotation.y, data.rotation.z, 0, false)
end
SendReactMessage("set_gizmo_entity", data)
end)