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,12 @@
# cps: CPS
Clicks per second over the last second. ([ADR 0052](../../docs/adr/0052-hud-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Buttons | Left and right, Left, Right | Left and right |
| HUD: CPS | position and scale | top left, under FPS (y 30), 1x |
```sh
./gradlew :features:cps:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// CPS (ADR 0052): clicks a second, left and right, on the HUD.
// 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)
}
@@ -0,0 +1,108 @@
package incari.features.cps;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.event.ClickCounter;
import incari.framework.event.ClickListener;
import incari.framework.event.Events;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.TextElement;
import incari.framework.setting.ChoiceSetting;
import org.jspecify.annotations.Nullable;
/** CPS: how many times the player clicked in the last second, left, right or both. */
public final class Cps extends Module {
/** Which buttons are counted. */
public enum Buttons {
/** "12 | 4 CPS". */
BOTH("Left and right"),
/** "12 CPS". */
LEFT("Left"),
/** "4 CPS". */
RIGHT("Right");
private final String label;
Buttons(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
final ChoiceSetting<Buttons> buttons = settings()
.choice("buttons", "Buttons", Buttons.values(), Buttons.BOTH, Buttons::label)
.describedAs("Which mouse buttons' clicks are counted.");
private final ClickCounter left = new ClickCounter();
private final ClickCounter right = new ClickCounter();
/** CPS, off until the player turns it on. */
public Cps() {
super("cps", "CPS", "Shows how many times a second you click.", Category.HUD);
on(Events.CLICK, this::onClick);
hud(new Counter());
}
private void onClick(int button) {
long now = system().game().millis();
if (button == ClickListener.LEFT) {
left.click(now);
} else if (button == ClickListener.RIGHT) {
right.click(now);
}
}
@Override
protected void onDisable() {
left.clear();
right.clear();
}
/** "12 | 4 CPS" for {@code buttons}. */
static String text(Buttons buttons, int left, int right) {
return switch (buttons) {
case BOTH -> left + " | " + right + " CPS";
case LEFT -> left + " CPS";
case RIGHT -> right + " CPS";
};
}
/** The count, on the glass. */
private final class Counter extends TextElement {
private int cachedLeft = -1;
private int cachedRight = -1;
private @Nullable Buttons cachedButtons;
private String cached = "";
Counter() {
super("cps", "CPS", Anchor.TOP_LEFT, 2, 30);
}
@Override
protected @Nullable String text(HudCanvas canvas) {
long now = system().game().millis();
int l = left.perSecond(now);
int r = right.perSecond(now);
Buttons chosen = buttons.get();
if (l != cachedLeft || r != cachedRight || chosen != cachedButtons) {
cachedLeft = l;
cachedRight = r;
cachedButtons = chosen;
cached = Cps.text(chosen, l, r);
}
return cached;
}
@Override
protected @Nullable String widest() {
return buttons.get() == Buttons.BOTH ? "00 | 00 CPS" : "00 CPS";
}
}
}
@@ -0,0 +1,5 @@
/** CPS (ADR 0052): clicks a second on the HUD. */
@NullMarked
package incari.features.cps;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,20 @@
package incari.features.cps;
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.cps", 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.cps..");
}
@@ -0,0 +1,44 @@
package incari.features.cps;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.event.ClickListener;
import incari.framework.testing.TestGame;
import org.junit.jupiter.api.Test;
class CpsTest {
private final Cps module = new Cps();
private final TestGame game = new TestGame(module);
@Test
void countsEachButtonsClicksOverTheLastSecond() {
module.setEnabled(true);
for (int i = 0; i < 9; i++) {
game.click(ClickListener.LEFT);
game.millis += 100;
}
game.click(ClickListener.RIGHT);
game.click(ClickListener.MIDDLE);
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"9 | 1 CPS\""));
game.millis += 600;
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"3 | 1 CPS\""));
game.millis += 1000;
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"0 | 0 CPS\""));
}
@Test
void clicksWhileOffArentCounted() {
game.click(ClickListener.LEFT);
module.setEnabled(true);
assertThat(game.drawHud().drawn).anyMatch(line -> line.startsWith("text \"0 | 0 CPS\""));
}
@Test
void writesOneButtonWhenAsked() {
assertThat(Cps.text(Cps.Buttons.LEFT, 12, 4)).isEqualTo("12 CPS");
assertThat(Cps.text(Cps.Buttons.RIGHT, 12, 4)).isEqualTo("4 CPS");
}
}