diff --git a/src/main/generated-sources/sarl/io/sarl/demos/fireworks/.Firework.java._trace b/src/main/generated-sources/sarl/io/sarl/demos/fireworks/.Firework.java._trace index 93456e5..10b82e0 100644 Binary files a/src/main/generated-sources/sarl/io/sarl/demos/fireworks/.Firework.java._trace and b/src/main/generated-sources/sarl/io/sarl/demos/fireworks/.Firework.java._trace differ diff --git a/src/main/sarl/io/sarl/demos/fireworks/Fireworks.sarl b/src/main/sarl/io/sarl/demos/fireworks/Fireworks.sarl index b0e3db7..7e4a7a7 100644 --- a/src/main/sarl/io/sarl/demos/fireworks/Fireworks.sarl +++ b/src/main/sarl/io/sarl/demos/fireworks/Fireworks.sarl @@ -7,7 +7,7 @@ import io.sarl.demos.fireworks.gui.FXMLViewerController import static io.janusproject.Boot.* class Firework { - static def main(controller: FXMLViewerController) { + static def main(controller : FXMLViewerController) { Boot::offline = true Boot::startJanus(typeof(LaunchingArea), controller) } diff --git a/src/main/sarl/io/sarl/demos/fireworks/FireworksFXApplication.sarl b/src/main/sarl/io/sarl/demos/fireworks/FireworksFXApplication.sarl index d2c6794..abc935e 100644 --- a/src/main/sarl/io/sarl/demos/fireworks/FireworksFXApplication.sarl +++ b/src/main/sarl/io/sarl/demos/fireworks/FireworksFXApplication.sarl @@ -14,8 +14,8 @@ class FireworksFXApplication extends Application { private var loader : FXMLLoader @Override - public def start(stage: Stage) throws Exception { - var location : URL = getClass().getResource("FireworksFXApplication.fxml"); + public def start(stage : Stage) throws Exception { + var location : URL = getClass().getResource("FireworksFXApplication.fxml"); loader = new FXMLLoader(); loader.setLocation(location); loader.setBuilderFactory(new JavaFXBuilderFactory()); @@ -26,14 +26,14 @@ class FireworksFXApplication extends Application { stage.show(); } - public static def main(args: String[]) { + public static def main(args : String[]) { launch(args); } @Override - public def stop() throws Exception { + public def stop() throws Exception { super.stop(); (loader.getController() as FXMLViewerController).cleanExit(); } - + } diff --git a/src/main/sarl/io/sarl/demos/fireworks/Positions.sarl b/src/main/sarl/io/sarl/demos/fireworks/Positions.sarl index 6634899..76555d8 100644 --- a/src/main/sarl/io/sarl/demos/fireworks/Positions.sarl +++ b/src/main/sarl/io/sarl/demos/fireworks/Positions.sarl @@ -8,54 +8,54 @@ import java.util.Vector import javafx.scene.paint.Color class RocketsPos { - public val ROCKETREFRESHDELAY = 100 - var position = new Vector() - var color: Color - var hidden = false - - public def getPosition(){ - return position - } - - public def setPosition(position: Vector){ - this.position = position - } - - public def getColor(){ - return color - } - - public def setColor(color: Color){ - this.color = color - } - - public def setHidden(hidden: boolean){ - this.hidden = hidden - } - - public def getHidden(){ - return this.hidden - } + public val ROCKETREFRESHDELAY = 100 + var position = new Vector() + var color : Color + var hidden = false + + public def getPosition() { + return position + } + + public def setPosition(position : Vector) { + this.position = position + } + + public def getColor() { + return color + } + + public def setColor(color : Color) { + this.color = color + } + + public def setHidden(hidden : boolean) { + this.hidden = hidden + } + + public def getHidden() { + return this.hidden + } } class FirePos { public val FIREREFRESHDELAY = 100 - var positions: List> - var color: Color - - public def getPositions(){ + var positions : List> + var color : Color + + public def getPositions() { return positions } - - public def setPositions(positions: List>){ + + public def setPositions(positions : List>) { this.positions = positions } - - public def getColor(){ + + public def getColor() { return color } - - public def setColor(color: Color){ + + public def setColor(color : Color) { this.color = color } } @@ -63,20 +63,19 @@ class FirePos { class Positions { var rockets = new HashMap() var fire = new HashMap() - - + public def getRockets() : Map { return rockets.unmodifiableView } - + public def getFire() : Map { return fire.unmodifiableView } - - public def setRocketPosition(id: UUID, position: Vector){ + + public def setRocketPosition(id : UUID, position : Vector) { var pos = new RocketsPos() pos.setPosition(position) - if (rockets.containsKey(id)){ + if (rockets.containsKey(id)) { pos.setColor(rockets.get(id).getColor) rockets.replace(id, pos) } else { @@ -84,19 +83,19 @@ class Positions { rockets.put(id, pos) } } - - public def removeRocketPosition(id: UUID){ + + public def removeRocketPosition(id : UUID) { rockets.remove(id) } - - public def hideHocketPosition(id: UUID){ + + public def hideHocketPosition(id : UUID) { rockets.get(id).setHidden(true) } - - public def setFirePosition(id: UUID, rocketID: UUID, positions: List>){ + + public def setFirePosition(id : UUID, rocketID : UUID, positions : List>) { var pos = new FirePos() pos.setPositions(positions) - if (fire.containsKey(id)){ + if (fire.containsKey(id)) { pos.setColor(fire.get(id).getColor) fire.replace(id, pos) } else { @@ -107,10 +106,9 @@ class Positions { fire.put(id, pos) } } - - public def removeFirePosition(id: UUID){ + + public def removeFirePosition(id : UUID) { fire.remove(id) } - -} +} diff --git a/src/main/sarl/io/sarl/demos/fireworks/agents/Fire.sarl b/src/main/sarl/io/sarl/demos/fireworks/agents/Fire.sarl index 85a21bd..722c0f3 100644 --- a/src/main/sarl/io/sarl/demos/fireworks/agents/Fire.sarl +++ b/src/main/sarl/io/sarl/demos/fireworks/agents/Fire.sarl @@ -18,23 +18,23 @@ import java.util.List import java.util.UUID import java.util.Vector -agent Fire { +agent Fire { uses Lifecycle, Logging, Behaviors, DefaultContextInteractions, Schedules - - var x: List - var y: List + + var x : List + var y : List var lifetime = 300 var frozen = false var destroyed = false var exited = false - var grid: Positions - var xf: Double - var yf: Double + var grid : Positions + var xf : Double + var yf : Double var id = UUID.randomUUID - var parentID: UUID - var move: AgentTask - var parentAgent: UUID - + var parentID : UUID + var move : AgentTask + var parentAgent : UUID + on Freeze { this.frozen = occurrence.value if (frozen) @@ -42,11 +42,11 @@ agent Fire { else wake(new UpdateFirePosition) } - + on Initialize { x = new ArrayList() y = new ArrayList() - if (occurrence.parameters.size.equals(4)){ + if (occurrence.parameters.size.equals(4)) { x.add(occurrence.parameters.get(0) as Double) y.add(occurrence.parameters.get(1) as Double) grid = occurrence.parameters.get(2) as Positions @@ -55,60 +55,67 @@ agent Fire { info("Error in fire Initialize : bad parameter number") } parentAgent = occurrence.spawner - + xf = Math.random() * 10.0 - Math.random() * 5 yf = Math.random() * 10.0 + 1.0 + } - } - on FireReady { - move = atFixedDelay(30)[try{ - wake(new UpdateFirePosition);} - catch(e: Exception) {e.printStackTrace}] + move = atFixedDelay(30) [ + try { + wake(new UpdateFirePosition); + } catch (e : Exception) { + e.printStackTrace + } + ] } - - on UpdateFirePosition [isFromMe(occurrence) && !frozen && !destroyed]{ + + on UpdateFirePosition [isFromMe(occurrence) && !frozen && !destroyed] { var newx = x.last + xf var newy = y.last + yf x.add(newx) y.add(newy) - - if (grid !== null){ + + if (grid !== null) { var list = new ArrayList> - x.forEach[pos | { - var nvect = new Vector(2) - nvect.add(pos) - list.add(nvect) - }] - y.forEach[pos, i | { - var nvect = list.get(i) - nvect.add(pos) - list.set(i, nvect) - }] + x.forEach [pos | + { + var nvect = new Vector(2) + nvect.add(pos) + list.add(nvect) + } + ] + y.forEach [pos, i | + { + var nvect = list.get(i) + nvect.add(pos) + list.set(i, nvect) + } + ] grid.setFirePosition(id, parentID, list) } - + lifetime = lifetime - 10 - - if (lifetime <= 0){ + + if (lifetime <= 0) { grid.removeFirePosition(id) this.cleanBeforeExit in(1000)[killMe] } } - - def cleanBeforeExit(){ + + def cleanBeforeExit() { cancel(move, true) exited = true destroyed = true } - + on Exit [!exited && isFrom(getParentID)] { frozen = true this.cleanBeforeExit emit(new Exit, Scopes.addresses(defaultSpace.getAddress(parentAgent))) killMe } - + } diff --git a/src/main/sarl/io/sarl/demos/fireworks/agents/LaunchingArea.sarl b/src/main/sarl/io/sarl/demos/fireworks/agents/LaunchingArea.sarl index c850a29..85fe3e1 100644 --- a/src/main/sarl/io/sarl/demos/fireworks/agents/LaunchingArea.sarl +++ b/src/main/sarl/io/sarl/demos/fireworks/agents/LaunchingArea.sarl @@ -21,68 +21,68 @@ import java.util.UUID agent LaunchingArea { uses DefaultContextInteractions, Lifecycle, Behaviors, Logging, InnerContextAccess - var rocketsQuantity: Integer - var fireQuantity: Integer - var gravity: Double - var grid: Positions = new Positions + var rocketsQuantity : Integer + var fireQuantity : Integer + var gravity : Double + var grid : Positions = new Positions var maxWidth = 10.0 var exited = false - + on SetupSettings { this.rocketsQuantity = occurrence.rocketsQuantity this.fireQuantity = occurrence.fireQuatity this.gravity = occurrence.gravity this.maxWidth = occurrence.maxWidth } - - on Exit [!hasMemberAgent]{ + + on Exit [!hasMemberAgent] { killMe } - + on Exit [hasMemberAgent && !exited] { exited = true innerContext.defaultSpace.emit(new Exit) } - - on Initialize [ occurrence.parameters.empty ] { + + on Initialize [occurrence.parameters.empty] { rocketsQuantity = 20 fireQuantity = 30 gravity = 0.5 - + info("Setup Area") - + } - - on Initialize [ !occurrence.parameters.empty ]{ + + on Initialize [!occurrence.parameters.empty] { var ctrl = occurrence.parameters.get(0) as FXMLViewerController var ^space = defaultContext.createSpace(OpenEventSpaceSpecification, UUID.randomUUID) ctrl.setGUISpace(^space) ^space.register(asEventListener) - + ctrl.listenAndDraw(grid) - + info("Setup Area") } - + on CreateArea { - var x: Double - var i=0 + var x : Double + var i = 0 var rnd = new Random() - while (i