make map generated code look better
Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
parent
e1feccb8f9
commit
061d352140
|
@ -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},
|
||||||
|
@ -14,10 +13,11 @@ pub const data = [100]Tile{
|
||||||
Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 2, .y = 2}, Tile{.x = 5, .y = 1},
|
Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 2, .y = 2}, Tile{.x = 5, .y = 1},
|
||||||
Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 2, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 2, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 5, .y = 2},
|
Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 2, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 2, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 5, .y = 2},
|
||||||
Tile{.x = 0, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 5, .y = 0},
|
Tile{.x = 0, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 5, .y = 0},
|
||||||
Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 4}, Tile{.x = 9, .y = 4},
|
Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 2}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 9, .y = 4}, Tile{.x = 1, .y = 4}, Tile{.x = 9, .y = 4},
|
||||||
};
|
};
|
||||||
|
|
||||||
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},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,17 @@ out += `const Rect = sh0rk.Rect;\n`;
|
||||||
out += `const Tile = sh0rk.Tile;\n\n`;
|
out += `const Tile = sh0rk.Tile;\n\n`;
|
||||||
|
|
||||||
let tiles = map.layers[0];
|
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) => {
|
tiles.data.forEach((tile, index) => {
|
||||||
tile -= 1;
|
tile -= 1;
|
||||||
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 += " ";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ out += "\n};\n\n";
|
||||||
if (map.layers.length >= 2) {
|
if (map.layers.length >= 2) {
|
||||||
let coll = map.layers[1];
|
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 => {
|
coll.objects.forEach(obj => {
|
||||||
const x = Math.round(obj.x);
|
const x = Math.round(obj.x);
|
||||||
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue