From 0a04de04f1520cd25ddc6981e435a635b056bff0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 12 Mar 2019 11:07:02 -0400 Subject: [PATCH] Format bugfixes --- core/assets/bundles/bundle.properties | 1 - .../anuke/mindustry/editor/DrawOperation.java | 33 ++++++++++--------- .../io/anuke/mindustry/editor/EditorTool.java | 15 ++++----- .../mindustry/editor/MapEditorDialog.java | 12 ------- core/src/io/anuke/mindustry/io/MapIO.java | 22 +++++++++---- core/src/io/anuke/mindustry/maps/Maps.java | 3 ++ 6 files changed, 42 insertions(+), 44 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 7379296bf3..a9207e030c 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -560,7 +560,6 @@ block.white-tree-dead.name = White Tree Dead block.white-tree.name = White Tree block.spore-cluster.name = Spore Cluster block.stained-rocks.name = Stained Rocks -block.stained-stone.name = Stained Stone block.stained-rocks-red.name = Stained Rocks Red block.stained-stone-red.name = Stained Stone Red block.stained-rocks-yellow.name = Stained Rocks Yellow diff --git a/core/src/io/anuke/mindustry/editor/DrawOperation.java b/core/src/io/anuke/mindustry/editor/DrawOperation.java index c4772dabed..c5b80cd201 100755 --- a/core/src/io/anuke/mindustry/editor/DrawOperation.java +++ b/core/src/io/anuke/mindustry/editor/DrawOperation.java @@ -21,31 +21,34 @@ public class DrawOperation{ } public void undo(MapEditor editor){ - for(int i = 0; i < array.size; i++){ + for(int i = array.size - 1; i >= 0; i--){ long l = array.get(i); - set(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.from(l)); + set(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.from(l)); } } public void redo(MapEditor editor){ for(int i = 0; i < array.size; i++){ long l = array.get(i); - set(editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.to(l)); + set(editor, editor.tile(TileOp.x(l), TileOp.y(l)), TileOp.type(l), TileOp.to(l)); } } - void set(Tile tile, byte type, byte to){ - if(type == OpType.floor.ordinal()){ - tile.setFloor((Floor)content.block(to)); - }else if(type == OpType.block.ordinal()){ - tile.setBlock(content.block(to)); - }else if(type == OpType.rotation.ordinal()){ - tile.setRotation(to); - }else if(type == OpType.team.ordinal()){ - tile.setTeam(Team.all[to]); - }else if(type == OpType.ore.ordinal()){ - tile.setOre(to); - } + void set(MapEditor editor, Tile tile, byte type, byte to){ + editor.load(() -> { + if(type == OpType.floor.ordinal()){ + tile.setFloor((Floor)content.block(to)); + }else if(type == OpType.block.ordinal()){ + tile.setBlock(content.block(to)); + }else if(type == OpType.rotation.ordinal()){ + tile.setRotation(to); + }else if(type == OpType.team.ordinal()){ + tile.setTeam(Team.all[to]); + }else if(type == OpType.ore.ordinal()){ + tile.setOre(to); + } + }); + editor.renderer().updatePoint(tile.x, tile.y); } @Struct diff --git a/core/src/io/anuke/mindustry/editor/EditorTool.java b/core/src/io/anuke/mindustry/editor/EditorTool.java index 690e193474..6effe3bbd8 100644 --- a/core/src/io/anuke/mindustry/editor/EditorTool.java +++ b/core/src/io/anuke/mindustry/editor/EditorTool.java @@ -10,22 +10,20 @@ import io.anuke.mindustry.content.Blocks; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Pos; import io.anuke.mindustry.world.Tile; +import io.anuke.mindustry.world.blocks.BlockPart; import io.anuke.mindustry.world.blocks.Floor; -import static io.anuke.mindustry.Vars.ui; -import static io.anuke.mindustry.Vars.world; - public enum EditorTool{ pick{ public void touched(MapEditor editor, int x, int y){ - if(!Structs.inBounds(x, y, world.width(), world.height())) return; + if(!Structs.inBounds(x, y, editor.width(), editor.height())) return; Tile tile = editor.tile(x, y); Block floor = tile.floor(), block = tile.block(); byte link = tile.getLinkByte(); - if(link != 0){ + if(block instanceof BlockPart && link != 0){ x -= (Pack.leftByte(link) - 8); y -= (Pack.rightByte(link) - 8); @@ -34,7 +32,6 @@ public enum EditorTool{ } editor.drawBlock = block == Blocks.air ? floor : block; - ui.editor.updateSelectedBlock(); } }, pencil{ @@ -86,7 +83,7 @@ public enum EditorTool{ MapEditor data; public void touched(MapEditor editor, int x, int y){ - if(!Structs.inBounds(x, y, world.width(), world.height())) return; + if(!Structs.inBounds(x, y, editor.width(), editor.height())) return; Tile tile = editor.tile(x, y); if(editor.drawBlock.isMultiblock()){ @@ -109,8 +106,8 @@ public enum EditorTool{ return; } - int width = world.width(); - int height = world.height(); + int width = editor.width(); + int height = editor.height(); IntPositionConsumer writer = (px, py) -> { Tile write = editor.tile(px, py); diff --git a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java index 5f4cda2fc6..f3a855cf2e 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java @@ -43,8 +43,6 @@ public class MapEditorDialog extends Dialog implements Disposable{ private boolean shownWithMap = false; private Array blocksOut = new Array<>(); - private ButtonGroup blockgroup; - public MapEditorDialog(){ super("", "dialog"); @@ -295,15 +293,6 @@ public class MapEditorDialog extends Dialog implements Disposable{ saved = false; } - public void updateSelectedBlock(){ - for(int j = 0; j < Vars.content.blocks().size; j++){ - if(editor.drawBlock.id == j && j < blockgroup.getButtons().size){ - blockgroup.getButtons().get(j).setChecked(true); - break; - } - } - } - public boolean hasPane(){ return Core.scene.getScrollFocus() == pane || Core.scene.getKeyboardFocus() != this; } @@ -475,7 +464,6 @@ public class MapEditorDialog extends Dialog implements Disposable{ pane.setFadeScrollBars(false); pane.setOverscroll(true, false); ButtonGroup group = new ButtonGroup<>(); - blockgroup = group; int i = 0; diff --git a/core/src/io/anuke/mindustry/io/MapIO.java b/core/src/io/anuke/mindustry/io/MapIO.java index 3c568f555a..4ace5c65fc 100644 --- a/core/src/io/anuke/mindustry/io/MapIO.java +++ b/core/src/io/anuke/mindustry/io/MapIO.java @@ -59,13 +59,20 @@ public class MapIO{ } } - //TODO implement public static Pixmap generatePreview(Map map) throws IOException{ - Pixmap pixmap = new Pixmap(map.width, map.height, Format.RGBA8888); + Pixmap floor = new Pixmap(map.width, map.height, Format.RGBA8888); + Pixmap wall = new Pixmap(map.width, map.height, Format.RGBA8888); + int black = Color.rgba8888(Color.BLACK); CachedTile tile = new CachedTile(){ + @Override + public void setFloor(Floor type){ + floor.drawPixel(x, floor.getHeight() - 1 - y, colorFor(type, Blocks.air, getTeam())); + } + @Override protected void changed(){ - pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, colorFor(floor(), block(), getTeam())); + int c = colorFor(Blocks.air, block(), getTeam()); + if(c != black) wall.drawPixel(x, floor.getHeight() - 1 - y, c); } }; readTiles(map, (x, y) -> { @@ -73,7 +80,9 @@ public class MapIO{ tile.y = (short)y; return tile; }); - return pixmap; + floor.drawPixmap(wall, 0, 0); + wall.dispose(); + return floor; } public static Pixmap generatePreview(Tile[][] tiles){ @@ -227,8 +236,8 @@ public class MapIO{ byte tagAmount = stream.readByte(); for(int i = 0; i < tagAmount; i++){ - stream.readUTF(); - stream.readUTF(); + stream.readUTF(); //key + stream.readUTF(); //val } } @@ -344,7 +353,6 @@ public class MapIO{ readLegacyMmapTiles(file, (x, y) -> tiles[x][y]); } - //TODO implement /**Reads a mmap in the old 4.0 .mmap format.*/ private static void readLegacyMmapTiles(FileHandle file, TileProvider tiles) throws IOException{ try(DataInputStream stream = new DataInputStream(file.read(bufferSize))){ diff --git a/core/src/io/anuke/mindustry/maps/Maps.java b/core/src/io/anuke/mindustry/maps/Maps.java index b1644a1ed7..bf3473cb8a 100644 --- a/core/src/io/anuke/mindustry/maps/Maps.java +++ b/core/src/io/anuke/mindustry/maps/Maps.java @@ -7,6 +7,7 @@ import io.anuke.arc.files.FileHandle; import io.anuke.arc.graphics.Texture; import io.anuke.arc.util.Disposable; import io.anuke.arc.util.Log; +import io.anuke.arc.util.Time; import io.anuke.mindustry.io.MapIO; import io.anuke.mindustry.world.Tile; @@ -55,6 +56,7 @@ public class Maps implements Disposable{ /** Load all maps. Should be called at application start. */ public void load(){ + Time.mark(); try{ for(String name : defaultMapNames){ FileHandle file = Core.files.internal("maps/" + name + "." + mapExtension); @@ -65,6 +67,7 @@ public class Maps implements Disposable{ } loadCustomMaps(); + Log.info("Time to load maps: {0}", Time.elapsed()); } /** Save a custom map to the directory. This updates all values and stored data necessary.