Added a builder for elements and made the buttons and damage bursts reflect the elemental color
This commit is contained in:
@@ -97,7 +97,7 @@ class BattleUI extends SignalConsumer {
|
||||
numPlaying += 1
|
||||
def helper = {
|
||||
val r = 25
|
||||
val color = Color.AliceBlue
|
||||
val color = element.bgColor
|
||||
val center = findCenter(target)
|
||||
|
||||
val circle = new Circle {
|
||||
|
||||
@@ -5,6 +5,7 @@ import javafx.scene.{control => jfxsc}
|
||||
|
||||
import scalafx.Includes._
|
||||
import scalafx.scene.control._
|
||||
import scalafx.scene.paint.Color
|
||||
|
||||
import fmon.stat.Move
|
||||
|
||||
@@ -19,10 +20,16 @@ class MoveButton {
|
||||
move = mv
|
||||
moveName.text = mv.name
|
||||
moveUses.text = s"${move.pp}/${move.pp}"
|
||||
moveBtn.style = s"-fx-background-color: ${colorString(mv.element.bgColor)}; -fx-text-fill: ${colorString(mv.element.fontColor)}"
|
||||
this.callback = callback
|
||||
}
|
||||
|
||||
def moveActivate(): Unit = {
|
||||
callback(move)
|
||||
}
|
||||
|
||||
def colorString(color: Color): String = {
|
||||
val s = color.toString()
|
||||
s"#${s.split("x")(1)}"
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,15 @@ package fmon.stat
|
||||
|
||||
import scala.io.Source
|
||||
|
||||
import scalafx.scene.paint.Color
|
||||
|
||||
import fmon.util.YamlHelper
|
||||
|
||||
case class Element(val name : String, val effect : Map[String, Double]) {
|
||||
case class Element(val name : String, val bgColor: Color, val fontColor: Color, val effect : Map[String, Double]) {
|
||||
|
||||
def -->(other : Element) = {
|
||||
effect.getOrElse(other.name, 1.0)
|
||||
}
|
||||
def -->(other : Element) = other <-- this
|
||||
|
||||
def <--(other : Element) = other --> this
|
||||
def <--(other : Element) = effect.getOrElse(other.name, 1.0)
|
||||
|
||||
override def toString = name
|
||||
}
|
||||
|
||||
@@ -1,174 +1,523 @@
|
||||
Bug:
|
||||
effect:
|
||||
Dark: 2.0
|
||||
Fairy: 0.5
|
||||
Fighting: 0.5
|
||||
Fire: 0.5
|
||||
Flying: 0.5
|
||||
Ghost: 0.5
|
||||
Grass: 2.0
|
||||
Poison: 0.5
|
||||
Psychic: 2.0
|
||||
Steel: 0.5
|
||||
name: Bug
|
||||
Dark:
|
||||
effect:
|
||||
Dark: 0.5
|
||||
Fairy: 0.5
|
||||
Fighting: 0.5
|
||||
Ghost: 2.0
|
||||
Psychic: 2.0
|
||||
name: Dark
|
||||
Dragon:
|
||||
effect:
|
||||
Dragon: 2.0
|
||||
Fairy: 0.0
|
||||
Steel: 0.5
|
||||
name: Dragon
|
||||
Electric:
|
||||
effect:
|
||||
Dragon: 0.5
|
||||
Electric: 0.5
|
||||
Flying: 2.0
|
||||
Grass: 0.5
|
||||
Ground: 0.0
|
||||
Water: 2.0
|
||||
name: Electric
|
||||
Fairy:
|
||||
effect:
|
||||
Dark: 2.0
|
||||
Dragon: 2.0
|
||||
Fighting: 2.0
|
||||
Fire: 0.5
|
||||
Poison: 0.5
|
||||
Steel: 0.5
|
||||
name: Fairy
|
||||
Fighting:
|
||||
effect:
|
||||
Bug: 0.5
|
||||
Dark: 2.0
|
||||
Fairy: 0.5
|
||||
Flying: 0.5
|
||||
Ghost: 0.0
|
||||
Ice: 2.0
|
||||
Normal: 2.0
|
||||
Poison: 0.5
|
||||
Psychic: 0.5
|
||||
Rock: 2.0
|
||||
Steel: 2.0
|
||||
name: Fighting
|
||||
Fire:
|
||||
effect:
|
||||
Bug: 2.0
|
||||
Dragon: 0.5
|
||||
Fire: 0.5
|
||||
Grass: 2.0
|
||||
Ice: 2.0
|
||||
Rock: 0.5
|
||||
Steel: 2.0
|
||||
Water: 0.5
|
||||
name: Fire
|
||||
Flying:
|
||||
effect:
|
||||
Bug: 2.0
|
||||
Electric: 0.5
|
||||
Fighting: 2.0
|
||||
Grass: 2.0
|
||||
Rock: 0.5
|
||||
Steel: 0.5
|
||||
name: Flying
|
||||
Ghost:
|
||||
effect:
|
||||
Dark: 0.5
|
||||
Ghost: 2.0
|
||||
Normal: 0.0
|
||||
Psychic: 2.0
|
||||
name: Ghost
|
||||
Grass:
|
||||
effect:
|
||||
Bug: 0.5
|
||||
Dragon: 0.5
|
||||
Fire: 0.5
|
||||
Flying: 0.5
|
||||
Grass: 0.5
|
||||
Ground: 2.0
|
||||
Poison: 0.5
|
||||
Rock: 2.0
|
||||
Steel: 0.5
|
||||
Water: 2.0
|
||||
name: Grass
|
||||
Ground:
|
||||
effect:
|
||||
Bug: 0.5
|
||||
Electric: 2.0
|
||||
Fire: 2.0
|
||||
Flying: 0.0
|
||||
Grass: 0.5
|
||||
Poison: 2.0
|
||||
Rock: 2.0
|
||||
Steel: 2.0
|
||||
name: Ground
|
||||
Ice:
|
||||
effect:
|
||||
Dragon: 2.0
|
||||
Fire: 0.5
|
||||
Flying: 2.0
|
||||
Grass: 2.0
|
||||
Ground: 2.0
|
||||
Ice: 0.5
|
||||
Steel: 0.5
|
||||
Water: 0.5
|
||||
name: Ice
|
||||
---
|
||||
Normal:
|
||||
name: "Normal"
|
||||
bgColor:
|
||||
red: 0.501960813999176
|
||||
green: 0.501960813999176
|
||||
blue: 0.501960813999176
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 0.0
|
||||
Rock: 0.5
|
||||
Steel: 0.5
|
||||
name: Normal
|
||||
Poison:
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 2.0
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 1.0
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 1.0
|
||||
Dark: 1.0
|
||||
Electric:
|
||||
name: "Electric"
|
||||
bgColor:
|
||||
red: 0.9019607901573181
|
||||
green: 0.9019607901573181
|
||||
blue: 0.3019607961177826
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Fairy: 2.0
|
||||
Ghost: 0.5
|
||||
Normal: 1.0
|
||||
Electric: 0.5
|
||||
Poison: 1.0
|
||||
Rock: 1.0
|
||||
Flying: 0.5
|
||||
Ghost: 1.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 1.0
|
||||
Ground: 2.0
|
||||
Steel: 0.5
|
||||
Bug: 1.0
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 1.0
|
||||
Dark: 1.0
|
||||
Poison:
|
||||
name: "Poison"
|
||||
bgColor:
|
||||
red: 0.6000000238418579
|
||||
green: 0.4000000059604645
|
||||
blue: 0.6000000238418579
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 0.5
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 0.5
|
||||
Ground: 2.0
|
||||
Steel: 1.0
|
||||
Bug: 0.5
|
||||
Fire: 1.0
|
||||
Fairy: 0.5
|
||||
Dragon: 1.0
|
||||
Psychic: 2.0
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Rock:
|
||||
name: "Rock"
|
||||
bgColor:
|
||||
red: 0.6000000238418579
|
||||
green: 0.4000000059604645
|
||||
blue: 0.0
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 0.5
|
||||
Electric: 1.0
|
||||
Poison: 0.5
|
||||
Rock: 1.0
|
||||
Flying: 0.5
|
||||
Ghost: 1.0
|
||||
Ice: 1.0
|
||||
Water: 2.0
|
||||
Fighting: 2.0
|
||||
Ground: 2.0
|
||||
Steel: 2.0
|
||||
Bug: 1.0
|
||||
Fire: 0.5
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 2.0
|
||||
Ground: 0.5
|
||||
Dark: 1.0
|
||||
Flying:
|
||||
name: "Flying"
|
||||
bgColor:
|
||||
red: 0.7019608020782471
|
||||
green: 0.6000000238418579
|
||||
blue: 1.0
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 2.0
|
||||
Poison: 1.0
|
||||
Rock: 2.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 2.0
|
||||
Water: 1.0
|
||||
Fighting: 0.5
|
||||
Ground: 0.0
|
||||
Steel: 1.0
|
||||
Bug: 0.5
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Ghost:
|
||||
name: "Ghost"
|
||||
bgColor:
|
||||
red: 0.501960813999176
|
||||
green: 0.3019607961177826
|
||||
blue: 0.501960813999176
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 0.0
|
||||
Electric: 1.0
|
||||
Poison: 0.5
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 2.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 0.0
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 0.5
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 1.0
|
||||
Dark: 2.0
|
||||
Ice:
|
||||
name: "Ice"
|
||||
bgColor:
|
||||
red: 0.7019608020782471
|
||||
green: 0.9019607901573181
|
||||
blue: 0.9019607901573181
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 2.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 0.5
|
||||
Water: 1.0
|
||||
Fighting: 2.0
|
||||
Ground: 1.0
|
||||
Steel: 2.0
|
||||
Bug: 1.0
|
||||
Fire: 2.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 1.0
|
||||
Dark: 1.0
|
||||
Water:
|
||||
name: "Water"
|
||||
bgColor:
|
||||
red: 0.501960813999176
|
||||
green: 0.6000000238418579
|
||||
blue: 1.0
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 2.0
|
||||
Poison: 1.0
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 0.5
|
||||
Water: 0.5
|
||||
Fighting: 1.0
|
||||
Ground: 1.0
|
||||
Steel: 0.5
|
||||
Bug: 1.0
|
||||
Fire: 0.5
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 2.0
|
||||
Dark: 1.0
|
||||
Fighting:
|
||||
name: "Fighting"
|
||||
bgColor:
|
||||
red: 0.800000011920929
|
||||
green: 0.20000000298023224
|
||||
blue: 0.20000000298023224
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 0.5
|
||||
Flying: 2.0
|
||||
Ghost: 1.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 1.0
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 0.5
|
||||
Fire: 1.0
|
||||
Fairy: 2.0
|
||||
Dragon: 1.0
|
||||
Psychic: 2.0
|
||||
Grass: 1.0
|
||||
Dark: 0.5
|
||||
Ground:
|
||||
name: "Ground"
|
||||
bgColor:
|
||||
red: 0.9019607901573181
|
||||
green: 0.7019608020782471
|
||||
blue: 0.3019607961177826
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 0.0
|
||||
Poison: 0.5
|
||||
Rock: 0.5
|
||||
Steel: 0.0
|
||||
name: Poison
|
||||
Psychic:
|
||||
effect:
|
||||
Dark: 0.0
|
||||
Fighting: 2.0
|
||||
Poison: 2.0
|
||||
Psychic: 0.5
|
||||
Steel: 0.5
|
||||
name: Psychic
|
||||
Rock:
|
||||
effect:
|
||||
Bug: 2.0
|
||||
Fighting: 0.5
|
||||
Fire: 2.0
|
||||
Flying: 2.0
|
||||
Ground: 0.5
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 2.0
|
||||
Steel: 0.5
|
||||
name: Rock
|
||||
Water: 2.0
|
||||
Fighting: 1.0
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 1.0
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 2.0
|
||||
Dark: 1.0
|
||||
Steel:
|
||||
name: "Steel"
|
||||
bgColor:
|
||||
red: 0.800000011920929
|
||||
green: 0.800000011920929
|
||||
blue: 0.800000011920929
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Electric: 0.5
|
||||
Fairy: 2.0
|
||||
Fire: 0.5
|
||||
Ice: 2.0
|
||||
Rock: 2.0
|
||||
Steel: 0.5
|
||||
Water: 0.5
|
||||
name: Steel
|
||||
Water:
|
||||
effect:
|
||||
Dragon: 0.5
|
||||
Fire: 2.0
|
||||
Grass: 0.5
|
||||
Normal: 0.5
|
||||
Electric: 1.0
|
||||
Poison: 0.0
|
||||
Rock: 0.5
|
||||
Flying: 0.5
|
||||
Ghost: 1.0
|
||||
Ice: 0.5
|
||||
Water: 1.0
|
||||
Fighting: 2.0
|
||||
Ground: 2.0
|
||||
Steel: 0.5
|
||||
Bug: 0.5
|
||||
Fire: 2.0
|
||||
Fairy: 0.5
|
||||
Dragon: 0.5
|
||||
Psychic: 0.5
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Bug:
|
||||
name: "Bug"
|
||||
bgColor:
|
||||
red: 0.7019608020782471
|
||||
green: 0.9019607901573181
|
||||
blue: 0.7019608020782471
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 2.0
|
||||
Flying: 2.0
|
||||
Ghost: 1.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 0.5
|
||||
Ground: 0.5
|
||||
Steel: 1.0
|
||||
Bug: 1.0
|
||||
Fire: 2.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Fire:
|
||||
name: "Fire"
|
||||
bgColor:
|
||||
red: 0.9019607901573181
|
||||
green: 0.501960813999176
|
||||
blue: 0.3019607961177826
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 2.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 0.5
|
||||
Water: 2.0
|
||||
Fighting: 1.0
|
||||
Ground: 2.0
|
||||
Steel: 0.5
|
||||
Bug: 0.5
|
||||
Fire: 0.5
|
||||
Fairy: 0.5
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Fairy:
|
||||
name: "Fairy"
|
||||
bgColor:
|
||||
red: 0.9019607901573181
|
||||
green: 0.7019608020782471
|
||||
blue: 0.800000011920929
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 2.0
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 0.5
|
||||
Ground: 1.0
|
||||
Steel: 2.0
|
||||
Bug: 0.5
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 0.0
|
||||
Psychic: 1.0
|
||||
Grass: 1.0
|
||||
Dark: 0.5
|
||||
Dragon:
|
||||
name: "Dragon"
|
||||
bgColor:
|
||||
red: 0.4000000059604645
|
||||
green: 0.20000000298023224
|
||||
blue: 0.4000000059604645
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 0.5
|
||||
Poison: 1.0
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 1.0
|
||||
Ice: 2.0
|
||||
Water: 0.5
|
||||
name: Water
|
||||
Fighting: 1.0
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 1.0
|
||||
Fire: 0.5
|
||||
Fairy: 2.0
|
||||
Dragon: 2.0
|
||||
Psychic: 1.0
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Psychic:
|
||||
name: "Psychic"
|
||||
bgColor:
|
||||
red: 1.0
|
||||
green: 0.501960813999176
|
||||
blue: 0.501960813999176
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 2.0
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 0.5
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 2.0
|
||||
Fire: 1.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 0.5
|
||||
Grass: 1.0
|
||||
Dark: 2.0
|
||||
Grass:
|
||||
name: "Grass"
|
||||
bgColor:
|
||||
red: 0.6000000238418579
|
||||
green: 0.800000011920929
|
||||
blue: 0.6000000238418579
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 0.5
|
||||
Poison: 2.0
|
||||
Rock: 1.0
|
||||
Flying: 2.0
|
||||
Ghost: 1.0
|
||||
Ice: 2.0
|
||||
Water: 0.5
|
||||
Fighting: 1.0
|
||||
Ground: 0.5
|
||||
Steel: 1.0
|
||||
Bug: 2.0
|
||||
Fire: 2.0
|
||||
Fairy: 1.0
|
||||
Dragon: 1.0
|
||||
Psychic: 1.0
|
||||
Grass: 0.5
|
||||
Dark: 1.0
|
||||
Dark:
|
||||
name: "Dark"
|
||||
bgColor:
|
||||
red: 0.3019607961177826
|
||||
green: 0.3019607961177826
|
||||
blue: 0.3019607961177826
|
||||
fontColor:
|
||||
red: 0.0
|
||||
green: 0.0
|
||||
blue: 0.0
|
||||
effect:
|
||||
Normal: 1.0
|
||||
Electric: 1.0
|
||||
Poison: 1.0
|
||||
Rock: 1.0
|
||||
Flying: 1.0
|
||||
Ghost: 0.5
|
||||
Ice: 1.0
|
||||
Water: 1.0
|
||||
Fighting: 2.0
|
||||
Ground: 1.0
|
||||
Steel: 1.0
|
||||
Bug: 2.0
|
||||
Fire: 1.0
|
||||
Fairy: 2.0
|
||||
Dragon: 1.0
|
||||
Psychic: 0.0
|
||||
Grass: 1.0
|
||||
Dark: 0.5
|
||||
|
||||
@@ -1,20 +1,55 @@
|
||||
package fmon.util
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.core._
|
||||
import com.fasterxml.jackson.databind._
|
||||
import com.fasterxml.jackson.databind.ser._
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer
|
||||
import com.fasterxml.jackson.databind.deser._
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
|
||||
import com.fasterxml.jackson.module.scala.DefaultScalaModule
|
||||
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
|
||||
|
||||
import java.io.InputStream
|
||||
import scalafx.scene.paint.Color
|
||||
|
||||
import java.io.{InputStream, OutputStream}
|
||||
|
||||
import scala.io.Source
|
||||
|
||||
import fmon.util._
|
||||
|
||||
class ColorSerializer extends StdSerializer[Color](classOf[Color]) {
|
||||
override def serialize(color: Color, jgen: JsonGenerator, serializer: SerializerProvider): Unit = {
|
||||
jgen.writeStartObject()
|
||||
jgen.writeFieldName("red")
|
||||
jgen.writeNumber(color.red)
|
||||
jgen.writeFieldName("green")
|
||||
jgen.writeNumber(color.green)
|
||||
jgen.writeFieldName("blue")
|
||||
jgen.writeNumber(color.blue)
|
||||
jgen.writeEndObject()
|
||||
}
|
||||
}
|
||||
|
||||
class ColorDeserializer extends StdDeserializer[Color](classOf[Color]) {
|
||||
override def deserialize(jp: JsonParser, ctxt: DeserializationContext): Color = {
|
||||
val node = jp.getCodec.readTree[JsonNode](jp)
|
||||
val red = node.get("red").asDouble()
|
||||
val green = node.get("green").asDouble()
|
||||
val blue = node.get("blue").asDouble()
|
||||
Color.color(red, green, blue)
|
||||
}
|
||||
}
|
||||
|
||||
object YamlHelper {
|
||||
val mapper = new ObjectMapper(new YAMLFactory()) with ScalaObjectMapper
|
||||
mapper.registerModule(DefaultScalaModule)
|
||||
val module = new SimpleModule()
|
||||
module.addSerializer(classOf[Color], new ColorSerializer)
|
||||
module.addDeserializer(classOf[Color], new ColorDeserializer)
|
||||
mapper.registerModule(module)
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
|
||||
def extract[T](text : String)(implicit m : Manifest[T]) : T = {
|
||||
@@ -50,4 +85,8 @@ object YamlHelper {
|
||||
def extractMap[T](source : InputStream)(implicit m: Manifest[T]) : Map[String, T] = {
|
||||
mapper.readValue[Map[String, T]](source)
|
||||
}
|
||||
|
||||
def writeMap[T](source: OutputStream, items: Map[String, T])(implicit m: Manifest[T]) = {
|
||||
mapper.writeValue(source, items)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user