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 = class(Entity, {
|
||||||
Decoration.type = "Decoration"
|
type = "Decoration",
|
||||||
Decoration.supertype = Entity.type
|
supertype = Entity.type,
|
||||||
Decoration.display = Animation:new(animation.particle.simple)
|
display = Animation:new(animation.particle.simple),
|
||||||
setmetatable(Decoration, Entity)
|
})
|
||||||
|
|
||||||
function Decoration:new(x,y,animation,light_data)
|
function Decoration:new(x,y,animation,light_data)
|
||||||
local o = Entity:new(x,y)
|
local o = Entity:new(x,y)
|
||||||
@ -22,7 +22,6 @@ function Decoration:new(x,y,animation,light_data)
|
|||||||
o:id()
|
o:id()
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
LoadedObjects.Entities = {}
|
LoadedObjects.Entities = {}
|
||||||
Entity = {}
|
Entity = class(nil, {type = "Entity"})
|
||||||
Entity.type = "Entity"
|
|
||||||
|
|
||||||
function Entity:new(x,y)
|
function Entity:new(x,y)
|
||||||
local o = {}
|
local o = {}
|
||||||
@ -26,7 +25,6 @@ function Entity:new(x,y)
|
|||||||
o.sprite_flip = { x = 1, y = 1}
|
o.sprite_flip = { x = 1, y = 1}
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ require "data/sfx"
|
|||||||
require "code/locale"
|
require "code/locale"
|
||||||
|
|
||||||
-- support functions
|
-- support functions
|
||||||
|
require "code/class"
|
||||||
require "code/math"
|
require "code/math"
|
||||||
require "code/draw"
|
require "code/draw"
|
||||||
require "code/hex"
|
require "code/hex"
|
||||||
|
Loading…
Reference in New Issue
Block a user