This commit is contained in:
Anuken
2020-03-14 12:29:12 -04:00
21 changed files with 120 additions and 90 deletions

View File

@@ -115,13 +115,13 @@ public class BlockIndexer{
if(structQuadrants == null) return;
//go through every tile... ouch
world.tiles.each(tile -> {
for(Tile tile : world.tiles){
if(tile.team() == team){
int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize;
structQuadrant(team).set(quadrantX, quadrantY);
}
});
}
}
/** @return whether this item is present on this map.*/

View File

@@ -120,9 +120,9 @@ public class EditorTile extends Tile{
}
@Override
protected void changed(){
protected void changed(Team team){
if(state.is(State.playing)){
super.changed();
super.changed(team);
return;
}
@@ -139,7 +139,7 @@ public class EditorTile extends Tile{
Block block = block();
if(block.hasEntity()){
entity = block.newEntity().init(this, false);
entity = block.newEntity().init(this, team, false);
entity.cons(new ConsumeModule(entity));
if(block.hasItems) entity.items(new ItemModule());
if(block.hasLiquids) entity.liquids(new LiquidModule());

View File

@@ -52,7 +52,7 @@ public class MapGenerateDialog extends FloatingDialog{
private CachedTile ctile = new CachedTile(){
//nothing.
@Override
protected void changed(){
protected void changed(Team team){
}
};

View File

@@ -94,10 +94,6 @@ abstract class BuilderComp implements Unitc, DrawLayerFlyingc{
//otherwise, update it.
BuildEntity entity = tile.ent();
if(entity == null){
return;
}
if(dst(tile) <= finalPlaceDst){
rotation = Mathf.slerpDelta(rotation, angleTo(entity), 0.4f);
}

View File

@@ -11,7 +11,7 @@ import static mindustry.Vars.state;
abstract class TeamComp implements Posc{
@Import float x, y;
Team team = Team.sharded;
Team team = Team.derelict;
public @Nullable
Tilec closestCore(){

View File

@@ -61,9 +61,10 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
private transient float sleepTime;
/** Sets this tile entity data to this and adds it if necessary. */
public Tilec init(Tile tile, boolean shouldAdd){
public Tilec init(Tile tile, Team team, boolean shouldAdd){
this.tile = tile;
this.block = tile.block();
this.team = team;
set(tile.drawx(), tile.drawy());
if(block.activeSound != Sounds.none){

View File

@@ -61,14 +61,12 @@ public class IndexedRenderer implements Disposable{
updateMatrix();
program.bind();
texture.bind();
program.setUniformMatrix4("u_projTrans", BatchShader.copyTransform(combined));
program.setUniformi("u_texture", 0);
mesh.render(program, Gl.triangles, 0, vertices.length / vsize);
}
public void setColor(Color color){

View File

@@ -257,10 +257,19 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(lastSchematic == null) return;
ui.showTextInput("$schematic.add", "$name", "", text -> {
lastSchematic.tags.put("name", text);
schematics.add(lastSchematic);
ui.showInfoFade("$schematic.saved");
ui.schematics.showInfo(lastSchematic);
Schematic replacement = schematics.all().find(s -> s.name().equals(text));
if(replacement != null){
ui.showConfirm("$confirm", "$schematic.replace", () -> {
schematics.overwrite(replacement, lastSchematic);
ui.showInfoFade("$schematic.saved");
ui.schematics.showInfo(replacement);
});
}else{
lastSchematic.tags.put("name", text);
schematics.add(lastSchematic);
ui.showInfoFade("$schematic.saved");
ui.schematics.showInfo(lastSchematic);
}
});
}

View File

@@ -127,6 +127,8 @@ public class Scripts implements Disposable{
if(!dir.exists()) return null; // Mod and folder not found
return loadSource(script, dir, validator);
}
currentMod = required;
return loadSource(script, required.root.child("scripts"), validator);
}

View File

@@ -11,7 +11,6 @@ import arc.scene.ui.TextButton.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.core.GameState.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -89,6 +88,13 @@ public class SchematicsDialog extends FloatingDialog{
buttons.addImageButton(Icon.pencil, style, () -> {
ui.showTextInput("$schematic.rename", "$name", s.name(), res -> {
Schematic replacement = schematics.all().find(other -> other.name().equals(res) && other != s);
if(replacement != null){
//renaming to an existing schematic is not allowed, as it is not clear how the tags would be merged, and which one should be removed
ui.showErrorMessage("$schematic.exists");
return;
}
s.tags.put("name", res);
s.save();
rebuildPane[0].run();

View File

@@ -1,5 +1,6 @@
package mindustry.world;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.modules.*;
@@ -19,7 +20,7 @@ public class CachedTile extends Tile{
}
@Override
protected void changed(){
protected void changed(Team team){
entity = null;
Block block = block();

View File

@@ -41,7 +41,7 @@ public class Tile implements Position{
this.block = wall;
//update entity and create it if needed
changed();
changed(Team.derelict);
}
public Tile(int x, int y, int floor, int overlay, int wall){
@@ -163,7 +163,7 @@ public class Tile implements Position{
preChanged();
this.block = type;
this.rotation = rotation == 0 ? 0 : (byte)Mathf.mod(rotation, 4);
changed();
changed(team);
if(entity != null){
entity.team(team);
@@ -510,7 +510,7 @@ public class Tile implements Position{
}
}
protected void changed(){
protected void changed(Team team){
if(entity != null){
entity.remove();
entity = null;
@@ -519,7 +519,7 @@ public class Tile implements Position{
Block block = block();
if(block.hasEntity()){
entity = block.newEntity().init(this, block.update);
entity = block.newEntity().init(this, team, block.update);
entity.cons(new ConsumeModule(entity));
if(block.hasItems) entity.items(new ItemModule());
if(block.hasLiquids) entity.liquids(new LiquidModule());

View File

@@ -11,7 +11,6 @@ public class Tiles implements Iterable<Tile>{
public final int width, height;
private final Tile[] array;
private final TileIterator iterator = new TileIterator();
public Tiles(int width, int height){
this.array = new Tile[width * height];
@@ -73,12 +72,8 @@ public class Tiles implements Iterable<Tile>{
@Override
public Iterator<Tile> iterator(){
if(iterator.index != 0 && iterator.index != array.length){
iterator.index = 0;
throw new IllegalArgumentException("Double iteration. " + iterator.index + " != " + array.length);
}
iterator.index = 0;
return iterator;
//iterating through the entire map is expensive anyway, so a new allocation doesn't make much of a difference
return new TileIterator();
}
private class TileIterator implements Iterator<Tile>{

View File

@@ -42,7 +42,7 @@ public class LiquidSource extends Block{
drawRequestConfigCenter(req, (Content)req.config, "center");
}
class LiquidSourceEntity extends TileEntity{
public class LiquidSourceEntity extends TileEntity{
public @Nullable Liquid source = null;
@Override