Skip to content

Commit

Permalink
add .assets file for fallback assets root, provide fallback if root a…
Browse files Browse the repository at this point in the history
…ssets not found
  • Loading branch information
Bixilon committed Oct 11, 2023
1 parent 233adde commit 4850cb0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ 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


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
Expand Down
Empty file.
Empty file.

0 comments on commit 4850cb0

Please sign in to comment.