diff --git a/src/wollok/game.wlk b/src/wollok/game.wlk index 08df97a6..d5d5da48 100644 --- a/src/wollok/game.wlk +++ b/src/wollok/game.wlk @@ -5,8 +5,16 @@ import wollok.vm.runtime */ object game { + /** Collection of visual objects in the game */ const visuals = [] + /** Is Game running? */ var property running = false + /** + * Allows to configure a visual component as "error reporter". + * Then every error in game board will be reported by this visual component, + * in a balloon message form. + */ + var property errorReporter = null override method initialize() { super() @@ -212,8 +220,10 @@ object game { */ method start() { self.running(true) - io.exceptionHandler({ exception => console.println(exception)}) - io.domainExceptionHandler({exception => self.say(exception.source(), exception.message())}) + io.exceptionHandler({ exception => exception.printStackTrace() }) + io.domainExceptionHandler({ exception => + const reporter = if (errorReporter == null) exception.source() else errorReporter + self.say(reporter, exception.message())}) } /** @@ -298,14 +308,7 @@ object game { * Default behavior is to show them, so this is not necessary. */ method showAttributes(visual) native - - /** - * Allows to configure a visual component as "error reporter". - * Then every error in game board will be reported by this visual component, - * in a balloon message form. - */ - method errorReporter(visual) native - + /** * Returns a sound object. Audio file must be a .mp3, .ogg or .wav file. */ diff --git a/test/game/actions.wpgm b/test/game/actions.wpgm index 5bff33ef..c860cf17 100644 --- a/test/game/actions.wpgm +++ b/test/game/actions.wpgm @@ -4,21 +4,35 @@ object visual { method position() = game.origin() } -program addVisual { +object reporter { + method position() = game.origin() +} + +program say { game.addVisual(visual) + game.start() + game.say(visual, "Hi!") } -program removeVisual { +program domainError { game.addVisual(visual) - game.removeVisual(visual) + new Tick(interval = 1, action = { visual.error("DOMAIN_ERROR") }).start() + game.start() + game.flushEvents(1) } -program say { +program domainErrorWithReporter { game.addVisual(visual) - game.say(visual, "Hi!") + game.addVisual(reporter) + game.errorReporter(reporter) + new Tick(interval = 1, action = { visual.error("DOMAIN_ERROR") }).start() + game.start() + game.flushEvents(1) } -program clear { +program genericError { game.addVisual(visual) - game.clear() + new Tick(interval = 1, action = { throw new Exception(message = "ERROR") }).start() + game.start() + game.flushEvents(1) } diff --git a/test/sanity/game/game.wtest b/test/sanity/game/game.wtest index f90058d4..bf2128f2 100644 --- a/test/sanity/game/game.wtest +++ b/test/sanity/game/game.wtest @@ -117,6 +117,12 @@ describe "Game" { assert.equals([myVisual, visual2, visual3].asSet(), game.allVisuals().asSet()) } + test "clear remove all visuals" { + game.addVisual(myVisual) + game.clear() + assert.that(game.allVisuals().isEmpty()) + } + test "cell size fails when set to 0" { assert.throwsException { => game.cellSize(0) } } @@ -160,7 +166,7 @@ describe "Game" { game.addVisualCharacter(character) // Simulate io.queueEvent(["keypress", "ArrowUp"]) - io.flushEvents(0) + game.flushEvents(0) assert.equals(game.at(0, 1), character.position()) }