make map generated code look better

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-07-01 13:41:41 -04:00
parent e1feccb8f9
commit 061d352140
2 changed files with 13 additions and 11 deletions

View File

@ -4,8 +4,7 @@ const Rect = sh0rk.Rect;
const Tile = sh0rk.Tile; const Tile = sh0rk.Tile;
pub const data = [100]Tile{ pub const data = [100]Tile{
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 7, .y = 1}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 7, .y = 1}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2}, Tile{.x = 8, .y = 2},
@ -18,6 +17,7 @@ pub const data = [100]Tile{
}; };
pub const coll = [2]Rect{ pub const coll = [2]Rect{
Rect{.base = Point{.x = 0, .y = 80}, .width = 160, .height = 80}, Rect{.base = Point{.x = 80, .y = 48}, .width = 16, .height = 32}, Rect{.base = Point{.x = 0, .y = 80}, .width = 160, .height = 80},
Rect{.base = Point{.x = 80, .y = 48}, .width = 16, .height = 32},
}; };

View File

@ -26,8 +26,10 @@ tiles.data.forEach((tile, index) => {
const tileY = Math.trunc(tile / tiles.height); const tileY = Math.trunc(tile / tiles.height);
const tileX = tile % tiles.width; const tileX = tile % tiles.width;
out += `Tile{.x = ${tileX}, .y = ${tileY}},`; out += `Tile{.x = ${tileX}, .y = ${tileY}},`;
if (index % 10 === 0) { if (index !== 0 && index % 10 === 0) {
out += "\n "; out += "\n ";
} else {
out += " ";
} }
}); });
@ -44,10 +46,10 @@ if (map.layers.length >= 2) {
const width = Math.round(obj.width); const width = Math.round(obj.width);
const height = Math.round(obj.height); const height = Math.round(obj.height);
out += ` Rect{.base = Point{.x = ${x}, .y = ${y}}, .width = ${width}, .height = ${height}},`; out += ` Rect{.base = Point{.x = ${x}, .y = ${y}}, .width = ${width}, .height = ${height}},\n`;
}); });
out += "\n};\n\n"; out += "};\n\n";
} }
await Deno.writeTextFile(outFname, out); await Deno.writeTextFile(outFname, out);