mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 18:34:56 -04:00
fix reference font provider
This commit is contained in:
parent
6b417993a8
commit
d9e26b1b86
@ -44,15 +44,16 @@ open class ResourceLocation(
|
|||||||
// throw IllegalArgumentException("Path '$path' is not allowed!")
|
// throw IllegalArgumentException("Path '$path' is not allowed!")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a prefix to the path of this resource location.
|
|
||||||
*
|
|
||||||
* @param prefix The prefix to add
|
|
||||||
*/
|
|
||||||
fun prefix(prefix: String): ResourceLocation {
|
fun prefix(prefix: String): ResourceLocation {
|
||||||
|
if (path.startsWith(prefix)) return this
|
||||||
return ResourceLocation(namespace, prefix + path)
|
return ResourceLocation(namespace, prefix + path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun suffix(suffix: String): ResourceLocation {
|
||||||
|
if (path.endsWith(suffix)) return this
|
||||||
|
return ResourceLocation(namespace, path + suffix)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the namespace is "minecraft", the path is returned. Otherwise, the full string is returned.
|
* @return If the namespace is "minecraft", the path is returned. Otherwise, the full string is returned.
|
||||||
*/
|
*/
|
||||||
|
@ -31,7 +31,7 @@ import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
|
|||||||
object FontLoader {
|
object FontLoader {
|
||||||
|
|
||||||
|
|
||||||
fun load(context: RenderContext, fontIndex: ResourceLocation, latch: AbstractLatch): Font? {
|
fun load(context: RenderContext, fontIndex: ResourceLocation, latch: AbstractLatch?): Font? {
|
||||||
val fontIndex = context.connection.assetsManager.getOrNull(fontIndex)?.readJsonObject() ?: return null
|
val fontIndex = context.connection.assetsManager.getOrNull(fontIndex)?.readJsonObject() ?: return null
|
||||||
|
|
||||||
val providersRaw = fontIndex["providers"].listCast<Map<String, Any>>()!!
|
val providersRaw = fontIndex["providers"].listCast<Map<String, Any>>()!!
|
||||||
|
@ -14,28 +14,17 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering.font.types
|
package de.bixilon.minosoft.gui.rendering.font.types
|
||||||
|
|
||||||
import de.bixilon.kutil.json.JsonObject
|
import de.bixilon.kutil.json.JsonObject
|
||||||
import de.bixilon.minosoft.assets.util.InputStreamUtil.readJsonObject
|
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
import de.bixilon.minosoft.gui.rendering.RenderContext
|
import de.bixilon.minosoft.gui.rendering.RenderContext
|
||||||
|
import de.bixilon.minosoft.gui.rendering.font.loader.FontLoader
|
||||||
import de.bixilon.minosoft.gui.rendering.font.types.factory.FontTypeFactory
|
import de.bixilon.minosoft.gui.rendering.font.types.factory.FontTypeFactory
|
||||||
import de.bixilon.minosoft.gui.rendering.font.types.factory.FontTypes
|
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
|
||||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
|
||||||
|
|
||||||
object ReferenceFontType : FontTypeFactory<FontType> {
|
object ReferenceFontType : FontTypeFactory<FontType> {
|
||||||
override val identifier = minecraft("reference")
|
override val identifier = minecraft("reference")
|
||||||
|
|
||||||
override fun build(context: RenderContext, data: JsonObject): FontType? {
|
override fun build(context: RenderContext, data: JsonObject): FontType? {
|
||||||
val id = data["id"]?.toResourceLocation()?.prefix("font/") ?: throw IllegalArgumentException("id missing!")
|
val index = data["id"]?.toResourceLocation()?.prefix("font/")?.suffix(".json") ?: throw IllegalArgumentException("id missing!")
|
||||||
val factory = FontTypes[id]
|
return FontLoader.load(context, index, null)
|
||||||
if (factory == null) {
|
|
||||||
Log.log(LogMessageType.ASSETS, LogLevels.WARN) { "Unknown font type $id" }
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return factory.build(context, context.connection.assetsManager[id].readJsonObject())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user