Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Languages: room for every game's translation
Mason Chen32f5d8451a0f
diff --git a/games/common/np_text.h b/games/common/np_text.hindex f29f1304..6e05434f 100644--- a/games/common/np_text.h+++ b/games/common/np_text.h@@ -111,30 +111,51 @@ static inline void np_accent(int acc, int x, int y, int scale, void (*plot)(intfor (int b = 0; b < scale; b++) plot(x + i * scale + b, y + j * scale + a, ctx);}-/* ---- the 12-pixel font */+/* ---- the 12-pixel font+ * Kept small, as the Chinese build holds a thousand letters and more: a letter is+ * its code point, the index of its sizes (letters share a few dozen) and its+ * bits, back to back with the others'; where they start is kept for every+ * 16th letter, the others' found by adding the sizes before them. */typedef struct {- uint16_t cp; /* (Chinese and its punctuation are all below 0x10000) */uint8_t adv, w, h; /* advance; the bitmap's size */int8_t x, y; /* the bitmap's top-left from the pen, y down from the top of a 12-pixel line */- uint16_t off; /* its first bit in rows: w x h bits, row by row, the first pixel first */} np_xglyph_t;typedef struct {uint32_t count;- const np_xglyph_t *glyphs; /* sorted by code point */- const uint8_t *rows; /* bits, lowest first in each byte */+ const uint16_t *cps; /* the letters, sorted (Chinese and its punctuation are all below 0x10000) */+ const uint8_t *size; /* each one's in sizes */+ const np_xglyph_t *sizes;+ const uint32_t *start; /* the first bit of letters 0, 16, 32... */+ const uint8_t *rows; /* w x h bits a letter, row by row, the first pixel first, lowest first in each byte */} np_xfont_t;extern const np_xfont_t np_xfont; /* the launcher's (launcher/src/np_xfont.h) */-/* The glyph of cp in the 12-pixel font, or NULL. */-static inline const np_xglyph_t *np_xglyph(uint32_t cp) {+/* The index of cp in the 12-pixel font, or -1. */+static inline int np_xindex(uint32_t cp) {uint32_t lo = 0, hi = np_xfont.count;while (lo < hi) {uint32_t m = (lo + hi) / 2;- if (np_xfont.glyphs[m].cp < cp) lo = m + 1;+ if (np_xfont.cps[m] < cp) lo = m + 1;else hi = m;}- return lo < np_xfont.count && np_xfont.glyphs[lo].cp == cp ? &np_xfont.glyphs[lo] : 0;+ return lo < np_xfont.count && np_xfont.cps[lo] == cp ? (int)lo : -1;+}++/* The glyph of cp in the 12-pixel font, or NULL. */+static inline const np_xglyph_t *np_xglyph(uint32_t cp) {+ int k = np_xindex(cp);+ return k < 0 ? 0 : &np_xfont.sizes[np_xfont.size[k]];+}++/* The first bit of cp's rows (cp in the font). */+static inline uint32_t np_xbit(uint32_t cp) {+ uint32_t k = (uint32_t)np_xindex(cp), bit = np_xfont.start[k / 16];+ for (uint32_t i = k & ~15u; i < k; i++) {+ const np_xglyph_t *g = &np_xfont.sizes[np_xfont.size[i]];+ bit += (uint32_t)g->w * g->h;+ }+ return bit;}/* Draws cp from the 12-pixel font with its line's top at (x, top), each font@@ -142,7 +163,7 @@ static inline const np_xglyph_t *np_xglyph(uint32_t cp) {static inline int np_xdraw(uint32_t cp, int x, int top, int scale, void (*plot)(int x, int y, void *ctx), void *ctx) {const np_xglyph_t *g = np_xglyph(cp);if (!g) return 0;- uint32_t bit = (uint32_t)g->off * 8;+ uint32_t bit = np_xbit(cp);for (int j = 0; j < g->h; j++)for (int i = 0; i < g->w; i++, bit++)if (np_xfont.rows[bit >> 3] >> (bit & 7) & 1)diff --git a/launcher/lang/fr.txt b/launcher/lang/fr.txtindex a88ce51f..799a0479 100644--- a/launcher/lang/fr.txt+++ b/launcher/lang/fr.txt@@ -99,3 +99,8 @@ NumBlocks NumBlocksNumDrive NumDrive2048 2048NumVisuals NumVisuals+# the games' credits+Inspired by Minecraft, not affiliated with Mojang Inspiré de Minecraft, sans lien avec Mojang+By Tatone26, from All the Apps Par Tatone26, tiré d'All the Apps+Inspired by Tatone26's All the Apps Inspiré d'All the Apps de Tatone26+Based on 2048 by Gabriele Cirulli D'après 2048 de Gabriele Cirullidiff --git a/launcher/lang/zh.txt b/launcher/lang/zh.txtindex dc44b915..4db0fefd 100644--- a/launcher/lang/zh.txt+++ b/launcher/lang/zh.txt@@ -98,3 +98,8 @@ NumBlocks NumBlocksNumDrive NumDrive2048 2048NumVisuals NumVisuals+# the games' credits+Inspired by Minecraft, not affiliated with Mojang 灵感来自《我的世界》,与 Mojang 无关+By Tatone26, from All the Apps 作者 Tatone26,出自 All the Apps+Inspired by Tatone26's All the Apps 灵感来自 Tatone26 的 All the Apps+Based on 2048 by Gabriele Cirulli 改编自 Gabriele Cirulli 的 2048diff --git a/launcher/src/np_xfont.h b/launcher/src/np_xfont.hindex 29fcf1d4..a074772b 100644--- a/launcher/src/np_xfont.h+++ b/launcher/src/np_xfont.h@@ -1,3 +1,3 @@/* Made by tools/xfont.py for a language build: the letters its texts use that the games' fonts don'thave. English needs none. See games/common/np_text.h. */-const np_xfont_t np_xfont = {0, 0, 0};+const np_xfont_t np_xfont = {0, 0, 0, 0, 0, 0};diff --git a/tools/lang.py b/tools/lang.pyindex 406459c2..18d2a8a6 100644--- a/tools/lang.py+++ b/tools/lang.py@@ -6,7 +6,7 @@ Texts players read are marked in the sources: T("...") in C, T!("...") in RustEnglish text as it is written in the source, a tab, then the translation (thesame escapes: \\n, \\"; UTF-8):- launcher/lang/<code>.txt the launcher, and the games' names and taglines (games/games.json)+ launcher/lang/<code>.txt the launcher, and the games' names, taglines and credits (games/games.json)games/<game>/lang/<code>.txt a gamelang.py strings [PART] every marked text of a part (or all), for translating@@ -63,7 +63,9 @@ def strings(part):found.append(s)if part == "launcher":for g in json.load(open(os.path.join(ROOT, "games", "games.json"))):- for k in ("title", "tagline"):+ for k in ("title", "tagline", "credit"):+ if not g.get(k):+ continuev = json.dumps(g[k], ensure_ascii=False)[1:-1]if v not in found:found.append(v)@@ -145,19 +147,22 @@ def tree(code, out):h = os.path.join(out, "games/common/np_text.h")text = open(h).read().replace("#define NP_TEXT_EXTRA 0", "#define NP_TEXT_EXTRA 1")open(h, "w").write(text)- # the games' names and taglines+ # the games' names, taglines and creditsgj = os.path.join(out, "games/games.json")games = json.load(open(gj))lt = tables["launcher"]for g in games:- for k in ("title", "tagline"):+ for k in ("title", "tagline", "credit"):+ if not g.get(k):+ continuekey = json.dumps(g[k], ensure_ascii=False)[1:-1]if key in lt:g[k] = json.loads(f'"{lt[key]}"')used.append(lt[key])- # (the screenshots in 32 colours, not 64: room for the translations and their letters)+ # (the screenshots in 16 colours, not 48: room for the translations and their letters; at the+ # carousel's size they look the same)for g in games:- g["colors"] = min(g.get("colors", 64), 32)+ g["colors"] = min(g.get("colors", 48), 16)json.dump(games, open(gj, "w"), indent=2, ensure_ascii=False)# node packages some games build withfor nm in ("games/numdash/node_modules",):diff --git a/tools/xfont.py b/tools/xfont.pyindex 92ab764c..5e0e1467 100644--- a/tools/xfont.py+++ b/tools/xfont.py@@ -71,32 +71,44 @@ def table(font_path, out, texts):cps = sorted(c for c in used if c in font and (c >= 0x2100 or 0x21 <= c < 0x180))L = ["/* Made by tools/xfont.py from Fusion Pixel 12px (SIL Open Font License 1.1): the letters this"," build's texts use that the games' fonts don't have. See games/common/np_text.h. */"]- rows = bytearray()- glyphs = []- for cp in cps:+ bits, sizes, size, start = [], [], [], []+ for k, cp in enumerate(cps):adv, x, y, w, h, r = font[cp]+ if cp >= 0x10000:+ raise SystemExit("xfont: letters above 0xFFFF")+ if k % 16 == 0:+ start.append(len(bits))stride = (w + 7) // 8- bits = [r[j * stride + i // 8] >> (i % 8) & 1 for j in range(h) for i in range(w)]- packed = bytearray((len(bits) + 7) // 8)- for k, b in enumerate(bits):- packed[k // 8] |= b << (k % 8)- if cp >= 0x10000 or len(rows) >= 0x10000:- raise SystemExit("xfont: too many letters for 16-bit offsets")- glyphs.append(f"{{{cp:#x}, {adv}, {w}, {h}, {x}, {y}, {len(rows)}}}")- rows += packed # (each letter starts on a byte: its offset counts bytes)+ bits += [r[j * stride + i // 8] >> (i % 8) & 1 for j in range(h) for i in range(w)]+ s = (adv, w, h, x, y) # (the Chinese letters share a few)+ if s not in sizes:+ sizes.append(s)+ size.append(sizes.index(s))+ if len(sizes) > 256:+ raise SystemExit("xfont: more than 256 sizes")+ rows = bytearray((len(bits) + 7) // 8)+ for k, b in enumerate(bits):+ rows[k // 8] |= b << (k % 8)++ def array(ctype, name, values, per_line=24):+ out = [f"static const {ctype} {name}[{len(values)}] = {{"]+ for i in range(0, len(values), per_line):+ out.append(" " + ", ".join(str(v) for v in values[i:i + per_line]) + ",")+ return out + ["};"]if cps:- L.append("static const np_xglyph_t np_xfont_glyphs[] = {")- L += [f" {g}," for g in glyphs]- L.append("};")- L.append(f"static const uint8_t np_xfont_rows[{len(rows)}] = {{")- for i in range(0, len(rows), 24):- L.append(" " + ", ".join(str(b) for b in rows[i:i + 24]) + ",")+ L += array("uint16_t", "np_xfont_cps", cps, 16)+ L += array("uint8_t", "np_xfont_size", size)+ L.append("static const np_xglyph_t np_xfont_sizes[] = {")+ L += [f" {{{adv}, {w}, {h}, {x}, {y}}}," for adv, w, h, x, y in sizes]L.append("};")- L.append(f"const np_xfont_t np_xfont = {{{len(cps)}, np_xfont_glyphs, np_xfont_rows}};")+ L += array("uint32_t", "np_xfont_start", start, 12)+ L += array("uint8_t", "np_xfont_rows", list(rows))+ L.append(f"const np_xfont_t np_xfont = {{{len(cps)}, np_xfont_cps, np_xfont_size, np_xfont_sizes, "+ "np_xfont_start, np_xfont_rows};")else:- L.append("const np_xfont_t np_xfont = {0, 0, 0};")+ L.append("const np_xfont_t np_xfont = {0, 0, 0, 0, 0, 0};")open(out, "w").write("\n".join(L) + "\n")- return len(cps), len(rows) + 10 * len(cps)+ return len(cps), 3 * len(cps) + 5 * len(sizes) + 4 * len(start) + len(rows)if __name__ == "__main__":