modular first test

This commit is contained in:
Song Minjae
2017-04-17 16:14:35 +09:00
parent 98d7548ce8
commit cec266d396
18 changed files with 128 additions and 56 deletions

View File

@@ -18,9 +18,9 @@ object CreatureBuilder {
* @Param jsonFileName with extension
*/
@Throws(IOException::class, SlickException::class)
operator fun invoke(jsonFileName: String): ActorWithSprite {
operator fun invoke(module: String, jsonFileName: String): ActorWithSprite {
val actor = ActorWithSprite(Actor.RenderOrder.MIDDLE)
InjectCreatureRaw(actor.actorValue, jsonFileName)
InjectCreatureRaw(actor.actorValue, module, jsonFileName)
return actor
}

View File

@@ -5,6 +5,7 @@ import net.torvald.random.Fudge3
import net.torvald.terrarum.langpack.Lang
import com.google.gson.JsonObject
import net.torvald.terrarum.ActorValue
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.gameactors.ActorHumanoid
import org.newdawn.slick.SlickException
import java.io.IOException
@@ -15,7 +16,6 @@ import java.security.SecureRandom
*/
object InjectCreatureRaw {
const val JSONPATH = "./assets/raw/creatures/"
private const val JSONMULT = "mult" // one appears in JSON files
/**
@@ -24,8 +24,8 @@ object InjectCreatureRaw {
* @param actorValueRef ActorValue object to be injected.
* @param jsonFileName with extension
*/
operator fun invoke(actorValueRef: ActorValue, jsonFileName: String) {
val jsonObj = JsonFetcher(JSONPATH + jsonFileName)
operator fun invoke(actorValueRef: ActorValue, module: String, jsonFileName: String) {
val jsonObj = JsonFetcher(ModuleManager.getPath(module, "creatures/$jsonFileName"))
val elementsInt = arrayOf(AVKey.BASEHEIGHT, AVKey.TOOLSIZE, AVKey.ENCUMBRANCE)
val elementsString = arrayOf(AVKey.RACENAME, AVKey.RACENAMEPLURAL)

View File

@@ -13,7 +13,7 @@ object PlayerBuilder {
operator fun invoke(): Actor {
val p: Actor = Player(Terrarum.ingame!!.world.time.currentTimeAsGameDate)
InjectCreatureRaw(p.actorValue, "CreatureHuman.json")
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
// attach sprite

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
@@ -15,14 +16,14 @@ object PlayerBuilderCynthia {
val p: HumanoidNPC = HumanoidNPC(
LuaAIWrapper("/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua"),
GameDate(100, 143)) // random value thrown
InjectCreatureRaw(p.actorValue, "CreatureHuman.json")
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.NAME] = "Cynthia"
p.makeNewSprite(26, 42, "assets/graphics/sprites/test_player_2.tga")
p.makeNewSprite(26, 42, ModuleManager.getPath("basegame", "sprites/test_player_2.tga"))
p.sprite!!.delay = 200
p.sprite!!.setRowsAndFrames(1, 1)

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.spriteanimation.SpriteAnimation
import com.google.gson.JsonObject
import net.torvald.terrarum.ActorValue
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.faction.FactionFactory
import net.torvald.terrarum.itemproperties.ItemCodex
@@ -27,11 +28,11 @@ object PlayerBuilderSigrid {
p.referenceID = 0x51621D // the only constant of this procedural universe
p.makeNewSprite(28, 51, "assets/graphics/sprites/test_player.tga")
p.makeNewSprite(28, 51, ModuleManager.getPath("basegame", "sprites/test_player.tga"))
p.sprite!!.delay = 200
p.sprite!!.setRowsAndFrames(1, 1)
p.makeNewSpriteGlow(28, 51, "assets/graphics/sprites/test_player_glow.tga")
p.makeNewSpriteGlow(28, 51, ModuleManager.getPath("basegame", "sprites/test_player_glow.tga"))
p.spriteGlow!!.delay = 200
p.spriteGlow!!.setRowsAndFrames(1, 1)
@@ -72,7 +73,7 @@ object PlayerBuilderSigrid {
p.setPosition((4096 * FeaturesDrawer.TILE_SIZE).toDouble(), (300 * 16).toDouble())
p.faction.add(FactionFactory.create("FactionSigrid.json"))
p.faction.add(FactionFactory.create("basegame", "factions/FactionSigrid.json"))

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModuleManager
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
@@ -9,14 +10,14 @@ import net.torvald.terrarum.mapdrawer.FeaturesDrawer
object PlayerBuilderTestSubject1 {
operator fun invoke(): Player {
val p: Player = Player(GameDate(100, 143)) // random value thrown
InjectCreatureRaw(p.actorValue, "CreatureHuman.json")
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.NAME] = "Test Subject 1"
p.makeNewSprite(48, 52, "assets/graphics/sprites/npc_template_anim_prototype.tga")
p.makeNewSprite(48, 52, ModuleManager.getPath("basegame", "sprites/npc_template_anim_prototype.tga"))
p.sprite!!.delay = 200
p.sprite!!.setRowsAndFrames(2, 4)

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors.faction
import net.torvald.JsonFetcher
import com.google.gson.JsonObject
import net.torvald.terrarum.ModuleManager
import java.io.IOException
@@ -10,14 +11,12 @@ import java.io.IOException
*/
object FactionFactory {
const val JSONPATH = "./assets/raw/factions/"
/**
* @param filename with extension
*/
@Throws(IOException::class)
fun create(filename: String): Faction {
val jsonObj = JsonFetcher(JSONPATH + filename)
fun create(module: String, path: String): Faction {
val jsonObj = JsonFetcher(ModuleManager.getPath(module, path))
val factionObj = Faction(jsonObj.get("factionname").asString)
jsonObj.get("factionamicable").asJsonArray.forEach { factionObj.addFactionAmicable(it.asString) }