From 97f5bf3cc4898cf3312efca9c05a63f2768515f3 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 24 Mar 2019 19:58:51 -0400 Subject: [PATCH] Code cleanup --- android/src/io/anuke/mindustry/AndroidLauncher.java | 2 +- .../main/java/io/anuke/annotations/Annotations.java | 12 ++++++++++++ build.gradle | 2 +- core/assets/bundles/bundle.properties | 3 ++- core/src/io/anuke/mindustry/core/Control.java | 5 ++++- core/src/io/anuke/mindustry/core/World.java | 12 +++++++++--- .../io/anuke/mindustry/editor/MapGenerateDialog.java | 2 +- core/src/io/anuke/mindustry/editor/MapRenderer.java | 2 +- core/src/io/anuke/mindustry/entities/Effects.java | 4 ++-- core/src/io/anuke/mindustry/input/InputHandler.java | 11 +++-------- .../world/blocks/production/PowerCrafter.java | 5 +---- .../test/java/power/ItemLiquidGeneratorTests.java | 4 ++-- tools/build.gradle | 2 +- tools/src/io/anuke/mindustry/BundleLauncher.java | 4 ++-- 14 files changed, 42 insertions(+), 28 deletions(-) diff --git a/android/src/io/anuke/mindustry/AndroidLauncher.java b/android/src/io/anuke/mindustry/AndroidLauncher.java index a7bb47034b..e146ebdfd6 100644 --- a/android/src/io/anuke/mindustry/AndroidLauncher.java +++ b/android/src/io/anuke/mindustry/AndroidLauncher.java @@ -133,7 +133,7 @@ public class AndroidLauncher extends AndroidApplication{ } @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults){ + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){ if(requestCode == PERMISSION_REQUEST_CODE){ for(int i : grantResults){ if(i != PackageManager.PERMISSION_GRANTED) return; diff --git a/annotations/src/main/java/io/anuke/annotations/Annotations.java b/annotations/src/main/java/io/anuke/annotations/Annotations.java index ce7832f76d..15609ced97 100644 --- a/annotations/src/main/java/io/anuke/annotations/Annotations.java +++ b/annotations/src/main/java/io/anuke/annotations/Annotations.java @@ -7,6 +7,18 @@ import java.lang.annotation.Target; 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.*/ @Target(ElementType.TYPE) @Retention(RetentionPolicy.SOURCE) diff --git a/build.gradle b/build.gradle index 1d208e44ad..3c9b36d043 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ allprojects{ arcHash = 'git ls-remote https://github.com/Anuken/Arc.git'.execute().text.split("\t")[0] }catch(e){ e.printStackTrace() - arcHash = "-SNAPSHOT"; + arcHash = "-SNAPSHOT" } } return arcHash diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index eebc3632d6..16293d6b70 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -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.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.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. editor.brush = Brush editor.openin = Open In Editor diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index b7bd5bb2a8..5192436524 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -8,7 +8,10 @@ import io.anuke.arc.graphics.GL20; import io.anuke.arc.graphics.g2d.Draw; import io.anuke.arc.graphics.g2d.TextureAtlas; 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.core.GameState.State; import io.anuke.mindustry.entities.Effects; diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index 914154e030..37e0137974 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.core; +import io.anuke.annotations.Annotations.Nullable; import io.anuke.arc.ApplicationListener; import io.anuke.arc.Core; import io.anuke.arc.Events; @@ -96,11 +97,11 @@ public class World implements ApplicationListener{ 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)); } - public Tile tile(int x, int y){ + public @Nullable Tile tile(int x, int y){ if(tiles == null){ return null; } @@ -112,7 +113,7 @@ public class World implements ApplicationListener{ 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)); } @@ -271,6 +272,11 @@ public class World implements ApplicationListener{ if(invalidMap){ 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{ invalidMap = true; diff --git a/core/src/io/anuke/mindustry/editor/MapGenerateDialog.java b/core/src/io/anuke/mindustry/editor/MapGenerateDialog.java index fe24a20590..d35f0048f7 100644 --- a/core/src/io/anuke/mindustry/editor/MapGenerateDialog.java +++ b/core/src/io/anuke/mindustry/editor/MapGenerateDialog.java @@ -233,7 +233,7 @@ public class MapGenerateDialog extends FloatingDialog{ Tile tile = editor.tile(x, y); DummyTile write = writeTiles[x][y]; - tile.setRotation((byte)write.rotation); + tile.setRotation(write.rotation); tile.setFloor((Floor)content.block(write.floor)); tile.setBlock(content.block(write.block)); tile.setTeam(Team.all[write.team]); diff --git a/core/src/io/anuke/mindustry/editor/MapRenderer.java b/core/src/io/anuke/mindustry/editor/MapRenderer.java index 65aa4fa56a..65a36b0858 100644 --- a/core/src/io/anuke/mindustry/editor/MapRenderer.java +++ b/core/src/io/anuke/mindustry/editor/MapRenderer.java @@ -140,7 +140,7 @@ public class MapRenderer implements Disposable{ offsetX = tilesize/2f - region.getWidth()/2f * Draw.scl; offsetY = tilesize/2f - region.getHeight()/2f * Draw.scl; }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{ region = Core.atlas.find("clear-editor"); } diff --git a/core/src/io/anuke/mindustry/entities/Effects.java b/core/src/io/anuke/mindustry/entities/Effects.java index 576d5cc56e..4a2f964b61 100644 --- a/core/src/io/anuke/mindustry/entities/Effects.java +++ b/core/src/io/anuke/mindustry/entities/Effects.java @@ -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); } - public static interface EffectRenderer{ + public interface EffectRenderer{ void render(EffectContainer effect); } } diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index b392de16b0..164088fb6f 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -308,25 +308,20 @@ public abstract class InputHandler implements InputProcessor{ } } - public boolean cursorNear(){ - return true; - } - 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); } } public void tryBreakBlock(int x, int y){ - if(cursorNear() && validBreak(x, y)){ + if(validBreak(x, y)){ breakBlock(x, y); } } public boolean validPlace(int x, int y, Block type, int rotation){ - return Build.validPlace(player.getTeam(), x, y, type, rotation) && - Mathf.dst(player.x, player.y, x * tilesize, y * tilesize) < Player.placeDistance; + return Build.validPlace(player.getTeam(), x, y, type, rotation); } public boolean validBreak(int x, int y){ diff --git a/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java b/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java index c57831f628..d04bf10c80 100644 --- a/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java +++ b/core/src/io/anuke/mindustry/world/blocks/production/PowerCrafter.java @@ -67,10 +67,7 @@ public class PowerCrafter extends Block{ if(outputItem != null && tile.entity.items.get(outputItem) >= itemCapacity){ return false; } - if(outputLiquid != null && tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f){ - return false; - } - return true; + return outputLiquid == null || !(tile.entity.liquids.get(outputLiquid) >= liquidCapacity - 0.01f); } @Override diff --git a/tests/src/test/java/power/ItemLiquidGeneratorTests.java b/tests/src/test/java/power/ItemLiquidGeneratorTests.java index 153b9ead50..9c6d88dae5 100644 --- a/tests/src/test/java/power/ItemLiquidGeneratorTests.java +++ b/tests/src/test/java/power/ItemLiquidGeneratorTests.java @@ -169,10 +169,10 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{ float currentDuration = 0.0f; while((currentDuration += Time.delta()) <= fakeItemDuration){ generator.update(tile); - assertEquals(expectedEfficiency, entity.productionEfficiency, "Duration: " + String.valueOf(currentDuration)); + assertEquals(expectedEfficiency, entity.productionEfficiency, "Duration: " + currentDuration); } generator.update(tile); - assertEquals(0.0f, entity.productionEfficiency, "Duration: " + String.valueOf(currentDuration)); + assertEquals(0.0f, entity.productionEfficiency, "Duration: " + currentDuration); } enum InputType{ diff --git a/tools/build.gradle b/tools/build.gradle index 0d4f7f2819..c5db3b5503 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -152,7 +152,7 @@ task scaleSprites4x(){ J = getRGB(x, y + 2), K = 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==F & B!=D & F!=H && (E!=C || E==A || E==I || C==J || C==L)) p2 = F diff --git a/tools/src/io/anuke/mindustry/BundleLauncher.java b/tools/src/io/anuke/mindustry/BundleLauncher.java index 8732638b89..f31cd060d4 100644 --- a/tools/src/io/anuke/mindustry/BundleLauncher.java +++ b/tools/src/io/anuke/mindustry/BundleLauncher.java @@ -30,7 +30,7 @@ public class BundleLauncher { Log.info("Parsing bundle: {0}", child); OrderedMap other = new OrderedMap<>(); - PropertiesUtils.load(other, Files.newBufferedReader(child, StandardCharsets.UTF_8)); + PropertiesUtils.load(other, Files.newBufferedReader(child, Strings.utf8)); removals.clear(); for(String key : other.orderedKeys()){ @@ -68,7 +68,7 @@ public class BundleLauncher { other.remove(key); } - Files.write(child, result.toString().getBytes(StandardCharsets.UTF_8)); + Files.write(child, result.toString().getBytes(Strings.utf8)); }catch (IOException e){ throw new RuntimeException(e);