1
0
mirror of https://github.com/klmp200/sarl-fireworks.git synced 2024-11-22 14:53:19 +00:00

reformatting all classes

This commit is contained in:
ngaud 2017-05-02 17:25:05 +02:00
parent 9890daffc8
commit 9316a74f07
10 changed files with 180 additions and 177 deletions

View File

@ -7,7 +7,7 @@ import io.sarl.demos.fireworks.gui.FXMLViewerController
import static io.janusproject.Boot.* import static io.janusproject.Boot.*
class Firework { class Firework {
static def main(controller: FXMLViewerController) { static def main(controller : FXMLViewerController) {
Boot::offline = true Boot::offline = true
Boot::startJanus(typeof(LaunchingArea), controller) Boot::startJanus(typeof(LaunchingArea), controller)
} }

View File

@ -14,7 +14,7 @@ class FireworksFXApplication extends Application {
private var loader : FXMLLoader private var loader : FXMLLoader
@Override @Override
public def start(stage: Stage) throws Exception { public def start(stage : Stage) throws Exception {
var location : URL = getClass().getResource("FireworksFXApplication.fxml"); var location : URL = getClass().getResource("FireworksFXApplication.fxml");
loader = new FXMLLoader(); loader = new FXMLLoader();
loader.setLocation(location); loader.setLocation(location);
@ -26,7 +26,7 @@ class FireworksFXApplication extends Application {
stage.show(); stage.show();
} }
public static def main(args: String[]) { public static def main(args : String[]) {
launch(args); launch(args);
} }

View File

@ -10,52 +10,52 @@ import javafx.scene.paint.Color
class RocketsPos { class RocketsPos {
public val ROCKETREFRESHDELAY = 100 public val ROCKETREFRESHDELAY = 100
var position = new Vector<Double>() var position = new Vector<Double>()
var color: Color var color : Color
var hidden = false var hidden = false
public def getPosition(){ public def getPosition() {
return position return position
} }
public def setPosition(position: Vector<Double>){ public def setPosition(position : Vector<Double>) {
this.position = position this.position = position
} }
public def getColor(){ public def getColor() {
return color return color
} }
public def setColor(color: Color){ public def setColor(color : Color) {
this.color = color this.color = color
} }
public def setHidden(hidden: boolean){ public def setHidden(hidden : boolean) {
this.hidden = hidden this.hidden = hidden
} }
public def getHidden(){ public def getHidden() {
return this.hidden return this.hidden
} }
} }
class FirePos { class FirePos {
public val FIREREFRESHDELAY = 100 public val FIREREFRESHDELAY = 100
var positions: List<Vector<Double>> var positions : List<Vector<Double>>
var color: Color var color : Color
public def getPositions(){ public def getPositions() {
return positions return positions
} }
public def setPositions(positions: List<Vector<Double>>){ public def setPositions(positions : List<Vector<Double>>) {
this.positions = positions this.positions = positions
} }
public def getColor(){ public def getColor() {
return color return color
} }
public def setColor(color: Color){ public def setColor(color : Color) {
this.color = color this.color = color
} }
} }
@ -64,7 +64,6 @@ class Positions {
var rockets = new HashMap<UUID, RocketsPos>() var rockets = new HashMap<UUID, RocketsPos>()
var fire = new HashMap<UUID, FirePos>() var fire = new HashMap<UUID, FirePos>()
public def getRockets() : Map<UUID, RocketsPos> { public def getRockets() : Map<UUID, RocketsPos> {
return rockets.unmodifiableView return rockets.unmodifiableView
} }
@ -73,10 +72,10 @@ class Positions {
return fire.unmodifiableView return fire.unmodifiableView
} }
public def setRocketPosition(id: UUID, position: Vector<Double>){ public def setRocketPosition(id : UUID, position : Vector<Double>) {
var pos = new RocketsPos() var pos = new RocketsPos()
pos.setPosition(position) pos.setPosition(position)
if (rockets.containsKey(id)){ if (rockets.containsKey(id)) {
pos.setColor(rockets.get(id).getColor) pos.setColor(rockets.get(id).getColor)
rockets.replace(id, pos) rockets.replace(id, pos)
} else { } else {
@ -85,18 +84,18 @@ class Positions {
} }
} }
public def removeRocketPosition(id: UUID){ public def removeRocketPosition(id : UUID) {
rockets.remove(id) rockets.remove(id)
} }
public def hideHocketPosition(id: UUID){ public def hideHocketPosition(id : UUID) {
rockets.get(id).setHidden(true) rockets.get(id).setHidden(true)
} }
public def setFirePosition(id: UUID, rocketID: UUID, positions: List<Vector<Double>>){ public def setFirePosition(id : UUID, rocketID : UUID, positions : List<Vector<Double>>) {
var pos = new FirePos() var pos = new FirePos()
pos.setPositions(positions) pos.setPositions(positions)
if (fire.containsKey(id)){ if (fire.containsKey(id)) {
pos.setColor(fire.get(id).getColor) pos.setColor(fire.get(id).getColor)
fire.replace(id, pos) fire.replace(id, pos)
} else { } else {
@ -108,9 +107,8 @@ class Positions {
} }
} }
public def removeFirePosition(id: UUID){ public def removeFirePosition(id : UUID) {
fire.remove(id) fire.remove(id)
} }
} }

View File

@ -21,19 +21,19 @@ import java.util.Vector
agent Fire { agent Fire {
uses Lifecycle, Logging, Behaviors, DefaultContextInteractions, Schedules uses Lifecycle, Logging, Behaviors, DefaultContextInteractions, Schedules
var x: List<Double> var x : List<Double>
var y: List<Double> var y : List<Double>
var lifetime = 300 var lifetime = 300
var frozen = false var frozen = false
var destroyed = false var destroyed = false
var exited = false var exited = false
var grid: Positions var grid : Positions
var xf: Double var xf : Double
var yf: Double var yf : Double
var id = UUID.randomUUID var id = UUID.randomUUID
var parentID: UUID var parentID : UUID
var move: AgentTask var move : AgentTask
var parentAgent: UUID var parentAgent : UUID
on Freeze { on Freeze {
this.frozen = occurrence.value this.frozen = occurrence.value
@ -46,7 +46,7 @@ agent Fire {
on Initialize { on Initialize {
x = new ArrayList() x = new ArrayList()
y = 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) x.add(occurrence.parameters.get(0) as Double)
y.add(occurrence.parameters.get(1) as Double) y.add(occurrence.parameters.get(1) as Double)
grid = occurrence.parameters.get(2) as Positions grid = occurrence.parameters.get(2) as Positions
@ -59,46 +59,53 @@ agent Fire {
xf = Math.random() * 10.0 - Math.random() * 5 xf = Math.random() * 10.0 - Math.random() * 5
yf = Math.random() * 10.0 + 1.0 yf = Math.random() * 10.0 + 1.0
} }
on FireReady { on FireReady {
move = atFixedDelay(30)[try{ move = atFixedDelay(30) [
wake(new UpdateFirePosition);} try {
catch(e: Exception) {e.printStackTrace}] 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 newx = x.last + xf
var newy = y.last + yf var newy = y.last + yf
x.add(newx) x.add(newx)
y.add(newy) y.add(newy)
if (grid !== null){ if (grid !== null) {
var list = new ArrayList<Vector<Double>> var list = new ArrayList<Vector<Double>>
x.forEach[pos | { x.forEach [pos |
{
var nvect = new Vector(2) var nvect = new Vector(2)
nvect.add(pos) nvect.add(pos)
list.add(nvect) list.add(nvect)
}] }
y.forEach[pos, i | { ]
y.forEach [pos, i |
{
var nvect = list.get(i) var nvect = list.get(i)
nvect.add(pos) nvect.add(pos)
list.set(i, nvect) list.set(i, nvect)
}] }
]
grid.setFirePosition(id, parentID, list) grid.setFirePosition(id, parentID, list)
} }
lifetime = lifetime - 10 lifetime = lifetime - 10
if (lifetime <= 0){ if (lifetime <= 0) {
grid.removeFirePosition(id) grid.removeFirePosition(id)
this.cleanBeforeExit this.cleanBeforeExit
in(1000)[killMe] in(1000)[killMe]
} }
} }
def cleanBeforeExit(){ def cleanBeforeExit() {
cancel(move, true) cancel(move, true)
exited = true exited = true
destroyed = true destroyed = true

View File

@ -21,10 +21,10 @@ import java.util.UUID
agent LaunchingArea { agent LaunchingArea {
uses DefaultContextInteractions, Lifecycle, Behaviors, Logging, InnerContextAccess uses DefaultContextInteractions, Lifecycle, Behaviors, Logging, InnerContextAccess
var rocketsQuantity: Integer var rocketsQuantity : Integer
var fireQuantity: Integer var fireQuantity : Integer
var gravity: Double var gravity : Double
var grid: Positions = new Positions var grid : Positions = new Positions
var maxWidth = 10.0 var maxWidth = 10.0
var exited = false var exited = false
@ -35,7 +35,7 @@ agent LaunchingArea {
this.maxWidth = occurrence.maxWidth this.maxWidth = occurrence.maxWidth
} }
on Exit [!hasMemberAgent]{ on Exit [!hasMemberAgent] {
killMe killMe
} }
@ -44,7 +44,7 @@ agent LaunchingArea {
innerContext.defaultSpace.emit(new Exit) innerContext.defaultSpace.emit(new Exit)
} }
on Initialize [ occurrence.parameters.empty ] { on Initialize [occurrence.parameters.empty] {
rocketsQuantity = 20 rocketsQuantity = 20
fireQuantity = 30 fireQuantity = 30
gravity = 0.5 gravity = 0.5
@ -53,7 +53,7 @@ agent LaunchingArea {
} }
on Initialize [ !occurrence.parameters.empty ]{ on Initialize [!occurrence.parameters.empty] {
var ctrl = occurrence.parameters.get(0) as FXMLViewerController var ctrl = occurrence.parameters.get(0) as FXMLViewerController
var ^space = defaultContext.createSpace(OpenEventSpaceSpecification, UUID.randomUUID) var ^space = defaultContext.createSpace(OpenEventSpaceSpecification, UUID.randomUUID)
ctrl.setGUISpace(^space) ctrl.setGUISpace(^space)
@ -66,21 +66,21 @@ agent LaunchingArea {
} }
on CreateArea { on CreateArea {
var x: Double var x : Double
var i=0 var i = 0
var rnd = new Random() var rnd = new Random()
while (i<rocketsQuantity){ while (i < rocketsQuantity) {
x = rnd.nextDouble() * maxWidth x = rnd.nextDouble() * maxWidth
spawnInContext(RocketLauncher, getInnerContext, x, 0.0, fireQuantity, gravity, grid) spawnInContext(RocketLauncher, getInnerContext, x, 0.0, fireQuantity, gravity, grid)
i++; i++;
} }
} }
on Freeze[!isFromMe(occurrence)] { on Freeze [!isFromMe(occurrence)] {
innerContext.defaultSpace.emit(occurrence) innerContext.defaultSpace.emit(occurrence)
} }
on MemberJoined [ occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity]{ on MemberJoined [occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity] {
info("Area Ready") info("Area Ready")
innerContext.defaultSpace.emit(new Launch) innerContext.defaultSpace.emit(new Launch)
} }

View File

@ -23,6 +23,7 @@ import java.util.Vector
agent Rocket { agent Rocket {
uses Lifecycle, Logging, Schedules, Behaviors, DefaultContextInteractions, InnerContextAccess uses Lifecycle, Logging, Schedules, Behaviors, DefaultContextInteractions, InnerContextAccess
var x : Double var x : Double
var y : Double var y : Double
var gravity : Double var gravity : Double
@ -33,16 +34,16 @@ agent Rocket {
var frozen = false var frozen = false
var exploded = false var exploded = false
var exited = false var exited = false
var grid: Positions var grid : Positions
var id: UUID var id : UUID
var move: AgentTask var move : AgentTask
on Exit [!hasMemberAgent]{ on Exit [!hasMemberAgent] {
emit(new Exit) emit(new Exit)
killMe killMe
} }
on Exit [hasMemberAgent && !exited]{ on Exit [hasMemberAgent && !exited] {
exploded = true exploded = true
frozen = true frozen = true
exited = true exited = true
@ -62,7 +63,7 @@ agent Rocket {
on Initialize { on Initialize {
info("New rocket launched") info("New rocket launched")
var rnd = new Random() var rnd = new Random()
if (occurrence.parameters.size.equals(7)){ if (occurrence.parameters.size.equals(7)) {
x = occurrence.parameters.get(0) as Double x = occurrence.parameters.get(0) as Double
y = occurrence.parameters.get(1) as Double y = occurrence.parameters.get(1) as Double
speedx = occurrence.parameters.get(2) as Double speedx = occurrence.parameters.get(2) as Double
@ -76,9 +77,13 @@ agent Rocket {
lifetime = rnd.nextInt(5) * 300 + 300 lifetime = rnd.nextInt(5) * 300 + 300
id = UUID.randomUUID id = UUID.randomUUID
move = atFixedDelay(30)[try{ move = atFixedDelay(30) [
wake(new UpdateRocketPosition);} try {
catch(e: Exception) {e.printStackTrace}] wake(new UpdateRocketPosition);
} catch (e : Exception) {
e.printStackTrace
}
]
} }
on UpdateRocketPosition [isFromMe(occurrence) && !frozen && !exploded] { on UpdateRocketPosition [isFromMe(occurrence) && !frozen && !exploded] {
@ -89,9 +94,9 @@ agent Rocket {
vect.add(x) vect.add(x)
vect.add(y) vect.add(y)
lifetime = lifetime - 10 lifetime = lifetime - 10
if (grid!==null) if (grid !== null)
grid.setRocketPosition(id, vect) grid.setRocketPosition(id, vect)
if (lifetime <= 0){ if (lifetime <= 0) {
exploded = true exploded = true
cancel(move, true) cancel(move, true)
grid.hideHocketPosition(id) grid.hideHocketPosition(id)
@ -100,20 +105,20 @@ agent Rocket {
} }
on Explode { on Explode {
for (var i=0; i < fireQuantity; i++){ for (var i = 0; i < fireQuantity; i++) {
spawnInContext(Fire, innerContext, x, y, grid, id) spawnInContext(Fire, innerContext, x, y, grid, id)
} }
// emit(new Launch) // emit(new Launch)
} }
on MemberLeft [!isFromMe(occurrence) && !frozen && !hasMemberAgent] { on MemberLeft [!isFromMe(occurrence) && !frozen && !hasMemberAgent] {
exited = true exited = true
grid.removeRocketPosition(id) grid.removeRocketPosition(id)
// emit(new Launch) // emit(new Launch)
killMe killMe
} }
on MemberJoined [!isFromMe(occurrence) && hasMemberAgent && memberAgentCount == fireQuantity]{ on MemberJoined [!isFromMe(occurrence) && hasMemberAgent && memberAgentCount == fireQuantity] {
innerContext.defaultSpace.emit(new FireReady) innerContext.defaultSpace.emit(new FireReady)
} }

View File

@ -17,11 +17,11 @@ agent RocketLauncher {
uses Logging, Behaviors, DefaultContextInteractions, InnerContextAccess, Lifecycle uses Logging, Behaviors, DefaultContextInteractions, InnerContextAccess, Lifecycle
var x: Double var x : Double
var y: Double var y : Double
var fireQuantity : Integer var fireQuantity : Integer
var gravity : Double var gravity : Double
var grid: Positions var grid : Positions
var exited = false var exited = false
on Exit [!hasMemberAgent] { on Exit [!hasMemberAgent] {
@ -44,7 +44,7 @@ agent RocketLauncher {
info("New rocket launcher created") info("New rocket launcher created")
} }
on Initialize [occurrence.parameters.empty]{ on Initialize [occurrence.parameters.empty] {
x = 0.0 x = 0.0
y = 0.0 y = 0.0
fireQuantity = 30 fireQuantity = 30
@ -61,11 +61,11 @@ agent RocketLauncher {
spawnInContext(Rocket, getInnerContext, x, y, vx, vy, gravity, fireQuantity, grid) spawnInContext(Rocket, getInnerContext, x, y, vx, vy, gravity, fireQuantity, grid)
} }
on Freeze[!isFromMe(occurrence)] { on Freeze [!isFromMe(occurrence)] {
innerContext.defaultSpace.emit(occurrence) innerContext.defaultSpace.emit(occurrence)
} }
on MemberLeft [!isFromMe(occurrence) && !exited]{ on MemberLeft [!isFromMe(occurrence) && !exited] {
wake(new Launch) wake(new Launch)
} }

View File

@ -36,7 +36,6 @@ event SetupSettings {
} }
} }
event Freeze { event Freeze {
var value : boolean var value : boolean
@ -44,6 +43,3 @@ event Freeze {
this.value = value this.value = value
} }
} }

View File

@ -23,29 +23,26 @@ import javafx.util.Duration
class FXMLViewerController implements EventListener { class FXMLViewerController implements EventListener {
private var ispace : OpenEventSpace;
private val id : UUID = UUID.randomUUID(); private val id : UUID = UUID.randomUUID();
private var ispace : OpenEventSpace;
private var launched : boolean = false; private var launched : boolean = false;
private var areaCreated : boolean = false; private var areaCreated : boolean = false;
@FXML @FXML
private var draw_zone : Canvas; private var draw_zone : Canvas;
@FXML @FXML
private var gravity_display : Label; private var gravity_display : Label;
@FXML @FXML
private var rocket_quantity_display : Label; private var rocket_quantity_display : Label;
@FXML @FXML
private var fire_quantity_display : Label; private var fire_quantity_display : Label;
@FXML @FXML
private var gravity_input : ScrollBar; private var gravity_input : ScrollBar;
@FXML @FXML
private var rocket_quantity_input : ScrollBar; private var rocket_quantity_input : ScrollBar;
@FXML @FXML
private var fire_quantity_input : ScrollBar; private var fire_quantity_input : ScrollBar;
@FXML @FXML
private var setup_button : Button; private var setup_button : Button;
@FXML @FXML