add class() for easy definition of classes
This commit is contained in:
parent
d20e5392f8
commit
1549976382
7
code/class.lua
Normal file
7
code/class.lua
Normal file
@ -0,0 +1,7 @@
|
||||
function class(super, self)
|
||||
assert(super == nil or super.__index == super)
|
||||
self = self or {}
|
||||
self.__index = self
|
||||
setmetatable(self, super)
|
||||
return self
|
||||
end
|
@ -1,8 +1,8 @@
|
||||
Decoration = {}
|
||||
Decoration.type = "Decoration"
|
||||
Decoration.supertype = Entity.type
|
||||
Decoration.display = Animation:new(animation.particle.simple)
|
||||
setmetatable(Decoration, Entity)
|
||||
Decoration = class(Entity, {
|
||||
type = "Decoration",
|
||||
supertype = Entity.type,
|
||||
display = Animation:new(animation.particle.simple),
|
||||
})
|
||||
|
||||
function Decoration:new(x,y,animation,light_data)
|
||||
local o = Entity:new(x,y)
|
||||
@ -22,7 +22,6 @@ function Decoration:new(x,y,animation,light_data)
|
||||
o:id()
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
LoadedObjects.Entities = {}
|
||||
Entity = {}
|
||||
Entity.type = "Entity"
|
||||
Entity = class(nil, {type = "Entity"})
|
||||
|
||||
function Entity:new(x,y)
|
||||
local o = {}
|
||||
@ -26,7 +25,6 @@ function Entity:new(x,y)
|
||||
o.sprite_flip = { x = 1, y = 1}
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
return o
|
||||
end
|
||||
|
||||
|
@ -7,6 +7,7 @@ require "data/sfx"
|
||||
require "code/locale"
|
||||
|
||||
-- support functions
|
||||
require "code/class"
|
||||
require "code/math"
|
||||
require "code/draw"
|
||||
require "code/hex"
|
||||
|
Loading…
Reference in New Issue
Block a user