Add more screens at once
[no changelog]
This commit is contained in:
@@ -268,6 +268,9 @@ avoid collisions with other texture packs that might use the same id for a gui.
|
|||||||
The `predicate` is just a normal [predicate](#predicates). This one does not support the vanilla predicates. You can
|
The `predicate` is just a normal [predicate](#predicates). This one does not support the vanilla predicates. You can
|
||||||
still use vanilla predicates in the resolved model, but this will not allow you to fall back to other global overrides.
|
still use vanilla predicates in the resolved model, but this will not allow you to fall back to other global overrides.
|
||||||
|
|
||||||
|
The `screen` specifies which screens your override will work on. This is purely for performance reasons, your filter
|
||||||
|
should work purely based on predicates if possible. You can specify multiply screens by using a json array.
|
||||||
|
|
||||||
### Global item texture Screens
|
### Global item texture Screens
|
||||||
|
|
||||||
In order to improve performance not all overrides are tested all the time. Instead you can prefilter by the screen that
|
In order to improve performance not all overrides are tested all the time. Instead you can prefilter by the screen that
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import moe.nea.firmament.events.subscription.SubscriptionOwner
|
|||||||
import moe.nea.firmament.features.FirmamentFeature
|
import moe.nea.firmament.features.FirmamentFeature
|
||||||
import moe.nea.firmament.util.IdentifierSerializer
|
import moe.nea.firmament.util.IdentifierSerializer
|
||||||
import moe.nea.firmament.util.MC
|
import moe.nea.firmament.util.MC
|
||||||
|
import moe.nea.firmament.util.json.SingletonSerializableList
|
||||||
import moe.nea.firmament.util.runNull
|
import moe.nea.firmament.util.runNull
|
||||||
|
|
||||||
object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalTextures.CustomGuiTextureOverride>(),
|
object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalTextures.CustomGuiTextureOverride>(),
|
||||||
@@ -46,7 +47,7 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GlobalItemOverride(
|
data class GlobalItemOverride(
|
||||||
val screen: Identifier,
|
val screen: @Serializable(SingletonSerializableList::class) List<Identifier>,
|
||||||
val model: Identifier,
|
val model: Identifier,
|
||||||
val predicate: FirmamentModelPredicate,
|
val predicate: FirmamentModelPredicate,
|
||||||
)
|
)
|
||||||
@@ -107,7 +108,8 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val byGuiClass = overrideResources.groupBy { it.screen }
|
val byGuiClass = overrideResources.flatMap { override -> override.screen.toSet().map { it to override } }
|
||||||
|
.groupBy { it.first }
|
||||||
val guiClasses = byGuiClass.entries
|
val guiClasses = byGuiClass.entries
|
||||||
.mapNotNull {
|
.mapNotNull {
|
||||||
val key = it.key
|
val key = it.key
|
||||||
@@ -123,7 +125,7 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText
|
|||||||
logger.error("Failed to load screen filter at $key", ex)
|
logger.error("Failed to load screen filter at $key", ex)
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
}
|
}
|
||||||
ItemOverrideCollection(screenFilter, it.value)
|
ItemOverrideCollection(screenFilter, it.value.map { it.second })
|
||||||
}
|
}
|
||||||
logger.info("Loaded ${overrideResources.size} global item overrides")
|
logger.info("Loaded ${overrideResources.size} global item overrides")
|
||||||
return CustomGuiTextureOverride(guiClasses)
|
return CustomGuiTextureOverride(guiClasses)
|
||||||
@@ -131,14 +133,14 @@ object CustomGlobalTextures : SinglePreparationResourceReloader<CustomGlobalText
|
|||||||
|
|
||||||
var guiClassOverrides = CustomGuiTextureOverride(listOf())
|
var guiClassOverrides = CustomGuiTextureOverride(listOf())
|
||||||
|
|
||||||
var matchingOverrides: List<ItemOverrideCollection> = listOf()
|
var matchingOverrides: Set<ItemOverrideCollection> = setOf()
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
fun onOpenGui(event: ScreenChangeEvent) {
|
fun onOpenGui(event: ScreenChangeEvent) {
|
||||||
val newTitle = event.new?.title
|
val newTitle = event.new?.title
|
||||||
matchingOverrides =
|
matchingOverrides =
|
||||||
if (newTitle == null) listOf()
|
if (newTitle == null) setOf()
|
||||||
else guiClassOverrides.classes.filter { it.screenFilter.title.matches(newTitle) }
|
else guiClassOverrides.classes.filterTo(mutableSetOf()) { it.screenFilter.title.matches(newTitle) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package moe.nea.firmament.util.json
|
||||||
|
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.builtins.ListSerializer
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
import kotlinx.serialization.json.JsonArray
|
||||||
|
import kotlinx.serialization.json.JsonDecoder
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
|
||||||
|
class SingletonSerializableList<T>(val child: KSerializer<T>) : KSerializer<List<T>> {
|
||||||
|
override val descriptor: SerialDescriptor
|
||||||
|
get() = JsonElement.serializer().descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): List<T> {
|
||||||
|
decoder as JsonDecoder
|
||||||
|
val list = JsonElement.serializer().deserialize(decoder)
|
||||||
|
if (list is JsonArray) {
|
||||||
|
return list.map {
|
||||||
|
decoder.json.decodeFromJsonElement(child, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return listOf(decoder.json.decodeFromJsonElement(child, list))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: List<T>) {
|
||||||
|
ListSerializer(child).serialize(encoder, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user