This commit is contained in:
Anuken
2026-08-28 17:46:02 -04:00
parent 4be3f27d5c
commit 19186c677c
7 changed files with 32 additions and 19 deletions
+2
View File
@@ -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
@@ -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){
@@ -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<Stat, Seq<StatValue>> map = stats.toMap().get(cat);
for(StatCat cat : statMap.keys()){
var map = statMap.get(cat);
if(map.size == 0) continue;
+2 -2
View File
@@ -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){
@@ -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
+2 -1
View File
@@ -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;
+1 -2
View File
@@ -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));
}