From ffa3bafa002c561f6f4a31e8bbca228c3606b1cc Mon Sep 17 00:00:00 2001 From: Insality Date: Sun, 30 May 2021 11:50:37 +0300 Subject: [PATCH] Add deep linking for exampes in html --- .luacheckrc | 1 + example/example.gui_script | 20 +++++++++++++++++++ .../grid_animations.gui_script | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index a99ebbd..82ec63c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -48,4 +48,5 @@ globals = { "buffer", "resource", "defos", + "html5", } diff --git a/example/example.gui_script b/example/example.gui_script index 25a65fd..0c56e51 100644 --- a/example/example.gui_script +++ b/example/example.gui_script @@ -17,6 +17,8 @@ end local function show_scene(self, scene_name, text_header) + print("Show scene:", scene_name) + monarch.show(scene_name) gui.set_enabled(gui.get_node("C_Anchor"), false) gui.set_enabled(self.button_menu.node, true) @@ -60,6 +62,9 @@ local function get_button(self, text, scene_name) local nodes = gui.clone_tree(prefab) local root = nodes["prefab_button"] gui.set_enabled(root, true) + + self.scene_names[scene_name] = text + self.druid:new_button(root, function() show_scene(self, scene_name, text) end):set_click_zone(self.lobby_scroll.view_node) @@ -84,6 +89,7 @@ end local function init_lobby(self) gui.set_enabled(gui.get_node("prefabs"), false) + self.scene_names = {} self.lobby_scroll = self.druid:new_scroll("lobby_view", "lobby_content") self.lobby_grid = self.druid:new_dynamic_grid("lobby_content") @@ -130,6 +136,18 @@ local function init_lobby(self) end +local function check_url(self) + if not html5 then + return + end + local example_arg = html5.run("new URLSearchParams(window.location.search).get('example')") + if example_arg and self.scene_names[example_arg] then + print("Start example: ", example_arg) + show_scene(self, example_arg, self.scene_names[example_arg] or "unknown") + end +end + + function init(self) -- Main lobby have more render priority (top panel) gui.set_render_order(10) @@ -140,6 +158,8 @@ function init(self) init_top_panel(self) init_lobby(self) + + timer.delay(0, false, check_url) end diff --git a/example/examples/grid/grid_animations/grid_animations.gui_script b/example/examples/grid/grid_animations/grid_animations.gui_script index 2a2ea12..a1b6e38 100644 --- a/example/examples/grid/grid_animations/grid_animations.gui_script +++ b/example/examples/grid/grid_animations/grid_animations.gui_script @@ -35,7 +35,7 @@ end function init(self) self.druid = druid.new(self) - self.grid = self.druid:new_grid("grid", "prefab", 5) + self.grid = self.druid:new_static_grid("grid", "prefab", 5) self.prefab = gui.get_node("prefab") gui.set_enabled(self.prefab, false)