diff --git a/Builder/.gitignore b/Builder/.gitignore
new file mode 100644
index 0000000..ae3c172
--- /dev/null
+++ b/Builder/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/Builder/src/fmon/builder/App.fxml b/Builder/src/fmon/builder/App.fxml
new file mode 100644
index 0000000..1d8b168
--- /dev/null
+++ b/Builder/src/fmon/builder/App.fxml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Builder/src/fmon/builder/App.scala b/Builder/src/fmon/builder/App.scala
new file mode 100644
index 0000000..f33da58
--- /dev/null
+++ b/Builder/src/fmon/builder/App.scala
@@ -0,0 +1,54 @@
+package fmon.builder
+
+import java.io.File
+
+import javafx.fxml.FXML
+import javafx.fxml.FXMLLoader
+import javafx.fxml.JavaFXBuilderFactory
+import javafx.scene.{control => jfxsc, layout => jfxsl}
+
+import scalafx.Includes._
+import scalafx.stage.FileChooser
+import FileChooser.ExtensionFilter
+
+trait Savable {
+ def saveTo(file: File): Unit
+ def openFrom(file: File): Unit
+}
+
+class App {
+ @FXML var pane: jfxsl.Pane = _
+
+ var builder: Savable = _
+
+
+ def open(): Unit = {
+ val fileChooser = new FileChooser {
+ title = "Open Resource File"
+ extensionFilters ++= Seq(
+ new ExtensionFilter("YAML Files", "*.yaml"),
+ new ExtensionFilter("All Files", "*.*")
+ )
+ }
+
+ val selectedFile = fileChooser.showOpenDialog(null)
+ if (selectedFile != null) {
+ builder openFrom selectedFile
+ }
+ }
+
+ def saveAs(): Unit = {
+ val fileChooser = new FileChooser {
+ title = "Open Resource File"
+ extensionFilters ++= Seq(
+ new ExtensionFilter("YAML Files", "*.yaml"),
+ new ExtensionFilter("All Files", "*.*")
+ )
+ }
+
+ val selectedFile = fileChooser.showSaveDialog(null)
+ if (selectedFile != null) {
+ builder saveTo selectedFile
+ }
+ }
+}
\ No newline at end of file
diff --git a/Builder/src/fmon/builder/ElementBuilder.fxml b/Builder/src/fmon/builder/ElementBuilder.fxml
new file mode 100644
index 0000000..b59180f
--- /dev/null
+++ b/Builder/src/fmon/builder/ElementBuilder.fxml
@@ -0,0 +1,93 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Builder/src/fmon/builder/ElementBuilder.scala b/Builder/src/fmon/builder/ElementBuilder.scala
new file mode 100644
index 0000000..025759c
--- /dev/null
+++ b/Builder/src/fmon/builder/ElementBuilder.scala
@@ -0,0 +1,227 @@
+package fmon.builder
+
+import java.io._
+
+import javafx.application.Application
+import javafx.fxml.FXML
+import javafx.fxml.FXMLLoader
+import javafx.fxml.JavaFXBuilderFactory
+import javafx.scene.{control => jfxsc, Parent, Scene}
+import javafx.stage.Stage
+
+import scalafx.Includes._
+import scalafx.beans.property._
+import scalafx.collections.ObservableBuffer
+import scalafx.scene.control._
+import scalafx.scene.paint.Color
+import scalafx.scene.layout._
+
+import org.yaml.snakeyaml.nodes._
+import org.yaml.snakeyaml.nodes.Tag
+import org.yaml.snakeyaml.constructor._
+import org.yaml.snakeyaml.representer._
+
+import fmon.stat.Element
+import fmon.util.YamlHelper
+
+import TableColumn._
+
+class ObsElement(name_ : String, bgColor_ : Color = Color.Gray, fontColor_ : Color = Color.Black) {
+ val name = new StringProperty(this, "name", name_)
+ val bgColor = new ObjectProperty[Color](this, "bgColor", bgColor_)
+ val fontColor = new ObjectProperty[Color](this, "fontColor", fontColor_)
+
+ val immune = new ObservableBuffer[ObsElement]()
+ val resist = new ObservableBuffer[ObsElement]()
+ val normal = new ObservableBuffer[ObsElement]()
+ val weak = new ObservableBuffer[ObsElement]()
+
+ def asElement = {
+ def toMap(buffer: ObservableBuffer[ObsElement], mult: Double) = {
+ buffer.map(e => (e.name(), mult)).toMap
+ }
+ val effect = toMap(immune, 0.0) ++ toMap(resist, 0.5) ++ toMap(normal, 1.0) ++ toMap(weak, 2.0)
+ new Element(name(), bgColor(), fontColor(), effect)
+ }
+
+ override def toString = name()
+}
+
+class ColorRepresenter extends Representer {
+ representers.put(classOf[Color], new ColorRepresent)
+
+ class ColorRepresent extends Represent {
+ override def representData(data: AnyRef): Node = {
+ val color = data.asInstanceOf[Color]
+ representScalar(new Tag("!color"), color.toString())
+ }
+ }
+}
+
+class ColorConstructor extends Constructor {
+ yamlConstructors.put(new Tag("!color"), new ConstructColor)
+
+ class ConstructColor extends AbstractConstruct {
+ override def construct(node: Node): AnyRef = {
+ val string = constructScalar(node.asInstanceOf[ScalarNode])
+ return Color.valueOf(string)
+ }
+ }
+}
+
+class ElementBuilder extends Savable {
+ @FXML var elements: jfxsc.ListView[ObsElement] = _
+ @FXML var add: jfxsc.Button = _
+ //@FXML var matchups: jfxsc.TableView[ObsElement] = _
+ var elementList = ObservableBuffer[ObsElement]()
+
+ @FXML var immuneView: jfxsc.ListView[ObsElement] = _
+ @FXML var resistView: jfxsc.ListView[ObsElement] = _
+ @FXML var normalView: jfxsc.ListView[ObsElement] = _
+ @FXML var weakView: jfxsc.ListView[ObsElement] = _
+
+ @FXML var name: jfxsc.TextField = _
+ @FXML var bgColor: jfxsc.ColorPicker = _
+ @FXML var textColor: jfxsc.ColorPicker = _
+ @FXML var button: jfxsc.Button = _
+
+ @FXML
+ def initialize(): Unit = {
+ elements.items = elementList
+ elementList ++= Seq(new ObsElement("Fire"), new ObsElement("Water"), new ObsElement("Leaf"))
+ elements.selectionModel().selectedIndex.onChange(selectionChange)
+ elements.selectionModel().selectFirst()
+
+ elementList.foreach(e => elementList.foreach(f => e.normal += f))
+ }
+
+ def selectionChange(): Unit = {
+ val element = elementList(elements.selectionModel().selectedIndex())
+ name.text = element.name()
+ bgColor.value = element.bgColor()
+ textColor.value = element.fontColor()
+
+ immuneView.items = element.immune
+ resistView.items = element.resist
+ normalView.items = element.normal
+ weakView.items = element.weak
+ updateFont()
+ }
+
+ def updateName(): Unit = {
+ button.text = name.text()
+ setChanges()
+ }
+
+ def updateBg(): Unit = {
+ updateFont()
+ }
+
+ def updateFont(): Unit = {
+ val bg = bgColor.value().toString().replaceFirst("0x", "#")
+ val color = textColor.value().toString().replaceFirst("0x", "#")
+ button.style = s"-fx-background-color: ${bg}; -fx-text-fill: ${color}"
+ setChanges()
+ }
+
+ def setChanges(): Unit = {
+ val element = elementList(elements.selectionModel().selectedIndex())
+ element.name.value = name.text()
+ element.bgColor.value = bgColor.value()
+ element.fontColor.value = textColor.value()
+ elements.refresh()
+ }
+
+ def addElement(): Unit = {
+ elementList += new ObsElement("New Element")
+ println(elements.items().size())
+ }
+
+ def immune2Resist(): Unit = {
+ val items = immuneView.selectionModel().getSelectedItems
+ resistView.items() ++= items
+ immuneView.items() --= items
+ }
+
+ def resist2Immune(): Unit = {
+ val items = resistView.selectionModel().getSelectedItems
+ immuneView.items() ++= items
+ resistView.items() --= items
+ }
+
+ def resist2Normal(): Unit = {
+ val items = resistView.selectionModel().getSelectedItems
+ normalView.items() ++= items
+ resistView.items() --= items
+ }
+
+ def normal2Resist(): Unit = {
+ val items = normalView.selectionModel().getSelectedItems
+ resistView.items() ++= items
+ normalView.items() --= items
+ }
+
+ def normal2Weak(): Unit = {
+ val items = normalView.selectionModel().getSelectedItems
+ weakView.items() ++= items
+ normalView.items() --= items
+ }
+
+ def weak2Normal(): Unit = {
+ val items = weakView.selectionModel().getSelectedItems
+ normalView.items() ++= items
+ weakView.items() --= items
+ }
+
+ override def saveTo(file: File): Unit = {
+ val elementMap = elementList.map(e => (e.name(), e.asElement)).toMap
+ YamlHelper.writeMap(new FileOutputStream(file), elementMap)
+ }
+
+ override def openFrom(file: File): Unit = {
+ val elementMap = YamlHelper.extractMap[Element](new FileInputStream(file))
+ val es = elementMap.values.map(e => new ObsElement(e.name, e.bgColor, e.fontColor)).toSeq
+ es.foreach(eo => es.foreach(fo => {
+ val e = elementMap(eo.name())
+ val f = elementMap(fo.name())
+ val mult = e <-- f
+ if (mult < 0.1) {
+ eo.immune += fo
+ } else if (mult < 0.75) {
+ eo.resist += fo
+ } else if (mult < 1.25) {
+ eo.normal += fo
+ } else {
+ eo.weak += fo
+ }
+ }))
+ elementList.clear()
+ elementList ++= es
+ elements.selectionModel().selectFirst()
+ }
+}
+
+object ElementBuilder {
+ class EBA extends Application {
+ override def start(primaryStage: Stage): Unit = {
+ val frameLoader = new FXMLLoader(getClass.getResource("App.fxml"))
+ val root: Parent = frameLoader.load()
+ val controller = frameLoader.getController[App]()
+
+ val builderLoader = new FXMLLoader(getClass.getResource("ElementBuilder.fxml"))
+ val builder: Parent = builderLoader.load()
+ val builderController = builderLoader.getController[ElementBuilder]()
+
+ controller.pane.children = builder
+ controller.builder = builderController
+
+ val scene: Scene = new Scene(root)
+ primaryStage.setScene(scene)
+ primaryStage.show()
+ }
+ }
+
+ def main(args: Array[String]): Unit = {
+ Application.launch(classOf[EBA], args: _*)
+ }
+}
\ No newline at end of file
diff --git a/FakeMon/src/fmon/battle/BattleUI.scala b/FakeMon/src/fmon/battle/BattleUI.scala
index 190b0c4..e35015f 100644
--- a/FakeMon/src/fmon/battle/BattleUI.scala
+++ b/FakeMon/src/fmon/battle/BattleUI.scala
@@ -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 {
diff --git a/FakeMon/src/fmon/battle/MoveButton.scala b/FakeMon/src/fmon/battle/MoveButton.scala
index f4346b7..b394433 100644
--- a/FakeMon/src/fmon/battle/MoveButton.scala
+++ b/FakeMon/src/fmon/battle/MoveButton.scala
@@ -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)}"
+ }
}
\ No newline at end of file
diff --git a/FakeMon/src/fmon/stat/Element.scala b/FakeMon/src/fmon/stat/Element.scala
index 1a65dff..a7edc6a 100644
--- a/FakeMon/src/fmon/stat/Element.scala
+++ b/FakeMon/src/fmon/stat/Element.scala
@@ -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
}
diff --git a/FakeMon/src/fmon/stat/data/elements.yaml b/FakeMon/src/fmon/stat/data/elements.yaml
index 7769681..0e9cfa0 100644
--- a/FakeMon/src/fmon/stat/data/elements.yaml
+++ b/FakeMon/src/fmon/stat/data/elements.yaml
@@ -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
diff --git a/FakeMon/src/fmon/util/YamlHelper.scala b/FakeMon/src/fmon/util/YamlHelper.scala
index 2fc081e..4d11f81 100644
--- a/FakeMon/src/fmon/util/YamlHelper.scala
+++ b/FakeMon/src/fmon/util/YamlHelper.scala
@@ -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)
+ }
}
\ No newline at end of file