mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
more score tests
This commit is contained in:
parent
46f69edb09
commit
1a55742f8f
@ -23,6 +23,6 @@ object BillbaordTextTestUtil {
|
|||||||
fun BillboardTextFeature.assertEmpty() {
|
fun BillboardTextFeature.assertEmpty() {
|
||||||
val text = this.text ?: return
|
val text = this.text ?: return
|
||||||
if (text.length == 0) return
|
if (text.length == 0) return
|
||||||
throw AssertionError("Text is empty but should not be!")
|
throw AssertionError("Text is not empty but should be!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import de.bixilon.minosoft.data.entities.entities.monster.Zombie
|
|||||||
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
||||||
import de.bixilon.minosoft.data.entities.entities.vehicle.boat.Boat
|
import de.bixilon.minosoft.data.entities.entities.vehicle.boat.Boat
|
||||||
import de.bixilon.minosoft.data.registries.entities.EntityFactory
|
import de.bixilon.minosoft.data.registries.entities.EntityFactory
|
||||||
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
import de.bixilon.minosoft.data.text.TextComponent
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.EntityRendererTestUtil.create
|
import de.bixilon.minosoft.gui.rendering.entities.EntityRendererTestUtil.create
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertEmpty
|
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertEmpty
|
||||||
@ -46,7 +47,7 @@ class EntityNameFeatureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun EntityNameFeature.customName(name: Any?) {
|
private fun EntityNameFeature.customName(name: Any?) {
|
||||||
renderer.entity.data[Entity.CUSTOM_NAME_DATA] = name
|
renderer.entity.data[Entity.CUSTOM_NAME_DATA] = ChatComponent.of(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun EntityNameFeature.isNameVisible(visible: Boolean) {
|
private fun EntityNameFeature.isNameVisible(visible: Boolean) {
|
||||||
@ -89,9 +90,10 @@ class EntityNameFeatureTest {
|
|||||||
fun `correct animal name`() {
|
fun `correct animal name`() {
|
||||||
val name = create(Pig)
|
val name = create(Pig)
|
||||||
val text = TextComponent("Pepper:")
|
val text = TextComponent("Pepper:")
|
||||||
|
name.isNameVisible(true)
|
||||||
name.customName(text)
|
name.customName(text)
|
||||||
name.updateName()
|
name.updateName()
|
||||||
assertSame(name.text, text) // TODO: verify visibility
|
assertSame(name.text, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun `animal with custom name visible`() {
|
fun `animal with custom name visible`() {
|
||||||
@ -124,7 +126,7 @@ class EntityNameFeatureTest {
|
|||||||
name.customName("Pepper")
|
name.customName("Pepper")
|
||||||
name.setTargeted(distance = 10.0)
|
name.setTargeted(distance = 10.0)
|
||||||
name.updateName()
|
name.updateName()
|
||||||
name.assertText()
|
name.assertEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun `remote player entity`() {
|
fun `remote player entity`() {
|
||||||
@ -241,8 +243,18 @@ class EntityNameFeatureTest {
|
|||||||
name.assertEmpty()
|
name.assertEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun `profile disabled`() {
|
||||||
|
val name = create(Pig)
|
||||||
|
name.renderer.renderer.profile.features.name.enabled = false
|
||||||
|
name.customName("Pepper")
|
||||||
|
name.isNameVisible(true)
|
||||||
|
name.updateName()
|
||||||
|
name.assertEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: targeted mob, invisible zombie
|
// TODO: targeted mob, invisible zombie
|
||||||
// TODO: mob, armor stand, player (local/remote), pig, non living (boat?)
|
// TODO: mob, armor stand, player (local/remote), pig, non living (boat?)
|
||||||
// TODO: isInvisible, teams (with team nametag visibility),
|
// TODO: isInvisible, teams (with team nametag visibility),
|
||||||
// TODO: profile
|
// TODO: profile
|
||||||
|
// TODO: render distance, sneaking
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,24 @@ package de.bixilon.minosoft.gui.rendering.entities.feature.text.name
|
|||||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
||||||
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
||||||
|
import de.bixilon.minosoft.data.scoreboard.ScoreboardObjective
|
||||||
|
import de.bixilon.minosoft.data.scoreboard.ScoreboardPositions
|
||||||
|
import de.bixilon.minosoft.data.scoreboard.ScoreboardScore
|
||||||
|
import de.bixilon.minosoft.data.text.BaseComponent
|
||||||
|
import de.bixilon.minosoft.data.text.TextComponent
|
||||||
|
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.EntityRendererTestUtil.create
|
import de.bixilon.minosoft.gui.rendering.entities.EntityRendererTestUtil.create
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertEmpty
|
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertEmpty
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertText
|
||||||
|
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillboardTextFeature
|
||||||
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.player.PlayerRenderer
|
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.player.PlayerRenderer
|
||||||
|
import org.testng.Assert.assertEquals
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
@Test(groups = ["entities", "rendering"])
|
@Test(groups = ["entities", "rendering"])
|
||||||
class EntityScoreFeatureTest {
|
class EntityScoreFeatureTest {
|
||||||
private val updateScore = EntityScoreFeature::class.java.getDeclaredMethod("updateScore").apply { isAccessible = true }
|
private val updateScore = EntityScoreFeature::class.java.getDeclaredMethod("updateScore").apply { isAccessible = true }
|
||||||
|
private val updateNameOffset = EntityScoreFeature::class.java.getDeclaredMethod("updateNameOffset").apply { isAccessible = true }
|
||||||
|
|
||||||
private fun createScore(): EntityScoreFeature {
|
private fun createScore(): EntityScoreFeature {
|
||||||
val renderer = create().create(RemotePlayerEntity).unsafeCast<PlayerRenderer<*>>()
|
val renderer = create().create(RemotePlayerEntity).unsafeCast<PlayerRenderer<*>>()
|
||||||
@ -36,12 +46,61 @@ class EntityScoreFeatureTest {
|
|||||||
updateScore.invoke(this)
|
updateScore.invoke(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun EntityScoreFeature.updateNameOffset() {
|
||||||
|
updateNameOffset.invoke(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun EntityScoreFeature.setScore() {
|
||||||
|
val renderer = this.renderer.unsafeCast<PlayerRenderer<*>>()
|
||||||
|
val objective = ScoreboardObjective("name", TextComponent("Score").color(ChatColors.LIGHT_PURPLE))
|
||||||
|
renderer.renderer.connection.scoreboard.positions[ScoreboardPositions.BELOW_NAME] = objective
|
||||||
|
objective.scores[renderer.entity.additional.name] = ScoreboardScore("name", objective, null, 1)
|
||||||
|
renderer.renderer.features.score.update()
|
||||||
|
}
|
||||||
|
|
||||||
fun `player without score`() {
|
fun `player without score`() {
|
||||||
val score = createScore()
|
val score = createScore()
|
||||||
score.updateScore()
|
score.updateScore()
|
||||||
score.assertEmpty()
|
score.assertEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun `player with score`() {
|
||||||
|
val score = createScore()
|
||||||
|
score.setScore()
|
||||||
|
score.updateScore()
|
||||||
|
score.assertText()
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: teams, invisibility, score, profile, correct text
|
fun `name offset without score`() {
|
||||||
|
val score = createScore()
|
||||||
|
score.setScore()
|
||||||
|
score.updateScore()
|
||||||
|
score.updateNameOffset()
|
||||||
|
assertEquals(score.renderer.name.offset, BillboardTextFeature.DEFAULT_OFFSET)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `name offset with score`() {
|
||||||
|
val score = createScore()
|
||||||
|
score.setScore()
|
||||||
|
score.updateScore()
|
||||||
|
score.updateNameOffset()
|
||||||
|
assertEquals(score.renderer.name.offset, BillboardTextFeature.DEFAULT_OFFSET + 0.24f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `profile disabled`() {
|
||||||
|
val score = createScore()
|
||||||
|
score.renderer.renderer.profile.features.score.enabled = false
|
||||||
|
score.setScore()
|
||||||
|
score.updateScore()
|
||||||
|
score.assertEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `correct text`() {
|
||||||
|
val score = createScore()
|
||||||
|
score.setScore()
|
||||||
|
score.updateScore()
|
||||||
|
assertEquals(score.text, BaseComponent("1", " ", TextComponent("Score").color(ChatColors.LIGHT_PURPLE)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: teams, invisibility
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* Minosoft
|
||||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
* Copyright (C) 2020-2023 Moritz Zwerger
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
@ -19,8 +19,8 @@ import de.bixilon.minosoft.protocol.packets.s2c.play.scoreboard.objective.Create
|
|||||||
|
|
||||||
class ScoreboardObjective(
|
class ScoreboardObjective(
|
||||||
val name: String,
|
val name: String,
|
||||||
var displayName: ChatComponent,
|
var displayName: ChatComponent? = null,
|
||||||
var unit: CreateObjectiveS2CP.ObjectiveUnits,
|
var unit: CreateObjectiveS2CP.ObjectiveUnits = CreateObjectiveS2CP.ObjectiveUnits.INTEGER,
|
||||||
) {
|
) {
|
||||||
val scores: LockMap<String, ScoreboardScore> = lockMapOf()
|
val scores: LockMap<String, ScoreboardScore> = lockMapOf()
|
||||||
|
|
||||||
|
@ -31,12 +31,16 @@ class EntityScoreFeature(renderer: PlayerRenderer<*>) : BillboardTextFeature(ren
|
|||||||
this.delta += delta
|
this.delta += delta
|
||||||
if (this.delta >= UPDATE_INTERVAL) {
|
if (this.delta >= UPDATE_INTERVAL) {
|
||||||
updateScore()
|
updateScore()
|
||||||
renderer.name.offset = if (this.text != null) NAME_OFFSET else DEFAULT_OFFSET
|
updateNameOffset()
|
||||||
this.delta = 0.0f
|
this.delta = 0.0f
|
||||||
}
|
}
|
||||||
super.update(millis, delta)
|
super.update(millis, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateNameOffset() {
|
||||||
|
renderer.name.offset = if (this.text != null) NAME_OFFSET else DEFAULT_OFFSET
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateScore() {
|
private fun updateScore() {
|
||||||
if (!renderScore()) {
|
if (!renderScore()) {
|
||||||
this.text = null
|
this.text = null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user