Compare commits
3 Commits
66c6ef44a5
...
cccc8d1b4d
Author | SHA1 | Date |
---|---|---|
Fierelier | cccc8d1b4d | |
Fierelier | 5bfe0ed61d | |
Fierelier | 31e446f232 |
|
@ -0,0 +1,27 @@
|
|||
local self = ...
|
||||
local engine = require("engine")
|
||||
|
||||
function self.create(element)
|
||||
element.memhiOriginal = element.memhi
|
||||
element.memhi = {}
|
||||
local mt = {
|
||||
__index = function(t,k)
|
||||
return element.memhiOriginal[k]
|
||||
end,
|
||||
__newindex = function(t,k,v)
|
||||
element.memhiOriginal[k] = v
|
||||
if k == "file" then
|
||||
if element.memlo.script ~= nil then self.destroy(element) end
|
||||
element.memlo.script = loadfile(engine.path(self._type.. "/" ..v))(element)
|
||||
end
|
||||
end
|
||||
}
|
||||
setmetatable(element.memhi,mt)
|
||||
end
|
||||
|
||||
function self.destroy(element)
|
||||
element.memlo.script.destroy(element)
|
||||
end
|
||||
|
||||
function self.unload()
|
||||
end
|
|
@ -3,6 +3,7 @@ local engine = {}
|
|||
function engine.null() end
|
||||
|
||||
engine.elements = {}
|
||||
engine.elementsByType = {}
|
||||
engine.elementTypes = {}
|
||||
engine.element = {}
|
||||
|
||||
|
@ -26,6 +27,7 @@ function engine.element.create(elementType)
|
|||
_references = 0
|
||||
}
|
||||
|
||||
engine.elementsByType[elementType] = {}
|
||||
assert(loadfile(engine.path(elementType.. ".lua")))(engine.elementTypes[elementType])
|
||||
end
|
||||
|
||||
|
@ -39,7 +41,8 @@ function engine.element.create(elementType)
|
|||
|
||||
local element = {
|
||||
memlo = {
|
||||
_children = {}
|
||||
_children = {},
|
||||
_type = engine.elementTypes[elementType]
|
||||
},
|
||||
memhi = {
|
||||
_id = id,
|
||||
|
@ -51,6 +54,7 @@ function engine.element.create(elementType)
|
|||
|
||||
engine.elementTypes[elementType].create(element)
|
||||
engine.elements[id] = element
|
||||
engine.elementsByType[elementType][id] = element
|
||||
return element
|
||||
end
|
||||
|
||||
|
@ -87,11 +91,13 @@ function engine.element.destroy(element,destroyChildren)
|
|||
|
||||
engine.elementTypes[element.memhi._type].destroy(element)
|
||||
engine.elements[element.memhi._id] = nil
|
||||
engine.elementsByType[element.memhi._type][element.memhi._id] = nil
|
||||
|
||||
engine.elementTypes[element.memhi._type]._references = engine.elementTypes[element.memhi._type]._references - 1
|
||||
if engine.elementTypes[element.memhi._type]._references == 0 then
|
||||
engine.elementTypes[element.memhi._type].unload()
|
||||
engine.elementTypes[element.memhi._type] = nil
|
||||
engine.elementsByType[element.memhi._type] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue