DEV Community

Frank
Frank

Posted on

Check that an osu! skin's ranking screen files are all present with Python

The ranking screen is a pile of separate sprites: the panel, the title, the accuracy and max-combo labels, the graph, the grade marks, the small grades, ranking-perfect, ranking-retry, ranking-replay, and ranking-winner. It is easy to ship a skin that customises the panel and a few grades, then leaves the rest on the default art. This script walks a skin folder (the folder that contains skin.ini) and reports which of those ranking-screen files are present, including @2x partners, and which are missing.

It uses only the Python standard library. Point it at the root of a skin.

#!/usr/bin/env python3
"""Report missing ranking-screen files in an osu! skin folder."""
import sys
from pathlib import Path

STEMS = [
    "ranking-panel",
    "ranking-title",
    "ranking-accuracy",
    "ranking-maxcombo",
    "ranking-graph",
    "ranking-perfect",
    "ranking-retry",
    "ranking-replay",
    "ranking-winner",
    "ranking-XH",
    "ranking-X",
    "ranking-SH",
    "ranking-S",
    "ranking-A",
    "ranking-B",
    "ranking-C",
    "ranking-D",
    "ranking-XH-small",
    "ranking-X-small",
    "ranking-SH-small",
    "ranking-S-small",
    "ranking-A-small",
    "ranking-B-small",
    "ranking-C-small",
    "ranking-D-small",
]
EXTS = {".png", ".jpg", ".jpeg", ".gif"}


def stems_in(folder: Path) -> set[str]:
    found: set[str] = set()
    for p in folder.rglob("*"):
        if not p.is_file() or p.suffix.lower() not in EXTS:
            continue
        name = p.name
        suffix = p.suffix
        if name.endswith("@2x" + suffix):
            stem = name[: -len("@2x" + suffix)]
            found.add(stem + "@2x")
        else:
            found.add(p.stem)
    return found


def main() -> int:
    if len(sys.argv) != 2:
        print("usage: check_ranking_files.py /path/to/skin-folder", file=sys.stderr)
        return 2
    root = Path(sys.argv[1])
    if not root.is_dir():
        print("not a folder: " + str(root), file=sys.stderr)
        return 2
    have = stems_in(root)
    missing_sd = []
    missing_hd = []
    present = []
    for stem in STEMS:
        sd = stem in have
        hd = (stem + "@2x") in have
        if sd:
            present.append(stem + (" +@2x" if hd else " (no @2x)"))
        else:
            missing_sd.append(stem)
        if sd and not hd:
            missing_hd.append(stem)
    print("checked %d ranking-screen stems in %s" % (len(STEMS), root))
    print("present %d" % len(present))
    for row in present:
        print("  ok  " + row)
    print("missing %d" % len(missing_sd))
    for stem in missing_sd:
        print("  MISSING  " + stem)
    if missing_hd:
        print("present but no @2x (%d)" % len(missing_hd))
        for stem in missing_hd:
            print("  no@2x  " + stem)
    return 1 if missing_sd else 0


if __name__ == "__main__":
    raise SystemExit(main())
Enter fullscreen mode Exit fullscreen mode

Save it as check_ranking_files.py and run python3 check_ranking_files.py /path/to/skin. A complete HD set prints present 25 and exits 0. Missing SD files exit 1, so you can use it in a packing script. The script does not try to parse skin.ini overrides, because the ranking screen almost always uses these fixed names.

A typical report looks like this when the panel and the large grades are present but the labels, graph, and small grades are not:

checked 25 ranking-screen stems in /tmp/skin_ranking_test220
present 3
  ok  ranking-panel (no @2x)
  ok  ranking-X (no @2x)
  ok  ranking-S (no @2x)
missing 22
  MISSING  ranking-title
  ...
Enter fullscreen mode Exit fullscreen mode

I ran the script on a temporary folder that only contained ranking-panel.png, ranking-X.png, and ranking-S.png. It reported those three as present without @2x, and listed the other twenty-two stems as missing, including ranking-graph, ranking-accuracy, ranking-maxcombo, ranking-retry, and the small grades. After adding ranking-title.png and ranking-title@2x.png, the next run moved the title to ok ranking-title +@2x.

If you are still hunting reference layouts for a complete ranking screen, you can browse finished skins on osuskins.org and then re-run the script on your own folder before you export the .osk.

Top comments (0)