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;
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 = 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{
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

@ -19,15 +19,17 @@ out += `const Rect = sh0rk.Rect;\n`;
out += `const Tile = sh0rk.Tile;\n\n`;
let tiles = map.layers[0];
out += `pub const data = [${tiles.data.length}]Tile{\n `;
out += `pub const data = [${tiles.data.length}]Tile{\n `;
tiles.data.forEach((tile, index) => {
tile -= 1;
const tileY = Math.trunc(tile / tiles.height);
const tileX = tile % tiles.width;
out += ` Tile{.x = ${tileX}, .y = ${tileY}},`;
if (index % 10 === 0) {
out += "\n ";
out += `Tile{.x = ${tileX}, .y = ${tileY}},`;
if (index !== 0 && index % 10 === 0) {
out += "\n ";
} else {
out += " ";
}
});
@ -36,7 +38,7 @@ out += "\n};\n\n";
if (map.layers.length >= 2) {
let coll = map.layers[1];
out += `pub const coll = [${coll.objects.length}]Rect{\n `;
out += `pub const coll = [${coll.objects.length}]Rect{\n`;
coll.objects.forEach(obj => {
const x = Math.round(obj.x);
@ -44,10 +46,10 @@ if (map.layers.length >= 2) {
const width = Math.round(obj.width);
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);