Skip to content

Commit fd93d47

Browse files
committed
Allow Actor methods on Nodes for easier setup
1 parent a7d0416 commit fd93d47

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

lib/konko-node.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ depend ('konko-node', std, 'stdlib')
2222
Node = {}
2323

2424
-- Version and author
25-
local VERSION = '1.3'
25+
local VERSION = '1.4'
2626
local AUTHOR = 'Sudospective'
2727

2828
local env = getfenv(2)
@@ -481,6 +481,24 @@ local function new(obj)
481481
node_idx = node_idx + 1
482482
t.IsNode = true
483483
setmetatable(t, Node)
484+
local actortable = env[t.Type] or Actor
485+
if t.Type == 'Quad' or t.Type == 'Sprite' then
486+
actortable = Actor
487+
for k, v in pairs(Sprite) do
488+
actortable[k] = v
489+
end
490+
end
491+
for k, v in pairs(actortable) do
492+
t[k] = function(self, ...)
493+
local nodefunc = self.NodeCommand
494+
local args = {...}
495+
self.NodeCommand = function(subself)
496+
if nodefunc then nodefunc(subself) end
497+
v(subself, table.unpack(args))
498+
end
499+
return self
500+
end
501+
end
484502
return t
485503
end
486504
local function FromFile(path)

lua/mods.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ for pn = 1, #GAMESTATE:GetEnabledPlayers() do
3737

3838
end
3939

40+
--[[
41+
42+
How the Node library works:
43+
44+
1. Create a new Node.
45+
local goodboy = Node.new('Quad')
46+
47+
2. Call Actor methods on Node.
48+
goodboy:Center():SetSize(64, 64):spin()
49+
50+
3. Call special Node methods.
51+
goodboy:SetUpdate(function(self, dt)
52+
self:aux(self:getaux() + dt):y(SCY + sin(self:getaux() * 2) * 64)
53+
end)
54+
55+
4. Add Node to tree.
56+
goodboy:AddToTree()
57+
58+
--]]
4059

4160
--[[
4261
Constants:

main/default.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ return subo(function()
6363
}
6464
subo.Actors.Mods = FG
6565
table.insert(subo.Actors, FG)
66-
table.insert(FG, run 'lua/mods')
66+
table.insert(FG, run 'mods')
6767
end)
6868

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

0 commit comments

Comments
 (0)