forge
Explore
Log in

Don't you dare go Hollow

courier

Clone
★ 0

0 watching0 forksRustAGPL-3.05.3 MiB6d9eeb9Tahinli21 days ago3 commits

gen_sprites.py14 lines, 1.2 KiBHistoryRawDownload
1import json, glob, os
2
3root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4out = ['#![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>,', '}', '']
5for 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} }};')
14open(os.path.join(root, 'src/sprites.rs'), 'w').write('\n'.join(out) + '\n')