Code cleanup

This commit is contained in:
Anuken
2019-03-24 19:58:51 -04:00
parent bb9573b85a
commit 97f5bf3cc4
14 changed files with 42 additions and 28 deletions

View File

@@ -133,7 +133,7 @@ public class AndroidLauncher extends AndroidApplication{
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults){ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
if(requestCode == PERMISSION_REQUEST_CODE){ if(requestCode == PERMISSION_REQUEST_CODE){
for(int i : grantResults){ for(int i : grantResults){
if(i != PackageManager.PERMISSION_GRANTED) return; if(i != PackageManager.PERMISSION_GRANTED) return;

View File

@@ -7,6 +7,18 @@ import java.lang.annotation.Target;
public class Annotations{ public class Annotations{
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Nullable{
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface NonNull{
}
/** Marks a class as serializable.*/ /** Marks a class as serializable.*/
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)

View File

@@ -43,7 +43,7 @@ allprojects{
arcHash = 'git ls-remote https://github.com/Anuken/Arc.git'.execute().text.split("\t")[0] arcHash = 'git ls-remote https://github.com/Anuken/Arc.git'.execute().text.split("\t")[0]
}catch(e){ }catch(e){
e.printStackTrace() e.printStackTrace()
arcHash = "-SNAPSHOT"; arcHash = "-SNAPSHOT"
} }
} }
return arcHash return arcHash

View File

@@ -184,7 +184,8 @@ builtin = Built-In
map.delete.confirm = Are you sure you want to delete this map? This action cannot be undone! map.delete.confirm = Are you sure you want to delete this map? This action cannot be undone!
map.random = [accent]Random Map map.random = [accent]Random Map
map.nospawn = This map does not have any cores for the player to spawn in! Add a[ROYAL] blue[] core to this map in the editor. map.nospawn = This map does not have any cores for the player to spawn in! Add a[ROYAL] blue[] core to this map in the editor.
map.nospawn.pvp = This map does not have any enemy cores for player to spawn into! Add[SCARLET] red[] cores to this map in the editor. map.nospawn.pvp = This map does not have any enemy cores for player to spawn into! Add[SCARLET] non-blue[] cores to this map in the editor.
map.nospawn.attack = This map does not have any enemy cores for player to attack! Add[SCARLET] red[] cores to this map in the editor.
map.invalid = Error loading map: corrupted or invalid map file. map.invalid = Error loading map: corrupted or invalid map file.
editor.brush = Brush editor.brush = Brush
editor.openin = Open In Editor editor.openin = Open In Editor

View File

@@ -8,7 +8,10 @@ import io.anuke.arc.graphics.GL20;
import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureAtlas; import io.anuke.arc.graphics.g2d.TextureAtlas;
import io.anuke.arc.input.KeyCode; import io.anuke.arc.input.KeyCode;
import io.anuke.arc.util.*; import io.anuke.arc.util.BufferUtils;
import io.anuke.arc.util.Interval;
import io.anuke.arc.util.Strings;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.Mechs; import io.anuke.mindustry.content.Mechs;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Effects; import io.anuke.mindustry.entities.Effects;

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.core; package io.anuke.mindustry.core;
import io.anuke.annotations.Annotations.Nullable;
import io.anuke.arc.ApplicationListener; import io.anuke.arc.ApplicationListener;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.Events; import io.anuke.arc.Events;
@@ -96,11 +97,11 @@ public class World implements ApplicationListener{
return tiles == null ? 0 : tiles[0].length; return tiles == null ? 0 : tiles[0].length;
} }
public Tile tile(int pos){ public @Nullable Tile tile(int pos){
return tiles == null ? null : tile(Pos.x(pos), Pos.y(pos)); return tiles == null ? null : tile(Pos.x(pos), Pos.y(pos));
} }
public Tile tile(int x, int y){ public @Nullable Tile tile(int x, int y){
if(tiles == null){ if(tiles == null){
return null; return null;
} }
@@ -112,7 +113,7 @@ public class World implements ApplicationListener{
return tiles[x][y]; return tiles[x][y];
} }
public Tile tileWorld(float x, float y){ public @Nullable Tile tileWorld(float x, float y){
return tile(Math.round(x / tilesize), Math.round(y / tilesize)); return tile(Math.round(x / tilesize), Math.round(y / tilesize));
} }
@@ -271,6 +272,11 @@ public class World implements ApplicationListener{
if(invalidMap){ if(invalidMap){
ui.showError("$map.nospawn.pvp"); ui.showError("$map.nospawn.pvp");
} }
}else if(!state.rules.waves){ //pvp maps need two cores to be valid
invalidMap = state.teams.get(waveTeam).cores.isEmpty();
if(invalidMap){
ui.showError("$map.nospawn.attack");
}
} }
}else{ }else{
invalidMap = true; invalidMap = true;

View File

@@ -233,7 +233,7 @@ public class MapGenerateDialog extends FloatingDialog{
Tile tile = editor.tile(x, y); Tile tile = editor.tile(x, y);
DummyTile write = writeTiles[x][y]; DummyTile write = writeTiles[x][y];
tile.setRotation((byte)write.rotation); tile.setRotation(write.rotation);
tile.setFloor((Floor)content.block(write.floor)); tile.setFloor((Floor)content.block(write.floor));
tile.setBlock(content.block(write.block)); tile.setBlock(content.block(write.block));
tile.setTeam(Team.all[write.team]); tile.setTeam(Team.all[write.team]);

View File

@@ -140,7 +140,7 @@ public class MapRenderer implements Disposable{
offsetX = tilesize/2f - region.getWidth()/2f * Draw.scl; offsetX = tilesize/2f - region.getWidth()/2f * Draw.scl;
offsetY = tilesize/2f - region.getHeight()/2f * Draw.scl; offsetY = tilesize/2f - region.getHeight()/2f * Draw.scl;
}else if(wall == Blocks.air && tile.ore() != null){ }else if(wall == Blocks.air && tile.ore() != null){
region = tile.ore().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.ore().editorVariantRegions().length-1)];; region = tile.ore().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.ore().editorVariantRegions().length-1)];
}else{ }else{
region = Core.atlas.find("clear-editor"); region = Core.atlas.find("clear-editor");
} }

View File

@@ -156,11 +156,11 @@ public class Effects{
} }
} }
public static interface EffectProvider{ public interface EffectProvider{
void createEffect(Effect effect, Color color, float x, float y, float rotation, Object data); void createEffect(Effect effect, Color color, float x, float y, float rotation, Object data);
} }
public static interface EffectRenderer{ public interface EffectRenderer{
void render(EffectContainer effect); void render(EffectContainer effect);
} }
} }

View File

@@ -308,25 +308,20 @@ public abstract class InputHandler implements InputProcessor{
} }
} }
public boolean cursorNear(){
return true;
}
public void tryPlaceBlock(int x, int y){ public void tryPlaceBlock(int x, int y){
if(block != null && validPlace(x, y, block, rotation) && cursorNear()){ if(block != null && validPlace(x, y, block, rotation)){
placeBlock(x, y, block, rotation); placeBlock(x, y, block, rotation);
} }
} }
public void tryBreakBlock(int x, int y){ public void tryBreakBlock(int x, int y){
if(cursorNear() && validBreak(x, y)){ if(validBreak(x, y)){
breakBlock(x, y); breakBlock(x, y);
} }
} }
public boolean validPlace(int x, int y, Block type, int rotation){ public boolean validPlace(int x, int y, Block type, int rotation){
return Build.validPlace(player.getTeam(), x, y, type, rotation) && return Build.validPlace(player.getTeam(), x, y, type, rotation);
Mathf.dst(player.x, player.y, x * tilesize, y * tilesize) < Player.placeDistance;
} }
public boolean validBreak(int x, int y){ public boolean validBreak(int x, int y){

View File

@@ -67,10 +67,7 @@ public class PowerCrafter extends Block{
if(outputItem != null && tile.entity.items.get(outputItem) >= itemCapacity){ if(outputItem != null && tile.entity.items.get(outputItem) >= itemCapacity){
return false; return false;
} }
if(outputLiquid != null && tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f){ return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f);
return false;
}
return true;
} }
@Override @Override

View File

@@ -169,10 +169,10 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
float currentDuration = 0.0f; float currentDuration = 0.0f;
while((currentDuration += Time.delta()) <= fakeItemDuration){ while((currentDuration += Time.delta()) <= fakeItemDuration){
generator.update(tile); generator.update(tile);
assertEquals(expectedEfficiency, entity.productionEfficiency, "Duration: " + String.valueOf(currentDuration)); assertEquals(expectedEfficiency, entity.productionEfficiency, "Duration: " + currentDuration);
} }
generator.update(tile); generator.update(tile);
assertEquals(0.0f, entity.productionEfficiency, "Duration: " + String.valueOf(currentDuration)); assertEquals(0.0f, entity.productionEfficiency, "Duration: " + currentDuration);
} }
enum InputType{ enum InputType{

View File

@@ -152,7 +152,7 @@ task scaleSprites4x(){
J = getRGB(x, y + 2), J = getRGB(x, y + 2),
K = getRGB(x - 2, y), K = getRGB(x - 2, y),
L = getRGB(x + 2, y), L = getRGB(x + 2, y),
M = getRGB(x, y - 2); M = getRGB(x, y - 2)
if (B==D && B!=F && D!=H && (E!=A || E==C || E==G || A==J || A==K)) p1 = B if (B==D && B!=F && D!=H && (E!=A || E==C || E==G || A==J || A==K)) p1 = B
if (B==F & B!=D & F!=H && (E!=C || E==A || E==I || C==J || C==L)) p2 = F if (B==F & B!=D & F!=H && (E!=C || E==A || E==I || C==J || C==L)) p2 = F

View File

@@ -30,7 +30,7 @@ public class BundleLauncher {
Log.info("Parsing bundle: {0}", child); Log.info("Parsing bundle: {0}", child);
OrderedMap<String, String> other = new OrderedMap<>(); OrderedMap<String, String> other = new OrderedMap<>();
PropertiesUtils.load(other, Files.newBufferedReader(child, StandardCharsets.UTF_8)); PropertiesUtils.load(other, Files.newBufferedReader(child, Strings.utf8));
removals.clear(); removals.clear();
for(String key : other.orderedKeys()){ for(String key : other.orderedKeys()){
@@ -68,7 +68,7 @@ public class BundleLauncher {
other.remove(key); other.remove(key);
} }
Files.write(child, result.toString().getBytes(StandardCharsets.UTF_8)); Files.write(child, result.toString().getBytes(Strings.utf8));
}catch (IOException e){ }catch (IOException e){
throw new RuntimeException(e); throw new RuntimeException(e);