mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 19:44:05 +09:00
support for external mods
This commit is contained in:
@@ -59,7 +59,8 @@ object ModMgr {
|
|||||||
val releaseDate: String,
|
val releaseDate: String,
|
||||||
val version: String,
|
val version: String,
|
||||||
val jar: String,
|
val jar: String,
|
||||||
val dependencies: Array<String>
|
val dependencies: Array<String>,
|
||||||
|
val isInternal: Boolean
|
||||||
) {
|
) {
|
||||||
override fun toString() =
|
override fun toString() =
|
||||||
"\tModule #$order -- $properName | $version | $author\n" +
|
"\tModule #$order -- $properName | $version | $author\n" +
|
||||||
@@ -131,10 +132,21 @@ object ModMgr {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val modMetadata = Properties()
|
val modMetadata = Properties()
|
||||||
modMetadata.load(FileInputStream("$modDirInternal/$moduleName/$metaFilename"))
|
|
||||||
|
|
||||||
if (File("$modDirInternal/$moduleName/$defaultConfigFilename").exists()) {
|
val _internalFile = File("$modDirInternal/$moduleName/$metaFilename")
|
||||||
val defaultConfig = JsonFetcher("$modDirInternal/$moduleName/$defaultConfigFilename")
|
val _externalFile = File("$modDirExternal/$moduleName/$metaFilename")
|
||||||
|
|
||||||
|
// external mod has precedence over the internal
|
||||||
|
val isInternal = if (_externalFile.exists()) false else if (_internalFile.exists()) true else throw FileNotFoundException()
|
||||||
|
val file = if (isInternal) _internalFile else _externalFile
|
||||||
|
val modDir = if (isInternal) modDirInternal else modDirExternal
|
||||||
|
|
||||||
|
fun getGdxFile(path: String) = if (isInternal) Gdx.files.internal(path) else Gdx.files.absolute(path)
|
||||||
|
|
||||||
|
modMetadata.load(FileInputStream(file))
|
||||||
|
|
||||||
|
if (File("$modDir/$moduleName/$defaultConfigFilename").exists()) {
|
||||||
|
val defaultConfig = JsonFetcher("$modDir/$moduleName/$defaultConfigFilename")
|
||||||
// read config and store it to the game
|
// read config and store it to the game
|
||||||
|
|
||||||
// write to user's config file
|
// write to user's config file
|
||||||
@@ -151,7 +163,7 @@ object ModMgr {
|
|||||||
val version = modMetadata.getProperty("version")
|
val version = modMetadata.getProperty("version")
|
||||||
val jar = modMetadata.getProperty("jar")
|
val jar = modMetadata.getProperty("jar")
|
||||||
val dependency = modMetadata.getProperty("dependency").split(Regex(""";[ ]*""")).filter { it.isNotEmpty() }.toTypedArray()
|
val dependency = modMetadata.getProperty("dependency").split(Regex(""";[ ]*""")).filter { it.isNotEmpty() }.toTypedArray()
|
||||||
val isDir = FileSystems.getDefault().getPath("$modDirInternal/$moduleName").toFile().isDirectory
|
val isDir = FileSystems.getDefault().getPath("$modDir/$moduleName").toFile().isDirectory
|
||||||
|
|
||||||
|
|
||||||
val versionNumeral = version.split('.')
|
val versionNumeral = version.split('.')
|
||||||
@@ -173,7 +185,7 @@ object ModMgr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
moduleInfo[moduleName] = ModuleMetadata(index, isDir, Gdx.files.internal("$modDirInternal/$moduleName/icon.png"), properName, description, author, packageName, entryPoint, releaseDate, version, jar, dependency)
|
moduleInfo[moduleName] = ModuleMetadata(index, isDir, getGdxFile("$modDir/$moduleName/icon.png"), properName, description, author, packageName, entryPoint, releaseDate, version, jar, dependency, isInternal)
|
||||||
|
|
||||||
printdbg(this, moduleInfo[moduleName])
|
printdbg(this, moduleInfo[moduleName])
|
||||||
|
|
||||||
@@ -192,7 +204,7 @@ object ModMgr {
|
|||||||
val urls = arrayOf<URL>()
|
val urls = arrayOf<URL>()
|
||||||
|
|
||||||
val cl = JarFileLoader(urls)
|
val cl = JarFileLoader(urls)
|
||||||
cl.addFile("${File(modDirInternal).absolutePath}/$moduleName/$jar")
|
cl.addFile("${File(modDir).absolutePath}/$moduleName/$jar")
|
||||||
moduleClassloader[moduleName] = cl
|
moduleClassloader[moduleName] = cl
|
||||||
newClass = cl.loadClass(entryPoint)
|
newClass = cl.loadClass(entryPoint)
|
||||||
}
|
}
|
||||||
@@ -325,14 +337,14 @@ object ModMgr {
|
|||||||
/** Returning files are read-only */
|
/** Returning files are read-only */
|
||||||
fun getGdxFile(module: String, path: String): FileHandle {
|
fun getGdxFile(module: String, path: String): FileHandle {
|
||||||
checkExistence(module)
|
checkExistence(module)
|
||||||
return if (true) // TODO if module is internal...
|
return if (moduleInfo[module]!!.isInternal)
|
||||||
Gdx.files.internal("$modDirInternal/$module/$path")
|
Gdx.files.internal("$modDirInternal/$module/$path")
|
||||||
else
|
else
|
||||||
Gdx.files.absolute("$modDirExternal/$module/$path")
|
Gdx.files.absolute("$modDirExternal/$module/$path")
|
||||||
}
|
}
|
||||||
fun getFile(module: String, path: String): File {
|
fun getFile(module: String, path: String): File {
|
||||||
checkExistence(module)
|
checkExistence(module)
|
||||||
return if (true) // TODO if module is internal...
|
return if (moduleInfo[module]!!.isInternal)
|
||||||
FileSystems.getDefault().getPath("$modDirInternal/$module/$path").toFile()
|
FileSystems.getDefault().getPath("$modDirInternal/$module/$path").toFile()
|
||||||
else
|
else
|
||||||
FileSystems.getDefault().getPath("$modDirExternal/$module/$path").toFile()
|
FileSystems.getDefault().getPath("$modDirExternal/$module/$path").toFile()
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ object CommandDict {
|
|||||||
printdbg(this, ModMgr.loadOrder.reversed().map { ModMgr.moduleInfo[it]?.packageName })
|
printdbg(this, ModMgr.loadOrder.reversed().map { ModMgr.moduleInfo[it]?.packageName })
|
||||||
|
|
||||||
((listOf("$" to "net.torvald.terrarum")) + ModMgr.loadOrder.reversed().map { it to ModMgr.moduleInfo[it]?.packageName }).forEach { (modName, packageRoot) ->
|
((listOf("$" to "net.torvald.terrarum")) + ModMgr.loadOrder.reversed().map { it to ModMgr.moduleInfo[it]?.packageName }).forEach { (modName, packageRoot) ->
|
||||||
if (modName != "$" && ModMgr.hasFile(modName, "commands.csv")) {
|
if (modName == "$" || modName != "$" && ModMgr.hasFile(modName, "commands.csv")) {
|
||||||
val commandsList = if (modName == "$") engineCommandList else ModMgr.getFile(modName, "commands.csv").readLines()
|
val commandsList = if (modName == "$") engineCommandList else ModMgr.getFile(modName, "commands.csv").readLines()
|
||||||
val packageConsole = "$packageRoot.console"
|
val packageConsole = "$packageRoot.console"
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ class UIItemSaving(parentUI: UICanvas, initialX: Int, initialY: Int) : UIItem(pa
|
|||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
val sx = index % circleSheet.horizontalCount
|
val sx = index % circleSheet.horizontalCount
|
||||||
val sy = index / circleSheet.horizontalCount
|
val sy = index / circleSheet.horizontalCount
|
||||||
batch.draw(circleSheet.get(sx, sy), (posX + (width - circleSheet.tileW) / 2).toFloat(), posY.toFloat())
|
// q&d fix for ArrayIndexOutOfBoundsException caused when saving huge world... wut?
|
||||||
|
if (sx in 0 until circleSheet.horizontalCount && sy in 0 until circleSheet.horizontalCount) {
|
||||||
|
batch.draw(circleSheet.get(sx, sy), (posX + (width - circleSheet.tileW) / 2).toFloat(), posY.toFloat())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user