Unified stat system
This commit is contained in:
@@ -1,68 +0,0 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** Describes one type of stat for a block. */
|
||||
public enum BlockStat{
|
||||
health(StatCategory.general),
|
||||
size(StatCategory.general),
|
||||
displaySize(StatCategory.general),
|
||||
buildTime(StatCategory.general),
|
||||
buildCost(StatCategory.general),
|
||||
memoryCapacity(StatCategory.general),
|
||||
|
||||
itemCapacity(StatCategory.items),
|
||||
itemsMoved(StatCategory.items),
|
||||
launchTime(StatCategory.items),
|
||||
maxConsecutive(StatCategory.items),
|
||||
|
||||
liquidCapacity(StatCategory.liquids),
|
||||
|
||||
powerCapacity(StatCategory.power),
|
||||
powerUse(StatCategory.power),
|
||||
powerDamage(StatCategory.power),
|
||||
powerRange(StatCategory.power),
|
||||
powerConnections(StatCategory.power),
|
||||
basePowerGeneration(StatCategory.power),
|
||||
|
||||
tiles(StatCategory.crafting),
|
||||
input(StatCategory.crafting),
|
||||
output(StatCategory.crafting),
|
||||
productionTime(StatCategory.crafting),
|
||||
drillTier(StatCategory.crafting),
|
||||
drillSpeed(StatCategory.crafting),
|
||||
maxUnits(StatCategory.crafting),
|
||||
linkRange(StatCategory.crafting),
|
||||
instructions(StatCategory.crafting),
|
||||
|
||||
speedIncrease(StatCategory.shooting),
|
||||
repairTime(StatCategory.shooting),
|
||||
range(StatCategory.shooting),
|
||||
shootRange(StatCategory.shooting),
|
||||
inaccuracy(StatCategory.shooting),
|
||||
shots(StatCategory.shooting),
|
||||
reload(StatCategory.shooting),
|
||||
powerShot(StatCategory.shooting),
|
||||
targetsAir(StatCategory.shooting),
|
||||
targetsGround(StatCategory.shooting),
|
||||
damage(StatCategory.shooting),
|
||||
ammo(StatCategory.shooting),
|
||||
shieldHealth(StatCategory.shooting),
|
||||
cooldownTime(StatCategory.shooting),
|
||||
|
||||
booster(StatCategory.optional),
|
||||
boostEffect(StatCategory.optional),
|
||||
affinities(StatCategory.optional);
|
||||
|
||||
public final StatCategory category;
|
||||
|
||||
BlockStat(StatCategory category){
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
return Core.bundle.get("blocks." + name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
82
core/src/mindustry/world/meta/Stat.java
Normal file
82
core/src/mindustry/world/meta/Stat.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package mindustry.world.meta;
|
||||
|
||||
import arc.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/** Describes one type of stat for content. */
|
||||
public enum Stat{
|
||||
health,
|
||||
size,
|
||||
displaySize,
|
||||
buildTime,
|
||||
buildCost,
|
||||
memoryCapacity,
|
||||
explosiveness,
|
||||
flammability,
|
||||
radioactivity,
|
||||
heatCapacity,
|
||||
viscosity,
|
||||
temperature,
|
||||
speed,
|
||||
buildSpeed,
|
||||
mineSpeed,
|
||||
mineTier,
|
||||
|
||||
itemCapacity(StatCat.items),
|
||||
itemsMoved(StatCat.items),
|
||||
launchTime(StatCat.items),
|
||||
maxConsecutive(StatCat.items),
|
||||
|
||||
liquidCapacity(StatCat.liquids),
|
||||
|
||||
powerCapacity(StatCat.power),
|
||||
powerUse(StatCat.power),
|
||||
powerDamage(StatCat.power),
|
||||
powerRange(StatCat.power),
|
||||
powerConnections(StatCat.power),
|
||||
basePowerGeneration(StatCat.power),
|
||||
|
||||
tiles(StatCat.crafting),
|
||||
input(StatCat.crafting),
|
||||
output(StatCat.crafting),
|
||||
productionTime(StatCat.crafting),
|
||||
drillTier(StatCat.crafting),
|
||||
drillSpeed(StatCat.crafting),
|
||||
maxUnits(StatCat.crafting),
|
||||
linkRange(StatCat.crafting),
|
||||
instructions(StatCat.crafting),
|
||||
|
||||
speedIncrease(StatCat.shooting),
|
||||
repairTime(StatCat.shooting),
|
||||
range(StatCat.shooting),
|
||||
shootRange(StatCat.shooting),
|
||||
inaccuracy(StatCat.shooting),
|
||||
shots(StatCat.shooting),
|
||||
reload(StatCat.shooting),
|
||||
powerShot(StatCat.shooting),
|
||||
targetsAir(StatCat.shooting),
|
||||
targetsGround(StatCat.shooting),
|
||||
damage(StatCat.shooting),
|
||||
ammo(StatCat.shooting),
|
||||
shieldHealth(StatCat.shooting),
|
||||
cooldownTime(StatCat.shooting),
|
||||
|
||||
booster(StatCat.optional),
|
||||
boostEffect(StatCat.optional),
|
||||
affinities(StatCat.optional);
|
||||
|
||||
public final StatCat category;
|
||||
|
||||
Stat(StatCat category){
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
Stat(){
|
||||
this.category = StatCat.general;
|
||||
}
|
||||
|
||||
public String localized(){
|
||||
return Core.bundle.get("stat." + name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package mindustry.world.meta;
|
||||
import arc.*;
|
||||
|
||||
/** A specific category for a stat. */
|
||||
public enum StatCategory{
|
||||
public enum StatCat{
|
||||
general,
|
||||
power,
|
||||
liquids,
|
||||
@@ -2,54 +2,71 @@ package mindustry.world.meta;
|
||||
|
||||
import arc.struct.ObjectMap.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.values.*;
|
||||
|
||||
/** Hold and organizes a list of block stats. */
|
||||
public class BlockStats{
|
||||
private final OrderedMap<StatCategory, OrderedMap<BlockStat, Seq<StatValue>>> map = new OrderedMap<>();
|
||||
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. */
|
||||
public boolean intialized = false;
|
||||
|
||||
@Nullable
|
||||
private OrderedMap<StatCat, OrderedMap<Stat, Seq<StatValue>>> map;
|
||||
private boolean dirty;
|
||||
|
||||
/** Adds a single float value with this stat, formatted to 2 decimal places. */
|
||||
public void add(BlockStat stat, float value, StatUnit unit){
|
||||
public void add(Stat stat, float value, StatUnit unit){
|
||||
add(stat, new NumberValue(value, unit));
|
||||
}
|
||||
|
||||
/** Adds a single float value with this stat and no unit. */
|
||||
public void add(Stat stat, float value){
|
||||
add(stat, value, StatUnit.none);
|
||||
}
|
||||
|
||||
/** Adds an integer percent stat value. Value is assumed to be in the 0-1 range. */
|
||||
public void addPercent(Stat stat, float value){
|
||||
add(stat, new NumberValue((int)(value * 100), StatUnit.percent));
|
||||
}
|
||||
|
||||
/** Adds a single y/n boolean value. */
|
||||
public void add(BlockStat stat, boolean value){
|
||||
public void add(Stat stat, boolean value){
|
||||
add(stat, new BooleanValue(value));
|
||||
}
|
||||
|
||||
/** Adds an item value. */
|
||||
public void add(BlockStat stat, Item item){
|
||||
public void add(Stat stat, Item item){
|
||||
add(stat, new ItemListValue(new ItemStack(item, 1)));
|
||||
}
|
||||
|
||||
/** Adds an item value. */
|
||||
public void add(BlockStat stat, ItemStack item){
|
||||
public void add(Stat stat, ItemStack item){
|
||||
add(stat, new ItemListValue(item));
|
||||
}
|
||||
|
||||
/** Adds an item value. */
|
||||
public void add(BlockStat stat, Liquid liquid, float amount, boolean perSecond){
|
||||
public void add(Stat stat, Liquid liquid, float amount, boolean perSecond){
|
||||
add(stat, new LiquidValue(liquid, amount, perSecond));
|
||||
}
|
||||
|
||||
public void add(BlockStat stat, Attribute attr){
|
||||
public void add(Stat stat, Attribute attr){
|
||||
add(stat, attr, false, 1f);
|
||||
}
|
||||
|
||||
public void add(BlockStat stat, Attribute attr, float scale){
|
||||
public void add(Stat stat, Attribute attr, float scale){
|
||||
add(stat, attr, false, scale);
|
||||
}
|
||||
|
||||
public void add(BlockStat stat, Attribute attr, boolean floating){
|
||||
public void add(Stat stat, Attribute attr, boolean floating){
|
||||
add(stat, attr, floating, 1f);
|
||||
}
|
||||
|
||||
public void add(BlockStat stat, Attribute attr, boolean floating, float scale){
|
||||
public void add(Stat stat, Attribute attr, boolean floating, float scale){
|
||||
for(Block block : Vars.content.blocks()){
|
||||
if(!block.isFloor() || block.asFloor().attributes.get(attr) == 0 || (block.asFloor().isLiquid && !floating)) continue;
|
||||
add(stat, new FloorEfficiencyValue(block.asFloor(), block.asFloor().attributes.get(attr) * scale));
|
||||
@@ -57,12 +74,14 @@ public class BlockStats{
|
||||
}
|
||||
|
||||
/** Adds a single string value with this stat. */
|
||||
public void add(BlockStat stat, String format, Object... args){
|
||||
public void add(Stat stat, String format, Object... args){
|
||||
add(stat, new StringValue(format, args));
|
||||
}
|
||||
|
||||
/** Adds a stat value. */
|
||||
public void add(BlockStat stat, StatValue value){
|
||||
public void add(Stat stat, StatValue value){
|
||||
if(map == null) map = new OrderedMap<>();
|
||||
|
||||
if(!map.containsKey(stat.category)){
|
||||
map.put(stat.category, new OrderedMap<>());
|
||||
}
|
||||
@@ -73,7 +92,9 @@ public class BlockStats{
|
||||
}
|
||||
|
||||
/** Removes a stat, if it exists. */
|
||||
public void remove(BlockStat stat){
|
||||
public void remove(Stat stat){
|
||||
if(map == null) map = new OrderedMap<>();
|
||||
|
||||
if(!map.containsKey(stat.category) || !map.get(stat.category).containsKey(stat)){
|
||||
throw new RuntimeException("No stat entry found: \"" + stat + "\" in block.");
|
||||
}
|
||||
@@ -83,11 +104,13 @@ public class BlockStats{
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
public OrderedMap<StatCategory, OrderedMap<BlockStat, Seq<StatValue>>> toMap(){
|
||||
public OrderedMap<StatCat, OrderedMap<Stat, Seq<StatValue>>> toMap(){
|
||||
if(map == null) map = new OrderedMap<>();
|
||||
|
||||
//sort stats by index if they've been modified
|
||||
if(dirty){
|
||||
map.orderedKeys().sort();
|
||||
for(Entry<StatCategory, OrderedMap<BlockStat, Seq<StatValue>>> entry : map.entries()){
|
||||
for(Entry<StatCat, OrderedMap<Stat, Seq<StatValue>>> entry : map.entries()){
|
||||
entry.value.orderedKeys().sort();
|
||||
}
|
||||
|
||||
37
core/src/mindustry/world/meta/values/BlockFilterValue.java
Normal file
37
core/src/mindustry/world/meta/values/BlockFilterValue.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class BlockFilterValue implements StatValue{
|
||||
public final Boolf<Block> pred;
|
||||
|
||||
public BlockFilterValue(Boolf<Block> pred){
|
||||
this.pred = pred;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
Seq<Block> list = content.blocks().select(pred);
|
||||
|
||||
table.table(l -> {
|
||||
l.left();
|
||||
|
||||
for(int i = 0; i < list.size; i++){
|
||||
Block item = list.get(i);
|
||||
|
||||
l.image(item.icon(Cicon.small)).size(8 * 3).padRight(2).padLeft(2).padTop(3).padBottom(3);
|
||||
l.add(item.localizedName).left().padLeft(1).padRight(4);
|
||||
if(i % 5 == 4){
|
||||
l.row();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
33
core/src/mindustry/world/meta/values/BlockListValue.java
Normal file
33
core/src/mindustry/world/meta/values/BlockListValue.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package mindustry.world.meta.values;
|
||||
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
|
||||
public class BlockListValue implements StatValue{
|
||||
public final Seq<Block> list;
|
||||
|
||||
public BlockListValue(Seq<Block> list){
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void display(Table table){
|
||||
|
||||
table.table(l -> {
|
||||
l.left();
|
||||
|
||||
for(int i = 0; i < list.size; i++){
|
||||
Block item = list.get(i);
|
||||
|
||||
l.image(item.icon(Cicon.small)).size(8 * 3).padRight(2).padLeft(2).padTop(3).padBottom(3);
|
||||
l.add(item.localizedName).left().padLeft(1).padRight(4);
|
||||
if(i % 5 == 4){
|
||||
l.row();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user