Spaces:
Running
Running
File size: 7,339 Bytes
950662b 6ed91fb 950662b 6ed91fb 950662b 6ed91fb 950662b 6ed91fb 950662b 6ed91fb 950662b 6ed91fb 950662b 6ed91fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | // Example map script: builds maps/hacker-lair.tmj (ELECTRONIC theme, 64x64: hacker lair in a digital network)
// by calling the builder API directly, without an MCP client. It is deterministic:
// re-running it reproduces the committed sample map. Run from the repository root
// after building the server (npm run build):
// node scripts/create-electronic-hacker-map.mjs
import { createMap, paintRect, paintWallBorder, eraseTile, placeObject, placeSpawn, serializeMap } from '../tiled-mcp/dist/builder.js';
import { getTheme } from '../tiled-mcp/dist/themes/index.js';
import { saveMapFile } from '../tiled-mcp/dist/tmj.js';
import { fileURLToPath } from 'node:url';
import fs from 'node:fs';
const theme = getTheme("ELECTRONIC");
const { mapId } = createMap({
name: "Electronic Network - Hacker Lair",
width: 64,
height: 64,
theme: theme,
orientation: "isometric",
});
console.log("Map created:", mapId);
// ---------- Helpers ----------
function openWall(x, y) {
eraseTile(mapId, "walls", x, y);
}
// ---------- Ground: the whole map in walkable_floor (outdoor electronic plaza) ----------
for (let y = 0; y < 64; y++) {
for (let x = 0; x < 64; x++) {
paintRect(mapId, "ground", x, y, x, y, "walkable_floor");
}
}
// Outer wall
paintWallBorder(mapId, 0, 0, 63, 63);
// ---------- Electronic rune symbol (centre 32,32) ----------
const CX = 32, CY = 32;
// Outer circle of circuit traces (radius 14-16)
for (let y = CY - 16; y <= CY + 16; y++) {
for (let x = CX - 16; x <= CX + 16; x++) {
const dx = x - CX;
const dy = y - CY;
const d2 = dx * dx + dy * dy;
if (d2 >= 196 && d2 <= 256) {
paintRect(mapId, "ground", x, y, x, y, "walkable_floor_alt");
}
}
}
// Inner circle of traces (radius 8-10)
for (let y = CY - 10; y <= CY + 10; y++) {
for (let x = CX - 10; x <= CX + 10; x++) {
const dx = x - CX;
const dy = y - CY;
const d2 = dx * dx + dy * dy;
if (d2 >= 64 && d2 <= 100) {
paintRect(mapId, "ground", x, y, x, y, "walkable_floor_alt");
}
}
}
// Radial traces linking both circles (8 directions)
for (let i = 0; i < 8; i++) {
const ang = i * 45;
const rad = ang * Math.PI / 180;
for (let r = 11; r <= 13; r++) {
const x = Math.round(CX + r * Math.cos(rad));
const y = Math.round(CY + r * Math.sin(rad));
if (x >= 0 && x < 64 && y >= 0 && y < 64) {
paintRect(mapId, "ground", x, y, x, y, "walkable_floor_alt");
}
}
}
// Circuit nodes on the outer circle (8 points) -> hazard
const nodeAngles = [0, 45, 90, 135, 180, 225, 270, 315];
for (const ang of nodeAngles) {
const rad = ang * Math.PI / 180;
const x = Math.round(CX + 15 * Math.cos(rad));
const y = Math.round(CY + 15 * Math.sin(rad));
if (x >= 0 && x < 64 && y >= 0 && y < 64) {
paintRect(mapId, "ground", x, y, x, y, "hazard_primary");
}
}
// Central core (chip / system core) -> obstacle_decor
paintRect(mapId, "ground", CX, CY, CX, CY, "obstacle_decor");
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const x = CX + dx;
const y = CY + dy;
if (x >= 0 && x < 64 && y >= 0 && y < 64) {
paintRect(mapId, "ground", x, y, x, y, "difficult_terrain");
}
}
}
// Electric shock zones around the nodes (difficult_terrain)
for (const ang of nodeAngles) {
const rad = ang * Math.PI / 180;
for (let r = 13; r <= 14; r++) {
const x = Math.round(CX + r * Math.cos(rad));
const y = Math.round(CY + r * Math.sin(rad));
if (x >= 0 && x < 64 && y >= 0 && y < 64) {
paintRect(mapId, "ground", x, y, x, y, "difficult_terrain");
}
}
}
// ---------- Hacker lair building (bottom centre) ----------
const BX1 = 22, BY1 = 44, BX2 = 41, BY2 = 60;
// Building walls
paintWallBorder(mapId, BX1, BY1, BX2, BY2);
// Interior floor
for (let y = BY1 + 1; y <= BY2 - 1; y++) {
for (let x = BX1 + 1; x <= BX2 - 1; x++) {
paintRect(mapId, "ground", x, y, x, y, "walkable_floor");
}
}
// Entrance door (middle of the building's north wall)
openWall(31, BY1);
paintRect(mapId, "ground", 31, BY1, 31, BY1, "door_closed");
// ---------- Hacker equipment inside ----------
// Terminals / screens (obstacle_decor)
paintRect(mapId, "decorations", 26, 48, 26, 48, "obstacle_decor");
paintRect(mapId, "decorations", 27, 48, 27, 48, "obstacle_decor");
paintRect(mapId, "decorations", 36, 48, 36, 48, "obstacle_decor");
paintRect(mapId, "decorations", 37, 48, 37, 48, "obstacle_decor");
paintRect(mapId, "decorations", 26, 54, 26, 54, "obstacle_decor");
paintRect(mapId, "decorations", 37, 54, 37, 54, "obstacle_decor");
// Servers / racks (obstacle_decor, 2x2)
paintRect(mapId, "decorations", 23, 50, 24, 51, "obstacle_decor");
paintRect(mapId, "decorations", 39, 50, 40, 51, "obstacle_decor");
// Cables / floor details (decoration_minor)
for (let i = 0; i < 20; i++) {
const x = BX1 + 2 + (i * 3) % (BX2 - BX1 - 5);
const y = BY1 + 2 + Math.floor((i * 3) / (BX2 - BX1 - 5)) * 3;
if (x < BX2 - 1 && y < BY2 - 1) {
paintRect(mapId, "decorations", x, y, x, y, "decoration_minor");
}
}
// ---------- Spawns ----------
// Player in front of the building door
placeSpawn(mapId, { x: 31, y: 42, role: "player", name: "player-start" });
// Hacker enemies inside the building
placeSpawn(mapId, { x: 26, y: 50, role: "enemy", npcName: "Network Hacker", name: "hacker-terminal-1" });
placeSpawn(mapId, { x: 37, y: 50, role: "enemy", npcName: "Network Hacker", name: "hacker-terminal-2" });
placeSpawn(mapId, { x: 31, y: 56, role: "enemy", npcName: "Network Hacker", name: "hacker-central" });
placeSpawn(mapId, { x: 24, y: 55, role: "enemy", npcName: "Security Daemon", name: "security-1" });
// Guard enemy near the rune's core
placeSpawn(mapId, { x: 32, y: 20, role: "enemy", npcName: "Rogue AI", name: "ai-core-guardian" });
// ---------- Objects ----------
// Data chest in the building
placeObject(mapId, { x: 30, y: 58, kind: "chest", name: "hacker-data-chest" });
// Stairs (access to the lower level)
paintRect(mapId, "ground", 31, 59, 31, 59, "stairs");
// ---------- Minor decorations around the rune ----------
const runeDecorSpots = [
[16, 32], [48, 32], [32, 16], [32, 48],
[22, 22], [42, 22], [22, 42], [42, 42],
];
for (const [ix, iy] of runeDecorSpots) {
paintRect(mapId, "decorations", ix, iy, ix, iy, "decoration_minor");
}
// ---------- Save the map ----------
const mapData = serializeMap(mapId);
const outPath = fileURLToPath(new URL('../maps/hacker-lair.tmj', import.meta.url));
await saveMapFile(mapId, outPath);
console.log("Saved:", outPath);
console.log("Size:", (fs.statSync(outPath).size / 1024).toFixed(2), "KB");
console.log("Grid:", mapData.width, "x", mapData.height);
console.log("Orientation:", mapData.orientation);
console.log("Theme:", mapData.properties.find(p => p.name === "theme")?.value);
console.log("Spawns:", mapData.layers.find(l => l.name === "spawns").objects.length);
console.log("Objects:", mapData.layers.find(l => l.name === "objects").objects.length);
console.log("Decoration tiles:", mapData.layers.find(l => l.name === "decorations").data.filter(g => g !== 0).length);
|