From 75a22827646fff501927b4450fc4ade9818db080 Mon Sep 17 00:00:00 2001 From: zxtej <83355748+zxtej@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:11:03 +0000 Subject: [PATCH] Feature: Janky mass wall replace --- core/src/mindustry/input/InputHandler.java | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 643e8131a0..4db80cbf03 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -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 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());