mirror of
				https://github.com/klmp200/sarl-fireworks.git
				synced 2025-10-31 17:13:11 +00:00 
			
		
		
		
	reformatting all classes
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							| @@ -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) | ||||
| 	} | ||||
|   | ||||
| @@ -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,7 +26,7 @@ class FireworksFXApplication extends Application { | ||||
| 		stage.show(); | ||||
| 	} | ||||
|  | ||||
| 	public static def main(args: String[]) { | ||||
| 	public static def main(args : String[]) { | ||||
| 		launch(args); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -8,54 +8,54 @@ import java.util.Vector | ||||
| import javafx.scene.paint.Color | ||||
|  | ||||
| class RocketsPos { | ||||
| 		public val ROCKETREFRESHDELAY = 100 | ||||
| 		var position = new Vector<Double>() | ||||
| 		var color: Color | ||||
| 		var hidden = false | ||||
| 	public val ROCKETREFRESHDELAY = 100 | ||||
| 	var position = new Vector<Double>() | ||||
| 	var color : Color | ||||
| 	var hidden = false | ||||
|  | ||||
| 		public def getPosition(){ | ||||
| 			return position | ||||
| 		} | ||||
| 	public def getPosition() { | ||||
| 		return position | ||||
| 	} | ||||
|  | ||||
| 		public def setPosition(position: Vector<Double>){ | ||||
| 			this.position = position | ||||
| 		} | ||||
| 	public def setPosition(position : Vector<Double>) { | ||||
| 		this.position = position | ||||
| 	} | ||||
|  | ||||
| 		public def getColor(){ | ||||
| 			return color | ||||
| 		} | ||||
| 	public def getColor() { | ||||
| 		return color | ||||
| 	} | ||||
|  | ||||
| 		public def setColor(color: Color){ | ||||
| 			this.color = color | ||||
| 		} | ||||
| 	public def setColor(color : Color) { | ||||
| 		this.color = color | ||||
| 	} | ||||
|  | ||||
| 		public def setHidden(hidden: boolean){ | ||||
| 			this.hidden = hidden | ||||
| 		} | ||||
| 	public def setHidden(hidden : boolean) { | ||||
| 		this.hidden = hidden | ||||
| 	} | ||||
|  | ||||
| 		public def getHidden(){ | ||||
| 			return this.hidden | ||||
| 		} | ||||
| 	public def getHidden() { | ||||
| 		return this.hidden | ||||
| 	} | ||||
| } | ||||
|  | ||||
| class FirePos { | ||||
| 	public val FIREREFRESHDELAY = 100 | ||||
| 	var positions: List<Vector<Double>> | ||||
| 	var color: Color | ||||
| 	var positions : List<Vector<Double>> | ||||
| 	var color : Color | ||||
|  | ||||
| 	public def getPositions(){ | ||||
| 	public def getPositions() { | ||||
| 		return positions | ||||
| 	} | ||||
|  | ||||
| 	public def setPositions(positions: List<Vector<Double>>){ | ||||
| 	public def setPositions(positions : List<Vector<Double>>) { | ||||
| 		this.positions = positions | ||||
| 	} | ||||
|  | ||||
| 	public def getColor(){ | ||||
| 	public def getColor() { | ||||
| 		return color | ||||
| 	} | ||||
|  | ||||
| 	public def setColor(color: Color){ | ||||
| 	public def setColor(color : Color) { | ||||
| 		this.color = color | ||||
| 	} | ||||
| } | ||||
| @@ -64,7 +64,6 @@ class Positions { | ||||
| 	var rockets = new HashMap<UUID, RocketsPos>() | ||||
| 	var fire = new HashMap<UUID, FirePos>() | ||||
|  | ||||
| 	 | ||||
| 	public def getRockets() : Map<UUID, RocketsPos> { | ||||
| 		return rockets.unmodifiableView | ||||
| 	} | ||||
| @@ -73,10 +72,10 @@ class Positions { | ||||
| 		return fire.unmodifiableView | ||||
| 	} | ||||
|  | ||||
| 	public def setRocketPosition(id: UUID, position: Vector<Double>){ | ||||
| 	public def setRocketPosition(id : UUID, position : Vector<Double>) { | ||||
| 		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 { | ||||
| @@ -85,18 +84,18 @@ class Positions { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	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<Vector<Double>>){ | ||||
| 	public def setFirePosition(id : UUID, rocketID : UUID, positions : List<Vector<Double>>) { | ||||
| 		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 { | ||||
| @@ -108,9 +107,8 @@ class Positions { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	public def removeFirePosition(id: UUID){ | ||||
| 	public def removeFirePosition(id : UUID) { | ||||
| 		fire.remove(id) | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -21,19 +21,19 @@ import java.util.Vector | ||||
| agent Fire { | ||||
| 	uses Lifecycle, Logging, Behaviors, DefaultContextInteractions, Schedules | ||||
|  | ||||
| 	var x: List<Double> | ||||
| 	var y: List<Double> | ||||
| 	var x : List<Double> | ||||
| 	var y : List<Double> | ||||
| 	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 | ||||
| @@ -46,7 +46,7 @@ agent Fire { | ||||
| 	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 | ||||
| @@ -59,46 +59,53 @@ agent Fire { | ||||
| 		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<Vector<Double>> | ||||
| 			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 | ||||
|   | ||||
| @@ -21,10 +21,10 @@ 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 | ||||
|  | ||||
| @@ -35,7 +35,7 @@ agent LaunchingArea { | ||||
| 		this.maxWidth = occurrence.maxWidth | ||||
| 	} | ||||
|  | ||||
| 	on Exit [!hasMemberAgent]{ | ||||
| 	on Exit [!hasMemberAgent] { | ||||
| 		killMe | ||||
| 	} | ||||
|  | ||||
| @@ -44,7 +44,7 @@ agent LaunchingArea { | ||||
| 		innerContext.defaultSpace.emit(new Exit) | ||||
| 	} | ||||
|  | ||||
| 	on Initialize [ occurrence.parameters.empty ] { | ||||
| 	on Initialize [occurrence.parameters.empty] { | ||||
| 		rocketsQuantity = 20 | ||||
| 		fireQuantity = 30 | ||||
| 		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 ^space = defaultContext.createSpace(OpenEventSpaceSpecification, UUID.randomUUID) | ||||
| 		ctrl.setGUISpace(^space) | ||||
| @@ -66,21 +66,21 @@ agent LaunchingArea { | ||||
| 	} | ||||
|  | ||||
| 	on CreateArea { | ||||
| 		var x: Double | ||||
| 		var i=0 | ||||
| 		var x : Double | ||||
| 		var i = 0 | ||||
| 		var rnd = new Random() | ||||
| 		while (i<rocketsQuantity){ | ||||
| 		while (i < rocketsQuantity) { | ||||
| 			x = rnd.nextDouble() * maxWidth | ||||
| 			spawnInContext(RocketLauncher, getInnerContext, x, 0.0, fireQuantity, gravity, grid) | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	on Freeze[!isFromMe(occurrence)] { | ||||
| 	on Freeze [!isFromMe(occurrence)] { | ||||
| 		innerContext.defaultSpace.emit(occurrence) | ||||
| 	} | ||||
|  | ||||
| 	on MemberJoined [ occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity]{ | ||||
| 	on MemberJoined [occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity] { | ||||
| 		info("Area Ready") | ||||
| 		innerContext.defaultSpace.emit(new Launch) | ||||
| 	} | ||||
|   | ||||
| @@ -23,6 +23,7 @@ import java.util.Vector | ||||
| agent Rocket { | ||||
|  | ||||
| 	uses Lifecycle, Logging, Schedules, Behaviors, DefaultContextInteractions, InnerContextAccess | ||||
|  | ||||
| 	var x : Double | ||||
| 	var y : Double | ||||
| 	var gravity : Double | ||||
| @@ -33,16 +34,16 @@ agent Rocket { | ||||
| 	var frozen = false | ||||
| 	var exploded = false | ||||
| 	var exited = false | ||||
| 	var grid: Positions | ||||
| 	var id: UUID | ||||
| 	var move: AgentTask | ||||
| 	var grid : Positions | ||||
| 	var id : UUID | ||||
| 	var move : AgentTask | ||||
|  | ||||
| 	on Exit [!hasMemberAgent]{ | ||||
| 	on Exit [!hasMemberAgent] { | ||||
| 		emit(new Exit) | ||||
| 		killMe | ||||
| 	} | ||||
|  | ||||
| 	on Exit [hasMemberAgent && !exited]{ | ||||
| 	on Exit [hasMemberAgent && !exited] { | ||||
| 		exploded = true | ||||
| 		frozen = true | ||||
| 		exited = true | ||||
| @@ -62,7 +63,7 @@ agent Rocket { | ||||
| 	on Initialize { | ||||
| 		info("New rocket launched") | ||||
| 		var rnd = new Random() | ||||
| 		if (occurrence.parameters.size.equals(7)){ | ||||
| 		if (occurrence.parameters.size.equals(7)) { | ||||
| 			x = occurrence.parameters.get(0) as Double | ||||
| 			y = occurrence.parameters.get(1) as Double | ||||
| 			speedx = occurrence.parameters.get(2) as Double | ||||
| @@ -76,9 +77,13 @@ agent Rocket { | ||||
| 		lifetime = rnd.nextInt(5) * 300 + 300 | ||||
| 		id = UUID.randomUUID | ||||
|  | ||||
| 		move = atFixedDelay(30)[try{  | ||||
| 			wake(new UpdateRocketPosition);} | ||||
| 			catch(e: Exception) {e.printStackTrace}] | ||||
| 		move = atFixedDelay(30) [ | ||||
| 			try { | ||||
| 				wake(new UpdateRocketPosition); | ||||
| 			} catch (e : Exception) { | ||||
| 				e.printStackTrace | ||||
| 			} | ||||
| 		] | ||||
| 	} | ||||
|  | ||||
| 	on UpdateRocketPosition [isFromMe(occurrence) && !frozen && !exploded] { | ||||
| @@ -89,9 +94,9 @@ agent Rocket { | ||||
| 		vect.add(x) | ||||
| 		vect.add(y) | ||||
| 		lifetime = lifetime - 10 | ||||
| 		if (grid!==null) | ||||
| 		if (grid !== null) | ||||
| 			grid.setRocketPosition(id, vect) | ||||
| 		if (lifetime <= 0){ | ||||
| 		if (lifetime <= 0) { | ||||
| 			exploded = true | ||||
| 			cancel(move, true) | ||||
| 			grid.hideHocketPosition(id) | ||||
| @@ -100,20 +105,20 @@ agent Rocket { | ||||
| 	} | ||||
|  | ||||
| 	on Explode { | ||||
| 		for (var i=0; i < fireQuantity; i++){ | ||||
| 		for (var i = 0; i < fireQuantity; i++) { | ||||
| 			spawnInContext(Fire, innerContext, x, y, grid, id) | ||||
| 		} | ||||
| //		emit(new Launch) | ||||
| 		// emit(new Launch) | ||||
| 	} | ||||
|  | ||||
| 	on MemberLeft [!isFromMe(occurrence) && !frozen && !hasMemberAgent] { | ||||
| 		exited = true | ||||
| 		grid.removeRocketPosition(id) | ||||
| //		emit(new Launch) | ||||
| 		// emit(new Launch) | ||||
| 		killMe | ||||
| 	} | ||||
|  | ||||
| 	on MemberJoined [!isFromMe(occurrence) && hasMemberAgent && memberAgentCount == fireQuantity]{ | ||||
| 	on MemberJoined [!isFromMe(occurrence) && hasMemberAgent && memberAgentCount == fireQuantity] { | ||||
| 		innerContext.defaultSpace.emit(new FireReady) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -17,11 +17,11 @@ agent RocketLauncher { | ||||
|  | ||||
| 	uses Logging, Behaviors, DefaultContextInteractions, InnerContextAccess, Lifecycle | ||||
|  | ||||
| 	var x: Double | ||||
| 	var y: Double | ||||
| 	var x : Double | ||||
| 	var y : Double | ||||
| 	var fireQuantity : Integer | ||||
| 	var gravity : Double | ||||
| 	var grid: Positions | ||||
| 	var grid : Positions | ||||
| 	var exited = false | ||||
|  | ||||
| 	on Exit [!hasMemberAgent] { | ||||
| @@ -44,7 +44,7 @@ agent RocketLauncher { | ||||
| 		info("New rocket launcher created") | ||||
| 	} | ||||
|  | ||||
| 	on Initialize [occurrence.parameters.empty]{ | ||||
| 	on Initialize [occurrence.parameters.empty] { | ||||
| 		x = 0.0 | ||||
| 		y = 0.0 | ||||
| 		fireQuantity = 30 | ||||
| @@ -61,11 +61,11 @@ agent RocketLauncher { | ||||
| 		spawnInContext(Rocket, getInnerContext, x, y, vx, vy, gravity, fireQuantity, grid) | ||||
| 	} | ||||
|  | ||||
| 	on Freeze[!isFromMe(occurrence)] { | ||||
| 	on Freeze [!isFromMe(occurrence)] { | ||||
| 		innerContext.defaultSpace.emit(occurrence) | ||||
| 	} | ||||
|  | ||||
| 	on MemberLeft [!isFromMe(occurrence) && !exited]{ | ||||
| 	on MemberLeft [!isFromMe(occurrence) && !exited] { | ||||
| 		wake(new Launch) | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -36,7 +36,6 @@ event SetupSettings { | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| event Freeze { | ||||
| 	var value : boolean | ||||
|  | ||||
| @@ -44,6 +43,3 @@ event Freeze { | ||||
| 		this.value = value | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -23,29 +23,26 @@ import javafx.util.Duration | ||||
|  | ||||
| class FXMLViewerController implements EventListener { | ||||
|  | ||||
| 	private var ispace : OpenEventSpace; | ||||
| 	private val id : UUID = UUID.randomUUID(); | ||||
|  | ||||
| 	private var ispace : OpenEventSpace; | ||||
| 	private var launched : boolean = false; | ||||
| 	private var areaCreated : boolean = false; | ||||
|  | ||||
| 	@FXML | ||||
| 	private var draw_zone : Canvas; | ||||
|  | ||||
| 	@FXML | ||||
| 	private var gravity_display : Label; | ||||
| 	@FXML | ||||
| 	private var rocket_quantity_display : Label; | ||||
| 	@FXML | ||||
| 	private var fire_quantity_display : Label; | ||||
|  | ||||
| 	@FXML | ||||
| 	private var gravity_input : ScrollBar; | ||||
| 	@FXML | ||||
| 	private var rocket_quantity_input : ScrollBar; | ||||
| 	@FXML | ||||
| 	private var fire_quantity_input : ScrollBar; | ||||
|  | ||||
| 	@FXML | ||||
| 	private var setup_button : Button; | ||||
| 	@FXML | ||||
|   | ||||
		Reference in New Issue
	
	Block a user