3
0
mirror of https://github.com/britzl/monarch.git synced 2025-11-27 19:30:54 +01:00

Compare commits

..

2 Commits
4.1.0 ... 4.2.0

Author SHA1 Message Date
Björn Ritzl
5d8fa8e220 monarch.post() requires monarch.on_post() 2023-08-03 08:35:04 +02:00
Björn Ritzl
df2a2a62ea Improved screen proxy url detection 2023-08-03 08:34:26 +02:00
3 changed files with 12 additions and 18 deletions

View File

@@ -177,7 +177,7 @@ Remove a previously added listener.
## monarch.post(screen_id, message_id, [message]) ## monarch.post(screen_id, message_id, [message])
Post a message to a visible screen. If the screen is created through a collection proxy it must have specified a receiver url. If the screen is created through a collection factory the function will post the message to all game objects within the collection. Post a message to a visible screen. The screen must have set a message listener using `monarch.on_post()`.
**PARAMETERS** **PARAMETERS**
* `screen_id` (string|hash) - Id of the screen to post message to * `screen_id` (string|hash) - Id of the screen to post message to

View File

@@ -21,7 +21,7 @@ local MSG_ENABLE = hash("enable")
local MSG_DISABLE = hash("disable") local MSG_DISABLE = hash("disable")
local DEPRECATED = hash("/__DEPRECATED__") local DEPRECATED = hash("__DEPRECATED__")
-- transition messages -- transition messages
M.TRANSITION = {} M.TRANSITION = {}
@@ -281,13 +281,13 @@ function M.register_proxy(id, proxy, settings)
screen.focus_url = settings and settings.focus_url screen.focus_url = settings and settings.focus_url
screen.receiver_url = settings and settings.receiver_url screen.receiver_url = settings and settings.receiver_url
screen.auto_preload = settings and settings.auto_preload screen.auto_preload = settings and settings.auto_preload
if screen.transition_url.path == DEPRECATED then if screen.transition_url.fragment == DEPRECATED then
screen.transition_url = nil screen.transition_url = nil
end end
if screen.focus_url.path == DEPRECATED then if screen.focus_url.fragment == DEPRECATED then
screen.focus_url = nil screen.focus_url = nil
end end
if screen.receiver_url.path == DEPRECATED then if screen.receiver_url.fragment == DEPRECATED then
screen.receiver_url = nil screen.receiver_url = nil
end end
if screen.auto_preload then if screen.auto_preload then
@@ -1173,17 +1173,11 @@ function M.post(id, message_id, message)
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)))
local screen = screens[id] local screen = screens[id]
if screen.proxy then
if screen.receiver_url then if screen.receiver_url then
log("post() sending message to", screen.receiver_url) log("post() sending message to", screen.receiver_url)
msg.post(screen.receiver_url, message_id, message) msg.post(screen.receiver_url, message_id, message)
else else
return false, "Unable to post message since screen has no receiver url specified" return false, "Unable to post message since screen has no receiver url specified. Set one using monarch.on_post()."
end
else
for id,instance in pairs(screen.factory_ids) do
msg.post(instance, message_id, message)
end
end end
return true return true
end end

View File

@@ -7,9 +7,9 @@ go.property("popup_on_popup", false)
go.property("timestep_below_popup", 1) go.property("timestep_below_popup", 1)
go.property("screen_keeps_input_focus_when_below_popup", false) go.property("screen_keeps_input_focus_when_below_popup", false)
go.property("others_keep_input_focus_when_below_screen", false) go.property("others_keep_input_focus_when_below_screen", false)
go.property("transition_url", msg.url("__DEPRECATED__")) go.property("transition_url", msg.url("#__DEPRECATED__"))
go.property("focus_url", msg.url("__DEPRECATED__")) go.property("focus_url", msg.url("#__DEPRECATED__"))
go.property("receiver_url", msg.url("__DEPRECATED__")) go.property("receiver_url", msg.url("#__DEPRECATED__"))
go.property("preload", false) go.property("preload", false)