Skip to content

Commit

Permalink
Catching Wollok errors - avoiding stack trace in console
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Aug 7, 2018
1 parent 4ebf971 commit 0ffe78b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class BalloonMessage {
color = aColor
}

def boolean shouldRemove(){
def boolean shouldRemove() {
return timestamp != 0 && new Date().time - timestamp > timeToLive
}

def draw(Window window, VisualComponent character) {
if (timestamp == 0)
timestamp = new Date().time

window.drawBallon(this.text, character.position, this.color)
window.drawBaloon(this.text, character.position, this.color)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Window {
font.draw(batch, glyphLayout, x, y)
}

def drawBallon(String text, Position position, Color color) {
def drawBaloon(String text, Position position, Color color) {
val baseWidth = 75
var newText = text
var plusWidth = 0
Expand Down
20 changes: 17 additions & 3 deletions org.uqbar.project.wollok.lib/src/wollok/lib/GameObject.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.uqbar.project.wollok.lib.WVisual

import static extension org.uqbar.project.wollok.interpreter.nativeobj.WollokJavaConversions.*
import static extension org.uqbar.project.wollok.lib.WollokSDKExtensions.*
import org.uqbar.project.wollok.interpreter.core.WollokProgramExceptionWrapper

/**
*
Expand Down Expand Up @@ -48,10 +49,16 @@ class GameObject {
def whenKeyPressedDo(WollokObject key, WollokObject action) {
var num = key.coerceToInteger
val function = action.asClosure
addListener(new KeyboardListener(num, [ function.doApply ]))
addListener(new KeyboardListener(num, [
try {
function.doApply
} catch (WollokProgramExceptionWrapper e) {
board.somebody?.scream(e.wollokMessage)
}
]))
}

def whenKeyPressedSay(WollokObject key, WollokObject functionObj) {
def whenKeyPressedSay(WollokObject key, WollokObject functionObj) {
val num = key.coerceToInteger
val function = functionObj.asClosure
addListener(new KeyboardListener(num, [ board.characterSay(function.doApply.asString) ]))
Expand All @@ -60,7 +67,14 @@ class GameObject {
def whenCollideDo(WollokObject visual, WollokObject action) {
var visualObject = board.findVisual(visual)
val function = action.asClosure
addListener(new CollisionListener(visualObject, [ function.doApply((it as WVisual).wObject) ]))
addListener(new CollisionListener(visualObject, [
try {
function.doApply((it as WVisual).wObject)
} catch (WollokProgramExceptionWrapper e) {
board.somebody?.scream(e.wollokMessage)
null
}
]))
}

def getObjectsIn(WollokObject position) {
Expand Down

0 comments on commit 0ffe78b

Please sign in to comment.