Round and pubsub lib.
This commit is contained in:
@@ -144,4 +144,13 @@ function Color:alphaBlend( dst, src, tint )
|
||||
return Color:new( RL.ColorAlphaBlend( dst, src, tint ) )
|
||||
end
|
||||
|
||||
function Color:lerp( color, amount )
|
||||
return Color:new(
|
||||
RL.Lerp( self.r, color.r, amount ),
|
||||
RL.Lerp( self.g, color.g, amount ),
|
||||
RL.Lerp( self.b, color.b, amount ),
|
||||
RL.Lerp( self.a, color.a, amount )
|
||||
)
|
||||
end
|
||||
|
||||
return Color
|
||||
|
||||
34
examples/resources/lib/pubsub.lua
Normal file
34
examples/resources/lib/pubsub.lua
Normal file
@@ -0,0 +1,34 @@
|
||||
local PubSub = {}
|
||||
PubSub.__index = PubSub
|
||||
|
||||
function PubSub:new()
|
||||
local object = setmetatable( {}, self )
|
||||
|
||||
object.signals = {}
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function PubSub:add( name )
|
||||
self.signals[ name ] = {}
|
||||
end
|
||||
|
||||
function PubSub:subscribe( name, func )
|
||||
table.insert( self.signals[ name ], func )
|
||||
end
|
||||
|
||||
function PubSub:unSubscribe( name, uFunc )
|
||||
for i, func in ipairs( self.signals[ name ] ) do
|
||||
if func == uFunc then
|
||||
table.remove( self.signals[ name ], i )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PubSub:publish( name, ... )
|
||||
for _, func in ipairs( self.signals[ name ] ) do
|
||||
func( ... )
|
||||
end
|
||||
end
|
||||
|
||||
return PubSub
|
||||
@@ -1,5 +1,10 @@
|
||||
-- Define useful global functions.
|
||||
|
||||
-- For luaJit compatibility.
|
||||
if table.unpack == nil then
|
||||
table.unpack = unpack
|
||||
end
|
||||
|
||||
local utillib = {}
|
||||
|
||||
function utillib.tableClone( org )
|
||||
|
||||
Reference in New Issue
Block a user