mirror of
https://github.com/britzl/monarch.git
synced 2025-06-27 10:27:49 +02:00
Added more documentation. Changed monarch.get_stack()
This commit is contained in:
parent
6529147e18
commit
1b3b16c355
@ -1,4 +1,4 @@
|
|||||||
name: "main"
|
name: "example"
|
||||||
scale_along_z: 0
|
scale_along_z: 0
|
||||||
embedded_instances {
|
embedded_instances {
|
||||||
id: "menu"
|
id: "menu"
|
@ -43,6 +43,10 @@ local function screen_from_script()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a screen exists in the current screen stack
|
||||||
|
-- @param id
|
||||||
|
-- @return true of the screen is in the stack
|
||||||
function M.in_stack(id)
|
function M.in_stack(id)
|
||||||
for i = 1, #stack do
|
for i = 1, #stack do
|
||||||
if stack[i].id == id then
|
if stack[i].id == id then
|
||||||
@ -52,13 +56,33 @@ function M.in_stack(id)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a screen is at the top of the stack
|
||||||
|
-- (primarily used for unit tests, but could have a usecase outside tests)
|
||||||
|
-- @param id
|
||||||
|
-- @return true if the screen is at the top of the stack
|
||||||
function M.is_top(id)
|
function M.is_top(id)
|
||||||
local top = stack[#stack]
|
local top = stack[#stack]
|
||||||
return top and top.id == id or false
|
return top and top.id == id or false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Register a new screen
|
||||||
|
-- This is done automatically by the screen.script. It is expected that the
|
||||||
|
-- caller of this function is a script component attached to the same game
|
||||||
|
-- object as the proxy. This is required since monarch will acquire and
|
||||||
|
-- release input focus of the game object where the proxy is attached.
|
||||||
|
-- @param id Unique id of the screen
|
||||||
|
-- @param proxy URL to the collection proxy containing the screen
|
||||||
|
-- @param popup true the screen is a popup
|
||||||
|
-- @param transition_url Optional URL to a script that is
|
||||||
|
-- responsible for the screen transitions
|
||||||
|
-- @param focus_url Optional URL to a script that is to be notified of
|
||||||
|
-- focus lost/gained events
|
||||||
function M.register(id, proxy, popup, transition_url, focus_url)
|
function M.register(id, proxy, popup, transition_url, focus_url)
|
||||||
assert(not screens[id], ("There is already a screen registered with id %s"):format(tostring(id)))
|
assert(not screens[id], ("There is already a screen registered with id %s"):format(tostring(id)))
|
||||||
|
assert(proxy, "You must provide a collection proxy URL")
|
||||||
|
local url = msg.url(proxy)
|
||||||
screens[id] = {
|
screens[id] = {
|
||||||
id = id,
|
id = id,
|
||||||
proxy = proxy,
|
proxy = proxy,
|
||||||
@ -69,6 +93,9 @@ function M.register(id, proxy, popup, transition_url, focus_url)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Unregister a screen
|
||||||
|
-- This is done automatically by the screen.script
|
||||||
|
-- @param id Id of the screen to unregister
|
||||||
function M.unregister(id)
|
function M.unregister(id)
|
||||||
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
|
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
|
||||||
screens[id] = nil
|
screens[id] = nil
|
||||||
@ -279,11 +306,14 @@ function M.on_message(message_id, message, sender)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Get a list of ids for the current screen stack
|
||||||
|
-- (primarily used for unit testing, but could have uses outside testing)
|
||||||
|
-- @return Table with screen ids. First entry is at the bottom of the
|
||||||
|
-- stack and the last value is at the top (and currently visible)
|
||||||
function M.get_stack()
|
function M.get_stack()
|
||||||
local s = {}
|
local s = {}
|
||||||
for k,v in pairs(stack) do
|
for k,v in pairs(stack) do
|
||||||
s[k] = v
|
s[k] = v.id
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ return function()
|
|||||||
error("Stack length mismatch", 2)
|
error("Stack length mismatch", 2)
|
||||||
end
|
end
|
||||||
for i=1,#actual_screens do
|
for i=1,#actual_screens do
|
||||||
if actual_screens[i].id ~= expected_screens[i] then
|
if actual_screens[i] ~= expected_screens[i] then
|
||||||
error("Stack content not matching", 2)
|
error("Stack content not matching", 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user