From 38f2f1e30a6a248577d6ef6cd791bb028e76ef5a Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 9 Oct 2018 22:52:28 -0400 Subject: [PATCH] Added legacy map importer --- core/assets/bundles/bundle.properties | 2 +- .../anuke/mindustry/core/ContentLoader.java | 2 + .../src/io/anuke/mindustry/core/Platform.java | 2 - .../mindustry/editor/MapEditorDialog.java | 9 +-- core/src/io/anuke/mindustry/io/MapIO.java | 38 ++++++++--- .../io/anuke/mindustry/world/ColorMapper.java | 2 +- .../mindustry/world/LegacyColorMapper.java | 67 +++++++++++++++++++ .../world/blocks/defense/ForceProjector.java | 4 +- .../world/blocks/defense/ShockMine.java | 2 +- .../world/blocks/defense/SurgeWall.java | 4 +- 10 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 core/src/io/anuke/mindustry/world/LegacyColorMapper.java diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index d7683c5ea1..0f363050ab 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -245,7 +245,7 @@ text.editor.importmap=Import Map text.editor.importmap.description=Import an already existing map text.editor.importfile=Import File text.editor.importfile.description=Import an external map file -text.editor.importimage=Import Terrain Image +text.editor.importimage=Import Legacy Image text.editor.importimage.description=Import an external map image file text.editor.export=Export... text.editor.exportfile=Export File diff --git a/core/src/io/anuke/mindustry/core/ContentLoader.java b/core/src/io/anuke/mindustry/core/ContentLoader.java index d8e611d86e..e9c3c2aaf8 100644 --- a/core/src/io/anuke/mindustry/core/ContentLoader.java +++ b/core/src/io/anuke/mindustry/core/ContentLoader.java @@ -23,6 +23,7 @@ import io.anuke.mindustry.type.Liquid; import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.ColorMapper; +import io.anuke.mindustry.world.LegacyColorMapper; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.util.Log; import io.anuke.ucore.util.ThreadArray; @@ -96,6 +97,7 @@ public class ContentLoader{ //not really a content class, but this makes initialization easier new ColorMapper(), + new LegacyColorMapper(), //recipes new Recipes(), diff --git a/core/src/io/anuke/mindustry/core/Platform.java b/core/src/io/anuke/mindustry/core/Platform.java index 7e1a7531f1..16291b2bfa 100644 --- a/core/src/io/anuke/mindustry/core/Platform.java +++ b/core/src/io/anuke/mindustry/core/Platform.java @@ -79,11 +79,9 @@ public abstract class Platform { }; } - //TODO iOS implementation /**Forces the app into landscape mode. Currently Android only.*/ public void beginForceLandscape(){} - //TODO iOS implementation /**Stops forcing the app into landscape orientation. Currently Android only.*/ public void endForceLandscape(){} } \ No newline at end of file diff --git a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java index 336e0cb42b..418e524061 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java @@ -3,6 +3,7 @@ package io.anuke.mindustry.editor; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Align; @@ -110,15 +111,15 @@ public class MapEditorDialog extends Dialog implements Disposable{ } }); }, true, mapExtension); - }/*, - "$text.editor.importimage", "$text.editor.importimage.description", "icon-file-image", (Listenable)() -> { + }, + "$text.editor.importimage", "$text.editor.importimage.description", "icon-file-image", (Runnable)() -> { if(gwt){ ui.showError("$text.web.unsupported"); }else { Platform.instance.showFileChooser("$text.loadimage", "Image Files", file -> { ui.loadGraphics(() -> { try{ - MapTileData data = MapIO.readPixmap(new Pixmap(file)); + MapTileData data = MapIO.readLegacyPixmap(new Pixmap(file)); editor.beginEdit(data, editor.getTags(), false); view.clearStack(); @@ -129,7 +130,7 @@ public class MapEditorDialog extends Dialog implements Disposable{ }); }, true, "png"); } - }*/)); + })); t.addImageTextButton("$text.editor.export", "icon-save-map", isize, () -> createDialog("$text.editor.export", "$text.editor.exportfile", "$text.editor.exportfile.description", "icon-file", (Runnable) () -> { diff --git a/core/src/io/anuke/mindustry/io/MapIO.java b/core/src/io/anuke/mindustry/io/MapIO.java index d46f66fd67..dac0364162 100644 --- a/core/src/io/anuke/mindustry/io/MapIO.java +++ b/core/src/io/anuke/mindustry/io/MapIO.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.IntIntMap; import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap.Entry; import io.anuke.mindustry.content.blocks.Blocks; +import io.anuke.mindustry.content.blocks.StorageBlocks; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.maps.Map; import io.anuke.mindustry.maps.MapMeta; @@ -16,11 +17,16 @@ import io.anuke.mindustry.maps.MapTileData.TileDataMarker; import io.anuke.mindustry.type.ContentType; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.ColorMapper; +import io.anuke.mindustry.world.LegacyColorMapper; +import io.anuke.mindustry.world.LegacyColorMapper.LegacyBlock; +import io.anuke.ucore.util.Bits; +import io.anuke.ucore.util.Structs; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; + import static io.anuke.mindustry.Vars.content; /** @@ -66,20 +72,36 @@ public class MapIO{ return pixmap; } - public static MapTileData readPixmap(Pixmap pixmap){ + /**Reads a pixmap in the old (3.5) map format.*/ + public static MapTileData readLegacyPixmap(Pixmap pixmap){ MapTileData data = new MapTileData(pixmap.getWidth(), pixmap.getHeight()); for(int x = 0; x < data.width(); x++){ for(int y = 0; y < data.height(); y++){ - Block block = ColorMapper.getByColor(pixmap.getPixel(y, pixmap.getWidth() - 1 - x)); + int color = pixmap.getPixel(y, pixmap.getWidth() - 1 - x); + LegacyBlock block = LegacyColorMapper.get(color); - if(block == null){ - data.write(x, y, DataPosition.floor, Blocks.stone.id); - }else{ - data.write(x, y, DataPosition.floor, block.id); + data.write(x, y, DataPosition.floor, block.floor.id); + data.write(x, y, DataPosition.elevation, (byte)block.elevation); + + //place core + if(color == Color.rgba8888(Color.GREEN)){ + for(int dx = 0; dx < 3; dx++){ + for(int dy = 0; dy < 3; dy++){ + int worldx = dx - 1 + x; + int worldy = dy - 1 + y; + + if(Structs.inBounds(worldx, worldy, pixmap.getWidth(), pixmap.getHeight())){ + data.write(worldx, worldy, DataPosition.wall, Blocks.blockpart.id); + data.write(worldx, worldy, DataPosition.rotationTeam, Bits.packByte((byte)0, (byte)Team.blue.ordinal())); + data.write(worldx, worldy, DataPosition.link, Bits.packByte((byte) (dx - 1 + 8), (byte) (dy - 1 + 8))); + } + } + } + + data.write(x, y, DataPosition.wall, StorageBlocks.core.id); + data.write(x, y, DataPosition.rotationTeam, Bits.packByte((byte)0, (byte)Team.blue.ordinal())); } - - data.write(x, y, DataPosition.wall, Blocks.air.id); } } diff --git a/core/src/io/anuke/mindustry/world/ColorMapper.java b/core/src/io/anuke/mindustry/world/ColorMapper.java index 14561e95dc..8c76090929 100644 --- a/core/src/io/anuke/mindustry/world/ColorMapper.java +++ b/core/src/io/anuke/mindustry/world/ColorMapper.java @@ -56,6 +56,6 @@ public class ColorMapper implements ContentList{ @Override public ContentType type(){ - return ContentType.mech; + return ContentType.block; } } diff --git a/core/src/io/anuke/mindustry/world/LegacyColorMapper.java b/core/src/io/anuke/mindustry/world/LegacyColorMapper.java new file mode 100644 index 0000000000..25b89ff057 --- /dev/null +++ b/core/src/io/anuke/mindustry/world/LegacyColorMapper.java @@ -0,0 +1,67 @@ +package io.anuke.mindustry.world; + +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.utils.IntMap; +import io.anuke.mindustry.content.Items; +import io.anuke.mindustry.content.blocks.Blocks; +import io.anuke.mindustry.content.blocks.OreBlocks; +import io.anuke.mindustry.game.ContentList; +import io.anuke.mindustry.type.ContentType; +import io.anuke.mindustry.world.blocks.Floor; + +public class LegacyColorMapper implements ContentList{ + private static IntMap blockMap = new IntMap<>(); + private static LegacyBlock defaultValue; + + public static LegacyBlock get(int color){ + return blockMap.get(color, defaultValue); + } + + @Override + public void load(){ + defaultValue = new LegacyBlock(Blocks.stone, 0); + + insert("ff0000", Blocks.dirt, 0); + insert("00ff00", Blocks.stone, 0); + insert("323232", Blocks.stone, 0); + insert("646464", Blocks.stone, 1); + insert("50965a", Blocks.grass, 0); + insert("5ab464", Blocks.grass, 1); + insert("506eb4", Blocks.water, 0); + insert("465a96", Blocks.deepwater, 0); + insert("252525", Blocks.blackstone, 0); + insert("575757", Blocks.blackstone, 1); + insert("988a67", Blocks.sand, 0); + insert("e5d8bb", Blocks.sand, 1); + insert("c2d1d2", Blocks.snow, 0); + insert("c4e3e7", Blocks.ice, 0); + insert("f7feff", Blocks.snow, 1); + insert("6e501e", Blocks.dirt, 0); + insert("ed5334", Blocks.lava, 0); + insert("292929", Blocks.oil, 0); + insert("c3a490", OreBlocks.get(Blocks.stone, Items.copper), 0); + insert("161616", OreBlocks.get(Blocks.stone, Items.coal), 0); + insert("6277bc", OreBlocks.get(Blocks.stone, Items.titanium), 0); + insert("83bc58", OreBlocks.get(Blocks.stone, Items.thorium), 0); + } + + @Override + public ContentType type(){ + return ContentType.block; + } + + private void insert(String color, Block block, int elevation){ + blockMap.put(Color.rgba8888(Color.valueOf(color)), new LegacyBlock(block, elevation)); + } + + public static class LegacyBlock{ + public final int elevation; + public final Floor floor; + + public LegacyBlock(Block floor, int elevation){ + this.elevation = elevation; + this.floor = (Floor) floor; + } + } + +} diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java index 915e0bfded..f4c6abd1dd 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java @@ -117,7 +117,7 @@ public class ForceProjector extends Block { if(entity.buildup >= breakage && !entity.broken){ entity.broken = true; entity.buildup = breakage; - Effects.effect(BlockFx.shieldBreak, tile.drawy(), tile.drawy(), radius); + Effects.effect(BlockFx.shieldBreak, tile.drawx(), tile.drawy(), radius); } if(entity.hit > 0f){ @@ -159,7 +159,7 @@ public class ForceProjector extends Block { ForceEntity entity = tile.entity(); if(entity.buildup <= 0f) return; - Draw.alpha(entity.buildup / breakage * 0.75f/* * Mathf.absin(Timers.time(), 10f - (entity.buildup/breakage)*6f, 1f)*/); + Draw.alpha(entity.buildup / breakage * 0.75f); Graphics.setAdditiveBlending(); Draw.rect(topRegion, tile.drawx(), tile.drawy()); diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/ShockMine.java b/core/src/io/anuke/mindustry/world/blocks/defense/ShockMine.java index be3e1c51f2..9b668969be 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/ShockMine.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/ShockMine.java @@ -14,7 +14,7 @@ public class ShockMine extends Block{ protected float cooldown = 80f; protected float tileDamage = 5f; - protected float damage = 10; + protected float damage = 13; protected int length = 10; protected int tendrils = 6; diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/SurgeWall.java b/core/src/io/anuke/mindustry/world/blocks/defense/SurgeWall.java index eb79b46eb2..5ed61ffaf3 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/SurgeWall.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/SurgeWall.java @@ -8,8 +8,8 @@ import io.anuke.ucore.util.Mathf; public class SurgeWall extends Wall{ protected float lightningChance = 0.05f; - protected float lightningDamage = 11f; - protected int lightningLength = 20; + protected float lightningDamage = 15f; + protected int lightningLength = 17; public SurgeWall(String name){ super(name);