## R4: traces every file under assets/ to the script that makes it, or to its original ## hand-written source, and writes the per-file table in docs/ASSET_PROVENANCE.md. ## `test_asset_provenance` fails if a file has no rule, a rule names a generator that ## doesn't exist, or the document is out of date. ## tools/godot.sh --script res://tools/provenance.gd extends SceneTree const ASSETS: String = "res://assets" const DOC: String = "res://docs/ASSET_PROVENANCE.md" ## Path pattern (relative to assets/, `*` wildcards) -> [source, how]. First match wins. const RULES: Array[Array] = [ ["PROVENANCE.md", "written by hand", "The summary of how each kind of asset is made."], ["audio/manifest.json", "tools/audio/generate.gd", "Each sound's category, length, SHA-256, peak and loudness, written as the sounds are baked."], ["audio/music_*.wav", "tools/audio/score.gd", "A layer of the original score: note lists written for Tidewall, synthesized by tools/audio/dsp.gd."], ["audio/*.wav", "tools/audio/recipes.gd", "Synthesized from seeded noise, oscillators, filters and decaying modes (tools/audio/dsp.gd)."], ["models/items/*", "tools/models/items.py", "An item model (OBJ and MTL) and its grip data (JSON), built from primitives in headless Blender."], ["icons/items/*.png", "tools/models/items.py", "The item's model rendered with Cycles on the CPU in headless Blender."], ["models/figure/*", "tools/models/figure.py", "A part of the player figure (OBJ and MTL) or its joint data (JSON), built from primitives in headless Blender."], ["icons/app/tidewall.svg", "written by hand", "The application icon, an SVG written for Tidewall in Palette colours."], ["icons/app/tidewall-*.png", "tools/app_icon.gd", "The hand-written SVG rasterised by the engine's SVG loader."], ] const HEADER: String = """# Asset provenance, file by file Every file under `assets/` and where it comes from: the script in this repository that generates it, or "written by hand" for an original source written for Tidewall. Nothing is sampled, recorded, downloaded or taken from a third party. How each kind of asset is made is described in [assets/PROVENANCE.md](../assets/PROVENANCE.md); the licence is CC BY-SA 4.0 ([LICENSE-ASSETS](../LICENSE-ASSETS)). Code-built art (terrain, sea, points of interest, props, build pieces, the ship, sea chests and effects) isn't a file here: it's drawn by the scripts under `src/client/`. This file is written by `tools/godot.sh --script res://tools/provenance.gd`, and `test/test_asset_provenance.gd` fails if it falls out of date or a file has no source. | File | Source | What it is | |---|---|---| """ func _init() -> void: var problems: Array[String] = problems_with(rows()) if not problems.is_empty(): for problem: String in problems: push_error(problem) quit(1) return var file: FileAccess = FileAccess.open(DOC, FileAccess.WRITE) file.store_string(render()) file.close() print("asset provenance: %d files in %s" % [rows().size(), DOC]) quit(0) ## Every file under assets/, sorted, without the engine's .import and .uid sidecars. static func files(dir: String = ASSETS, prefix: String = "") -> Array[String]: var found: Array[String] = [] for name: String in DirAccess.get_files_at(dir): if name.ends_with(".import") or name.ends_with(".uid"): continue found.append(prefix + name) for sub: String in DirAccess.get_directories_at(dir): found.append_array(files(dir.path_join(sub), prefix + sub + "/")) found.sort() return found ## [path, source, how] for each file, with an empty source where no rule matches. static func rows() -> Array[Array]: var out: Array[Array] = [] for path: String in files(): var row: Array = [path, "", ""] for rule: Array in RULES: if path.match(rule[0]): row = [path, rule[1], rule[2]] break out.append(row) return out static func problems_with(table: Array[Array]) -> Array[String]: var found: Array[String] = [] for row: Array in table: var source: String = row[1] if source.is_empty(): found.append("assets/%s: no recorded source; add a rule to tools/provenance.gd" % row[0]) elif source != "written by hand" and not FileAccess.file_exists("res://" + source): found.append("assets/%s: its generator %s doesn't exist" % [row[0], source]) return found static func render() -> String: var lines: Array[String] = [] for row: Array in rows(): var source: String = row[1] var shown: String = source if source == "written by hand" else "`%s`" % source lines.append("| `assets/%s` | %s | %s |" % [row[0], shown, row[2]]) return HEADER + "\n".join(lines) + "\n"