add .assets file for fallback assets root, provide fallback if root assets not found

This commit is contained in:
Moritz Zwerger 2023-10-11 23:07:51 +02:00
parent 233addebdd
commit 4850cb09c1
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 5 additions and 2 deletions

View File

@ -19,7 +19,6 @@ import de.bixilon.minosoft.assets.resource.ResourceAssetsManager
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
import java.io.FileNotFoundException
import java.net.URLDecoder
import java.nio.charset.StandardCharsets
@ -27,7 +26,11 @@ import java.nio.charset.StandardCharsets
object ResourcesAssetsUtil {
fun create(clazz: Class<*>, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX): AssetsManager {
val rootResources = clazz.classLoader.getResource(prefix) ?: throw FileNotFoundException("Can not find assets root for $clazz")
val rootResources = clazz.classLoader.getResource(prefix) ?: clazz.classLoader.getResource("$prefix/.assets")
if (rootResources == null) {
Log.log(LogMessageType.OTHER, LogLevels.FATAL) { "Can not find \"$prefix\" assets root for $clazz" }
return ResourceAssetsManager(clazz, prefix)
}
return when (rootResources.protocol) {
"file" -> DirectoryAssetsManager(rootResources.path.removeSuffix("/").removeSuffix(prefix), canUnload, prefix) // Read them directly from the folder

View File