Files
Triforce-Source/tests/test_file_select_cards.py
ruckus7382sfgsgdf b527e29adb Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
2026-11-28 10:54:41 -06:00

185 lines
12 KiB
Python

"""The file select drawn as the game's own Load list (gpu/vk/vk_game_tex.h make_file_skin, vk_menu.cpp draw_files; no game).
(2026-11-25) The owner, of the file select at 21:9: "It is very broken and it's only optimized for 16:9. I want you to
optimize it for ultra-wide as well. I want you to improve the design, fix up the UI, use the in-game assets, fix the
out-of-place buttons and overlapping prompts." It had the options' layout: the list at the left of the grid, a caption box
at its right (over the title, and over the performance overlay on a wide screen), and a Play button of its own under the
list. This compiles vk_game_tex.h's card and tag makers with made-up textures and checks:
- the card is the game's texture stretched as the game's layout stretches it: 469 texels wider, the picture's part and
the curl's part at their own size, only the part between them stretched;
- its fill is the measured grain's colours, its frame and its rule theirs, its alpha the shape's (or the frame's, where
the frame goes past it); the rule is taken from Frame_00 in its box only;
- the tag is its plate's colour with the rim's over it;
and reads the source: one column in the middle of the grid (draw_menu), the card, the tag, the cursor and the plates from
the game's textures with a drawn fallback for each, no Play button and no caption box, the line about the choice under the
cards, a click on the chosen card plays it, and the prompts kept inside a window narrower than 16:9.
python -I -B tests/test_file_select_cards.py [--cxx clang++]
"""
import argparse
import subprocess
import tempfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
VK = ROOT / "gpu" / "vk"
RUN_ALL_ARGS = ["--cxx", "{cxx}"]
def check(ok, why):
if not ok:
raise SystemExit("FAIL: " + why)
def function(text, head):
start = text.index(head)
end = text.index("{", start) + 1
depth = 1
while depth:
depth += (text[end] == "{") - (text[end] == "}")
end += 1
return text[start:end]
PROGRAM = r"""
#include <cstdio>
#include <cstdlib>
#include "vk_game_tex.h"
using namespace mkwvk::game_tex;
static int fails = 0;
static void near(const Image& im, uint32_t x, uint32_t y, const unsigned char* rgb, int a, int tol, const char* what) {
const unsigned char* px = &im.rgba[((size_t)y * im.w + x) * 4];
if (std::abs(px[0] - rgb[0]) > tol || std::abs(px[1] - rgb[1]) > tol || std::abs(px[2] - rgb[2]) > tol || std::abs(px[3] - a) > 1) {
std::printf("FAIL: %s at %u,%u: %d,%d,%d,%d, not %d,%d,%d,%d\n", what, x, y, px[0], px[1], px[2], px[3], rgb[0], rgb[1], rgb[2], a);
fails++;
}
}
static Image blank(uint32_t w, uint32_t h, bool mask) {
Image im;
im.w = w, im.h = h, im.mask = mask;
im.rgba.assign((size_t)w * h * 4, 255);
for (size_t i = 0; i < (size_t)w * h; i++) im.rgba[i * 4 + 3] = 0;
return im;
}
static void set_a(Image& im, uint32_t x, uint32_t y, int a) { im.rgba[((size_t)y * im.w + x) * 4 + 3] = (unsigned char)a; }
int main() {
// the game's textures' size: the shape over all but a margin, a frame line at x 100 (the picture's part), 600 (the
// stretched part) and 900 (the curl's part), across at y 20; Frame_00 the same with a rule at y 156 and a mark outside
// the rule's box (at y 60) that must not show
Image base = blank(997, 283, false), frame = blank(997, 283, true), ruled = blank(997, 283, false);
for (uint32_t y = 18; y < 265; y++)
for (uint32_t x = 12; x < 986; x++) set_a(base, x, y, 255);
for (uint32_t y = 14; y < 268; y++) set_a(frame, 100, y, 255), set_a(frame, 600, y, 255), set_a(frame, 900, y, 255);
for (uint32_t x = 11; x < 989; x++) set_a(frame, x, 20, 255);
set_a(frame, 990, 140, 255); // (past the shape: the frame's own alpha)
for (uint32_t x = 480; x < 720; x++) set_a(ruled, x, 156, 255);
set_a(ruled, 300, 60, 255);
const Image card = make_file_card(base, frame, ruled, nullptr);
if (card.w != 997 + kFileCardMore || card.h != 283 || card.mask) std::printf("FAIL: the card is %ux%u\n", card.w, card.h), fails++;
unsigned char mid[3];
for (int k = 0; k < 3; k++) mid[k] = (unsigned char)((kFileCardLo[k] + kFileCardHi[k]) * 0.5f + 0.5f);
near(card, 200, 140, mid, 255, 1, "the fill (no grain: its middle colour)");
near(card, 100, 140, kFileCardLine, 255, 1, "the frame in the picture's part, where it is");
near(card, 900 + kFileCardMore, 140, kFileCardLine, 255, 1, "the frame in the curl's part, moved by the stretch");
near(card, 990 + kFileCardMore, 140, kFileCardLine, 255, 1, "the frame past the shape");
near(card, 900, 140, mid, 255, 1, "the fill where the curl's part was before the stretch");
// (600 in the stretched part: at 470 + 130 * (714 / 245), about 849, a texel or two wide)
const uint32_t at600 = kFileCardKeepL + (uint32_t)((600.0f - kFileCardKeepL) * (kFileCardKeepR + kFileCardMore - kFileCardKeepL) / (kFileCardKeepR - kFileCardKeepL));
int found = 0;
for (uint32_t x = at600 - 3; x <= at600 + 3; x++) found |= card.rgba[((size_t)140 * card.w + x) * 4] == kFileCardLine[0];
if (!found) std::printf("FAIL: the frame in the stretched part is not near %u\n", at600), fails++;
near(card, 1000, 20, kFileCardLine, 255, 1, "the frame across the stretched part");
near(card, 600, 156, kFileCardRule, 255, 1, "the rule");
near(card, 300, 60, mid, 255, 1, "Frame_00 outside the rule's box");
near(card, 5, 140, mid, 0, 255, "outside the shape (nothing)");
// the tag: its plate's colour, the rim's over it
Image plate = blank(4, 1, true), rim = blank(4, 1, true);
set_a(plate, 0, 0, 255), set_a(plate, 1, 0, 255), set_a(rim, 1, 0, 255), set_a(rim, 2, 0, 128);
const Image tag = make_file_tag(plate, rim);
near(tag, 0, 0, kFileTagFill, 255, 1, "the tag's plate");
near(tag, 1, 0, kFileTagRim, 255, 1, "the tag's rim over its plate");
near(tag, 2, 0, kFileTagRim, 128, 1, "the tag's rim alone");
near(tag, 3, 0, kFileTagFill, 0, 255, "outside the tag");
return fails ? 1 : 0;
}
"""
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cxx", default="clang++")
args = parser.parse_args()
tex = (VK / "vk_game_tex.h").read_text(encoding="utf-8")
ui = (VK / "vk_ui.h").read_text(encoding="utf-8")
menu = (VK / "vk_menu.cpp").read_text(encoding="utf-8")
skin = function(tex, "inline bool make_skin(")
check("make_file_skin(bntx, skin);" in skin, "make_skin does not make the file select's pieces")
files = function(tex, "inline void make_file_skin(")
for made in ('"file_card"', '"file_tag"', '"file_cursor_line"', '"file_cursor_glow"'):
check(made in files, "make_file_skin does not make " + made)
check("return false" not in files and files.count("if (read(") == 3, "a missing piece of the file select is not left out alone")
check('"DataFileImportantStateBase_DataDileImportantStateBase_00", "DataFileImportantStateBase_DataDileImportantStateBase_01"' in skin,
"the plates of the stones and medallions are not taken (by the archive's own spelling)")
draw = function(menu, "void draw_menu(ui::Ctx& c, bool perf_under) {")
check("if (page == kFilesPage) files_columns(k, &cx0, &cx1);" in draw, "the file select's column is not its own")
cols = function(menu, "void files_columns(")
check("-kFilesColumnHalf" in cols and "kFilesColumnHalf, 0).x" in cols, "the file select's column is not in the middle")
page = function(menu, "void draw_files(ui::Ctx& c) {")
for name in ('ui::art("file_card")', 'ui::art("file_tag")', 'ui::art("file_cursor_line")', 'ui::art("file_cursor_glow")'):
check(name in page, "draw_files does not draw " + name)
check("else ui::plate(c, a, b, i == cur);" in page and "} else ui::cursor(c, a, b, k);" in page, "a card or its cursor has no fallback")
# ((2026-11-26) the owner: hover, the game's settings' animations, the opening's, the blur in place of the shade)
check("files_focus[i].step(now, i == files_choice, settle);" in page and "ui::alpha(ui::kCursor, k)" in page and
"ui::glow_layers(c, cursor_glow, a - m, b + m, 150, 120, ui::kCursorGlow, ui::kCursorGlowBase, ui::kCursorGlowHdr, k);" in page,
"a card's cursor does not fade in and out as the game's settings' buttons'")
check("files_screen.step(prof_now(), open_now.load() && page == kFilesPage);" in menu and
"files_blur.store(open_now.load() && page == kFilesPage && files_at_title, std::memory_order_relaxed);" in menu and
"bool menu_backdrop_blurred() { return files_blur.load(std::memory_order_relaxed); }" in menu,
"Save Select's In is not stepped, or the picture behind it over the title not asked out of focus")
framegen = (VK / "vk_framegen.cpp").read_text(encoding="utf-8")
sides = framegen[framegen.index("WideSides wide_sides() {"):]
sides = sides[: sides.index("\n}\n")]
check("if (menu_backdrop_blurred()) {" in sides and "w.x0 = kWholeBlur, w.side = 1;" in sides and
"wide_possible.store(true, std::memory_order_relaxed);" in sides and
"float side_x0(const WideSides& w) { return w.x0 == kWholeBlur ? 2.0f : w.x0; }" in framegen and
"float side_x1(const WideSides& w) { return w.x0 == kWholeBlur ? 3.0f : 1.0f - w.x0; }" in framegen and
framegen.count("side_x0(wide), side_x1(wide)") == 2 and "1.0f - wide.x0" not in framegen,
"the picture behind Save Select is not blurred whole by the sides' own pass")
shader = (VK / "shaders" / "fg_scale.comp").read_text(encoding="utf-8")
check("max(1.0 - smoothstep(x0, x0 + feather, x), smoothstep(x1 - feather, x1, x))" in shader and
"if (pc.side != 0 && pc.x1 > pc.x0) {" in shader, "the window pass's sides do not cover a picture whose edges are past it")
check("caption(" not in page and "columns(c," not in page, "the file select still has the options' caption box")
check("menu_hit::kButton" not in page and "ui::button(" not in page, "the file select still has a Play button of its own")
check("menu_hit::kListLine, i);" in page and "ui::prompt_bar(c, prompts," in page, "the cards are not clicked, or no prompts")
check("CalcWordWrapPosition" in page and "bottom + ui::lu(c, 110)" in page, "what choosing does is not said under the cards")
check("textured_poly(c, pic.texture->GetTexRef(), poly, uv, 6);" in page, "the save's picture is not cut as the game's thumbnail")
plate = function(menu, "void files_plate(")
check("if (!stones && !medals) return;" in plate and "else c.d->AddNgonFilled(" in plate, "the plate is drawn with nothing held, or has no fallback")
tick = function(menu, "void menu_tick() {")
mouse = tick[tick.index("} else if (open_now.load() && page == kFilesPage) {"):]
mouse = mouse[: mouse.index("const auto leave")]
check("if (on_card && (moved || ptr.pressed) && files_choice != hit.index) files_choice = hit.index, changed = true;" in mouse and
"else if (on_card && (ptr.pressed & HOS_MOUSE_LEFT)) press[7] = true;" in mouse,
"the mouse onto a card does not choose it, or a click on the chosen card does not play it")
check("if (!files_screen.ready(prof_now()) && ease_live && !still_files) {" in mouse, "Save Select takes input while its In plays")
check("menu_hit::kButton" not in mouse, "the file select still takes a Play button's click")
bar = function(ui, "inline float prompt_bar(")
check("right = std::min(at(c, 1840, 0).x, c.w - lu(c, 80));" in bar, "the prompts go past a window narrower than 16:9")
with tempfile.TemporaryDirectory(prefix="file-cards-") as tmp:
src, exe = Path(tmp) / "cards.cpp", Path(tmp) / "cards.exe"
src.write_text(PROGRAM, encoding="utf-8")
inc = [VK, ROOT / "gpu" / "third_party" / "suyu", VK / "compat", ROOT / "gpu" / "compat"]
subprocess.run([args.cxx, "-std=c++20", "-O1", "-w", *("-I" + str(p) for p in inc), str(src), "-o", str(exe)], check=True)
r = subprocess.run([str(exe)], capture_output=True, text=True)
check(r.returncode == 0, "the cards as made:\n" + r.stdout)
print("PASS: the file select's cards, tag, cursor and column as the game's Load list")
if __name__ == "__main__":
main()