Skip to content

Commit

Permalink
Allow Actor methods on Nodes for easier setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudospective committed Jan 21, 2023
1 parent a7d0416 commit fd93d47
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/konko-node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ depend ('konko-node', std, 'stdlib')
Node = {}

-- Version and author
local VERSION = '1.3'
local VERSION = '1.4'
local AUTHOR = 'Sudospective'

local env = getfenv(2)
Expand Down Expand Up @@ -481,6 +481,24 @@ local function new(obj)
node_idx = node_idx + 1
t.IsNode = true
setmetatable(t, Node)
local actortable = env[t.Type] or Actor
if t.Type == 'Quad' or t.Type == 'Sprite' then
actortable = Actor
for k, v in pairs(Sprite) do
actortable[k] = v
end
end
for k, v in pairs(actortable) do
t[k] = function(self, ...)
local nodefunc = self.NodeCommand
local args = {...}
self.NodeCommand = function(subself)
if nodefunc then nodefunc(subself) end
v(subself, table.unpack(args))
end
return self
end
end
return t
end
local function FromFile(path)
Expand Down
19 changes: 19 additions & 0 deletions lua/mods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ for pn = 1, #GAMESTATE:GetEnabledPlayers() do

end

--[[
How the Node library works:
1. Create a new Node.
local goodboy = Node.new('Quad')
2. Call Actor methods on Node.
goodboy:Center():SetSize(64, 64):spin()
3. Call special Node methods.
goodboy:SetUpdate(function(self, dt)
self:aux(self:getaux() + dt):y(SCY + sin(self:getaux() * 2) * 64)
end)
4. Add Node to tree.
goodboy:AddToTree()
--]]

--[[
Constants:
Expand Down
2 changes: 1 addition & 1 deletion main/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ return subo(function()
}
subo.Actors.Mods = FG
table.insert(subo.Actors, FG)
table.insert(FG, run 'lua/mods')
table.insert(FG, run 'mods')
end)

-- This is our overarching ActorFrame which will hold everything on screen.
Expand Down

0 comments on commit fd93d47

Please sign in to comment.