Archive incari-client (client, 26.3, clean)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# customscoreboard: Custom Scoreboard
|
||||
|
||||
Lets you place and scale the server's scoreboard sidebar like any HUD element. The editor shows a sample when the server sends none. ([ADR 0050](../../docs/adr/0050-first-modules-game-view.md))
|
||||
|
||||
| Setting | Kind | Default |
|
||||
| --- | --- | --- |
|
||||
| HUD: Scoreboard | position and scale | right, a unit in, 1x (the game's place) |
|
||||
|
||||
```sh
|
||||
./gradlew :features:customscoreboard:check
|
||||
```
|
||||
@@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
}
|
||||
|
||||
// Custom Scoreboard (ADR 0050): the server's scoreboard sidebar placed and sized by the player.
|
||||
// A feature module: it sees the module framework and nothing else.
|
||||
dependencies {
|
||||
api(project(":framework"))
|
||||
|
||||
testImplementation(testFixtures(project(":framework")))
|
||||
testImplementation(platform(libs.junit.bom))
|
||||
testImplementation(libs.junit.jupiter)
|
||||
testImplementation(libs.assertj)
|
||||
testImplementation(libs.archunit)
|
||||
testRuntimeOnly(libs.junit.launcher)
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package incari.features.customscoreboard;
|
||||
|
||||
import incari.framework.Category;
|
||||
import incari.framework.Module;
|
||||
import incari.framework.game.GamePart;
|
||||
import incari.framework.hud.Anchor;
|
||||
import incari.framework.hud.GamePartElement;
|
||||
|
||||
/**
|
||||
* Custom Scoreboard: the scoreboard sidebar a server sends, wherever the player puts it and at the
|
||||
* size they choose. The game draws the sidebar as it always does (its lines, its numbers, the
|
||||
* client's look); the module only takes over where ({@link GamePartElement}), so it's placed with
|
||||
* the HUD editor like any other element. Nothing shows while the server sends no sidebar.
|
||||
*/
|
||||
public final class CustomScoreboard extends Module {
|
||||
|
||||
/** Custom Scoreboard, off until the player turns it on. */
|
||||
public CustomScoreboard() {
|
||||
super(
|
||||
"customscoreboard",
|
||||
"Custom Scoreboard",
|
||||
"Move and resize the scoreboard a server shows, with the HUD editor.",
|
||||
Category.HUD);
|
||||
// The game's place: on the right, a unit in, about halfway down.
|
||||
hud(new GamePartElement(GamePart.SCOREBOARD, "sidebar", Anchor.RIGHT, 1, 0));
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/** Custom Scoreboard (ADR 0050): the server's scoreboard sidebar placed and sized by the player. */
|
||||
@NullMarked
|
||||
package incari.features.customscoreboard;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package incari.features.customscoreboard;
|
||||
|
||||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
||||
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
import com.tngtech.archunit.junit.AnalyzeClasses;
|
||||
import com.tngtech.archunit.junit.ArchTest;
|
||||
import com.tngtech.archunit.lang.ArchRule;
|
||||
|
||||
/** A feature sees the module framework and the JDK's basics: no game, platform or other feature. */
|
||||
@AnalyzeClasses(packages = "incari.features.customscoreboard", importOptions = ImportOption.DoNotIncludeTests.class)
|
||||
class BoundaryTest {
|
||||
|
||||
@ArchTest
|
||||
static final ArchRule onlyTheFramework = classes()
|
||||
.should()
|
||||
.onlyDependOnClassesThat()
|
||||
.resideInAnyPackage(
|
||||
"java.lang..",
|
||||
"java.util..",
|
||||
"org.jspecify..",
|
||||
"incari.framework..",
|
||||
"incari.features.customscoreboard..");
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package incari.features.customscoreboard;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import incari.framework.game.GamePart;
|
||||
import incari.framework.hud.Anchor;
|
||||
import incari.framework.hud.HudElement;
|
||||
import incari.framework.testing.TestGame;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CustomScoreboardTest {
|
||||
|
||||
private final CustomScoreboard module = new CustomScoreboard();
|
||||
private final TestGame game = new TestGame(module);
|
||||
private final HudElement sidebar = module.hudElements().get(0);
|
||||
|
||||
@Test
|
||||
void takesTheSidebarFromTheGameOnlyWhileOn() {
|
||||
assertThat(game.system().holds(GamePart.SCOREBOARD)).isFalse();
|
||||
module.setEnabled(true);
|
||||
assertThat(game.system().holds(GamePart.SCOREBOARD)).isTrue();
|
||||
module.setEnabled(false);
|
||||
assertThat(game.system().holds(GamePart.SCOREBOARD)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void drawsTheSidebarWhereTheGameWouldByDefault() {
|
||||
module.setEnabled(true);
|
||||
game.parts.put(GamePart.SCOREBOARD, new int[] {80, 60});
|
||||
// Right side, a unit in, middle of a 320 by 240 screen.
|
||||
assertThat(game.drawHud().drawn).containsExactly("part SCOREBOARD 80x60 at 239,90");
|
||||
}
|
||||
|
||||
@Test
|
||||
void drawsItWhereThePlayerPutItAtTheirScale() {
|
||||
module.setEnabled(true);
|
||||
game.parts.put(GamePart.SCOREBOARD, new int[] {80, 60});
|
||||
sidebar.anchor().set(Anchor.TOP_LEFT);
|
||||
sidebar.offsetX().set(4);
|
||||
sidebar.offsetY().set(10);
|
||||
sidebar.scale().set(0.5F);
|
||||
assertThat(game.drawHud().drawn).containsExactly("part SCOREBOARD 40x30 at 4,10");
|
||||
}
|
||||
|
||||
@Test
|
||||
void nothingWithoutASidebarButASampleInTheEditor() {
|
||||
module.setEnabled(true);
|
||||
assertThat(game.drawHud().drawn).isEmpty();
|
||||
assertThat(game.drawHud(true).drawn).containsExactly("part SCOREBOARD 60x40 at 259,100");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user