Merge remote-tracking branch 'upstream/master' into wall-stats

This commit is contained in:
Leonwang4234
2020-10-20 15:49:46 -07:00
217 changed files with 2932 additions and 2468 deletions

View File

@@ -4,18 +4,22 @@ package mindustry.world.meta;
public enum BlockFlag{
/** Enemy core; primary target for all units. */
core,
/** Producer of important goods. */
producer,
/** A turret. */
/** Something that generates power. */
generator,
/** Any turret. */
turret,
/** A block that transforms resources. */
factory,
/** Repair point. */
repair,
/** Rally point. */
rally,
/** Block that stored power for resupply. */
powerRes,
battery,
/** Block used for resupply. */
resupply,
/** Any reactor block. */
reactor,
/** Any block that boosts unit capacity. */
unitModifier;

View 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));
}
}

View File

@@ -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,

View File

@@ -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();
}

View 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();
}
}
});
}
}

View 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();
}
}
});
}
}