From 9b42695c1cb3958875e4cf68109bd0e787f76a42 Mon Sep 17 00:00:00 2001 From: xzxADIxzx <76255437+xzxADIxzx@users.noreply.github.com> Date: Tue, 4 Mar 2025 15:37:58 +0300 Subject: [PATCH] add caching for the next wave info --- src/java/schema/tools/Units.java | 23 +++++++++++++++++++++++ src/resources/bundles/bundle.properties | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/java/schema/tools/Units.java b/src/java/schema/tools/Units.java index 06bfbe8..3eb54d2 100644 --- a/src/java/schema/tools/Units.java +++ b/src/java/schema/tools/Units.java @@ -4,6 +4,7 @@ import arc.func.*; import arc.struct.*; import arc.util.*; +import mindustry.content.*; import mindustry.entities.*; import mindustry.entities.abilities.*; import mindustry.game.EventType.*; @@ -33,6 +34,11 @@ public class Units { /** Current shield or null if absent. */ private ShieldArcAbility arcShield; + /** Summary health and shield of all units on the next wave. */ + public float waveHealth, waveShield; + /** Total amount of units and bosses on the next wave. */ + public ObjectIntMap waveUnits = new ObjectIntMap<>(), waveBosses = new ObjectIntMap<>(); + public Units() { Events.on(WorldLoadEvent.class, e -> draw = true); Events.on(UnitChangeEvent.class, e -> { @@ -81,4 +87,21 @@ public void draw(Cons cons) { /** Returns the percentage health of the force field. */ public float shieldf() { return shield() / maxShield; } + + /** Refreshes the information about the next wave. */ + public void refreshWaveInfo() { + waveHealth = waveShield = 0f; + waveUnits.clear(); + waveBosses.clear(); + + state.rules.spawns.each(g -> g.type != null, g -> { + int amount = g.getSpawned(state.wave - 1); + if (amount == 0) return; + + waveHealth += g.type.health * amount; + waveShield += g.getShield(state.wave - 1); + + (g.effect == StatusEffects.boss ? waveBosses : waveUnits).put(g.type, amount); + }); + } } diff --git a/src/resources/bundles/bundle.properties b/src/resources/bundles/bundle.properties index 843d8ed..5a3d5c5 100644 --- a/src/resources/bundles/bundle.properties +++ b/src/resources/bundles/bundle.properties @@ -1,5 +1,5 @@ update.name = [red]\u26A0[] Schema is outdated! -update.info = Your version of the mod is [accent]outdated[].\nThis annoying dialog can be turned off in settings.\n\n[gray]The current version is v{0} while the latest is v{1}[] +update.info = Your version of the mod is [accent]outdated[].\nThis annoying dialog can be turned off in settings.\n\n[disabled]The current version is v{0} while the latest is v{1}[] # dialogs