| 1 | import json, glob, os |
| 2 | |
| 3 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 4 | out = ['#![allow(dead_code)]', '', 'pub struct Spr {', ' pub path: &\'static str,', ' pub size: (f32, f32),', ' pub origin: (f32, f32),', ' pub foot: (i32, i32),', ' pub smoke: &\'static [(f32, f32)],', ' pub cell: (u32, u32),', ' pub grid: (u32, u32),', ' pub glow: Option<&\'static str>,', '}', ''] |
| 5 | for f in sorted(glob.glob(os.path.join(root, 'tools/manifest/*.json'))): |
| 6 | for name, e in sorted(json.load(open(f)).items()): |
| 7 | w, h = e['size'] |
| 8 | ox, oy = e['origin'] |
| 9 | cell = e.get('cell') or [w, h] |
| 10 | grid = e.get('grid') or [1, 1] |
| 11 | sm = ', '.join(f'({dx:.1f}, {dy:.1f})' for dx, dy in e.get('smoke', [])) |
| 12 | glow = f'Some("gfx/{name}_e.png")' if e.get('glow') else 'None' |
| 13 | out.append(f'pub const {name.upper()}: Spr = Spr {{ path: "gfx/{name}.png", size: ({w:.1f}, {h:.1f}), origin: ({ox:.1f}, {oy:.1f}), foot: ({e["foot"][0]}, {e["foot"][1]}), smoke: &[{sm}], cell: ({cell[0]}, {cell[1]}), grid: ({grid[0]}, {grid[1]}), glow: {glow} }};') |
| 14 | open(os.path.join(root, 'src/sprites.rs'), 'w').write('\n'.join(out) + '\n') |