Skip to content

Commit

Permalink
Merge pull request #82 from AvantTeam/custom-stat-moment
Browse files Browse the repository at this point in the history
Convert graph stat display to custom stats
  • Loading branch information
MEEPofFaith authored Nov 16, 2022
2 parents fd8e4c2 + fa25f08 commit 30d53d3
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 81 deletions.
42 changes: 23 additions & 19 deletions main/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -258,34 +258,38 @@ unit.unity-modularUnit.description = tonk
unit.unity-modularUnit.details = tonk

## Stats
ui.graph.torque = Torque Module
ui.graph.heat = Heat Module
ui.graph.crucible = Crucible Module
stat.unity-cruciblecapacity = {0} items
category.unity-torque = Torque
category.unity-heat = Heat
category.unity-crucible = Crucible Info

stat.unity-itemmeltpoint= Melting Point: {0}°C
stat.unity-seebeckStrength = @ power units per second per ΔKelvin
stat.unity-emissiveness.name = Emissivity
stat.unity-emissiveness = {0} heat energy units per ΔKelvin per second
stat.unity-heatcapacity.name = Heat Capacity
stat.unity-heatcapacity = Every {0} heat energy units increases temp by 1 Kelvin
stat.unity-heatconductivity.name = Heat Conductivity
stat.unity-heatconductivity = {0} heat energy units per ΔKelvin per second
stat.unity-maxtemp = Max Temperature: {0}°C
stat.unity-friction.name = Friction
stat.unity-friction = {0} Torque per rpm
stat.unity-inertia.name = Mass
stat.unity-inertia = {0}
stat.unity-maxspeed.name = Max effective speed
stat.unity-maxspeed = {0} rpm
stat.unity-maxtorque.name = Max torque generated
stat.unity-maxtorque = {0} Torque
stat.unity-emissiveness = Emissivity
stat.unity-emissiveness.info = {0} heat energy units per ΔKelvin per second
stat.unity-heatcapacity = Heat Capacity
stat.unity-heatcapacity.info = Every {0} heat energy units increases temp by 1 Kelvin
stat.unity-heatconductivity = Heat Conductivity
stat.unity-heatconductivity.info = {0} heat energy units per ΔKelvin per second
stat.unity-maxtemp = Max Temperature
stat.unity-friction = Friction
stat.unity-friction.info = {0} Torque per rpm
stat.unity-inertia = Mass
stat.unity-maxspeed = Max effective speed
stat.unity-maxtorque = Max torque generated
stat.unity-cruciblecapacity = Liquid Capacity
stat.unity-cruciblemelts = Melting Points

stat.unity-negligible = [green]Negligible: ({0})
stat.unity-small = [acid]Minor: ({0})
stat.unity-moderate = [yellow]Moderate: ({0})
stat.unity-significant = [gold]Significant: ({0})
stat.unity-major = [orange]Major: ({0})
stat.unity-extreme = [red]Extreme: ({0})

unit.unity-rpm = rpm
unit.unity-torque = Torque
unit.unity-celcius = °C

## Bars
bar.unity-torquespeed = Speed: {0} rpm
bar.unity-torqueinertia = Mass: {0}
Expand Down
32 changes: 14 additions & 18 deletions main/src/unity/world/graph/CrucibleGraphNode.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package unity.world.graph;

import arc.*;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.io.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.world.meta.*;
import unity.ui.*;
import unity.world.graph.CrucibleGraph.*;
import unity.world.meta.*;
import unity.world.meta.CrucibleRecipes.*;

import static mindustry.Vars.content;


public class CrucibleGraphNode extends GraphNode<CrucibleGraph>{
public float capacity;
Expand All @@ -43,22 +39,22 @@ public CrucibleGraphNode(GraphBuild build, float totalCapacity, boolean crafts){
baseSize = Mathf.sqr(build.getBuild().block.size);
}
}

@Override
public void displayStats(Table table){
table.row();
table.table(bt -> {
bt.left().defaults().padRight(3).left();
bt.row();
addStatLine(bt,Stat.liquidCapacity.localized(),Core.bundle.format("stat.unity-cruciblecapacity",this.capacity));
if(doesCrafting){
for(var melt:CrucibleRecipes.items){
bt.row();
bt.add(new CrucibleMeltStatElement(melt.key));
}
}
}).padTop(-9).fillX().padLeft(0).left().get().background( Tex.underline);
//stats.add(Stat.abilities,);
public void setStats(Stats stats){
stats.add(UnityStat.crucibleCapacity, capacity, StatUnit.items);
if(doesCrafting){
stats.add(UnityStat.crucibleMeltingPoints, table -> {
table.table(t -> {
for(var melt : CrucibleRecipes.items){
t.row();
t.add(new CrucibleMeltStatElement(melt.key));
}
});
});
}
}

@Override
public void displayBars(Table table){
table.row();
Expand Down
17 changes: 4 additions & 13 deletions main/src/unity/world/graph/GraphBlockConfig.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package unity.world.graph;

import arc.*;
import arc.func.*;
import arc.graphics.g2d.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.entities.units.*;
import mindustry.graphics.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import unity.world.graph.GraphConnector.*;
Expand Down Expand Up @@ -113,17 +111,10 @@ public FixedConnectionConfig( Class<T> tClass,Prov<T> newGraph, int... connectio
}

public void setStats(Stats stats){
stats.add(Stat.abilities,table -> {
for(var gcnfig:nodeConfig){
table.row();
table.add(Core.bundle.get("ui.graph."+Graphs.graphInfo.get(gcnfig.key).name)).growX().left().color(Pal.accent);
table.row();
table.image().growX().pad(5).padLeft(0).padRight(0).height(3).color(Pal.accent);
GraphNode gn = gcnfig.value.get(null);
table.row();
table.table(gn::displayStats).growX();
}
});
for(var gcnfig : nodeConfig){
GraphNode<?> gn = gcnfig.value.get(null);
gn.setStats(stats);
}
}

public Block getBlock(){
Expand Down
24 changes: 9 additions & 15 deletions main/src/unity/world/graph/GraphNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import unity.world.meta.*;

//orginally GraphModule
public class GraphNode<T extends Graph>{
Expand Down Expand Up @@ -56,8 +57,9 @@ public <W extends GraphConnector<T>> W getConnectorOfType(Class<W> cls){
return null;
}

public void setStats(Stats stats){}

public void displayBars(Table table){}
public void displayStats(Table table){};
private static String[] levelNames = {
"stat.unity-negligible",
"stat.unity-small",
Expand All @@ -74,21 +76,13 @@ public String getNamedLevel(float val, float level[]){
}
return levelNames[levelNames.length-1];
}
public void addBundleStatLevelLine(Table table, String bundlename, float val, float level[]){
addStatLine(table, Core.bundle.get(bundlename+".name"),Core.bundle.format(getNamedLevel(val,level),Core.bundle.format(bundlename,val)));
}
public void addBundleStatLine(Table table, String bundlename, Object val){
addStatLine(table, Core.bundle.get(bundlename+".name"),Core.bundle.format(bundlename,val));

public void addLevelStat(Stats stats, Stat stat, float val, float[] levels){
stats.add(stat, Core.bundle.format(getNamedLevel(val, levels), Core.bundle.format("stat." + stat.name + ".info", val)));
}
public void addStatLine(Table table, String name, String val){
table.row();
table.table(inset -> {
inset.left();
inset.add("[lightgray]" + name + ":[] ").left().top();
inset.add(val);
inset.add().size(10f);

}).fillX().padLeft(10);

public void addStat(Stats stats, Stat stat, Object val){
stats.add(stat, Core.bundle.format("stat." + stat.name + ".info", val));
}

public void removeEdge(GraphNode g){
Expand Down
13 changes: 7 additions & 6 deletions main/src/unity/world/graph/HeatGraphNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.world.meta.*;
import unity.world.meta.*;

import static unity.graphics.UnityPal.*;

Expand Down Expand Up @@ -168,11 +170,10 @@ public void addHeatEnergy(float e){
}

@Override
public void displayStats(Table table){
addBundleStatLevelLine(table,"stat.unity-emissiveness",emissiveness*60,new float[]{0.5f,1f,3f,10,20});
addBundleStatLine(table,"stat.unity-heatcapacity",heatcapacity);
addBundleStatLine(table,"stat.unity-heatconductivity",conductivity*60);
addBundleStatLine(table,"stat.unity-maxtemp",maxTemp-celsiusZero);
//
public void setStats(Stats stats){
addLevelStat(stats, UnityStat.emissivity, emissiveness * 60f, new float[]{0.5f, 1f, 3f, 10f, 20f});
addStat(stats, UnityStat.heatCapacity, heatcapacity);
addStat(stats, UnityStat.heatConductivity, conductivity);
stats.add(UnityStat.maxTemperature, maxTemp - celsiusZero, UnityStatUnit.celcius);
}
}
17 changes: 7 additions & 10 deletions main/src/unity/world/graph/TorqueGraphNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import arc.util.*;
import mindustry.graphics.*;
import mindustry.ui.*;
import mindustry.world.meta.*;
import unity.world.meta.*;

public class TorqueGraphNode extends GraphNode<TorqueGraph>{
public float baseFriction, baseInertia, baseForce=0;
Expand Down Expand Up @@ -68,15 +70,10 @@ public float getForce(){
}

@Override
public void displayStats(Table table){
addBundleStatLevelLine(table,"stat.unity-friction",baseFriction*(60.0f),new float[]{0.5f,1,2,5,10});
addBundleStatLine(table,"stat.unity-inertia",baseInertia);
if(maxSpeed > 0){
addBundleStatLine(table,"stat.unity-maxspeed",maxSpeed*10);
}
if(maxTorque > 0){
addBundleStatLine(table,"stat.unity-maxtorque",maxTorque);
}

public void setStats(Stats stats){
addLevelStat(stats, UnityStat.friction, baseFriction * 60f, new float[]{0.5f, 1f, 2f, 5f, 10});
stats.add(UnityStat.inertia, baseInertia);
if(maxSpeed > 0) stats.add(UnityStat.maxSpeed, maxSpeed * 10f, UnityStatUnit.rpm);
if(maxTorque > 0) stats.add(UnityStat.maxTorque, maxTorque, UnityStatUnit.torque);
}
}
20 changes: 20 additions & 0 deletions main/src/unity/world/meta/UnityStat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package unity.world.meta;

import mindustry.world.meta.*;

public class UnityStat{
public static final Stat

friction = new Stat("unity-friction", UnityStatCat.torque),
inertia = new Stat("unity-inertia", UnityStatCat.torque),
maxSpeed = new Stat("unity-maxspeed", UnityStatCat.torque),
maxTorque = new Stat("unity-maxtorque", UnityStatCat.torque),

emissivity = new Stat("unity-emissiveness", UnityStatCat.heat),
heatCapacity = new Stat("unity-heatcapacity", UnityStatCat.heat),
heatConductivity = new Stat("unity-heatconductivity", UnityStatCat.heat),
maxTemperature = new Stat("unity-maxtemp", UnityStatCat.heat),

crucibleCapacity = new Stat("unity-cruciblecapacity", UnityStatCat.crucible),
crucibleMeltingPoints = new Stat("unity-cruciblemelts", UnityStatCat.crucible);
}
11 changes: 11 additions & 0 deletions main/src/unity/world/meta/UnityStatCat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package unity.world.meta;

import mindustry.world.meta.*;

public class UnityStatCat{
public static final StatCat

torque = new StatCat("unity-torque"),
heat = new StatCat("unity-heat"),
crucible = new StatCat("unity-crucible");
}
12 changes: 12 additions & 0 deletions main/src/unity/world/meta/UnityStatUnit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package unity.world.meta;

import mindustry.world.meta.*;

public class UnityStatUnit{
public static final StatUnit

rpm = new StatUnit("unity-rpm"),
torque = new StatUnit("unity-torque"),

celcius = new StatUnit("unity-celcius", false);
}

0 comments on commit 30d53d3

Please sign in to comment.