strip_variants.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. """Makes stripped copies of a scene wallpaper for comparing the two engines step by step.
  3. strip_variants.py <id> [out dir] (LWE_WORKSHOP_DIR as for the other tools)
  4. Writes folders <out>/<id>_base, <id>_fx, <id>_fxp and <id>_full that both engines can load as plain scene folders:
  5. base image layers only: no effects, no particle systems, no text
  6. fx base with the layers' effects
  7. fxp fx with the particle systems
  8. full fx and particles and text (the scene as shipped, unpacked)
  9. Capture each with render_we.py <folder> and score it with align_scan.py <folder>; the step at which the difference
  10. appears says which kind of layer it comes from. Presets (no scene.pkg) are skipped.
  11. """
  12. import json
  13. import subprocess
  14. import sys
  15. from pathlib import Path
  16. HERE = Path(__file__).resolve().parent
  17. WORKSHOP = Path(__import__('os').environ.get('LWE_WORKSHOP_DIR', '/workspace/SteamLibrary/steamapps/workshop/content/431960'))
  18. def is_text(obj):
  19. return 'text' in obj and 'image' not in obj and 'particle' not in obj
  20. def build(item, variant, out):
  21. source = WORKSHOP / item
  22. folder = out / f'{item}_{variant}'
  23. folder.mkdir(parents = True, exist_ok = True)
  24. subprocess.run([sys.executable, str(HERE.parent / 'unpack_pkg.py'), str(source / 'scene.pkg'), str(folder)],
  25. check = True, stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)
  26. scene = json.loads((folder / 'scene.json').read_text())
  27. kept = []
  28. for obj in scene['objects']:
  29. if variant != 'full' and is_text(obj):
  30. continue
  31. if variant in ('base', 'fx') and 'particle' in obj:
  32. continue
  33. if variant == 'base' and 'effects' in obj:
  34. obj['effects'] = []
  35. kept.append(obj)
  36. scene['objects'] = kept
  37. (folder / 'scene.json').write_text(json.dumps(scene))
  38. project = json.loads((source / 'project.json').read_text(encoding = 'utf-8-sig'))
  39. project['file'] = 'scene.json'
  40. (folder / 'project.json').write_text(json.dumps(project, ensure_ascii = False))
  41. return folder
  42. def main():
  43. item = sys.argv[1]
  44. out = Path(sys.argv[2]) if len(sys.argv) > 2 else Path.home() / '.local/share/we_live/tests/strip'
  45. if not (WORKSHOP / item / 'scene.pkg').exists():
  46. print(item, 'has no scene.pkg')
  47. return
  48. for variant in ('base', 'fx', 'fxp', 'full'):
  49. print(build(item, variant, out))
  50. if __name__ == '__main__':
  51. main()