Skip to content

Commit

Permalink
refactor: address some of the code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pvaiko committed Nov 5, 2024
1 parent 921d647 commit 95de318
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions scripts/util/HelperNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ HelperNode = CpObject()
function HelperNode:init(name, rootNode)
self.node = createTransformGroup(name)
self.rootNode = rootNode
link(self.rootNode, self.node)
if self.rootNode then
link(self.rootNode, self.node)
end
end

--- Safely destroy a node
function HelperNode:destroy()
if self.node and entityExists(self.node) then
unlink(self.node)
if self.rootNode then
unlink(self.node)
end
delete(self.node)
end
end
Expand All @@ -53,6 +57,16 @@ function HelperNode:place(x, y, z, yRotation)
end
end

--- Get the position of a point relative to node, in the helper node's coordinate system.
---@param node number
---@param lx number x coordinate of the point relative to the node
---@param ly number y coordinate of the point relative to the node
---@param lz number z coordinate of the point relative to the node
---@return number, number, number
function HelperNode:localToLocal(node, lx, ly, lz)
return localToLocal(node, self.node, lx, ly, lz)
end

---@param text string|nil
function HelperNode:draw(text)
if entityExists(self.node) then
Expand Down Expand Up @@ -98,13 +112,3 @@ function HelperTerrainNode:placeAtNode(node, y, lx, ly, lz)
setRotation(self.node, xRotation, yRotation, zRotation)
self:place(x, y or 0, z)
end

--- Get the position of a point relative to node, in the helper node's coordinate system.
---@param node number
---@param lx number x coordinate of the point relative to the node
---@param ly number y coordinate of the point relative to the node
---@param lz number z coordinate of the point relative to the node
---@return number, number, number
function HelperTerrainNode:localToLocal(node, lx, ly, lz)
return localToLocal(node, self.node, lx, ly, lz)
end

0 comments on commit 95de318

Please sign in to comment.