fix reference font provider

This commit is contained in:
Bixilon 2023-06-16 16:11:34 +02:00
parent 6b417993a8
commit d9e26b1b86
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 10 additions and 20 deletions

View File

@ -44,15 +44,16 @@ open class ResourceLocation(
// 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 {
if (path.startsWith(prefix)) return this
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.
*/

View File

@ -31,7 +31,7 @@ import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
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 providersRaw = fontIndex["providers"].listCast<Map<String, Any>>()!!

View File

@ -14,28 +14,17 @@
package de.bixilon.minosoft.gui.rendering.font.types
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.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.FontTypes
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> {
override val identifier = minecraft("reference")
override fun build(context: RenderContext, data: JsonObject): FontType? {
val id = data["id"]?.toResourceLocation()?.prefix("font/") ?: throw IllegalArgumentException("id missing!")
val factory = FontTypes[id]
if (factory == null) {
Log.log(LogMessageType.ASSETS, LogLevels.WARN) { "Unknown font type $id" }
return null
}
return factory.build(context, context.connection.assetsManager[id].readJsonObject())
val index = data["id"]?.toResourceLocation()?.prefix("font/")?.suffix(".json") ?: throw IllegalArgumentException("id missing!")
return FontLoader.load(context, index, null)
}
}