mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-12 03:37:27 +07:00
Added map-specific generator
This commit is contained in:
parent
2f76684113
commit
5ec11c61bd
@ -18,8 +18,8 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.Content;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Saves;
|
||||
import io.anuke.mindustry.game.GlobalData;
|
||||
import io.anuke.mindustry.game.Saves;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.input.Binding;
|
||||
import io.anuke.mindustry.input.DesktopInput;
|
||||
|
@ -254,12 +254,9 @@ public class World implements ApplicationListener{
|
||||
ui.showError("$map.nospawn.pvp");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
invalidMap = false;
|
||||
}
|
||||
|
||||
if(invalidMap) Core.app.post(() -> state.set(State.menu));
|
||||
|
||||
}
|
||||
|
||||
public void notifyChanged(Tile tile){
|
||||
@ -410,7 +407,7 @@ public class World implements ApplicationListener{
|
||||
* - setting up multiblocks<br>
|
||||
* - updating occlusion<br>
|
||||
* Usually used before placing structures on a tile array.*/
|
||||
void prepareTiles(Tile[][] tiles){
|
||||
public void prepareTiles(Tile[][] tiles){
|
||||
|
||||
//find multiblocks
|
||||
IntArray multiblocks = new IntArray();
|
||||
|
@ -83,7 +83,7 @@ public class BlockRenderer{
|
||||
Draw.shader();
|
||||
}
|
||||
|
||||
/**Process all blocks to draw, simultaneously updating the block shadow framebuffer.*/
|
||||
/**Process all blocks to draw.*/
|
||||
public void processBlocks(){
|
||||
iterateidx = 0;
|
||||
|
||||
@ -108,28 +108,25 @@ public class BlockRenderer{
|
||||
for(int y = miny; y <= maxy; y++){
|
||||
boolean expanded = (Math.abs(x - avgx) > rangex || Math.abs(y - avgy) > rangey);
|
||||
Tile tile = world.rawTile(x, y);
|
||||
Block block = tile.block();
|
||||
|
||||
if(tile != null){
|
||||
Block block = tile.block();
|
||||
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
||||
tile.block().drawShadow(tile);
|
||||
}
|
||||
|
||||
if(!expanded && block != Blocks.air && world.isAccessible(x, y)){
|
||||
tile.block().drawShadow(tile);
|
||||
if(block != Blocks.air){
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.shadow);
|
||||
addRequest(tile, Layer.block);
|
||||
}
|
||||
|
||||
if(block != Blocks.air){
|
||||
if(!expanded){
|
||||
addRequest(tile, Layer.shadow);
|
||||
addRequest(tile, Layer.block);
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null && block.isLayer(tile)){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
if(block.expanded || !expanded){
|
||||
if(block.layer != null && block.isLayer(tile)){
|
||||
addRequest(tile, block.layer);
|
||||
}
|
||||
|
||||
if(block.layer2 != null && block.isLayer2(tile)){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
if(block.layer2 != null && block.isLayer2(tile)){
|
||||
addRequest(tile, block.layer2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class Maps implements Disposable{
|
||||
/**List of all built-in maps.*/
|
||||
private static final String[] defaultMapNames = {"sandbox"};
|
||||
private static final String[] defaultMapNames = {};
|
||||
/**Tile format version.*/
|
||||
private static final int version = 0;
|
||||
|
||||
@ -57,9 +57,28 @@ public class Maps implements Disposable{
|
||||
return maps.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**Loads a map from the map folder and returns it. Should only be used for zone maps.
|
||||
* Does not add this map to the map list.*/
|
||||
public Map loadInternalMap(String name){
|
||||
FileHandle file = Core.files.internal("maps/" + name + "." + mapExtension);
|
||||
|
||||
try(DataInputStream ds = new DataInputStream(file.read())) {
|
||||
MapMeta meta = MapIO.readMapMeta(ds);
|
||||
Map map = new Map(name, meta, false, file::read);
|
||||
|
||||
if (!headless){
|
||||
map.texture = new Texture(MapIO.generatePixmap(MapIO.readTileData(ds, meta, true)));
|
||||
}
|
||||
|
||||
return map;
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**Load all maps. Should be called at application start.*/
|
||||
public void load(){
|
||||
try {
|
||||
try{
|
||||
for (String name : defaultMapNames) {
|
||||
FileHandle file = Core.files.internal("maps/" + name + "." + mapExtension);
|
||||
loadMap(file.nameWithoutExtension(), file::read, false);
|
||||
|
@ -3,12 +3,17 @@ package io.anuke.mindustry.maps.generators;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
public abstract class Generator{
|
||||
public final int width, height;
|
||||
public int width, height;
|
||||
|
||||
public Generator(int width, int height){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Generator(){}
|
||||
|
||||
/**Initialize special variables like maps.*/
|
||||
public void init(){}
|
||||
|
||||
public abstract void generate(Tile[][] tiles);
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package io.anuke.mindustry.maps.generators;
|
||||
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.io.MapIO;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
import io.anuke.mindustry.maps.MapTileData;
|
||||
import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class MapGenerator extends Generator{
|
||||
private final Map map;
|
||||
|
||||
public MapGenerator(String mapName){
|
||||
map = world.maps.loadInternalMap(mapName);
|
||||
width = map.meta.width;
|
||||
height = map.meta.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Tile[][] tiles){
|
||||
MapTileData data = MapIO.readTileData(map, true);
|
||||
|
||||
data.position(0, 0);
|
||||
TileDataMarker marker = data.newDataMarker();
|
||||
|
||||
for(int y = 0; y < data.height(); y++){
|
||||
for(int x = 0; x < data.width(); x++){
|
||||
data.read(marker);
|
||||
|
||||
tiles[x][y] = new Tile(x, y, marker.floor, marker.wall == Blocks.blockpart.id ? 0 : marker.wall, marker.rotation, marker.team);
|
||||
}
|
||||
}
|
||||
|
||||
world.prepareTiles(tiles);
|
||||
}
|
||||
}
|
@ -20,6 +20,11 @@ public class Zone extends UnlockableContent{
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
generator.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden(){
|
||||
return true;
|
||||
|
@ -46,7 +46,7 @@ public class DeployDialog extends FloatingDialog{
|
||||
data.removeItems(zone.deployCost);
|
||||
hide();
|
||||
world.playZone(zone);
|
||||
}).size(150f).disabled(b -> !data.hasItems(zone.deployCost));
|
||||
}).size(150f)/*.disabled(b -> !data.hasItems(zone.deployCost))*/;
|
||||
t.row();
|
||||
t.table(req -> {
|
||||
req.left();
|
||||
|
@ -2,7 +2,6 @@ package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.arc.Core;
|
||||
import io.anuke.arc.entities.Effects.Effect;
|
||||
import io.anuke.arc.function.BiPredicate;
|
||||
import io.anuke.arc.function.Predicate;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.graphics.g2d.Draw;
|
||||
@ -10,8 +9,8 @@ import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.math.geom.Geometry;
|
||||
import io.anuke.arc.math.geom.Vector2;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.content.Fx;
|
||||
import io.anuke.mindustry.content.StatusEffects;
|
||||
import io.anuke.mindustry.type.Liquid;
|
||||
import io.anuke.mindustry.type.StatusEffect;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@ -52,11 +51,9 @@ public class Floor extends Block{
|
||||
public boolean playerUnmineable = false;
|
||||
protected TextureRegion edgeRegion;
|
||||
protected TextureRegion[] edgeRegions;
|
||||
protected TextureRegion[] cliffRegions;
|
||||
protected TextureRegion[] variantRegions;
|
||||
protected Vector2[] offsets;
|
||||
protected Predicate<Floor> blends = block -> block != this && !block.blendOverride(this);
|
||||
protected BiPredicate<Tile, Tile> tileBlends = (tile, other) -> false;
|
||||
protected boolean blend = true;
|
||||
|
||||
public Floor(String name){
|
||||
@ -96,12 +93,6 @@ public class Floor extends Block{
|
||||
edgeRegions[i] = result;
|
||||
offsets[i] = new Vector2(-padSize + rx, -padSize + ry);
|
||||
}
|
||||
|
||||
cliffRegions = new TextureRegion[4];
|
||||
cliffRegions[0] = Core.atlas.find(name + "-cliff-edge-2");
|
||||
cliffRegions[1] = Core.atlas.find(name + "-cliff-edge");
|
||||
cliffRegions[2] = Core.atlas.find(name + "-cliff-edge-1");
|
||||
cliffRegions[3] = Core.atlas.find(name + "-cliff-side");
|
||||
}
|
||||
|
||||
//load variant regions for drawing
|
||||
@ -115,6 +106,8 @@ public class Floor extends Block{
|
||||
variantRegions = new TextureRegion[1];
|
||||
variantRegions[0] = Core.atlas.find(name);
|
||||
}
|
||||
|
||||
region = variantRegions[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user