Skip to content

Commit f2724bb

Browse files
committed
Added option to remove transition
Fixes #117
1 parent 18a8d1e commit f2724bb

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

game.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = 0.9
44
dependencies#0 = https://github.com/britzl/deftest/archive/2.7.0.zip
55

66
[bootstrap]
7-
main_collection = /example/advanced/advanced.collectionc
7+
main_collection = /test/test.collectionc
88

99
[input]
1010
game_binding = /input/game.input_bindingc

monarch/monarch.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,14 +1321,13 @@ end
13211321
-- IMPORTANT! You must call monarch.on_message() from the same script as
13221322
-- this function was called
13231323
-- @param id Screen id to associate transition with
1324-
-- @param fn Transition handler function
1324+
-- @param fn Transition handler function or nil to remove transition
13251325
function M.on_transition(id, fn)
13261326
assert(id, "You must provide a screen id")
1327-
assert(fn, "You must provide a transition function")
13281327
id = tohash(id)
13291328
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
13301329
local screen = screens[id]
1331-
screen.transition_url = msg.url()
1330+
screen.transition_url = fn and msg.url() or nil
13321331
screen.transition_fn = fn
13331332
end
13341333

test/data/transition1.gui_script

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
local monarch = require "monarch.monarch"
12
local transitions = require "monarch.transitions.gui"
23

34
function init(self)
4-
self.transition = transitions.in_right_out_left(gui.get_node("root"), 1)
5+
local transition = transitions.in_right_out_left(gui.get_node("root"), 1)
6+
monarch.on_transition("transition1", transition)
57
end
68

79
function on_message(self, message_id, message, sender)
8-
print(message_id)
9-
self.transition.handle(message_id, message, sender)
10+
monarch.on_message(message_id, message, sender)
1011
end

test/test_monarch.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,23 @@ return function()
379379
assert(wait_until_not_busy())
380380
end)
381381

382+
it("should be possible to remove a transition", function()
383+
local start = socket.gettime()
384+
monarch.show(TRANSITION1)
385+
assert(wait_until_stack({ TRANSITION1 }))
386+
assert(wait_until_not_busy())
387+
local t = socket.gettime() - start
388+
assert_greater_than(t, 0.2)
389+
390+
monarch.on_transition(TRANSITION1, nil)
391+
start = socket.gettime()
392+
monarch.hide(TRANSITION1)
393+
assert(wait_until_stack({ }))
394+
assert(wait_until_not_busy())
395+
local t = socket.gettime() - start
396+
assert_less_than(t, 0.1)
397+
end)
398+
382399
it("should be able to preload a screen and wait for it", function()
383400
assert(not monarch.is_preloading(TRANSITION1))
384401
monarch.preload(TRANSITION1)
@@ -569,5 +586,6 @@ return function()
569586
assert(not monarch.is_popup(SCREEN1))
570587
assert(monarch.is_popup(POPUP1))
571588
end)
589+
572590
end)
573591
end

test/test_transitions.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe("transitions", function()
4040

4141
local node = gui.new_box_node(vmath.vector3(), vmath.vector3(100, 100, 0))
4242
local duration = 2
43+
local delay = 0
4344
local t = transitions.create(node)
4445
t.show_in(dummy_transition1, easing.OUT, duration, delay or 0)
4546
t.show_in(dummy_transition2, easing.OUT, duration, delay or 0)
@@ -57,6 +58,7 @@ describe("transitions", function()
5758

5859
local node = gui.new_box_node(vmath.vector3(), vmath.vector3(100, 100, 0))
5960
local duration = 2
61+
local delay = 0
6062
local t = transitions.create(node)
6163
.show_in(dummy_transition, easing.OUT, duration, delay or 0)
6264
.show_out(dummy_transition, easing.IN, duration, delay or 0)

0 commit comments

Comments
 (0)