Files
EVEngine/scripts/generate_building_starter_assets.py
西风逍遥游 31880f0021 feat(examples): gate examples in CI and make repository scripts UTF-8 on every host
`examples/<name>/` was a tested surface in name only. The source-quality job had
no examples check at all, and scripts/smoke_examples.sh accepted any process that
had not printed one of its error markers: a project that died during startup,
exited after a single frame, or crashed without a marker was reported as PASS.
Nothing stopped a malformed or unregistered example from reaching dev, which is
how 14 examples arrived without READMEs and 20 were never registered in the
overview table.

Source side
- scripts/check_examples.py classifies every directory under examples/ as either
  runnable (main.nut plus a config.nut that assigns the engine `config` table) or
  as a reviewed non-runnable sample listed in NON_RUNNABLE_EXAMPLES with a
  reason. Both kinds must own a README.md and appear in examples/README.md.
  Stale exemptions and overview links to missing directories fail as well.
- `make check/examples` and a new source-quality CI step run the gate.
- scripts/tests/test_check_examples.py covers it and pins each failure mode
  against fixtures.

Runtime side
- scripts/smoke_examples.sh now enforces liveness, not just marker absence: every
  runnable example must still be running after MIN_RUN_SECONDS (default 2s; CI
  passes 2s), and a process that dies inside that window fails whatever its exit
  code. A clean self-exit after the window passes with an explicit note instead
  of being silently accepted as a pass.
- The Linux CI step sets MIN_RUN_SECONDS=2 and keeps RUN_SECONDS=6, so the job's
  wall clock is unchanged (13.7 min of its 20 min budget on dev).

Windows / GBK
- scripts/utf8_stdio.py re-encodes stdout/stderr as UTF-8 and every scripts/*.py
  program calls it as the first statement of its __main__ block. On a Chinese
  Windows a redirected stream falls back to the ANSI code page (cp936), and
  printing a character that code page cannot encode (arrows, superscripts, bullet
  separators, emoji - all common in this repository) raised UnicodeEncodeError
  and turned a checker into a traceback.
- The mirror image is input: read_text() without encoding= decoded UTF-8
  repository text as cp936 and raised UnicodeDecodeError.
- scripts/tests/test_utf8_stdio.py enforces both conventions for every script and
  test module; text file I/O and child-process decoding now pass encoding="utf-8"
  explicitly.
- Unit-test invocations run with `python3 -X utf8` so the runner's own output
  never follows the host code page.

Violations the new gates found on top of dev, fixed here: 14 examples shipped
without a README (fluid3d, mesh-impact-lab, mesh-modifier-lab, spline-tube-lab on
the earlier dev tip, plus pcg-depth-of-field, pcg-detail-overwrite,
pcg-layer-culling, pcg-location-system, pcg-runtime-orchestration,
pcg-scene-player-culling, pcg-snow-wind, pcg-thunder-strike, pcg-ui-scaler and
pcg-underwater added by #397), 20 were missing from the overview table (those 14
plus archspace-editor, geometry-stroke-lab, interior-mapping, layered-animation,
triplanar-decal, terrain-stamping), and scripts/export_meshret_onnx.py had no
UTF-8 stdio guard.

Verified locally: `python -m ruff check scripts` (All checks passed);
scripts/check_test_manifest.py; scripts/check_quality_metadata.py;
scripts/check_architecture_contracts.py --base HEAD; scripts/check_nodiscard.py;
`make -n check/examples`; scripts/check_examples.py (125 examples: 118 runnable,
7 reviewed non-runnable); and `python -X utf8 -m unittest discover -s scripts/tests
-p "test_*.py"` (155 tests, OK). The runtime half of the contract needs a Linux
headless build, so it is verified by the CI examples smoke step rather than
locally.
2026-09-15 20:20:23 +08:00

64 lines
2.8 KiB
Python

from pathlib import Path
from PIL import Image, ImageDraw
import random
root = Path('examples')
out = root / 'building' / 'starter'
out.mkdir(exist_ok=True)
for kind, count in [('grass', 8), ('road', 6)]:
for n in range(count):
im = Image.new('RGBA', (32, 32), (89, 117, 54, 255))
d = ImageDraw.Draw(im)
rng = random.Random(n)
for i in range(40):
x, y = (rng.randrange(32), rng.randrange(32))
d.point((x, y), fill=(116, 140, 69, 255))
if kind == 'road':
for y in range(0, 32, 8):
for x in range(0, 32, 8):
d.rounded_rectangle((x + 1, y + 1, x + 7, y + 7), radius=2, fill=(139 + n * 3, 137 + n * 3, 119 + n * 3, 255))
im.save(out / f'{kind}{n}.png')
for name in ['house', 'stall', 'dock', 'crate', 'barrel']:
im = Image.new('RGBA', (32, 32))
d = ImageDraw.Draw(im)
d.rectangle((3, 10, 29, 30), fill=(144, 109, 65, 255), outline=(66, 48, 31, 255))
if name == 'house':
d.polygon([(0, 13), (16, 0), (31, 13)], fill=(123, 64, 39, 255))
d.rectangle((13, 20, 19, 30), fill=(51, 38, 26, 255))
else:
for y in range(12, 30, 4):
d.line((4, y, 28, y), fill=(72, 51, 33, 255))
im.save(out / (name + '.png'))
Image.new('RGBA', (1, 1), 'white').save(out / 'pixel.png')
out = root / 'building-tilemap' / 'starter'
out.mkdir(exist_ok=True)
files = [n for n in range(121) if n != 66]
variants = [11, 12, 13, 2, 3, 37, 69, 72, 73, 7, 8, 10, 14, 108, 114, 116]
allfiles = files + [n for n in variants for _ in range(4)]
a = Image.new('RGBA', (640, (len(allfiles) + 9) // 10 * 46))
for i, n in enumerate(allfiles):
c = (74, 110, 49, 255)
if n in [2, 3, 37, 69, 72, 73]:
c = (145, 137, 112, 255)
if n in [7, 8, 10]:
c = (179, 151, 97, 255)
if n in [14, 108]:
c = (46, 117, 145, 255)
if n in [114, 116]:
c = (32, 71, 111, 255)
im = Image.new('RGBA', (64, 46))
d = ImageDraw.Draw(im)
d.polygon([(32, 0), (63, 23), (32, 45), (0, 23)], fill=c)
rng = random.Random(i)
for k in range(25):
x, y = (rng.randrange(64), rng.randrange(46))
if im.getpixel((x, y))[3]:
d.point((x, y), fill=tuple((min(255, v + 12) for v in c[:3])) + (255,))
a.paste(im, (i % 10 * 64, i // 10 * 46))
a.save(out / 'c14-atlas.png')
im = Image.new('RGBA', (64, 46))
ImageDraw.Draw(im).polygon([(32, 0), (63, 23), (32, 45), (0, 23)], fill=(255, 255, 255, 24), outline='white', width=2)
im.save(out / 'cursor.png')
mapping = {n: i + 1 for i, n in enumerate(files)}
v = {n: list(range(121 + i * 4, 125 + i * 4)) for i, n in enumerate(variants)}
(out / 'catalog.nut').write_text('c14Gids <- {' + ','.join(('[%d]=%d' % p for p in mapping.items())) + '};\nc14Variants <- {' + ','.join(('[%d]=[%s]' % (n, ','.join(map(str, g))) for n, g in v.items())) + '};\n', encoding='utf-8')