126 lines
2.5 KiB
Plaintext
126 lines
2.5 KiB
Plaintext
package io.sarl.demos.fireworks
|
|
|
|
import java.util.HashMap
|
|
import java.util.List
|
|
import java.util.Map
|
|
import java.util.UUID
|
|
import java.util.Vector
|
|
import javafx.scene.paint.Color
|
|
|
|
/*
|
|
* Data structure used to represent a rocket position
|
|
*/
|
|
class RocketsPos {
|
|
public val ROCKETREFRESHDELAY = 100
|
|
|
|
var position = new Vector<Double>()
|
|
var color : Color
|
|
var hidden = false
|
|
|
|
public def getPosition() {
|
|
return position
|
|
}
|
|
|
|
public def setPosition(position : Vector<Double>) {
|
|
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
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Data structure used to represent a fire position
|
|
*/
|
|
class FirePos {
|
|
public val FIREREFRESHDELAY = 100
|
|
var positions : List<Vector<Double>>
|
|
var color : Color
|
|
|
|
public def getPositions() {
|
|
return positions
|
|
}
|
|
|
|
public def setPositions(positions : List<Vector<Double>>) {
|
|
this.positions = positions
|
|
}
|
|
|
|
public def getColor() {
|
|
return color
|
|
}
|
|
|
|
public def setColor(color : Color) {
|
|
this.color = color
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Data structure referencing every position of every fire and rocket existing
|
|
* This object is read by the GUI for display
|
|
*/
|
|
class Positions {
|
|
var rockets = new HashMap<UUID, RocketsPos>()
|
|
var fire = new HashMap<UUID, FirePos>()
|
|
|
|
public def getRockets() : Map<UUID, RocketsPos> {
|
|
return rockets.unmodifiableView
|
|
}
|
|
|
|
public def getFire() : Map<UUID, FirePos> {
|
|
return fire.unmodifiableView
|
|
}
|
|
|
|
public def setRocketPosition(id : UUID, position : Vector<Double>) {
|
|
var pos = new RocketsPos()
|
|
pos.setPosition(position)
|
|
if (rockets.containsKey(id)) {
|
|
pos.setColor(rockets.get(id).getColor)
|
|
rockets.replace(id, pos)
|
|
} else {
|
|
pos.setColor(Color.color(Math.random(), Math.random(), Math.random()))
|
|
rockets.put(id, pos)
|
|
}
|
|
}
|
|
|
|
public def removeRocketPosition(id : UUID) {
|
|
rockets.remove(id)
|
|
}
|
|
|
|
public def hideHocketPosition(id : UUID) {
|
|
rockets.get(id).setHidden(true)
|
|
}
|
|
|
|
public def setFirePosition(id : UUID, rocketID : UUID, positions : List<Vector<Double>>) {
|
|
var pos = new FirePos()
|
|
pos.setPositions(positions)
|
|
if (fire.containsKey(id)) {
|
|
pos.setColor(fire.get(id).getColor)
|
|
fire.replace(id, pos)
|
|
} else {
|
|
if (this.rockets.containsKey(rocketID))
|
|
pos.setColor(this.rockets.get(rocketID).getColor)
|
|
else
|
|
pos.setColor(Color.color(Math.random(), Math.random(), Math.random()))
|
|
fire.put(id, pos)
|
|
}
|
|
}
|
|
|
|
public def removeFirePosition(id : UUID) {
|
|
fire.remove(id)
|
|
}
|
|
|
|
}
|