mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 10:27:47 +02:00
ability to extend components, stubs for sounds and locale
This commit is contained in:
parent
9af3046ca4
commit
0d98e435b6
@ -7,7 +7,7 @@ local STRING = "string"
|
|||||||
|
|
||||||
--- New druid era, registering components
|
--- New druid era, registering components
|
||||||
local components = {
|
local components = {
|
||||||
-- base
|
-- basic
|
||||||
button = require("druid.base.button"),
|
button = require("druid.base.button"),
|
||||||
-- text = require("druid.base.text"),
|
-- text = require("druid.base.text"),
|
||||||
-- android_back = require("druid.base.android_back"),
|
-- android_back = require("druid.base.android_back"),
|
||||||
@ -15,18 +15,22 @@ local components = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local function register_components()
|
local function register_basic_components()
|
||||||
for k, v in pairs(components) do
|
for k, v in pairs(components) do
|
||||||
-- TODO: Find better solution to creating elements?
|
M.register(k, v)
|
||||||
M["new_" .. k] = function(factory, name, ...)
|
|
||||||
M.create(factory, v, name, ...)
|
|
||||||
end
|
|
||||||
print("[Druid]: register component", k)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
register_components()
|
register_basic_components()
|
||||||
|
|
||||||
|
|
||||||
|
function M.register(name, module)
|
||||||
|
-- TODO: Find better solution to creating elements?
|
||||||
|
M["new_" .. name] = function(factory, node_name, ...)
|
||||||
|
M.create(factory, module, node_name, ...)
|
||||||
|
end
|
||||||
|
print("[Druid]: register component", name)
|
||||||
|
end
|
||||||
|
|
||||||
--- Called on_message
|
--- Called on_message
|
||||||
function M.on_message(factory, message_id, message, sender)
|
function M.on_message(factory, message_id, message, sender)
|
||||||
if message_id == data.LAYOUT_CHANGED then
|
if message_id == data.LAYOUT_CHANGED then
|
||||||
@ -104,8 +108,8 @@ end
|
|||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
local function create(meta, factory, name, ...)
|
local function create(module, factory, name, ...)
|
||||||
local instance = setmetatable({}, {__index = meta})
|
local instance = setmetatable({}, {__index = module})
|
||||||
instance.parent = factory
|
instance.parent = factory
|
||||||
if name then
|
if name then
|
||||||
if type(name) == STRING then
|
if type(name) == STRING then
|
||||||
@ -119,7 +123,7 @@ local function create(meta, factory, name, ...)
|
|||||||
end
|
end
|
||||||
factory[#factory + 1] = instance
|
factory[#factory + 1] = instance
|
||||||
|
|
||||||
local register_to = meta.interest or {}
|
local register_to = module.interest or {}
|
||||||
for i, v in ipairs(register_to) do
|
for i, v in ipairs(register_to) do
|
||||||
if not factory[v] then
|
if not factory[v] then
|
||||||
factory[v] = {}
|
factory[v] = {}
|
||||||
@ -134,9 +138,8 @@ local function create(meta, factory, name, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function M.create(factory, meta, name, ...)
|
function M.create(factory, module, name, ...)
|
||||||
local instance = create(meta, factory, name)
|
local instance = create(module, factory, name)
|
||||||
instance.factory = factory
|
|
||||||
|
|
||||||
if instance.init then
|
if instance.init then
|
||||||
instance:init(...)
|
instance:init(...)
|
||||||
@ -144,4 +147,14 @@ function M.create(factory, meta, name, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.get_text(name)
|
||||||
|
-- override to get text for localized text
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function M.play_sound(name)
|
||||||
|
-- override to play sound with name
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
return M
|
return M
|
Loading…
x
Reference in New Issue
Block a user