Skip to content

Commit

Permalink
Feature: Janky mass wall replace
Browse files Browse the repository at this point in the history
  • Loading branch information
zxtej committed Oct 31, 2024
1 parent b2f595f commit 75a2282
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions core/src/mindustry/input/InputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -1675,8 +1675,35 @@ protected void freezeSelection(int x1, int y1, int x2, int y2, boolean flush, in
}
}

private void updateWallLine(int x1, int y1, int x2, int y2){
String blockType = block.name.split("-wall")[0];
Seq<Block> equivalents = Vars.content.blocks().select(block -> block.name.startsWith(blockType + "-wall"));

int xmin = Math.min(x1, x2), xmax = Math.max(x1, x2), ymin = Math.min(y1, y2), ymax = Math.max(y1, y2);
for(int y = ymin; y <= ymax; ++y){
for(int x = xmin; x <= xmax; ++x){
var tile = world.tile(x, y);
if(tile == null) continue;
var otherBlock = tile.block();
if(otherBlock == null || otherBlock == block || otherBlock.group != BlockGroup.walls) continue;
Tile otherTile;
if(tile.build == null || (otherTile = tile.build.tile) == null || (otherTile != tile &&
// include blocks that overlap with but not necessarily originate within the rect
(x != xmin || otherTile.y != y) && (y != ymin && otherTile.x != x))) continue;
if(equivalents.contains(otherBlock, true)) continue;
var replacement = equivalents.find(candidate -> candidate.size == otherBlock.size);
if(replacement == null) continue;
var plan = new BuildPlan(otherTile.x, otherTile.y, 0, replacement, null);
plan.animScale = 1f;
linePlans.add(plan);
}
}
}

protected void updateLine(int x1, int y1, int x2, int y2){
linePlans.clear();
if(block.group == BlockGroup.walls && Core.input.shift()) updateWallLine(x1, y1, x2, y2);
else
iterateLine(x1, y1, x2, y2, l -> {
rotation = l.rotation;
var plan = new BuildPlan(l.x, l.y, l.rotation, block, block.nextConfig());
Expand Down

0 comments on commit 75a2282

Please sign in to comment.