From 8df7ddd32f5f48465462b8e8210ca4f091406f4b Mon Sep 17 00:00:00 2001 From: Brian Kramer Date: Wed, 8 Nov 2017 09:29:25 -0800 Subject: [PATCH] Adding monarch.screen_exists(id) In some projects may need to wait until initial screen has been registered before attempting to show it --- example/main.script | 10 +++++++++- monarch/monarch.lua | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/example/main.script b/example/main.script index 3bead44..83439c5 100644 --- a/example/main.script +++ b/example/main.script @@ -1,6 +1,14 @@ local monarch = require "monarch.monarch" function init(self) - monarch.show(hash("menu")) + self.wait = true msg.post("@render:/", "clear_color", { color = vmath.vector4(0.4, 0.6, 0.8,1.0) }) end + +function update(self) + -- Ensure that the initial screen has had enough time to register + if self.wait == true and monarch.screen_exists(hash("menu")) then + self.wait = false + monarch.show(hash("menu")) + end +end diff --git a/monarch/monarch.lua b/monarch/monarch.lua index fce3bb2..37f4e23 100644 --- a/monarch/monarch.lua +++ b/monarch/monarch.lua @@ -152,6 +152,13 @@ function M.data(id) return screens[id].data end +--- Checks to see if a screen id is registered +-- @param id Id of the screen to check if is registered +-- @return True or False if the screen id is registered or not +function M.screen_exists(id) + return screens[id] ~= nil +end + --- Show a new screen -- @param id Id of the screen to show -- @param options Table with options when showing the screen (can be nil). Valid values: