mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-22 20:41:58 -08:00
Added legacy map importer
This commit is contained in:
parent
02004011ec
commit
38f2f1e30a
10 changed files with 111 additions and 21 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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(){}
|
||||
}
|
||||
|
|
@ -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) () -> {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,6 @@ public class ColorMapper implements ContentList{
|
|||
|
||||
@Override
|
||||
public ContentType type(){
|
||||
return ContentType.mech;
|
||||
return ContentType.block;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
67
core/src/io/anuke/mindustry/world/LegacyColorMapper.java
Normal file
67
core/src/io/anuke/mindustry/world/LegacyColorMapper.java
Normal file
|
|
@ -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<LegacyBlock> 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue