mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
crash if can not find theme
This commit is contained in:
parent
1597ada864
commit
b3ce614120
@ -9,7 +9,7 @@ Assets are [Game Files](https://wiki.vg/Game_files). For example:
|
||||
- Language Files
|
||||
- Block/Item models
|
||||
- (Icons)
|
||||
- Maybe more, but not relevant at this time´```
|
||||
- Maybe more, but not relevant at this time
|
||||
|
||||
## Index assets
|
||||
|
||||
|
@ -61,6 +61,9 @@ interface AssetsManager {
|
||||
*/
|
||||
fun unload()
|
||||
|
||||
operator fun contains(path: ResourceLocation): Boolean
|
||||
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_ASSETS_PREFIX = "assets"
|
||||
}
|
||||
|
@ -81,4 +81,8 @@ class DirectoryAssetsManager(
|
||||
}
|
||||
return FileUtil.safeReadFile(path.filePath, false)
|
||||
}
|
||||
|
||||
override fun contains(path: ResourceLocation): Boolean {
|
||||
return path in assets
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import de.bixilon.kutil.latch.CountUpAndDownLatch
|
||||
import de.bixilon.minosoft.assets.AssetsManager
|
||||
import de.bixilon.minosoft.assets.util.FileAssetsUtil.toAssetName
|
||||
import de.bixilon.minosoft.assets.util.FileUtil.readJson
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.util.zip.ZipInputStream
|
||||
@ -31,6 +32,9 @@ class ZipAssetsManager(
|
||||
val prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX,
|
||||
) : FileAssetsManager(canUnload) {
|
||||
|
||||
constructor(file: File, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX) : this(ZipInputStream(FileInputStream(file)), canUnload, prefix)
|
||||
constructor(path: String, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX) : this(File(path), canUnload, prefix)
|
||||
|
||||
override fun load(latch: CountUpAndDownLatch) {
|
||||
check(!loaded) { "Already loaded!" }
|
||||
|
||||
@ -56,6 +60,7 @@ class ZipAssetsManager(
|
||||
loaded = true
|
||||
}
|
||||
|
||||
constructor(file: File, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX) : this(ZipInputStream(FileInputStream(file)), canUnload, prefix)
|
||||
constructor(path: String, canUnload: Boolean = true, prefix: String = AssetsManager.DEFAULT_ASSETS_PREFIX) : this(File(path), canUnload, prefix)
|
||||
override fun contains(path: ResourceLocation): Boolean {
|
||||
return path in assets
|
||||
}
|
||||
}
|
||||
|
@ -139,6 +139,13 @@ class JarAssetsManager(
|
||||
loaded = false
|
||||
}
|
||||
|
||||
override fun contains(path: ResourceLocation): Boolean {
|
||||
if (path.namespace != ProtocolDefinition.DEFAULT_NAMESPACE) {
|
||||
return false
|
||||
}
|
||||
return path.path in jarAssets
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val REQUIRED_FILE_PREFIXES = arrayOf(
|
||||
"blockstates/",
|
||||
|
@ -150,4 +150,8 @@ class IndexAssetsManager(
|
||||
override fun getOrNull(path: ResourceLocation): InputStream? {
|
||||
return FileAssetsUtil.readVerified(assets[path]?.hash ?: return null, verify, hashType = FileAssetsUtil.HashTypes.SHA1) ?: throw AssetCorruptedError(path)
|
||||
}
|
||||
|
||||
override fun contains(path: ResourceLocation): Boolean {
|
||||
return path in assets
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +85,18 @@ class PriorityAssetsManager(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun contains(path: ResourceLocation): Boolean {
|
||||
for ((namespace, managers) in managers) {
|
||||
if (path.namespace != namespace) {
|
||||
continue
|
||||
}
|
||||
for (manager in managers) {
|
||||
if (path in manager) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.eros.controller.EmbeddedJavaFXController
|
||||
import de.bixilon.minosoft.gui.eros.controller.JavaFXController
|
||||
import de.bixilon.minosoft.gui.eros.controller.JavaFXWindowController
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import javafx.application.HostServices
|
||||
import javafx.application.Platform
|
||||
import javafx.css.StyleableProperty
|
||||
@ -51,6 +52,8 @@ object JavaFXUtil {
|
||||
lateinit var BIXILON_LOGO: Group
|
||||
private var watchingTheme = false
|
||||
|
||||
val THEME_ASSETS_MANAGER = Minosoft.MINOSOFT_ASSETS_MANAGER
|
||||
|
||||
private fun startThemeWatcher() {
|
||||
if (watchingTheme) {
|
||||
return
|
||||
@ -62,8 +65,7 @@ object JavaFXUtil {
|
||||
stage ?: continue
|
||||
stage.scene.stylesheets.clear()
|
||||
stage.scene.stylesheets.add(DEFAULT_STYLE)
|
||||
val theme = ErosProfileManager.selected.theme.theme
|
||||
stage.scene.stylesheets.add("resource:minosoft:eros/themes/$theme.css")
|
||||
stage.scene.stylesheets.add(getThemeURL(it))
|
||||
}
|
||||
}
|
||||
watchingTheme = true
|
||||
@ -78,7 +80,7 @@ object JavaFXUtil {
|
||||
|
||||
stage.scene.stylesheets.add(DEFAULT_STYLE)
|
||||
val theme = ErosProfileManager.selected.theme.theme
|
||||
stage.scene.stylesheets.add("resource:minosoft:eros/themes/$theme.css")
|
||||
stage.scene.stylesheets.add(getThemeURL(theme))
|
||||
|
||||
stages.cleanup()
|
||||
stages.add(stage)
|
||||
@ -200,4 +202,13 @@ object JavaFXUtil {
|
||||
this.requestFocus()
|
||||
this.toFront()
|
||||
}
|
||||
|
||||
private fun getThemeURL(name: String): String {
|
||||
val path = "minosoft:eros/themes/$name.css"
|
||||
if (path.toResourceLocation() !in THEME_ASSETS_MANAGER) {
|
||||
throw Exception("Can not load theme: $name")
|
||||
}
|
||||
|
||||
return "resource:$path"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user