mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 03:44:54 -04:00
mod loading: directory
This commit is contained in:
parent
d2053491ae
commit
a8c36160e8
@ -18,6 +18,7 @@ import de.bixilon.kutil.concurrent.pool.DefaultThreadPool
|
|||||||
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
import de.bixilon.kutil.concurrent.worker.unconditional.UnconditionalWorker
|
||||||
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||||
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
import de.bixilon.kutil.watcher.DataWatcher.Companion.watched
|
||||||
|
import de.bixilon.minosoft.assets.directory.DirectoryAssetsManager
|
||||||
import de.bixilon.minosoft.assets.file.ZipAssetsManager
|
import de.bixilon.minosoft.assets.file.ZipAssetsManager
|
||||||
import de.bixilon.minosoft.assets.util.FileUtil.readJson
|
import de.bixilon.minosoft.assets.util.FileUtil.readJson
|
||||||
import de.bixilon.minosoft.modding.loader.LoaderUtil.load
|
import de.bixilon.minosoft.modding.loader.LoaderUtil.load
|
||||||
@ -35,7 +36,7 @@ import java.util.jar.JarInputStream
|
|||||||
|
|
||||||
object ModLoader {
|
object ModLoader {
|
||||||
private val BASE_PATH = RunConfiguration.HOME_DIRECTORY + "mods/"
|
private val BASE_PATH = RunConfiguration.HOME_DIRECTORY + "mods/"
|
||||||
private const val MANFIEST = "manifest.json"
|
private const val MANIFEST = "manifest.json"
|
||||||
private val mods: MutableList<MinosoftMod> = mutableListOf()
|
private val mods: MutableList<MinosoftMod> = mutableListOf()
|
||||||
private var latch: CountUpAndDownLatch? = null
|
private var latch: CountUpAndDownLatch? = null
|
||||||
var currentPhase by watched(LoadingPhases.PRE_BOOT)
|
var currentPhase by watched(LoadingPhases.PRE_BOOT)
|
||||||
@ -63,8 +64,34 @@ object ModLoader {
|
|||||||
DefaultThreadPool += { createDirectories() }
|
DefaultThreadPool += { createDirectories() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun MinosoftMod.scanDirectory(base: File, file: File) {
|
||||||
|
if (file.isFile) {
|
||||||
|
this.classLoader.load(file.path.removePrefix(base.path).removePrefix("/"), FileInputStream(file).readAllBytes())
|
||||||
|
}
|
||||||
|
if (file.isDirectory) {
|
||||||
|
for (sub in file.listFiles()!!) {
|
||||||
|
scanDirectory(base, sub)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun MinosoftMod.processDirectory(file: File) {
|
private fun MinosoftMod.processDirectory(file: File) {
|
||||||
TODO("Directory")
|
val files = file.listFiles()!!
|
||||||
|
val assets = DirectoryAssetsManager(file.path)
|
||||||
|
assets.load(CountUpAndDownLatch(0))
|
||||||
|
|
||||||
|
for (sub in files) {
|
||||||
|
if (sub.isDirectory && sub.name == "assets") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (sub.isFile && sub.name == MANIFEST) {
|
||||||
|
manifest = FileInputStream(sub).readJson()
|
||||||
|
}
|
||||||
|
scanDirectory(file, sub)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.assetsManager = assets
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun MinosoftMod.processJar(file: File) {
|
private fun MinosoftMod.processJar(file: File) {
|
||||||
@ -78,7 +105,7 @@ object ModLoader {
|
|||||||
|
|
||||||
if (entry.name.endsWith(".class") && entry is JarEntry) {
|
if (entry.name.endsWith(".class") && entry is JarEntry) {
|
||||||
this.classLoader.load(entry, stream)
|
this.classLoader.load(entry, stream)
|
||||||
} else if (entry.name == MANFIEST) {
|
} else if (entry.name == MANIFEST) {
|
||||||
manifest = stream.readJson(false)
|
manifest = stream.readJson(false)
|
||||||
} else {
|
} else {
|
||||||
assets.push(entry.name, stream)
|
assets.push(entry.name, stream)
|
||||||
|
@ -20,5 +20,5 @@ data class ModManifest(
|
|||||||
val uuid: UUID,
|
val uuid: UUID,
|
||||||
val version: String,
|
val version: String,
|
||||||
val main: String,
|
val main: String,
|
||||||
val authors: List<String>? = emptyList(),
|
val authors: List<String> = emptyList(),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user