Skip to content

Commit

Permalink
Removing returns, var replaced by val when necessary, fixed missing i…
Browse files Browse the repository at this point in the history
…18n message and errorReporter added
  • Loading branch information
fdodino committed Aug 8, 2018
1 parent 39a2242 commit 0d6e10b
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BalloonMessage {
}

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

def draw(Window window, VisualComponent character) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Image {
override equals(Object obj) {
if(obj === null) return false

var other = obj as Image
val other = obj as Image
getPath == other.getPath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.uqbar.project.wollok.game.messages"; //$NON-NLS-1$

public static String WollokGame_NoMessage;
public static String WollokGame_CharacterKeyNotFound;

static {
// initialize resource bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class Position {
override equals(Object obj) {
if(obj === null) return false

var other = obj as Position
val other = obj as Position
x == other.x && y == other.y
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ abstract class VisualComponent {

def void addMessage(String message, Color color) {
if (message.length > MESSAGE_MAX_LENGTH) {
var beginning = message.substring(0, MESSAGE_TRIM_LENGTH) + ".."
var end = ".." + message.substring(MESSAGE_TRIM_LENGTH, message.length)
val beginning = message.substring(0, MESSAGE_TRIM_LENGTH) + ".."
val end = ".." + message.substring(MESSAGE_TRIM_LENGTH, message.length)
this.addMessage(beginning, color)
this.addMessage(end, color)
return
Expand All @@ -71,24 +71,24 @@ abstract class VisualComponent {
}

def isInMyZone(){
var xMouse = Gdx.input.x
var yMouse = Gdx.input.y
var bottomX = position.xinPixels
var bottomY = Gameboard.getInstance().pixelHeight - position.yinPixels
var topX = bottomX + Gameboard.CELLZISE
var topY = bottomY - Gameboard.CELLZISE
val xMouse = Gdx.input.x
val yMouse = Gdx.input.y
val bottomX = position.xinPixels
val bottomY = Gameboard.getInstance().pixelHeight - position.yinPixels
val topX = bottomX + Gameboard.CELLZISE
val topY = bottomY - Gameboard.CELLZISE
return (xMouse > bottomX && xMouse < topX) && (yMouse < bottomY && yMouse > topY)
}


def hasMessages() {
var textToDelete = new ArrayList<BalloonMessage>()
val textToDelete = new ArrayList<BalloonMessage>()
for (var i = 0; i < this.balloonMessages.size; i++) {
if (balloonMessages.get(i).shouldRemove)
textToDelete.add(balloonMessages.get(i))
}
balloonMessages.removeAll(textToDelete)
return balloonMessages.size > 0
balloonMessages.size > 0
}

def getCurrentMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import java.util.Collection
import java.util.List
import org.apache.log4j.Logger
import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.game.Messages
import org.uqbar.project.wollok.game.Position
import org.uqbar.project.wollok.game.VisualComponent
import org.uqbar.project.wollok.game.helpers.Application
import org.uqbar.project.wollok.game.listeners.ArrowListener
import org.uqbar.project.wollok.game.listeners.GameboardListener
import org.uqbar.project.wollok.interpreter.core.WollokProgramExceptionWrapper
import org.uqbar.project.wollok.game.Messages

@Accessors
class Gameboard {
Expand All @@ -28,12 +28,13 @@ class Gameboard {
List<VisualComponent> components = newArrayList
List<GameboardListener> listeners = newArrayList
VisualComponent character

@Accessors(NONE) VisualComponent errorReporter

def static getInstance() {
if (instance === null) {
instance = new Gameboard()
}
return instance
instance
}

new() {
Expand Down Expand Up @@ -84,13 +85,9 @@ class Gameboard {
components.forEach[it.draw(window)]
}

def pixelHeight() {
return height * CELLZISE
}
def pixelHeight() { height * CELLZISE }

def pixelWidth() {
return width * CELLZISE
}
def pixelWidth() { width * CELLZISE }

def clear() {
components.clear()
Expand Down Expand Up @@ -140,4 +137,13 @@ class Gameboard {
]
if (everybody.isEmpty) null else everybody.last
}

def errorReporter(VisualComponent visual) {
this.errorReporter = visual
}

def VisualComponent errorReporter() {
errorReporter ?: somebody
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,78 +13,81 @@ import org.uqbar.project.wollok.game.WGPosition
class GameboardInputProcessor implements InputProcessor {

override boolean keyDown(int keycode) {
return false
false
}

override boolean keyUp(int keycode) {
return false
false
}

override boolean keyTyped(char character) {
return false
false
}

override boolean touchDown(int x, int y, int pointer, int button) {
var inverseY = Gameboard.getInstance().pixelHeight() - y
var position = new WGPosition(x / Gameboard.CELLZISE, inverseY / Gameboard.CELLZISE )
val inverseY = Gameboard.getInstance().pixelHeight() - y
val position = new WGPosition(x / Gameboard.CELLZISE, inverseY / Gameboard.CELLZISE )

var Iterable<VisualComponent> lista = Gameboard.getInstance.getComponentsInPosition(position)
val Iterable<VisualComponent> lista = Gameboard.getInstance.getComponentsInPosition(position)

//System.out.println("Click en " + x + "," + y + " con boton" + button)
//System.out.println("Hay " + lista.size + " elementos")
if (button == 1) {
//Gameboard.getInstance.getStage.addActor(MenuBuilder.buildMenu(x, y))
}
return true
true
}

override boolean touchUp(int x, int y, int pointer, int button) {
return false
false
}

override boolean touchDragged(int x, int y, int pointer) {
return false
false
}

override boolean mouseMoved(int x, int y) {
return false
false
}

override boolean scrolled(int amount) {
return false
false
}

}

public class MenuBuilder {

def static ScrollPane buildMenu(int x, int y) {
var BitmapFont font = new BitmapFont()
font.setUseIntegerPositions(false)
val font = new BitmapFont() => [
useIntegerPositions = false
]

var LabelStyle lStyle = new LabelStyle()
val lStyle = new LabelStyle()
lStyle.font = font

var Table mainTable = new Table()
mainTable.defaults().width(80)

var ScrollPane scrollPane = new ScrollPane(mainTable)
scrollPane.setFillParent(false)
scrollPane.setX(x)
scrollPane.setY(y)

var Button b1 = new Button()
b1.add(new Label("Move", lStyle))
b1.left()
mainTable.add(b1)
mainTable.row()

var Button b2 = new Button()
b2.add(new Label("Attack", lStyle))
b2.left()
mainTable.add(b2)
mainTable.row()

return scrollPane
val mainTable = new Table() => [
defaults().width(80)
]

val scrollPane = new ScrollPane(mainTable) => [
fillParent = false
setX = x
setY = y
]

mainTable => [
add(new Button() => [
add(new Label("Move", lStyle))
left
])
row
add(new Button() => [
add(new Label("Attack", lStyle))
left
])
row
]
scrollPane
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ class GameboardRendering implements ApplicationListener {

override create() {
Gdx.input.setInputProcessor(new GameboardInputProcessor())
var camera = new OrthographicCamera(0, 0)
val camera = new OrthographicCamera(0, 0)
camera.setToOrtho(false, gameboard.pixelWidth(), gameboard.pixelHeight())
this.window = new Window(camera)
}

override render() {
this.window.clear()

this.gameboard.draw(this.window)

this.window.end()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Window {
val patch3 = new NinePatch(new Texture(Gdx.files.internal("speech3.png")), 30, 60, 40, 50)
val patch4 = new NinePatch(new Texture(Gdx.files.internal("speech4.png")), 30, 60, 40, 50)
val patches = #[patch, patch2, patch3, patch4]

val defaultImage = new Texture(Gdx.files.internal("wko.png")) //TODO: Merge with WollokConventionExtensions DEFAULT_IMAGE
val notFoundText = "IMAGE\nNOT\nFOUND"
val textBitmap = new BitmapFont()
Expand Down Expand Up @@ -76,7 +77,7 @@ class Window {

def drawBalloon(String text, Position position, Color color) {
val baseWidth = 75
var newText = text
val newText = text
var plusWidth = 0
glyphLayout.reset
this.setText(newText, baseWidth, color)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.uqbar.project.wollok.game.helpers

import com.badlogic.gdx.Input.Keys
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input.Keys
import org.eclipse.osgi.util.NLS
import org.uqbar.project.wollok.game.Messages

class Keyboard {

Expand All @@ -27,8 +29,7 @@ class Keyboard {
try {
return typeof(Keys).getDeclaredField(aKey.toUpperCase).get(typeof(Integer)) as Integer;
} catch (Exception e) {
// TODO: i18n
throw new RuntimeException("No se encuentra el caracter " + aKey + ".")
throw new RuntimeException(NLS.bind(Messages.WollokGame_CharacterKeyNotFound, aKey))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ArrowListener implements GameboardListener {
}

override notify(Gameboard gameboard) {
listeners.forEach[it.notify(gameboard)]
listeners.forEach[notify(gameboard)]
}

override isObserving(VisualComponent component) {
listeners.exists[it.isObserving(component)]
listeners.exists[isObserving(component)]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TimeListener implements GameboardListener {
try {
block.apply
} catch (WollokProgramExceptionWrapper e) {
gameboard.somebody?.scream(e.wollokMessage)
gameboard.errorReporter?.scream(e.wollokMessage)
}
timeSinceLastRun = System.currentTimeMillis
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#
#
WollokGame_NoMessage = NO MESSAGE
WollokGame_CharacterKeyNotFound = Character key [{0}] not found.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#
#
WollokGame_NoMessage = FALTA MENSAJE
WollokGame_CharacterKeyNotFound = No se encuentra el caracter {0} .
19 changes: 13 additions & 6 deletions org.uqbar.project.wollok.lib/src/wollok/lib.wlk
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,24 @@ object game {
method boardGround(image) native

/**
* Attributes will not show when user mouse over a visual component.
* Default behavior is to show them.
*/
* Attributes will not show when user mouse over a visual component.
* Default behavior is to show them.
*/
method hideAttributes(visual) native

/**
* Attributes will appear again when user mouse over a visual component.
* Default behavior is to show them, so this is not necessary.
*/
* Attributes will appear again when user mouse over a visual component.
* 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

/**
* @private
*/
Expand Down
Loading

0 comments on commit 0d6e10b

Please sign in to comment.