More fixes

This commit is contained in:
Anuken
2019-03-12 11:31:14 -04:00
parent 0a04de04f1
commit e4875903f1
6 changed files with 21 additions and 15 deletions

View File

@@ -235,6 +235,11 @@ public class World implements ApplicationListener{
try{
createTiles(map.width, map.height);
for(int x = 0; x < map.width; x++){
for(int y = 0; y < map.height; y++){
tiles[x][y] = new Tile(x, y);
}
}
MapIO.readTiles(map, tiles);
prepareTiles(tiles);
}catch(Exception e){

View File

@@ -3,7 +3,6 @@ package io.anuke.mindustry.editor;
import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.util.Log;
import io.anuke.arc.util.Pack;
import io.anuke.arc.util.Structs;
import io.anuke.mindustry.content.Blocks;
@@ -17,8 +16,6 @@ import io.anuke.mindustry.world.blocks.Floor;
import java.io.IOException;
import static io.anuke.mindustry.Vars.world;
public class MapEditor{
public static final int[] brushSizes = {1, 2, 3, 4, 5, 9, 15, 20};
@@ -59,7 +56,7 @@ public class MapEditor{
loading = false;
}
public void beginEdit(Tile[][] tiles) throws IOException{
public void beginEdit(Tile[][] tiles){
reset();
this.tiles = tiles;
@@ -120,13 +117,12 @@ public class MapEditor{
}
public void draw(int x, int y, boolean paint, Block drawBlock, double chance){
//byte rotationTeam = Pack.byteByte(drawBlock.rotate ? (byte)rotation : 0, drawBlock.synthetic() ? (byte)drawTeam.ordinal() : 0);
boolean isfloor = drawBlock instanceof Floor && drawBlock != Blocks.air;
if(drawBlock.isMultiblock()){
x = Mathf.clamp(x, (drawBlock.size-1)/2, world.width() - drawBlock.size/2 - 1);
y = Mathf.clamp(y, (drawBlock.size-1)/2, world.height() - drawBlock.size/2 - 1);
x = Mathf.clamp(x, (drawBlock.size-1)/2, width() - drawBlock.size/2 - 1);
y = Mathf.clamp(y, (drawBlock.size-1)/2, height() - drawBlock.size/2 - 1);
int offsetx = -(drawBlock.size - 1) / 2;
int offsety = -(drawBlock.size - 1) / 2;
@@ -137,7 +133,7 @@ public class MapEditor{
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
if(Structs.inBounds(worldx, worldy, world.width(), world.height())){
if(Structs.inBounds(worldx, worldy, width(), height())){
Tile tile = tiles[worldx][worldy];
if(i == 1){

View File

@@ -71,6 +71,7 @@ public class MapIO{
@Override
protected void changed(){
super.changed();
int c = colorFor(Blocks.air, block(), getTeam());
if(c != black) wall.drawPixel(x, floor.getHeight() - 1 - y, c);
}

View File

@@ -16,7 +16,6 @@ import io.anuke.mindustry.gen.Serialization;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.BlockPart;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -44,7 +43,6 @@ public abstract class SaveFileVersion{
}
public void writeMap(DataOutputStream stream) throws IOException{
//write world size
stream.writeShort(world.width());
stream.writeShort(world.height());
@@ -59,7 +57,7 @@ public abstract class SaveFileVersion{
for(int j = i + 1; j < world.width() * world.height() && consecutives < 255; j++){
Tile nextTile = world.tile(j % world.width(), j / world.width());
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getOre() != tile.getOre()){
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getOre() != tile.getOre()){
break;
}
@@ -75,7 +73,7 @@ public abstract class SaveFileVersion{
Tile tile = world.tile(i % world.width(), i / world.width());
stream.writeByte(tile.getBlockID());
if(tile.block() instanceof BlockPart){
if(tile.block() == Blocks.part){
stream.writeByte(tile.link);
}else if(tile.entity != null){
stream.writeByte(Pack.byteByte(tile.getTeamID(), tile.getRotation())); //team + rotation
@@ -141,6 +139,7 @@ public abstract class SaveFileVersion{
int x = i % width, y = i / width;
Block block = content.block(stream.readByte());
Tile tile = tiles[x][y];
tile.setBlock(block);
if(block == Blocks.part){
tile.link = stream.readByte();
@@ -172,8 +171,6 @@ public abstract class SaveFileVersion{
i += consecutives;
}
tiles[x][y] = tile;
}
content.setTemporaryMapper(null);

View File

@@ -79,6 +79,12 @@ public class MapGenerator extends Generator{
@Override
public void generate(Tile[][] tiles){
try{
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
tiles[x][y] = new Tile(x, y);
}
}
MapIO.readTiles(map, tiles);
Array<Point2> players = new Array<>();
Array<Point2> enemies = new Array<>();

View File

@@ -45,6 +45,7 @@ public class Tile implements Position, TargetTrait{
public Tile(int x, int y){
this.x = (short) x;
this.y = (short) y;
wall = floor = (Floor)Blocks.air;
}
public Tile(int x, int y, byte floor, byte wall){