ludic/tools/ludic-cli/assets.ludic
Orkuncakilkaya 55b0e2ebf6 feat(windows): the ludic CLI and ludic bundle on Windows
The CLI's shell commands go through shell(), which is run() on POSIX and a
scratch script handed to Git for Windows' bash on Windows (exit codes read
directly there). compile_app links through `ludicc -o` on Windows, ludic run
starts the .exe, and ludic-dev build and ensure_ludicc assemble
selfhost/ludicc.win.seed.ll, which ludic-dev reseed now writes beside the
macOS seed. ludic bundle makes build/<name>/ with a GUI-subsystem exe carrying
the .ico beside `app icon` as an llvm-rc resource, game.lpak and packs.index;
ludicc gains --gui and --link, and quotes its whole link line for cmd.exe.

Verified: ludic-dev test 135/135, selfhost-test 32/32; on the PC a checkout
bootstraps from the Windows seed, ludic-dev build makes the toolchain, and
`ludic bundle` makes build/Maroon Lake/, which runs from its own folder.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 03:01:33 +03:00

73 lines
2.8 KiB
Text

# assets.ludic — fetch the CC0 Poly Haven assets the renderer uses
# (ported off tools/glgen/fetch_assets.sh, the last shell script in the tree).
#
# ludic assets [--force] (a game, fetching what the renderer needs)
# ludic dev fetch-assets [--force] (the same thing, from a Ludic checkout)
#
# The manifest is `packages/ludic.render3d/assets.manifest` — one `<relative path> <url>`
# pair per line — and it belongs to the renderer, not to any one project: the renderer
# decides which scanned materials it wants. It ships with the package (and so with the
# toolchain), so a game outside this repo fetches the right set without keeping its own
# copy of the list. The files land in the PROJECT, under assets/polyhaven/: they are
# large and redistributable from their origin, so they are fetched rather than tracked
# by anyone.
# the manifest that belongs to the renderer, in a checkout or in the install
function assets_manifest_path() -> pointer {
let local = "packages/ludic.render3d/assets.manifest"
if file_exists(local) { return local }
var home = getenv("LUDIC_HOME")
if home == null or slen(home) == 0 { home = `{getenv_or("HOME", "")}/.ludic` }
let inst = `{home}/packages/ludic.render3d/assets.manifest`
if file_exists(inst) { return inst }
return ""
}
function cmd_fetch_assets() -> int {
let force = arg_count() > 2 and arg(2) == "--force"
let root = "assets/polyhaven"
let mpath = assets_manifest_path()
if mpath == "" { err("ludic assets: cannot find packages/ludic.render3d/assets.manifest (is the toolchain installed?)\n"); return 1 }
let manifest = read_file(mpath)
if manifest == null { err(`ludic assets: cannot read {mpath}\n`); return 1 }
var got = 0
var had = 0
var failed = 0
let n = slen(manifest)
var i = 0
while i < n {
var j = i
while j < n and manifest[j] != 10 { j += 1 }
let line = Text.trim(str_sub(manifest, i, j))
i = j + 1
if slen(line) == 0 { continue }
# split the line into <relative path> <url> on the first run of whitespace
let ln = slen(line)
var k = 0
while k < ln and not str_space(line[k]) { k += 1 }
let rel = str_sub(line, 0, k)
while k < ln and str_space(line[k]) { k += 1 }
let url = Text.trim(str_sub(line, k, ln))
if slen(rel) == 0 or slen(url) == 0 { continue }
let dest = `{root}/{rel}`
if not force and shq(`test -s {dest}`) {
had += 1
continue
}
print(`fetch {rel}`)
shell(`mkdir -p "$(dirname {dest})"`)
if not shq(`curl -sSL --retry 3 -o {dest} {url}`) {
err(`fetch-assets: cannot fetch {rel}\n`)
shell(`rm -f {dest}`)
failed += 1
} else {
got += 1
}
}
if failed > 0 { err(`fetch-assets: {string(failed)} failed\n`); return 1 }
print(`OK {string(got)} fetched, {string(had)} already present`)
return 0
}