Archive incari-client (client, 26.3, clean)

This commit is contained in:
2026-11-28 00:54:38 -06:00
parent 7a6174687f
commit 12838e838c
2383 changed files with 280266 additions and 0 deletions
@@ -0,0 +1,100 @@
package incari.features.fpsdisplay;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.TextElement;
import incari.framework.hud.Tone;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import org.jspecify.annotations.Nullable;
/** FPS Display: the frames drawn in the last second, as the debug screen counts them. */
public final class FpsDisplay extends Module {
/** How the count is written. */
public enum Format {
/** "120 FPS". */
AFTER("120 FPS"),
/** "FPS: 120". */
BEFORE("FPS: 120"),
/** "120". */
NUMBER("120");
private final String label;
Format(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final ChoiceSetting<Format> format = settings()
.choice("format", "Format", Format.values(), Format.AFTER, Format::label)
.describedAs("How the FPS is shown.");
final BooleanSetting speedColors = settings()
.bool("speed-colors", "Color by speed", false)
.describedAs("Green from 60 frames a second, amber from 30, red below.");
/** FPS Display, off until the player turns it on. */
public FpsDisplay() {
super("fpsdisplay", "FPS Display", "Shows how many frames a second the game draws.", Category.HUD);
hud(new Counter());
}
/** "120 FPS" in {@code format}. */
static String text(Format format, int fps) {
return switch (format) {
case AFTER -> fps + " FPS";
case BEFORE -> "FPS: " + fps;
case NUMBER -> Integer.toString(fps);
};
}
/** The count, on the glass. */
private final class Counter extends TextElement {
private int cachedFps = -1;
private @Nullable Format cachedFormat;
private String cached = "";
Counter() {
super("fps", "FPS", Anchor.TOP_LEFT, 2, 14);
}
@Override
protected @Nullable String text(HudCanvas canvas) {
int fps = system().game().fps();
Format chosen = format.get();
if (fps != cachedFps || chosen != cachedFormat) {
cachedFps = fps;
cachedFormat = chosen;
cached = FpsDisplay.text(chosen, fps);
}
return cached;
}
@Override
protected @Nullable String widest() {
return switch (format.get()) {
case AFTER -> "000 FPS";
case BEFORE -> "FPS: 000";
case NUMBER -> "000";
};
}
@Override
protected Tone tone() {
if (!speedColors.get()) {
return Tone.TEXT;
}
int fps = system().game().fps();
return fps >= 60 ? Tone.POSITIVE : fps >= 30 ? Tone.WARNING : Tone.NEGATIVE;
}
}
}
@@ -0,0 +1,5 @@
/** FPS Display (ADR 0052): the frame rate on the HUD. */
@NullMarked
package incari.features.fpsdisplay;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.fpsdisplay;
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.fpsdisplay", 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.fpsdisplay..");
}
@@ -0,0 +1,45 @@
package incari.features.fpsdisplay;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.setting.BooleanSetting;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class FpsDisplayTest {
private final FpsDisplay module = new FpsDisplay();
private final TestGame game = new TestGame(module);
@Test
void drawsNothingWhileOff() {
assertThat(game.drawHud().drawn).isEmpty();
}
@Test
void writesTheFrameRateOnTheGlass() {
module.setEnabled(true);
game.fps = 144;
assertThat(game.drawHud().drawn)
.contains("fill 50x14 at 2,14 BACKGROUND")
.anyMatch(line -> line.startsWith("text \"144 FPS\""));
}
@Test
void followsTheFormat() {
assertThat(FpsDisplay.text(FpsDisplay.Format.BEFORE, 60)).isEqualTo("FPS: 60");
assertThat(FpsDisplay.text(FpsDisplay.Format.NUMBER, 7)).isEqualTo("7");
}
@Test
void colorsBySpeedWhenAsked() {
module.setEnabled(true);
((BooleanSetting) module.settings().get("speed-colors")).set(true);
game.fps = 24;
assertThat(game.drawHud().drawn)
.anyMatch(line -> line.startsWith("text \"24 FPS\"") && line.endsWith("NEGATIVE"));
game.fps = 75;
assertThat(game.drawHud().drawn)
.anyMatch(line -> line.startsWith("text \"75 FPS\"") && line.endsWith("POSITIVE"));
}
}