Improve handling npc sprites

This commit is contained in:
Phillip Thelen 2024-04-02 15:32:16 +02:00
parent 8b4af8272f
commit 31ec2652de
3 changed files with 20 additions and 2 deletions

View file

@ -36,7 +36,7 @@ class AppConfigManager(contentRepository: ContentRepository?) : com.habitrpg.com
private val remoteConfig = FirebaseRemoteConfig.getInstance()
fun shopSpriteSuffix(): String? {
return worldState?.npcImageSuffix
return worldState?.findNpcImageSuffix()
}
fun maxChatLength(): Long {

View file

@ -21,4 +21,19 @@ open class WorldState : RealmObject(), BaseObject {
@SerializedName("currentEventList")
var events: RealmList<WorldStateEvent> = RealmList()
fun findNpcImageSuffix(): String? {
if (!npcImageSuffix.isNullOrBlank()) {
return npcImageSuffix
} else if (!currentEvent?.npcImageSuffix.isNullOrBlank()) {
return currentEvent?.npcImageSuffix
} else {
for (event in events) {
if (!event.npcImageSuffix.isNullOrBlank()) {
return event.npcImageSuffix
}
}
}
return null
}
}

View file

@ -21,7 +21,10 @@ class NPCBannerView(context: Context, attrs: AttributeSet?) : FrameLayout(contex
var shopSpriteSuffix: String? = null
set(value) {
field = if (value.isNullOrEmpty() || value.startsWith("_")) {
field = if (value.isNullOrEmpty()) {
""
} else if (value.startsWith("_")) {
value
} else {
"_$value"