diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index af2bac4ec7..eff39d53db 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -1319,6 +1319,7 @@ bar.strength = [stat]{0}[lightgray]x strength bar.regenerationrate = [stat]{0}/sec[lightgray] regen rate bar.activationtimer = Activates in {0} bar.activated = Activated +bar.upto = Up to {0} units.processorcontrol = [lightgray]Processor Controlled @@ -1370,6 +1371,7 @@ unit.liquidunits = liquid units unit.powerunits = power units unit.powerequilibrium = power equilibrium unit.heatunits = heat units +unit.heatunitsperside = heat units per side unit.degrees = degrees unit.seconds = seconds unit.minutes = mins diff --git a/core/src/mindustry/ctype/UnlockableContent.java b/core/src/mindustry/ctype/UnlockableContent.java index 620fad3a69..d68b4e1ad1 100644 --- a/core/src/mindustry/ctype/UnlockableContent.java +++ b/core/src/mindustry/ctype/UnlockableContent.java @@ -141,18 +141,22 @@ public abstract class UnlockableContent extends MappableContent{ return minfo.mod == null || isPatchContent() ? description : description + "\n" + Core.bundle.format("mod.display", minfo.mod.meta.displayName); } - /** Checks stat initialization state. Call before displaying stats. */ + /** @deprecated just call computeStats() every time, there's no reason to cache it. This will be removed in v9. */ + @Deprecated public void checkStats(){ - if(!stats.intialized){ - setStats(); - stats.intialized = true; - } + computeStats(); } - /** Initializes stats on demand. Should only be called once. Only called before something is displayed. */ + /** Initializes stats on demand. Called every time the block stats are shown. */ public void setStats(){ } + public Stats computeStats(){ + this.stats = new Stats(); + setStats(); + return this.stats; + } + /** Display any extra info after details. */ public void displayExtra(Table table){ diff --git a/core/src/mindustry/ui/dialogs/ContentInfoDialog.java b/core/src/mindustry/ui/dialogs/ContentInfoDialog.java index 061214ea1a..227a4a1461 100644 --- a/core/src/mindustry/ui/dialogs/ContentInfoDialog.java +++ b/core/src/mindustry/ui/dialogs/ContentInfoDialog.java @@ -38,8 +38,9 @@ public class ContentInfoDialog extends BaseDialog{ Table table = new Table(); table.margin(10); - //initialize stats if they haven't been yet - content.checkStats(); + //compute stats every time + var stats = content.computeStats(); + var statMap = stats.toMap(); table.table(title1 -> { title1.image(content.uiIcon).size(iconXLarge).scaling(Scaling.fit); @@ -58,7 +59,7 @@ public class ContentInfoDialog extends BaseDialog{ } if(content.description != null){ - var any = content.stats.toMap().size > 0; + var any = statMap.size > 0; if(any){ table.add("@category.purpose").color(Pal.accent).fillX().padTop(10); @@ -68,16 +69,14 @@ public class ContentInfoDialog extends BaseDialog{ table.add("[lightgray]" + UI.formatIcons(content.displayDescription())).wrap().fillX().padLeft(any ? 10 : 0).width(500f).padTop(any ? 0 : 10).left(); table.row(); - if(!content.stats.useCategories && any){ + if(!stats.useCategories && any){ table.add("@category.general").fillX().color(Pal.accent); table.row(); } } - Stats stats = content.stats; - - for(StatCat cat : stats.toMap().keys()){ - OrderedMap> map = stats.toMap().get(cat); + for(StatCat cat : statMap.keys()){ + var map = statMap.get(cat); if(map.size == 0) continue; diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 583d9532a8..182f434ec4 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -637,6 +637,8 @@ public class Block extends UnlockableContent implements Senseable{ public void setStats(){ super.setStats(); + stats.useCategories = true; + stats.add(Stat.size, "@x@", size, size); if(synthetic()){ @@ -1464,8 +1466,6 @@ public class Block extends UnlockableContent implements Senseable{ setBars(); - stats.useCategories = true; - //TODO check for double power consumption if(!logicConfigurable){ diff --git a/core/src/mindustry/world/blocks/power/NuclearReactor.java b/core/src/mindustry/world/blocks/power/NuclearReactor.java index 7ec3f4c5f8..7bbaaa58d7 100644 --- a/core/src/mindustry/world/blocks/power/NuclearReactor.java +++ b/core/src/mindustry/world/blocks/power/NuclearReactor.java @@ -90,6 +90,14 @@ public class NuclearReactor extends PowerGenerator{ if(hasItems){ stats.add(Stat.productionTime, itemDuration / 60f, StatUnit.seconds); } + if(heatOutput > 0f && (ui.planet.isShown() ? ui.planet.state.planet : state.isGame() ? state.getPlanet() : null) == Planets.erekir){ + stats.add(Stat.output, table -> { + //using StatUnit.localized() strips the icon + String unit = "[red]" + Iconc.waves + "[] " + Strings.fixed(heatOutput, 0) + " " + Core.bundle.get("unit.heatunitsperside"); + + table.add(Core.bundle.format("bar.upto", unit)); + }); + } } @Override diff --git a/core/src/mindustry/world/meta/Stats.java b/core/src/mindustry/world/meta/Stats.java index 5f7ce8f08e..8a1bd0d5da 100644 --- a/core/src/mindustry/world/meta/Stats.java +++ b/core/src/mindustry/world/meta/Stats.java @@ -15,7 +15,8 @@ import java.util.*; public class Stats{ /** Whether to display stats with categories. If false, categories are completely ignored during display. */ public boolean useCategories = false; - /** Whether these stats are initialized yet. */ + /** @deprecated does nothing, will be removed in v9 */ + @Deprecated public boolean intialized = false; /** Production time period in ticks. Used for crafters. **/ public float timePeriod = -1; diff --git a/tests/src/test/java/PatcherTests.java b/tests/src/test/java/PatcherTests.java index 846dcb9e7a..c2c5bd281c 100644 --- a/tests/src/test/java/PatcherTests.java +++ b/tests/src/test/java/PatcherTests.java @@ -173,7 +173,6 @@ public class PatcherTests{ @Test void unitWeapons() throws Exception{ - UnitTypes.dagger.checkStats(); UnitTypes.dagger.stats.add(Stat.charge, 999); assertNotNull(UnitTypes.dagger.stats.toMap().get(StatCat.general).get(Stat.charge)); @@ -195,7 +194,7 @@ public class PatcherTests{ Vars.logic.reset(); - UnitTypes.dagger.checkStats(); + UnitTypes.dagger.computeStats(); assertNull(UnitTypes.dagger.stats.toMap().get(StatCat.general).get(Stat.charge)); }