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,16 @@
# cooldownindicator: Cooldown Indicator
Shows the attack cooldown as a bar, ring or percentage, in place of the game's indicator (which is held Off while this is on). ([ADR 0053](../../docs/adr/0053-visual-and-combat-modules.md))
| Setting | Kind | Default |
| --- | --- | --- |
| Style | Bar, Ring, Percent | Bar |
| Bar width / height | 8-80 / 1-6 | 24 / 2 |
| Ring size | 6-24 | 10 |
| Hide when charged | on/off | on |
| Show charged on target | on/off | on |
| Custom colors | on/off, two colors | off |
```sh
./gradlew :features:cooldownindicator:check
```
@@ -0,0 +1,16 @@
plugins {
`java-library`
}
// Cooldown Indicator (ADR 0053): the attack cooldown as a bar, ring or number, in place of the game's indicator.
// 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,234 @@
package incari.features.cooldownindicator;
import incari.framework.Category;
import incari.framework.Module;
import incari.framework.game.Game;
import incari.framework.game.GameOption;
import incari.framework.hud.Anchor;
import incari.framework.hud.HudCanvas;
import incari.framework.hud.HudElement;
import incari.framework.hud.Tone;
import incari.framework.setting.BooleanSetting;
import incari.framework.setting.ChoiceSetting;
import incari.framework.setting.ColorSetting;
import incari.framework.setting.IntSetting;
/**
* Cooldown Indicator: 1.9's attack cooldown the way the player wants it, in place of the game's
* indicator (whose option it holds at Off while on). A bar, a ring round the crosshair, or the
* charge as a percentage; hidden once charged, or shown full while the crosshair is on a target.
*/
public final class CooldownIndicator extends Module {
/** How the charge is drawn. */
public enum Style {
BAR("Bar"),
RING("Ring"),
NUMBER("Percent");
private final String label;
Style(String label) {
this.label = label;
}
/** What the settings screen calls it. */
public String label() {
return label;
}
}
/** The ring's thickness, in GUI units. */
static final float RING_WIDTH = 1.5F;
/** The charge the HUD editor shows. */
static final float SAMPLE = 0.6F;
final ChoiceSetting<Style> style = settings()
.choice("style", "Style", Style.values(), Style.BAR, Style::label)
.describedAs("A bar, a ring around the crosshair, or a percentage.");
final IntSetting barWidth =
settings().integer("bar-width", "Bar width", 8, 80, 24).visibleWhen(() -> style.get() == Style.BAR);
final IntSetting barHeight =
settings().integer("bar-height", "Bar height", 1, 6, 2).visibleWhen(() -> style.get() == Style.BAR);
final IntSetting ringSize = settings()
.integer("ring-size", "Ring size", 6, 24, 10)
.describedAs("The ring's radius, in GUI units.")
.visibleWhen(() -> style.get() == Style.RING);
final BooleanSetting hideWhenReady = settings()
.bool("hide-when-ready", "Hide when charged", true)
.describedAs("Shows the indicator only while the attack charges.");
final BooleanSetting readyOnTarget = settings()
.bool("ready-on-target", "Show charged on target", true)
.describedAs("Shows it full when the crosshair is on a mob or player in reach.")
.visibleWhen(hideWhenReady::get);
final BooleanSetting customColors = settings()
.bool("custom-colors", "Custom colors", false)
.describedAs("Off: charging in the accent, charged in green.");
final ColorSetting chargingColor =
settings().color("charging-color", "Charging color", 0xA9DCFF).visibleWhen(customColors::get);
final ColorSetting readyColor =
settings().color("ready-color", "Charged color", 0x8FE3B0).visibleWhen(customColors::get);
/** Cooldown Indicator, off until the player turns it on. */
public CooldownIndicator() {
super(
"cooldownindicator",
"Cooldown Indicator",
"Replaces the attack indicator with a bar, ring or percentage.",
Category.COMBAT);
// The game's own indicator is off while this one is on.
holdOption(GameOption.ATTACK_INDICATOR, () -> 0);
hud(new Bar());
hud(new Ring());
}
/** The charge now, or -1 if nothing should show. */
float charge(HudCanvas canvas) {
Game game = system().game();
if (game.player() == null) {
return canvas.editing() ? SAMPLE : -1;
}
float strength = Math.min(1, game.attackStrength());
if (strength >= 1 && hideWhenReady.get() && !(readyOnTarget.get() && game.onTarget())) {
return canvas.editing() ? SAMPLE : -1;
}
return strength;
}
int color(float charge) {
if (customColors.get()) {
return charge >= 1 ? readyColor.get() : chargingColor.get();
}
return 0;
}
Tone tone(float charge) {
return charge >= 1 ? Tone.POSITIVE : Tone.ACCENT;
}
/** "60%". */
static String percent(float charge) {
return Math.round(charge * 100) + "%";
}
/** The bar, or the percentage: below the crosshair by default. */
private final class Bar extends HudElement {
private int cachedPercent = -1;
private String cachedText = "";
Bar() {
super("bar", "Cooldown", Anchor.CENTER, 0, 12);
}
@Override
public boolean isLive() {
return true;
}
@Override
public boolean isPlaceable() {
return style.get() != Style.RING;
}
@Override
public boolean isVisible() {
return style.get() != Style.RING && system().game().player() != null;
}
private String text(float charge) {
int percent = Math.round(charge * 100);
if (percent != cachedPercent) {
cachedPercent = percent;
cachedText = percent(charge);
}
return cachedText;
}
@Override
public int width(HudCanvas canvas) {
return style.get() == Style.NUMBER ? canvas.textWidth("100%") : barWidth.get();
}
@Override
public int height(HudCanvas canvas) {
return style.get() == Style.NUMBER ? canvas.lineHeight() : barHeight.get();
}
@Override
public void draw(HudCanvas canvas) {
float charge = charge(canvas);
if (charge < 0) {
return;
}
if (style.get() == Style.NUMBER) {
String text = text(charge);
int x = (width(canvas) - canvas.textWidth(text)) / 2;
if (customColors.get()) {
canvas.text(text, x, 0, color(charge));
} else {
canvas.text(text, x, 0, tone(charge));
}
return;
}
int w = barWidth.get();
int h = barHeight.get();
canvas.fill(0, 0, w, h, Tone.BACKGROUND);
int filled = Math.round(w * charge);
if (customColors.get()) {
canvas.fill(0, 0, filled, h, color(charge));
} else {
canvas.fill(0, 0, filled, h, tone(charge));
}
}
}
/** The ring round the crosshair. */
private final class Ring extends HudElement {
Ring() {
super("ring", "Cooldown ring", Anchor.CENTER, 0, 0);
}
@Override
public boolean isLive() {
return true;
}
@Override
public boolean isPlaceable() {
return style.get() == Style.RING;
}
@Override
public boolean isVisible() {
return style.get() == Style.RING && system().game().player() != null;
}
@Override
public int width(HudCanvas canvas) {
return ringSize.get() * 2;
}
@Override
public int height(HudCanvas canvas) {
return ringSize.get() * 2;
}
@Override
public void draw(HudCanvas canvas) {
float charge = charge(canvas);
if (charge < 0) {
return;
}
float r = ringSize.get();
canvas.ring(r, r, r, RING_WIDTH, Tone.BACKGROUND);
if (customColors.get()) {
canvas.arc(r, r, r, RING_WIDTH, charge, color(charge));
} else {
canvas.arc(r, r, r, RING_WIDTH, charge, tone(charge));
}
}
}
}
@@ -0,0 +1,5 @@
/** Cooldown Indicator (ADR 0053): 1.9's attack cooldown, drawn as the player likes. */
@NullMarked
package incari.features.cooldownindicator;
import org.jspecify.annotations.NullMarked;
@@ -0,0 +1,24 @@
package incari.features.cooldownindicator;
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.cooldownindicator", 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.cooldownindicator..");
}
@@ -0,0 +1,56 @@
package incari.features.cooldownindicator;
import static org.assertj.core.api.Assertions.assertThat;
import incari.framework.game.GameOption;
import incari.framework.testing.TestGame;
import java.util.List;
import org.junit.jupiter.api.Test;
class CooldownIndicatorTest {
private final CooldownIndicator module = new CooldownIndicator();
private final TestGame game = new TestGame(module);
@Test
void holdsTheGamesIndicatorOffWhileOn() {
game.options.put(GameOption.ATTACK_INDICATOR, 2.0);
module.setEnabled(true);
assertThat(game.option(GameOption.ATTACK_INDICATOR)).isZero();
module.setEnabled(false);
assertThat(game.option(GameOption.ATTACK_INDICATOR)).isEqualTo(2.0);
}
@Test
void drawsTheChargeAsABarBelowTheCrosshair() {
module.setEnabled(true);
game.join();
game.attackStrength = 0.5F;
List<String> drawn = game.drawLive().drawn;
assertThat(drawn).containsExactly("fill 24x2 at 148,131 BACKGROUND", "fill 12x2 at 148,131 ACCENT");
}
@Test
void hidesWhenChargedUnlessOnATarget() {
module.setEnabled(true);
game.join();
assertThat(game.drawLive().drawn).isEmpty();
game.onTarget = true;
assertThat(game.drawLive().drawn).contains("fill 24x2 at 148,131 POSITIVE");
}
@Test
void ringsTheCrosshair() {
module.setEnabled(true);
module.style.set(CooldownIndicator.Style.RING);
game.join();
game.attackStrength = 0.25F;
assertThat(game.drawLive().drawn)
.containsExactly("ring r10 at 160,120 BACKGROUND", "arc r10 25% at 160,120 ACCENT");
}
@Test
void writesThePercentage() {
assertThat(CooldownIndicator.percent(0.604F)).isEqualTo("60%");
}
}