mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
apparently I was just doing it wrong :/
This commit is contained in:
@@ -5,7 +5,10 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.utils.Disposable
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.CommonResourcePool
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
@@ -45,6 +48,8 @@ class ItemWearableWorldRadar(originalID: String) : GameItem(originalID) {
|
||||
val ui = WearableWorldRadarUI(vm)
|
||||
|
||||
init {
|
||||
super.equipPosition = EquipPosition.HAND_GRIP
|
||||
|
||||
vm.getIO().blockTransferPorts[1].attachDevice(WorldRadar())
|
||||
vm.peripheralTable[1] = PeripheralEntry(
|
||||
ExtDisp(vm, 160, 140), 32768, 1, 0
|
||||
|
||||
Binary file not shown.
@@ -28,6 +28,7 @@ import net.torvald.terrarum.gamecontroller.IME;
|
||||
import net.torvald.terrarum.gamecontroller.InputStrober;
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler;
|
||||
import net.torvald.terrarum.gamecontroller.TerrarumKeyboardEvent;
|
||||
import net.torvald.terrarum.gameitems.GameItem;
|
||||
import net.torvald.terrarum.gameworld.GameWorld;
|
||||
import net.torvald.terrarum.imagefont.TinyAlphNum;
|
||||
import net.torvald.terrarum.langpack.Lang;
|
||||
@@ -851,6 +852,15 @@ public class App implements ApplicationListener {
|
||||
* Init stuffs which needs GL context
|
||||
*/
|
||||
private void postInit() {
|
||||
ModMgr.INSTANCE.invoke(); // invoke Module Manager
|
||||
printdbg(this, "all modules loaded successfully");
|
||||
|
||||
|
||||
// test print
|
||||
System.out.println("[App] Test printing every registered item");
|
||||
Terrarum.INSTANCE.getItemCodex().getItemCodex().values().stream().map(GameItem::getOriginalID).forEach(System.out::println);
|
||||
|
||||
|
||||
// create tile atlas
|
||||
printdbg(this, "Making terrain textures...");
|
||||
tileMaker = new CreateTileAtlas();
|
||||
@@ -878,14 +888,13 @@ public class App implements ApplicationListener {
|
||||
System.err.println("[AppLoader] failed to create audio device: Audio device occupied by Exclusive Mode Device? (e.g. ASIO4all)");
|
||||
}
|
||||
|
||||
CommonResourcePool.INSTANCE.loadAll();
|
||||
|
||||
// if there is a predefined screen, open that screen after my init process
|
||||
if (injectScreen != null) {
|
||||
setScreen(injectScreen);
|
||||
}
|
||||
else {
|
||||
ModMgr.INSTANCE.invoke(); // invoke Module Manager
|
||||
CommonResourcePool.INSTANCE.loadAll();
|
||||
printdbg(this, "all modules loaded successfully");
|
||||
IngameRenderer.initialise();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.savegame.ByteArray64GrowableOutputStream
|
||||
import net.torvald.terrarum.savegame.ByteArray64Reader
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import org.apache.commons.csv.CSVFormat
|
||||
@@ -20,7 +18,6 @@ import org.apache.commons.csv.CSVRecord
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.PrintStream
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
@@ -132,12 +129,12 @@ object ModMgr {
|
||||
|
||||
// for modules that has JAR defined
|
||||
if (jar.isNotBlank()) {
|
||||
// val urls = arrayOf<URL>()
|
||||
val urls = arrayOf<URL>()
|
||||
|
||||
// val cl = JarFileLoader(urls)
|
||||
// cl.addFile("${File(modDir).absolutePath}/$moduleName/$jar")
|
||||
// moduleClassloader[moduleName] = cl
|
||||
// newClass = cl.loadClass(entryPoint)
|
||||
val cl = JarFileLoader(urls)
|
||||
cl.addFile("${File(modDir).absolutePath}/$moduleName/$jar")
|
||||
moduleClassloader[moduleName] = cl
|
||||
newClass = cl.loadClass(entryPoint)
|
||||
}
|
||||
// for modules that are not (meant to be used by the "basegame" kind of modules)
|
||||
else {
|
||||
@@ -147,11 +144,7 @@ object ModMgr {
|
||||
catch (e: Throwable) {
|
||||
printdbgerr(this, "$moduleName failed to load, skipping...")
|
||||
printdbgerr(this, "\t$e")
|
||||
val ba = ByteArray64GrowableOutputStream()
|
||||
val sw = PrintStream(ba, true)
|
||||
e.printStackTrace(sw)
|
||||
val bw = ByteArray64Reader(ba.toByteArray64(), Charsets.UTF_8)
|
||||
printdbgerr(this, bw.readText())
|
||||
print(App.csiR); e.printStackTrace(System.out); print(App.csi0)
|
||||
moduleInfo.remove(moduleName)
|
||||
}
|
||||
|
||||
@@ -183,6 +176,9 @@ object ModMgr {
|
||||
print(App.csiR); e.printStackTrace(System.out); print(App.csi0)
|
||||
moduleInfo.remove(moduleName)
|
||||
}
|
||||
finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -315,15 +311,24 @@ object ModMgr {
|
||||
|
||||
|
||||
object GameBlockLoader {
|
||||
init {
|
||||
Terrarum.blockCodex = BlockCodex()
|
||||
Terrarum.wireCodex = WireCodex()
|
||||
}
|
||||
|
||||
@JvmStatic operator fun invoke(module: String) {
|
||||
Terrarum.blockCodex = BlockCodex(module, "blocks/blocks.csv")
|
||||
Terrarum.wireCodex = WireCodex(module, "wires/")
|
||||
Terrarum.blockCodex.fromModule(module, "blocks/blocks.csv")
|
||||
Terrarum.wireCodex.fromModule(module, "wires/")
|
||||
}
|
||||
}
|
||||
|
||||
object GameItemLoader {
|
||||
val itemPath = "items/"
|
||||
|
||||
init {
|
||||
Terrarum.itemCodex = ItemCodex()
|
||||
}
|
||||
|
||||
@JvmStatic operator fun invoke(module: String) {
|
||||
register(module, CSVFetcher.readFromModule(module, itemPath + "itemid.csv"))
|
||||
}
|
||||
@@ -339,8 +344,6 @@ object ModMgr {
|
||||
}
|
||||
|
||||
private fun register(module: String, csv: List<CSVRecord>) {
|
||||
Terrarum.itemCodex = ItemCodex()
|
||||
|
||||
csv.forEach {
|
||||
val className: String = it["classname"].toString()
|
||||
val internalID: Int = it["id"].toInt()
|
||||
@@ -353,14 +356,12 @@ object ModMgr {
|
||||
val loadedClass = Class.forName(className)
|
||||
val loadedClassConstructor = loadedClass.getConstructor(ItemID::class.java)
|
||||
val loadedClassInstance = loadedClassConstructor.newInstance(itemName)
|
||||
|
||||
ItemCodex[itemName] = loadedClassInstance as GameItem
|
||||
}
|
||||
else {
|
||||
val loadedClass = it.loadClass(className)
|
||||
val loadedClassConstructor = loadedClass.getConstructor(ItemID::class.java)
|
||||
val loadedClassInstance = loadedClassConstructor.newInstance(itemName)
|
||||
|
||||
ItemCodex[itemName] = loadedClassInstance as GameItem
|
||||
}
|
||||
}
|
||||
@@ -379,8 +380,12 @@ object ModMgr {
|
||||
object GameMaterialLoader {
|
||||
val matePath = "materials/"
|
||||
|
||||
init {
|
||||
Terrarum.materialCodex = MaterialCodex()
|
||||
}
|
||||
|
||||
@JvmStatic operator fun invoke(module: String) {
|
||||
Terrarum.materialCodex = MaterialCodex(module, matePath + "materials.csv")
|
||||
Terrarum.materialCodex.fromModule(module, matePath + "materials.csv")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class BlockCodex {
|
||||
/**
|
||||
* Later entry (possible from other modules) will replace older ones
|
||||
*/
|
||||
internal constructor(module: String, path: String) : this() {
|
||||
fun fromModule(module: String, path: String) {
|
||||
App.printmsg(this, "Building block properties table")
|
||||
try {
|
||||
register(module, CSVFetcher.readFromModule(module, path))
|
||||
|
||||
@@ -38,7 +38,7 @@ class WireCodex {
|
||||
* @param module name of the module
|
||||
* @param path to the "wires" directory, not path to the CSV; must end with a slash!
|
||||
*/
|
||||
internal constructor(module: String, path: String) : this() {
|
||||
fun fromModule(module: String, path: String) {
|
||||
App.printmsg(this, "Building wire properties table for module $module")
|
||||
try {
|
||||
register(module, path, CSVFetcher.readFromModule(module, path + "wires.csv"))
|
||||
|
||||
@@ -17,46 +17,50 @@ object CommandDict {
|
||||
printdbg(this, ModMgr.loadOrder.reversed())
|
||||
printdbg(this, ModMgr.loadOrder.reversed().map { ModMgr.moduleInfo[it]?.packageName })
|
||||
|
||||
(listOf("net.torvald.terrarum") + ModMgr.loadOrder.reversed().mapNotNull { ModMgr.moduleInfo[it]?.packageName }).forEach{ packageRoot ->
|
||||
(listOf("net.torvald.terrarum") + ModMgr.loadOrder.reversed().mapNotNull { ModMgr.moduleInfo[it]?.packageName }).forEach { packageRoot ->
|
||||
printdbg(this, packageRoot)
|
||||
val packageConsole = "$packageRoot.console"
|
||||
val stream = ClassLoader.getSystemClassLoader().getResourceAsStream(packageConsole.replace('.','/'))
|
||||
val reader = BufferedReader(InputStreamReader(stream))
|
||||
val stream = ClassLoader.getSystemClassLoader().getResourceAsStream(packageConsole.replace('.', '/'))
|
||||
|
||||
reader.lines()
|
||||
.filter{ it.endsWith(".class") && !it.contains('$') }
|
||||
.map { Class.forName("$packageConsole.${it.substring(0, it.lastIndexOf('.'))}") }
|
||||
.forEach {
|
||||
if (stream != null) { // not all modules have extra console commands
|
||||
|
||||
printdbg(this, "> Trying to instantiate ${it.canonicalName}")
|
||||
val reader = BufferedReader(InputStreamReader(stream))
|
||||
|
||||
try {
|
||||
val instance = it.kotlin.objectInstance ?: it.kotlin.java.newInstance()
|
||||
reader.lines()
|
||||
.filter { it.endsWith(".class") && !it.contains('$') }
|
||||
.map { Class.forName("$packageConsole.${it.substring(0, it.lastIndexOf('.'))}") }
|
||||
.forEach {
|
||||
|
||||
val aliases = instance.javaClass.getAnnotation(ConsoleAlias::class.java)?.aliasesCSV?.split(',')?.map { it.trim() }
|
||||
val noexport = instance.javaClass.getAnnotation(ConsoleNoExport::class.java)
|
||||
printdbg(this, "> Trying to instantiate ${it.canonicalName}")
|
||||
|
||||
if (noexport == null) {
|
||||
try {
|
||||
val instance = it.kotlin.objectInstance ?: it.kotlin.java.newInstance()
|
||||
|
||||
dict[instance.javaClass.simpleName.lowercase()] = instance as ConsoleCommand
|
||||
aliases?.forEach {
|
||||
dict[it] = instance as ConsoleCommand
|
||||
val aliases = instance.javaClass.getAnnotation(ConsoleAlias::class.java)?.aliasesCSV?.split(',')?.map { it.trim() }
|
||||
val noexport = instance.javaClass.getAnnotation(ConsoleNoExport::class.java)
|
||||
|
||||
if (noexport == null) {
|
||||
|
||||
dict[instance.javaClass.simpleName.lowercase()] = instance as ConsoleCommand
|
||||
aliases?.forEach {
|
||||
dict[it] = instance as ConsoleCommand
|
||||
}
|
||||
|
||||
printdbg(this, "Class instantiated: ${instance.javaClass.simpleName}")
|
||||
if (aliases != null)
|
||||
printdbg(this, " Annotations: $aliases")
|
||||
}
|
||||
|
||||
printdbg(this, "Class instantiated: ${instance.javaClass.simpleName}")
|
||||
if (aliases != null)
|
||||
printdbg(this, " Annotations: $aliases")
|
||||
}
|
||||
catch (e: ClassCastException) {
|
||||
printdbgerr(this, "${it.canonicalName} is not a ConsoleCommand")
|
||||
}
|
||||
catch (e: InstantiationException) {
|
||||
printdbgerr(this, "Could not instantiate ${it.canonicalName}")
|
||||
e.printStackTrace(System.err)
|
||||
}
|
||||
}
|
||||
catch (e: ClassCastException) {
|
||||
printdbgerr(this, "${it.canonicalName} is not a ConsoleCommand")
|
||||
}
|
||||
catch (e: InstantiationException) {
|
||||
printdbgerr(this, "Could not instantiate ${it.canonicalName}")
|
||||
e.printStackTrace(System.err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package net.torvald.terrarum.itemproperties
|
||||
|
||||
import net.torvald.terrarum.App
|
||||
import net.torvald.terrarum.App.printmsg
|
||||
import net.torvald.terrarum.Codex
|
||||
import net.torvald.terrarum.blockproperties.floatVal
|
||||
import net.torvald.terrarum.blockproperties.intVal
|
||||
import net.torvald.terrarum.utils.CSVFetcher
|
||||
import org.apache.commons.csv.CSVRecord
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* To be used with items AND TILES (electricity resistance, thermal conductivity)
|
||||
@@ -39,8 +41,12 @@ class MaterialCodex {
|
||||
|
||||
internal constructor()
|
||||
|
||||
internal constructor(module: String, path: String) : this() {
|
||||
register(CSVFetcher.readFromModule(module, path))
|
||||
fun fromModule(module: String, path: String) {
|
||||
App.printmsg(this, "Building material properties table")
|
||||
try {
|
||||
register(CSVFetcher.readFromModule(module, path))
|
||||
}
|
||||
catch (e: IOException) { e.printStackTrace() }
|
||||
}
|
||||
|
||||
fun fromCSV(module: String, csvString: String) {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package net.torvald.terrarum.modulebasegame.console
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.Terrarum.PLAYER_REF_ID
|
||||
import net.torvald.terrarum.console.ConsoleCommand
|
||||
import net.torvald.terrarum.console.Echo
|
||||
import net.torvald.terrarum.console.EchoError
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.Terrarum.PLAYER_REF_ID
|
||||
import net.torvald.terrarum.gameactors.ActorID
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.Pocketed
|
||||
|
||||
/**
|
||||
@@ -21,6 +20,9 @@ internal object Inventory : ConsoleCommand {
|
||||
if (args.size == 1) {
|
||||
printUsage()
|
||||
}
|
||||
else if (args[1] == "target") {
|
||||
targetID = if (args[2].lowercase() == "player") PLAYER_REF_ID else args[2].toInt()
|
||||
}
|
||||
else {
|
||||
val actor = getActor()
|
||||
if (actor != null) {
|
||||
@@ -28,7 +30,6 @@ internal object Inventory : ConsoleCommand {
|
||||
"list" -> listInventory(actor)
|
||||
"add" -> if (args.size > 3) addItem(actor, args[2], args[3].toInt()) else addItem(actor, args[2])
|
||||
"remove" -> if (args.size > 3) removeItem(actor, args[2], args[3].toInt()) else removeItem(actor, args[2])
|
||||
"target" -> targetID = if (args[2].lowercase() == "player") PLAYER_REF_ID else args[2].toInt()
|
||||
"equip" -> equipItem(actor, args[2])
|
||||
"unequip"-> unequipItem(actor, args[2])
|
||||
else -> printUsage()
|
||||
|
||||
Reference in New Issue
Block a user