Code cleanup

This commit is contained in:
Anuken
2018-10-06 11:56:39 -04:00
parent 0ce226d0c9
commit fd107ab5b8
48 changed files with 94 additions and 195 deletions

View File

@@ -136,8 +136,7 @@ public class ContentLoader{
}
//set up ID mapping
for(int k = 0; k < contentMap.length; k ++){
Array<Content> arr = contentMap[k];
for(Array<Content> arr : contentMap){
for(int i = 0; i < arr.size; i++){
int id = arr.get(i).id;
if(id < 0) id += 256;

View File

@@ -19,8 +19,7 @@ public abstract class Platform {
public String format(Date date){return "invalid";}
/**Format a number by adding in commas or periods where needed.*/
public String format(int number){return "invalid";}
/**Show a native error dialog.*/
public void showError(String text){}
/**Add a text input dialog that should show up after the field is tapped.*/
public void addDialog(TextField field){
addDialog(field, 16);

View File

@@ -180,11 +180,6 @@ public class UI extends SceneModule{
loadfrag.build(group);
}
@Override
public boolean hasMouse(){
return super.hasMouse();
}
@Override
public void resize(int width, int height){
super.resize(width, height);

View File

@@ -102,7 +102,7 @@ public enum EditorTool{
byte brt = Bits.packByte((byte) editor.getDrawRotation(), (byte) editor.getDrawTeam().ordinal());
dest = floor ? bf : bw;
byte draw = (byte) editor.getDrawBlock().id;
byte draw = editor.getDrawBlock().id;
if(dest == draw){
return;

View File

@@ -48,7 +48,7 @@ public class MapEditor{
if(clear){
for(int x = 0; x < map.width(); x++){
for(int y = 0; y < map.height(); y++){
map.write(x, y, DataPosition.floor, (byte) Blocks.stone.id);
map.write(x, y, DataPosition.floor, Blocks.stone.id);
}
}
}
@@ -277,7 +277,7 @@ public class MapEditor{
map = new MapTileData(width, height);
for(int x = 0; x < map.width(); x++){
for(int y = 0; y < map.height(); y++){
map.write(x, y, DataPosition.floor, (byte) Blocks.stone.id);
map.write(x, y, DataPosition.floor, Blocks.stone.id);
}
}
renderer.resize(width, height);

View File

@@ -12,14 +12,14 @@ import io.anuke.ucore.entities.impl.BaseBulletType;
import io.anuke.ucore.util.Translator;
public abstract class BulletType extends Content implements BaseBulletType<Bullet>{
public float lifetime = 100;
public float speed = 1f;
public float damage = 1;
public float lifetime;
public float speed;
public float damage;
public float hitsize = 4;
public float drawSize = 20f;
public float drag = 0f;
public boolean pierce;
public Effect hiteffect = null, despawneffect = null;
public Effect hiteffect, despawneffect;
/**Knockback in velocity.*/
public float knockback;

View File

@@ -32,7 +32,6 @@ import io.anuke.ucore.util.SeedRandom;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.bulletGroup;
import static io.anuke.mindustry.Vars.world;
@@ -161,14 +160,10 @@ public class Lightning extends SolidEntity implements Poolable, DrawTrait, SyncT
}
@Override
public void write(DataOutput data) throws IOException{
}
public void write(DataOutput data){}
@Override
public void read(DataInput data, long time) throws IOException{
}
public void read(DataInput data, long time){}
@Override
public float lifetime(){

View File

@@ -334,16 +334,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
@Override
public void drawUnder(){
}
@Override
public void drawOver(){
}
@Override
public float getMaxVelocity(){
return type.maxVelocity;

View File

@@ -39,7 +39,6 @@ import static io.anuke.mindustry.Vars.*;
public class Drone extends FlyingUnit implements BuilderTrait{
protected static float discoverRange = 120f;
protected static boolean initialized;
protected static int timerRepairEffect = timerIndex++;
protected Item targetItem;
@@ -234,17 +233,7 @@ public class Drone extends FlyingUnit implements BuilderTrait{
}
};
{
initEvents();
}
/**
* Initialize placement event notifier system.
* Static initialization is to be avoided, thus, this is done lazily.
*/
private static void initEvents(){
if(initialized) return;
static{
Events.on(BlockBuildEvent.class, event -> {
EntityGroup<BaseUnit> group = unitGroups[event.team.ordinal()];
@@ -257,8 +246,6 @@ public class Drone extends FlyingUnit implements BuilderTrait{
}
}
});
initialized = true;
}
private void notifyPlaced(BuildEntity entity){

View File

@@ -31,8 +31,7 @@ public class Unlocks{
* @return whether or not this content was newly unlocked.
*/
public boolean unlockContent(UnlockableContent content){
if(rootSet().isUnlocked(content)) return false;
return currentSet().unlockContent(content);
return !rootSet().isUnlocked(content) && currentSet().unlockContent(content);
}
private ContentUnlockSet currentSet(){
@@ -76,7 +75,7 @@ public class Unlocks{
public void load(){
sets.clear();
ObjectMap<String, ObjectMap<ContentType, Array<String>>> result = Settings.getObject("content-sets", ObjectMap.class, () -> new ObjectMap<>());
ObjectMap<String, ObjectMap<ContentType, Array<String>>> result = Settings.getObject("content-sets", ObjectMap.class, ObjectMap::new);
for(Entry<String, ObjectMap<ContentType, Array<String>>> outer : result.entries()){
ContentUnlockSet cset = new ContentUnlockSet();

View File

@@ -252,7 +252,7 @@ public class MobileInput extends InputHandler implements GestureListener{
act.addImageButton("icon-arrow", 16 * 2f, () -> rotation = Mathf.mod(rotation + 1, 4))
.update(i -> i.getImage().setRotationOrigin(rotation * 90, Align.center))
.disabled(i -> recipe == null || !recipe.result.rotate);
}).visible(() -> mode != none).touchable(Touchable.enabled);;
}).visible(() -> mode != none).touchable(Touchable.enabled);
c.row();
@@ -267,7 +267,7 @@ public class MobileInput extends InputHandler implements GestureListener{
showGuide("deconstruction");
}
}).update(l -> l.setChecked(mode == breaking));
}).margin(5).touchable(Touchable.enabled);;
}).margin(5).touchable(Touchable.enabled);
c.table("pane", cancel -> {
cancel.defaults().size(60f);

View File

@@ -74,12 +74,12 @@ public class MapIO{
Block block = ColorMapper.getByColor(pixmap.getPixel(y, pixmap.getWidth() - 1 - x));
if(block == null){
data.write(x, y, DataPosition.floor, (byte) Blocks.stone.id);
data.write(x, y, DataPosition.floor, Blocks.stone.id);
}else{
data.write(x, y, DataPosition.floor, (byte) block.id);
data.write(x, y, DataPosition.floor, block.id);
}
data.write(x, y, DataPosition.wall, (byte) Blocks.air.id);
data.write(x, y, DataPosition.wall, Blocks.air.id);
}
}

View File

@@ -55,21 +55,19 @@ public abstract class SaveFileVersion{
Array<Content>[] map = content.getContentMap();
int mappable = 0;
for(int i =0; i < map.length; i ++){
Array<Content> arr = map[i];
for(Array<Content> arr : map){
if(arr.size > 0 && arr.first() instanceof MappableContent){
mappable ++;
mappable++;
}
}
stream.writeByte(mappable);
for(int i =0; i < map.length; i ++){
Array<Content> arr = map[i];
for(Array<Content> arr : map){
if(arr.size > 0 && arr.first() instanceof MappableContent){
stream.writeByte(arr.first().getContentType().ordinal());
stream.writeShort(arr.size);
for(Content c : arr){
stream.writeUTF(((MappableContent)c).getContentName());
stream.writeUTF(((MappableContent) c).getContentName());
}
}
}

View File

@@ -152,7 +152,7 @@ public class TypeIO{
@WriteClass(Block.class)
public static void writeBlock(ByteBuffer buffer, Block block){
buffer.put((byte) block.id);
buffer.put(block.id);
}
@ReadClass(Block.class)
@@ -278,7 +278,7 @@ public class TypeIO{
@WriteClass(Liquid.class)
public static void writeLiquid(ByteBuffer buffer, Liquid liquid){
buffer.put((byte) liquid.id);
buffer.put(liquid.id);
}
@ReadClass(Liquid.class)
@@ -298,7 +298,7 @@ public class TypeIO{
@WriteClass(BulletType.class)
public static void writeBulletType(ByteBuffer buffer, BulletType type){
buffer.put((byte) type.id);
buffer.put(type.id);
}
@ReadClass(BulletType.class)
@@ -308,7 +308,7 @@ public class TypeIO{
@WriteClass(Item.class)
public static void writeItem(ByteBuffer buffer, Item item){
buffer.put(item == null ? -1 : (byte) item.id);
buffer.put(item == null ? -1 : item.id);
}
@ReadClass(Item.class)
@@ -319,7 +319,7 @@ public class TypeIO{
@WriteClass(Recipe.class)
public static void writeRecipe(ByteBuffer buffer, Recipe recipe){
buffer.put((byte) recipe.id);
buffer.put(recipe.id);
}
@ReadClass(Recipe.class)

View File

@@ -159,7 +159,7 @@ public class Maps implements Disposable{
}
}else{
customMapNames = Settings.getObject("custom-maps", Array.class, () -> new Array<>());
customMapNames = Settings.getObject("custom-maps", Array.class, Array::new);
for(String name : customMapNames){
try{

View File

@@ -16,35 +16,42 @@ import static io.anuke.mindustry.Vars.mobile;
public class SectorPresets{
private final GridMap<SectorPreset> presets = new GridMap<SectorPreset>(){{
//base tutorial mission
put(0, 0, new SectorPreset(TutorialSector.getMissions(), Array.with(Items.copper), 1));
put(0, 0, new SectorPreset(TutorialSector.getMissions(), 1));
//water mission
put(-2, 0, new SectorPreset(Array.with(), Array.with(Items.copper), 1));
put(-2, 0, new SectorPreset(Array.with(), 1));
//command center mission
//TODO generate enemy base
//TODO make 2x2
//TODO more gen info
put(0, 1, new SectorPreset(Structs.array(new BlockMission(UnitBlocks.daggerFactory), Missions.blockRecipe(UnitBlocks.commandCenter),
new CommandMission(UnitCommand.retreat), new CommandMission(UnitCommand.attack), new BattleMission()), Array.with(Items.copper), 1));
new CommandMission(UnitCommand.retreat), new CommandMission(UnitCommand.attack), new BattleMission()), 2));
//reconstructor mission
put(0, -1, new SectorPreset(Structs.array(Missions.blockRecipe(mobile ? UpgradeBlocks.tridentPad : UpgradeBlocks.deltaPad),
new MechMission(Mechs.delta)), Array.with(Items.copper), 1));
new MechMission(Mechs.delta)), 1));
//oil mission
put(1, 0, new SectorPreset(Array.with(), Array.with(Items.copper), 1));
put(1, 0, new SectorPreset(Array.with(), 1));
}};
private final GridMap<Array<Item>> orePresets = new GridMap<Array<Item>>(){{
put(0, 0, Array.with(Items.copper));
put(1, 0, Array.with(Items.copper, Items.lead, Items.coal));
}};
public Array<Item> getOres(int x, int y){
return orePresets.get(x, y);
}
public SectorPreset get(int x, int y){
return presets.get(x, y);
}
public static class SectorPreset{
public final Array<Mission> missions;
public final Array<Item> ores;
public final int size;
public SectorPreset(Array<Mission> missions, Array<Item> ores, int size){
public SectorPreset(Array<Mission> missions, int size){
this.missions = missions;
this.ores = ores;
this.size = size;
}

View File

@@ -207,12 +207,7 @@ public class Sectors{
}
public Array<Item> getOres(int x, int y){
if(x == 0 && y == 0){
return Array.with(Items.copper);
}else if(x == 1 && y == 0){
return Array.with(Items.copper, Items.lead, Items.coal);
}
return Array.with(Items.copper);
return presets.getOres(x, y) == null ? Array.with(Items.copper) : presets.getOres(x, y);
}
/**Unlocks a sector. This shows nearby sectors.*/
@@ -263,7 +258,7 @@ public class Sectors{
}
grid.clear();
Array<Sector> out = Settings.getObject("sectors", Array.class, () -> new Array<>());
Array<Sector> out = Settings.getObject("sectors", Array.class, Array::new);
for(Sector sector : out){
createTexture(sector);
@@ -297,6 +292,7 @@ public class Sectors{
if(presets.get(sector.x, sector.y) != null){
SectorPreset p = presets.get(sector.x, sector.y);
sector.missions.addAll(p.missions);
sector.width = sector.height = p.size;
}else{
genMissions(sector);
}

View File

@@ -276,8 +276,8 @@ public class Administration{
}
private void load(){
playerInfo = Settings.getObject("player-info", ObjectMap.class, () -> new ObjectMap<>());
bannedIPs = Settings.getObject("banned-ips", Array.class, () -> new Array<>());
playerInfo = Settings.getObject("player-info", ObjectMap.class, ObjectMap::new);
bannedIPs = Settings.getObject("banned-ips", Array.class, Array::new);
}
@Serialize

View File

@@ -22,7 +22,6 @@ import io.anuke.ucore.util.Log;
import io.anuke.ucore.util.Strings;
import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.port;
public class JoinDialog extends FloatingDialog{
Array<Server> servers = new Array<>();
@@ -327,7 +326,7 @@ public class JoinDialog extends FloatingDialog{
}
private void loadServers(){
servers = Settings.getObject("server-list", Array.class, () -> new Array<>());
servers = Settings.getObject("server-list", Array.class, Array::new);
}
private void saveServers(){

View File

@@ -52,7 +52,6 @@ public class SaveDialog extends LoadDialog{
slot.save();
}catch(Throwable e){
e.printStackTrace();
e = (e.getCause() == null ? e : e.getCause());
ui.showError("[orange]" + Bundles.get("text.savefail"));
}

View File

@@ -313,8 +313,8 @@ public class BlocksFragment extends Fragment{
descTable.row();
descTable.add(requirements);
descTable.left();
descTable.add(requirements);
for(ItemStack stack : recipe.requirements){
requirements.addImage(stack.item.region).size(8 * 3);

View File

@@ -142,7 +142,7 @@ public class BuildBlock extends Block{
for(TextureRegion region : target.getBlockIcon()){
Shaders.blockbuild.region = region;
Shaders.blockbuild.progress = (float) entity.progress;
Shaders.blockbuild.progress = entity.progress;
Shaders.blockbuild.apply();
Draw.rect(region, tile.drawx(), tile.drawy(), target.rotate ? tile.getRotation() * 90 : 0);
@@ -165,11 +165,6 @@ public class BuildBlock extends Block{
}
}
@Override
public void update(Tile tile){
}
@Override
public TileEntity newEntity(){
return new BuildEntity();

View File

@@ -27,7 +27,7 @@ public class Floor extends Block{
120, 29, 122, 30, 123, 31, 126, 32, 127, 33, 208, 34, 210, 35, 214, 36, 216, 37,
218, 38, 219, 39, 222, 40, 223, 41, 248, 42, 250, 43, 251, 44, 254, 45, 255, 46, 0, 47);
/** number of different variant regions to use */
public int variants = 0;
public int variants;
/** edge fallback, used mainly for ores */
public String edge = "stone";
/** Multiplies unit velocity by this when walked on. */

View File

@@ -10,7 +10,6 @@ import io.anuke.ucore.scene.ui.ButtonGroup;
import io.anuke.ucore.scene.ui.ImageButton;
import io.anuke.ucore.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.*;
public interface SelectionTrait{

View File

@@ -6,10 +6,6 @@ import io.anuke.mindustry.world.ItemBuffer;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.util.Mathf;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class BufferedItemBridge extends ExtendingItemBridge{
protected int timerAccept = timers++;
@@ -47,15 +43,5 @@ public class BufferedItemBridge extends ExtendingItemBridge{
class BufferedItemBridgeEntity extends ItemBridgeEntity{
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
@Override
public void write(DataOutputStream stream) throws IOException{
super.write(stream);
}
@Override
public void read(DataInputStream stream) throws IOException{
super.read(stream);
}
}
}

View File

@@ -77,9 +77,7 @@ public class Conduit extends LiquidBlock{
Tile other = tile.getNearby(Mathf.mod(tile.getRotation() - direction, 4));
if(other != null) other = other.target();
if(other == null || !(other.block().hasLiquids) || !(other.block().outputsLiquid)) return false;
return (tile.getNearby(tile.getRotation()) == other)
|| (!other.block().rotate || other.getNearby(other.getRotation()) == tile);
return other != null && other.block().hasLiquids && other.block().outputsLiquid && ((tile.getNearby(tile.getRotation()) == other) || (!other.block().rotate || other.getNearby(other.getRotation()) == tile));
}
@Override

View File

@@ -20,9 +20,6 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.itemSize;
import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.*;
public class Conveyor extends Block{

View File

@@ -80,11 +80,6 @@ public class WarpGate extends PowerBlock{
entity.color = color;
}
@Override
public void setStats(){
super.setStats();
}
@Override
public void playerPlaced(Tile tile){
Call.setTeleporterColor(null, tile, lastColor);

View File

@@ -32,11 +32,6 @@ public class Fracker extends SolidPump{
topRegion = Draw.region(name + "-top");
}
@Override
public void setStats(){
super.setStats();
}
@Override
public void draw(Tile tile){
FrackerEntity entity = tile.entity();

View File

@@ -9,7 +9,6 @@ import io.anuke.mindustry.world.consumers.ConsumeLiquid;
import io.anuke.mindustry.world.meta.BlockBar;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
public class LiquidMixer extends LiquidBlock{

View File

@@ -166,11 +166,8 @@ public class PowerSmelter extends PowerBlock{
}
}
if(useFlux && item.fluxiness >= minFlux){
return tile.entity.items.get(item) < itemCapacity;
}
return useFlux && item.fluxiness >= minFlux && tile.entity.items.get(item) < itemCapacity;
return false;
}
@Override

View File

@@ -9,7 +9,6 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Effects.Effect;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
@@ -107,8 +106,7 @@ public class SolidPump extends Pump{
@Override
protected boolean isValid(Tile tile){
if(tile == null) return false;
return !tile.floor().isLiquid;
return tile != null && !tile.floor().isLiquid;
}
@Override

View File

@@ -179,12 +179,6 @@ public class CoreBlock extends StorageBlock{
return tile.entity.items.get(item) < itemCapacity && item.type == ItemType.material;
}
@Override
public void onDestroyed(Tile tile){
super.onDestroyed(tile);
//TODO more dramatic effects
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
if(Net.server() || !Net.active()) super.handleItem(item, tile, source);

View File

@@ -28,11 +28,6 @@ public class Vault extends StorageBlock{
}
}
@Override
public void handleItem(Item item, Tile tile, Tile source){
super.handleItem(item, tile, source);
}
@Override
public boolean acceptItem(Item item, Tile tile, Tile source){
return tile.entity.items.total() < itemCapacity;

View File

@@ -32,8 +32,7 @@ public class ConsumePower extends Consume{
@Override
public boolean valid(Block block, TileEntity entity){
if(entity.power == null) return false;
return entity.power.amount >= use(block, entity);
return entity.power != null && entity.power.amount >= use(block, entity);
}
@Override