Skip to content

Commit

Permalink
Generic overlay tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuken committed Apr 12, 2019
1 parent ef2b8be commit 46c3b35
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 104 deletions.
2 changes: 1 addition & 1 deletion core/src/io/anuke/mindustry/editor/DrawOperation.java
Expand Up @@ -50,7 +50,7 @@ void set(MapEditor editor, Tile tile, byte type, byte to){
}else if(type == OpType.team.ordinal()){
tile.setTeam(Team.all[to]);
}else if(type == OpType.ore.ordinal()){
tile.setOreByte(to);
tile.setOverlayID(to);
}
});
editor.renderer().updatePoint(tile.x, tile.y);
Expand Down
19 changes: 9 additions & 10 deletions core/src/io/anuke/mindustry/editor/EditorTile.java
Expand Up @@ -6,8 +6,7 @@
import io.anuke.mindustry.gen.TileOp;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.*;
import io.anuke.mindustry.world.modules.*;

import static io.anuke.mindustry.Vars.ui;
Expand All @@ -25,19 +24,19 @@ public Team getTeam(){

@Override
public void setFloor(Floor type){
if(type instanceof OreBlock){
if(type instanceof OverlayFloor){
//don't place on liquids
if(!floor().isLiquid) setOreByte(type.id);
setOverlayID(type.id);
return;
}

Block previous = floor();
Block ore = ore();
Block ore = overlay();
if(previous == type && ore == Blocks.air) return;
super.setFloor(type);
//ore may get nullified so make sure to save editrs
if(ore() != ore){
op(TileOp.get(x, y, (byte)OpType.ore.ordinal(), ore.id, ore().id));
if(overlay() != ore){
op(TileOp.get(x, y, (byte)OpType.ore.ordinal(), ore.id, overlay().id));
}
if(previous != type){
op(TileOp.get(x, y, (byte)OpType.floor.ordinal(), previous.id, type.id));
Expand Down Expand Up @@ -69,10 +68,10 @@ public void setRotation(byte rotation){
}

@Override
public void setOreByte(byte ore){
byte previous = getOreByte();
public void setOverlayID(byte ore){
byte previous = getOverlayID();
if(previous == ore) return;
super.setOreByte(ore);
super.setOverlayID(ore);
op(TileOp.get(x, y, (byte)OpType.ore.ordinal(), previous, ore));
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/io/anuke/mindustry/editor/EditorTool.java
Expand Up @@ -31,7 +31,7 @@ public void touched(MapEditor editor, int x, int y){
return;
}

editor.drawBlock = tile.block() == Blocks.air ? tile.ore() == Blocks.air ? tile.floor() : tile.ore() : tile.block();
editor.drawBlock = tile.block() == Blocks.air ? tile.overlay() == Blocks.air ? tile.floor() : tile.overlay() : tile.block();
}
},
pencil{
Expand Down Expand Up @@ -100,7 +100,7 @@ public void touched(MapEditor editor, int x, int y){
boolean synth = editor.drawBlock.synthetic();

Block draw = editor.drawBlock;
dest = draw instanceof OreBlock ? tile.ore() : isfloor ? floor : block;
dest = draw instanceof OverlayFloor ? tile.overlay() : isfloor ? floor : block;

if(dest == draw || block == Blocks.part || block.isMultiblock()){
return;
Expand All @@ -115,10 +115,10 @@ public void touched(MapEditor editor, int x, int y){
Tile write = editor.tile(px, py);

if(isfloor){
if(alt && !(draw instanceof OreBlock)){
Block ore = write.ore();
if(alt && !(draw instanceof OverlayFloor)){
Block ore = write.overlay();
write.setFloor((Floor)draw);
write.setOre(ore);
write.setOverlay(ore);
}else{
write.setFloor((Floor)draw);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public void touched(MapEditor editor, int x, int y){
boolean eq(int px, int py){
Tile tile = data.tile(px, py);

return (data.drawBlock instanceof OreBlock ? tile.ore() : isfloor ? tile.floor() : tile.block()) == dest && !(data.drawBlock instanceof OreBlock && tile.floor().isLiquid);
return (data.drawBlock instanceof OverlayFloor ? tile.overlay() : isfloor ? tile.floor() : tile.block()) == dest && !(data.drawBlock instanceof OverlayFloor && tile.floor().isLiquid);
}
},
zoom;
Expand Down
4 changes: 2 additions & 2 deletions core/src/io/anuke/mindustry/editor/MapEditorDialog.java
Expand Up @@ -26,7 +26,7 @@
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.OverlayFloor;
import io.anuke.mindustry.world.blocks.storage.CoreBlock;

import static io.anuke.mindustry.Vars.*;
Expand Down Expand Up @@ -486,7 +486,7 @@ private void addBlockSelection(Table table){
if(core != 0) return core;
int synth = Boolean.compare(b1.synthetic(), b2.synthetic());
if(synth != 0) return synth;
int ore = Boolean.compare(b1 instanceof OreBlock, b2 instanceof OreBlock);
int ore = Boolean.compare(b1 instanceof OverlayFloor, b2 instanceof OverlayFloor);
if(ore != 0) return ore;
return Integer.compare(b1.id, b2.id);
});
Expand Down
8 changes: 4 additions & 4 deletions core/src/io/anuke/mindustry/editor/MapGenerateDialog.java
Expand Up @@ -220,7 +220,7 @@ void apply(){
for(int x = 0; x < editor.width(); x++){
for(int y = 0; y < editor.height(); y++){
Tile tile = editor.tile(x, y);
input.begin(editor, x, y, tile.floor(), tile.block(), tile.ore());
input.begin(editor, x, y, tile.floor(), tile.block(), tile.overlay());
filter.apply(input);
writeTiles[x][y].set(input.floor, input.block, input.ore, tile.getTeam(), tile.getRotation());
}
Expand All @@ -237,7 +237,7 @@ void apply(){
tile.setFloor((Floor)content.block(write.floor));
tile.setBlock(content.block(write.block));
tile.setTeam(Team.all[write.team]);
tile.setOre(content.block(write.ore));
tile.setOverlay(content.block(write.ore));
}
}
});
Expand Down Expand Up @@ -295,7 +295,7 @@ void update(){
//get result from buffer1 if there's filters left, otherwise get from editor directly
if(filters.isEmpty()){
Tile tile = editor.tile(px * scaling, py * scaling);
color = MapIO.colorFor(tile.floor(), tile.block(), tile.ore(), Team.none);
color = MapIO.colorFor(tile.floor(), tile.block(), tile.overlay(), Team.none);
}else{
DummyTile tile = buffer1[px][py];
color = MapIO.colorFor(content.block(tile.floor), content.block(tile.block), content.block(tile.ore), Team.none);
Expand Down Expand Up @@ -339,7 +339,7 @@ void set(DummyTile other){
}

void set(Tile other){
set(other.floor(), other.block(), other.ore(), other.getTeam(), other.getRotation());
set(other.floor(), other.block(), other.overlay(), other.getTeam(), other.getRotation());
}

}
Expand Down
4 changes: 2 additions & 2 deletions core/src/io/anuke/mindustry/editor/MapRenderer.java
Expand Up @@ -138,8 +138,8 @@ private void render(int wx, int wy){
region = !Core.atlas.isFound(wall.editorIcon()) ? Core.atlas.find("clear-editor") : wall.editorIcon();
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)];
}else if(wall == Blocks.air && tile.overlay() != null){
region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)];
}else{
region = Core.atlas.find("clear-editor");
}
Expand Down
Expand Up @@ -9,15 +9,14 @@
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Block.Icon;
import io.anuke.mindustry.world.blocks.Floor;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.*;

import static io.anuke.mindustry.Vars.updateEditorOnChange;

public abstract class FilterOption{
public static final Predicate<Block> floorsOnly = b -> (b instanceof Floor && !(b instanceof OreBlock)) && Core.atlas.isFound(b.icon(Icon.full));
public static final Predicate<Block> floorsOnly = b -> (b instanceof Floor && !(b instanceof OverlayFloor)) && Core.atlas.isFound(b.icon(Icon.full));
public static final Predicate<Block> wallsOnly = b -> (!b.synthetic() && !(b instanceof Floor)) && Core.atlas.isFound(b.icon(Icon.full));
public static final Predicate<Block> oresOnly = b -> b instanceof OreBlock && Core.atlas.isFound(b.icon(Icon.full));
public static final Predicate<Block> oresOnly = b -> b instanceof OverlayFloor && Core.atlas.isFound(b.icon(Icon.full));

public abstract void build(Table table);

Expand Down
2 changes: 1 addition & 1 deletion core/src/io/anuke/mindustry/graphics/MinimapRenderer.java
Expand Up @@ -130,7 +130,7 @@ public void updateUnitArray(){

private int colorFor(Tile tile){
tile = tile.target();
return MapIO.colorFor(tile.floor(), tile.block(), tile.ore(), tile.getTeam());
return MapIO.colorFor(tile.floor(), tile.block(), tile.overlay(), tile.getTeam());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/io/anuke/mindustry/input/InputHandler.java
Expand Up @@ -234,7 +234,7 @@ boolean tryBeginMine(Tile tile){
boolean canMine(Tile tile){
return !Core.scene.hasMouse()
&& tile.drop() != null && tile.drop().hardness <= player.mech.drillPower
&& !(tile.floor().playerUnmineable && tile.ore() == Blocks.air)
&& !(tile.floor().playerUnmineable && tile.overlay() == Blocks.air)
&& player.acceptsItem(tile.drop())
&& tile.block() == Blocks.air && player.dst(tile.worldx(), tile.worldy()) <= Player.mineDistance;
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/io/anuke/mindustry/io/MapIO.java
Expand Up @@ -75,7 +75,7 @@ public void setFloor(Floor type){
}

@Override
public void setOreByte(byte b){
public void setOverlayID(byte b){
if(b != 0)
floors.drawPixel(x, floors.getHeight() - 1 - y, colorFor(floor(), Blocks.air, content.block(b), getTeam()));
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Pixmap generatePreview(Tile[][] tiles){
for(int x = 0; x < pixmap.getWidth(); x++){
for(int y = 0; y < pixmap.getHeight(); y++){
Tile tile = tiles[x][y];
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, colorFor(tile.floor(), tile.block(), tile.ore(), tile.getTeam()));
pixmap.drawPixel(x, pixmap.getHeight() - 1 - y, colorFor(tile.floor(), tile.block(), tile.overlay(), tile.getTeam()));
}
}
return pixmap;
Expand Down Expand Up @@ -144,13 +144,13 @@ public static void writeMap(FileHandle file, Map map, Tile[][] tiles) throws IOE
for(int i = 0; i < tiles.length * tiles[0].length; i++){
Tile tile = tiles[i % width][i / width];
stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getOreByte());
stream.writeByte(tile.getOverlayID());
int consecutives = 0;

for(int j = i + 1; j < width * height && consecutives < 255; j++){
Tile nextTile = tiles[j % width][j / width];

if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getOreByte() != tile.getOreByte()){
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.block() != Blocks.air || nextTile.getOverlayID() != tile.getOverlayID()){
break;
}

Expand Down Expand Up @@ -272,13 +272,13 @@ private static void readTiles(FileHandle file, int width, int height, TileProvid

Tile tile = tiles.get(x, y);
tile.setFloor((Floor)content.block(floorid));
tile.setOre(content.block(oreid));
tile.setOverlay(content.block(oreid));

for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
Tile newTile = tiles.get(newx, newy);
newTile.setFloor((Floor)content.block(floorid));
newTile.setOre(content.block(oreid));
newTile.setOverlay(content.block(oreid));
}

i += consecutives;
Expand Down Expand Up @@ -337,7 +337,7 @@ public static void readLegacyPixmap(Pixmap pixmap, Tile[][] tiles){

tile.setFloor(block.floor);
tile.setBlock(block.wall);
if(block.ore != null) tile.setOre(block.ore);
if(block.ore != null) tile.setOverlay(block.ore);

//place core
if(color == Color.rgba8888(Color.GREEN)){
Expand Down Expand Up @@ -437,7 +437,7 @@ private static void readLegacyMmapTiles(FileHandle file, TileProvider tiles) thr
}

if(oreMap.containsKey(floorb)){
tile.setOre(content.block(oreMap.get(floorb, 0)));
tile.setOverlay(content.block(oreMap.get(floorb, 0)));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/io/anuke/mindustry/io/SaveFileVersion.java
Expand Up @@ -44,13 +44,13 @@ public void writeMap(DataOutputStream stream) throws IOException{
for(int i = 0; i < world.width() * world.height(); i++){
Tile tile = world.tile(i % world.width(), i / world.width());
stream.writeByte(tile.getFloorID());
stream.writeByte(tile.getOreByte());
stream.writeByte(tile.getOverlayID());
int consecutives = 0;

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.getOreByte() != tile.getOreByte()){
if(nextTile.getFloorID() != tile.getFloorID() || nextTile.getOverlayID() != tile.getOverlayID()){
break;
}

Expand Down Expand Up @@ -116,12 +116,12 @@ public void readMap(DataInputStream stream) throws IOException{
Block ore = content.block(oreid);

tiles[x][y] = new Tile(x, y, floorid, (byte)0);
tiles[x][y].setOre(ore);
tiles[x][y].setOverlay(ore);

for(int j = i + 1; j < i + 1 + consecutives; j++){
int newx = j % width, newy = j / width;
Tile newTile = new Tile(newx, newy, floorid, (byte)0);
newTile.setOre(ore);
newTile.setOverlay(ore);
tiles[newx][newy] = newTile;
}

Expand Down
Expand Up @@ -145,10 +145,10 @@ public void pass(Tile[][] tiles, IntPositionConsumer r){
for(int y = 0; y < height; y++){
floor = tiles[x][y].floor();
block = tiles[x][y].block();
ore = tiles[x][y].ore();
ore = tiles[x][y].overlay();
r.accept(x, y);
tiles[x][y] = new Tile(x, y, floor.id, block.id);
tiles[x][y].setOre(ore);
tiles[x][y].setOverlay(ore);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/io/anuke/mindustry/maps/generators/MapGenerator.java
Expand Up @@ -125,7 +125,7 @@ public void generate(Tile[][] tiles){

if(distortFloor){
tile.setFloor(tiles[newX][newY].floor());
tile.setOre(tiles[newX][newY].ore());
tile.setOverlay(tiles[newX][newY].overlay());
}

for(Decoration decor : decorations){
Expand Down Expand Up @@ -168,7 +168,7 @@ public void generate(Tile[][] tiles){
double dst = Mathf.dst(x, y);
if(dst < frad && Structs.inBounds(wx, wy, tiles) && (dst <= rad || Mathf.chance(0.5))){
Tile tile = tiles[wx][wy];
tile.clearOre();
tile.clearOverlay();
}
}
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ public void generate(Tile[][] tiles){
ore = Blocks.air;
generate(x, y);
tiles[x][y] = new Tile(x, y, floor.id, block.id);
tiles[x][y].setOre(ore);
tiles[x][y].setOverlay(ore);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/io/anuke/mindustry/type/Item.java
Expand Up @@ -100,7 +100,7 @@ public enum Icon{
}
}

/** Allocates a new array containing all items the generate ores. */
/** Allocates a new array containing all items that generate ores. */
public static Array<Item> getAllOres(){
return content.blocks().select(b -> b instanceof OreBlock).map(b -> ((Floor)b).itemDrop);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/io/anuke/mindustry/type/Loadout.java
Expand Up @@ -74,7 +74,7 @@ public void setup(int x, int y){
tile.setRotation((byte)entry.value.rotation);
if(entry.value.ore != null){
for(Tile t : tile.getLinkedTiles(outArray)){
t.setOre(entry.value.ore);
t.setOverlay(entry.value.ore);
}
}
}
Expand Down
Expand Up @@ -337,6 +337,6 @@ Block getSelected(){

/** Returns the block currently being hovered over in the world. */
Block tileDisplayBlock(){
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.ore() != Blocks.air ? hoverTile.ore() : null;
return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.overlay() != Blocks.air ? hoverTile.overlay() : null;
}
}

0 comments on commit 46c3b35

Please sign in to comment.