feat(io): adaptive ASCII map width; document map command, mark sub-project done
AsciiMap sizes room boxes to the longest visible name (capped) so names like 'Dark Hallway' are no longer truncated; connector centering follows. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,8 +11,9 @@ import java.util.Set;
|
||||
*/
|
||||
public final class AsciiMap {
|
||||
|
||||
private static final int INNER = 7; // room name field width
|
||||
private static final int GAP = 3; // horizontal corridor width
|
||||
private static final int MIN_INNER = 7; // minimum room name field width
|
||||
private static final int MAX_INNER = 14; // cap so the map stays compact
|
||||
private static final int GAP = 3; // horizontal corridor width
|
||||
|
||||
private AsciiMap() {
|
||||
}
|
||||
@@ -24,10 +25,12 @@ public final class AsciiMap {
|
||||
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
int inner = MIN_INNER;
|
||||
Map<Long, RoomCell> at = new HashMap<>();
|
||||
for (RoomCell c : view.cells()) {
|
||||
maxX = Math.max(maxX, c.x());
|
||||
maxY = Math.max(maxY, c.y());
|
||||
inner = Math.max(inner, Math.min(MAX_INNER, c.name().length()));
|
||||
at.put(key(c.x(), c.y()), c);
|
||||
}
|
||||
|
||||
@@ -50,19 +53,23 @@ public final class AsciiMap {
|
||||
String hz = unicode ? "─" : "-";
|
||||
String vt = unicode ? "│" : "|";
|
||||
|
||||
int boxW = inner + 2;
|
||||
int leftPad = (boxW - 1) / 2;
|
||||
int rightPad = boxW - 1 - leftPad;
|
||||
|
||||
StyledText.Builder b = StyledText.builder();
|
||||
for (int gy = 0; gy <= maxY; gy++) {
|
||||
for (int line = 0; line < 3; line++) {
|
||||
for (int gx = 0; gx <= maxX; gx++) {
|
||||
RoomCell c = at.get(key(gx, gy));
|
||||
if (c == null) {
|
||||
b.plain(" ".repeat(INNER + 2));
|
||||
b.plain(" ".repeat(boxW));
|
||||
} else if (line == 0) {
|
||||
styled(b, tl + hz.repeat(INNER) + tr, c.state());
|
||||
styled(b, tl + hz.repeat(inner) + tr, c.state());
|
||||
} else if (line == 2) {
|
||||
styled(b, bl + hz.repeat(INNER) + br, c.state());
|
||||
styled(b, bl + hz.repeat(inner) + br, c.state());
|
||||
} else {
|
||||
styled(b, vt + center(label(c), INNER) + vt, c.state());
|
||||
styled(b, vt + center(label(c, inner), inner) + vt, c.state());
|
||||
}
|
||||
if (gx < maxX) {
|
||||
if (line == 1 && hEdge.contains(key(gx, gy))) {
|
||||
@@ -77,9 +84,9 @@ public final class AsciiMap {
|
||||
if (gy < maxY) {
|
||||
for (int gx = 0; gx <= maxX; gx++) {
|
||||
if (vEdge.contains(key(gx, gy))) {
|
||||
b.plain(" ".repeat(4)).dim(vt).plain(" ".repeat(4));
|
||||
b.plain(" ".repeat(leftPad)).dim(vt).plain(" ".repeat(rightPad));
|
||||
} else {
|
||||
b.plain(" ".repeat(INNER + 2));
|
||||
b.plain(" ".repeat(boxW));
|
||||
}
|
||||
if (gx < maxX) {
|
||||
b.plain(" ".repeat(GAP));
|
||||
@@ -99,10 +106,10 @@ public final class AsciiMap {
|
||||
}
|
||||
}
|
||||
|
||||
private static String label(RoomCell c) {
|
||||
private static String label(RoomCell c, int inner) {
|
||||
String n = c.name();
|
||||
if (n.length() > INNER) {
|
||||
n = n.substring(0, INNER);
|
||||
if (n.length() > inner) {
|
||||
n = n.substring(0, inner);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user