Remove JsonHelper. Json will no longer be supported. Data files will be in Yaml only (which they already were)
This commit is contained in:
parent
ad6780362b
commit
d2ee6debf8
@ -2,9 +2,6 @@ package fmon
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
import org.json4s.DefaultFormats
|
||||
import org.json4s.ext.EnumNameSerializer
|
||||
|
||||
import scala.util.Random
|
||||
|
||||
import fmon.util.Dice
|
||||
@ -18,7 +15,6 @@ package object stat {
|
||||
type Target = Target.Value
|
||||
type XpCurve = XpCurve.Val
|
||||
|
||||
implicit val formats = DefaultFormats + new EnumNameSerializer(MoveType) + new EnumNameSerializer(Gender)
|
||||
implicit def rngDice(rng : Random) = new Dice(rng)
|
||||
implicit def ptrToMonster(ptr : MonsterPtr) : Monster = ptr.mon
|
||||
implicit def templateToStatus(status: StatusTemplate): Status = status.build
|
||||
|
@ -1,52 +0,0 @@
|
||||
package fmon.util
|
||||
|
||||
import org.json4s._
|
||||
import org.json4s.jackson.JsonMethods._
|
||||
import org.json4s.ext.EnumNameSerializer
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
import scala.io.Source
|
||||
|
||||
object JsonHelper {
|
||||
|
||||
// Maybe Look at Jackson-YAML & Jackson-Scala
|
||||
|
||||
implicit val formats = fmon.stat.formats
|
||||
|
||||
def extract[T](text : String)(implicit mf : Manifest[T]) : T = {
|
||||
val json = parse(text)
|
||||
json.extract[T]
|
||||
}
|
||||
|
||||
def extract[T](source : Source)(implicit mf : Manifest[T]) : T = {
|
||||
val text = source.getLines().mkString("\n")
|
||||
extract(text)
|
||||
}
|
||||
|
||||
def extractFromFile[T](filename : String)(implicit mf : Manifest[T]) : T = {
|
||||
using(filename : InputStream)(reader => extract(Source.fromInputStream(filename)))
|
||||
}
|
||||
|
||||
def toScala(jvalue : JValue): Any = jvalue match {
|
||||
case JNothing => null
|
||||
case JNull => null
|
||||
case JString(s) => s
|
||||
case JDouble(num) => num.toDouble
|
||||
case JDecimal(num) => num.toInt
|
||||
case JInt(num) => num.toInt
|
||||
case JLong(num) => num.toLong
|
||||
case JBool(value) => value
|
||||
case JObject(obj) => obj.map{ case (s, o) => {
|
||||
(s, toScala(o))
|
||||
}}.toMap
|
||||
case JArray(arr) => arr.map(toScala)
|
||||
case JSet(data) => data.map(toScala)
|
||||
}
|
||||
|
||||
def loadFromSource(source : Source) : List[Map[String, Any]] = {
|
||||
val text = source.getLines().mkString("\n")
|
||||
val array = parse(text).asInstanceOf[JArray]
|
||||
array.arr.map(jo => toScala(jo).asInstanceOf[Map[String, Any]])
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user