mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-17 14:04:05 +09:00
com.torvald → net.torvald
Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4 Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
This commit is contained in:
62
src/net/torvald/terrarum/gameactors/faction/Faction.kt
Normal file
62
src/net/torvald/terrarum/gameactors/faction/Faction.kt
Normal file
@@ -0,0 +1,62 @@
|
||||
package net.torvald.terrarum.gameactors.faction
|
||||
|
||||
import net.torvald.random.HQRNG
|
||||
import java.util.HashSet
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-15.
|
||||
*/
|
||||
class Faction(factionName: String) {
|
||||
|
||||
lateinit var factionName: String
|
||||
lateinit var factionAmicable: HashSet<String>
|
||||
lateinit var factionNeutral: HashSet<String>
|
||||
lateinit var factionHostile: HashSet<String>
|
||||
lateinit var factionFearful: HashSet<String>
|
||||
var factionID: Long = HQRNG().nextLong()
|
||||
|
||||
init {
|
||||
this.factionName = factionName
|
||||
factionAmicable = HashSet<String>()
|
||||
factionNeutral = HashSet<String>()
|
||||
factionHostile = HashSet<String>()
|
||||
factionFearful = HashSet<String>()
|
||||
}
|
||||
|
||||
fun renewFactionName(factionName: String) {
|
||||
this.factionName = factionName
|
||||
}
|
||||
|
||||
fun addFactionAmicable(faction: String) {
|
||||
factionAmicable.add(faction)
|
||||
}
|
||||
|
||||
fun addFactionNeutral(faction: String) {
|
||||
factionNeutral.add(faction)
|
||||
}
|
||||
|
||||
fun addFactionHostile(faction: String) {
|
||||
factionHostile.add(faction)
|
||||
}
|
||||
|
||||
fun addFactionFearful(faction: String) {
|
||||
factionFearful.add(faction)
|
||||
}
|
||||
|
||||
fun removeFactionAmicable(faction: String) {
|
||||
factionAmicable.remove(faction)
|
||||
}
|
||||
|
||||
fun removeFactionNeutral(faction: String) {
|
||||
factionNeutral.remove(faction)
|
||||
}
|
||||
|
||||
fun removeFactionHostile(faction: String) {
|
||||
factionHostile.remove(faction)
|
||||
}
|
||||
|
||||
fun removeFactionFearful(faction: String) {
|
||||
factionFearful.remove(faction)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.torvald.terrarum.gameactors.faction
|
||||
|
||||
import net.torvald.JsonFetcher
|
||||
import com.google.gson.JsonObject
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-02-15.
|
||||
*/
|
||||
object FactionFactory {
|
||||
|
||||
const val JSONPATH = "./res/raw/factions/"
|
||||
|
||||
/**
|
||||
* @param filename with extension
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun create(filename: String): Faction {
|
||||
val jsonObj = JsonFetcher.readJson(JSONPATH + filename)
|
||||
val factionObj = Faction(jsonObj.get("factionname").asString)
|
||||
|
||||
|
||||
jsonObj.get("factionamicable").asJsonArray.forEach { s -> factionObj.addFactionAmicable(s.asString) }
|
||||
jsonObj.get("factionneutral").asJsonArray.forEach { s -> factionObj.addFactionNeutral(s.asString) }
|
||||
jsonObj.get("factionhostile").asJsonArray.forEach { s -> factionObj.addFactionHostile(s.asString) }
|
||||
jsonObj.get("factionfearful").asJsonArray.forEach { s -> factionObj.addFactionFearful(s.asString) }
|
||||
|
||||
return factionObj
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user