diff --git a/game.project b/game.project index b05c6b4..4b5505e 100644 --- a/game.project +++ b/game.project @@ -4,7 +4,7 @@ version = 0.9 dependencies = https://github.com/britzl/deftest/archive/1.2.1.zip [bootstrap] -main_collection = /example/example.collectionc +main_collection = /test/test.collectionc [input] game_binding = /input/game.input_bindingc diff --git a/test/data/popup1.collection b/test/data/popup1.collection new file mode 100644 index 0000000..aede829 --- /dev/null +++ b/test/data/popup1.collection @@ -0,0 +1,37 @@ +name: "popup1" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"popup1\"\n" + " component: \"/test/data/popup1.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/test/data/popup1.gui b/test/data/popup1.gui new file mode 100644 index 0000000..4c72314 --- /dev/null +++ b/test/data/popup1.gui @@ -0,0 +1,131 @@ +script: "" +fonts { + name: "example" + font: "/assets/example.font" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 320.0 + y: 568.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "box" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_AUTO +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "POPUP 1" + font: "example" + id: "text" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "box" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/test/data/popup2.collection b/test/data/popup2.collection new file mode 100644 index 0000000..9e95fe2 --- /dev/null +++ b/test/data/popup2.collection @@ -0,0 +1,37 @@ +name: "popup2" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"popup2\"\n" + " component: \"/test/data/popup2.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/test/data/popup2.gui b/test/data/popup2.gui new file mode 100644 index 0000000..b05510a --- /dev/null +++ b/test/data/popup2.gui @@ -0,0 +1,131 @@ +script: "" +fonts { + name: "example" + font: "/assets/example.font" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 320.0 + y: 568.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "box" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_AUTO +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 100.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "POPUP 2" + font: "example" + id: "text" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "box" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/test/data/screens.collection b/test/data/screens.collection index dc7bdd2..47aebec 100644 --- a/test/data/screens.collection +++ b/test/data/screens.collection @@ -116,3 +116,139 @@ embedded_instances { z: 1.0 } } +embedded_instances { + id: "popup1" + data: "components {\n" + " id: \"screen\"\n" + " component: \"/monarch/screen.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " properties {\n" + " id: \"screen_id\"\n" + " value: \"popup1\"\n" + " type: PROPERTY_TYPE_HASH\n" + " }\n" + " properties {\n" + " id: \"popup\"\n" + " value: \"true\"\n" + " type: PROPERTY_TYPE_BOOLEAN\n" + " }\n" + " properties {\n" + " id: \"popup_on_popup\"\n" + " value: \"false\"\n" + " type: PROPERTY_TYPE_BOOLEAN\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"collectionproxy\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/test/data/popup1.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} +embedded_instances { + id: "popup2" + data: "components {\n" + " id: \"screen\"\n" + " component: \"/monarch/screen.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " properties {\n" + " id: \"screen_id\"\n" + " value: \"popup2\"\n" + " type: PROPERTY_TYPE_HASH\n" + " }\n" + " properties {\n" + " id: \"popup\"\n" + " value: \"true\"\n" + " type: PROPERTY_TYPE_BOOLEAN\n" + " }\n" + " properties {\n" + " id: \"popup_on_popup\"\n" + " value: \"true\"\n" + " type: PROPERTY_TYPE_BOOLEAN\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"collectionproxy\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/test/data/popup2.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/test/test_monarch.lua b/test/test_monarch.lua index ac9f450..e7e952c 100644 --- a/test/test_monarch.lua +++ b/test/test_monarch.lua @@ -3,6 +3,8 @@ local monarch = require "monarch.monarch" local SCREEN1 = hash("screen1") local SCREEN2 = hash("screen2") +local POPUP1 = hash("popup1") +local POPUP2 = hash("popup2") local FOOBAR = hash("foobar") return function() @@ -130,6 +132,47 @@ return function() assert_stack({ SCREEN1 }) end) - + + it("should be able to show one popup on top of another the Popup On Popup flag is set", function() + monarch.show(SCREEN1) + assert(wait_until_shown(SCREEN1), "Screen1 was never shown") + assert_stack({ SCREEN1 }) + monarch.show(POPUP1) + assert(wait_until_shown(POPUP1), "Popup1 was never shown") + assert_stack({ SCREEN1, POPUP1 }) + monarch.show(POPUP2) + assert(wait_until_shown(POPUP2), "Popup2 was never shown") + assert_stack({ SCREEN1, POPUP1, POPUP2 }) + end) + + + it("should close any open popups when showing a popup without the Popup On Popup flag", function() + monarch.show(SCREEN1) + assert(wait_until_shown(SCREEN1), "Screen1 was never shown") + assert_stack({ SCREEN1 }) + monarch.show(POPUP2) + assert(wait_until_shown(POPUP2), "Popup2 was never shown") + assert_stack({ SCREEN1, POPUP2 }) + monarch.show(POPUP1) + assert(wait_until_shown(POPUP1), "Popup1 was never shown") + assert_stack({ SCREEN1, POPUP1 }) + end) + + + it("should close any open popups when showing a non-popup", function() + monarch.show(SCREEN1) + assert(wait_until_shown(SCREEN1), "Screen1 was never shown") + assert_stack({ SCREEN1 }) + monarch.show(POPUP1) + assert(wait_until_shown(POPUP1), "Popup1 was never shown") + assert_stack({ SCREEN1, POPUP1 }) + monarch.show(POPUP2) + assert(wait_until_shown(POPUP2), "Popup2 was never shown") + assert_stack({ SCREEN1, POPUP1, POPUP2 }) + monarch.show(SCREEN2) + assert(wait_until_shown(SCREEN2), "Popup2 was never shown") + assert_stack({ SCREEN1, SCREEN2 }) + end) + end) end