Skip to content

Commit

Permalink
Merge pull request #153 from TruncateGame/feat/rendering-and-generation
Browse files Browse the repository at this point in the history
💯 commits of rendering, generation, and daily puzzle features
  • Loading branch information
bglw authored Jan 29, 2024
2 parents 7b2625e + cda3258 commit c25afd5
Show file tree
Hide file tree
Showing 90 changed files with 8,933 additions and 4,925 deletions.
77 changes: 77 additions & 0 deletions .backstage/build-tile-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env node

const fs = require("fs");
const path = require("path");

const INPUT_FILE = path.join(__dirname, "../truncate_client/img/tile_order");
const OUTPUT_RUST = path.join(__dirname, "../truncate_client/src/utils/tex/tiles.rs");
const OUTPUT_JS = path.join(__dirname, "../web_client/src/_data/tiles.js");

const raw_tiles = fs
.readFileSync(INPUT_FILE, { encoding: "utf8" })
.split("\n");

const quad_tiles = {};
for (const tile of raw_tiles) {
if (/_(nw|ne|se|sw)$/i.test(tile)) {
const tile_base = tile.replace(/_(nw|ne|se|sw)$/i, '');
const tile_corner = tile.match(/_(nw|ne|se|sw)$/i)?.[1];
quad_tiles[tile_base] = quad_tiles[tile_base] || {};
quad_tiles[tile_base][tile_corner?.toLowerCase() || "??"] = true
}
}

const rs_map = [
`#![cfg_attr(rustfmt, rustfmt_skip)]\n`,
`#![allow(dead_code)]\n`,
`use super::{Tex, TexQuad};\n`,
`const fn t(tile: usize) -> Tex {`,
` Tex { tile, tint: None }`,
`}\n`,
`pub const MAX_TILE: usize = ${raw_tiles.length};`,
...raw_tiles.map((tile, i) =>
`pub const ${tile}: Tex = t(${i});`
),
`\npub mod quad {`,
` use super::*;\n`,
...Object.entries(quad_tiles).map(([tile, quadrants]) =>
` pub const ${tile}: TexQuad = [${[
quadrants.nw ? `${tile}_NW` : `NONE`,
quadrants.ne ? `${tile}_NE` : `NONE`,
quadrants.se ? `${tile}_SE` : `NONE`,
quadrants.sw ? `${tile}_SW` : `NONE`,
].join(', ')}];`
),
`}`
].join("\n");

fs.writeFileSync(OUTPUT_RUST, rs_map);

const js_map = [
`const tiles = {`,
...raw_tiles.map((tile, i) =>
` ${tile}: ${i},`
),
`};\n`,
`const quads = {`,
...Object.entries(quad_tiles).map(([tile, quadrants]) =>
` ${tile}: [[${[
quadrants.nw ? `tiles.${tile}_NW` : `tiles.NONE`,
quadrants.ne ? `tiles.${tile}_NE` : `tiles.NONE`,
].join(', ')}],[${[
quadrants.sw ? `tiles.${tile}_SW` : `tiles.NONE`,
quadrants.se ? `tiles.${tile}_SE` : `tiles.NONE`,
].join(', ')}]],`
),
`};\n`,
`module.exports = async function () {`,
` return {`,
` ...tiles,`,
` QUAD: {`,
` ...quads,`,
` }`,
` }`,
`}`,
].join("\n");

fs.writeFileSync(OUTPUT_JS, js_map);
17 changes: 17 additions & 0 deletions .backstage/cmds
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# migrations
sqlx migrate add -r some_migration_name
sqlx migrate revert
sqlx migrate run

# create staging db
fly postgres create

# prod
flyctl secrets set -a truncate-citadel "DATABASE_URL=..."
# staging
flyctl secrets set -a truncate-coup "DATABASE_URL=..."

# Remember ?sslmode=disable on the database url

# to access postgresql://localhost:15432
fly proxy 15432:5432 -a truncate-staging
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ truncate_client/img/package-lock.json
_site
# ungzipped word definition db
defs.db
local_defs.db
unsummed_wordlist.txt
unmarked_wordlist.txt
objectionable.json
objectionable.json
.env
Loading

0 comments on commit c25afd5

Please sign in to comment.