fixup gen_sprites
This commit is contained in:
parent
eded1071c4
commit
2d367e6ded
|
@ -6,7 +6,7 @@ if [[ $# < 1 ]]; then
|
|||
fi
|
||||
|
||||
src_dir=$1
|
||||
out_dir=assets/sprite/
|
||||
out_dir=assets/sprites/
|
||||
dpi=192
|
||||
|
||||
svg_to_png="inkscape -C"
|
||||
|
@ -24,8 +24,11 @@ function gen() {
|
|||
dst_png=$out_dir/$name.png
|
||||
dst_map=$out_dir/$name.map
|
||||
|
||||
$svg_to_png $src -o $dst_png -d $dpi || exit 1
|
||||
$gen_sprite_map < $src > $dst_map || exit 1
|
||||
[[ "$src" -nt "$dst_png" ]] &&
|
||||
($svg_to_png $src -o $dst_png -d $dpi || exit 1)
|
||||
|
||||
[[ "$src" -nt "$dst_map" ]] &&
|
||||
($gen_sprite_map < $src > $dst_map || exit 1)
|
||||
}
|
||||
|
||||
gen blocks 192
|
||||
|
|
|
@ -16,6 +16,12 @@ let sexp_of_clip c =
|
|||
List.map Sexplib.Conv.sexp_of_int
|
||||
[c.x; c.y; c.w; c.h; c.ox; c.oy])
|
||||
|
||||
let sexp_of_sprite_map clips =
|
||||
Sexp.List (
|
||||
Atom "map" ::
|
||||
(List.sort (fun a b -> compare b.name a.name) clips |>
|
||||
List.rev_map sexp_of_clip))
|
||||
|
||||
let svg v = ("http://www.w3.org/2000/svg", v)
|
||||
let ink v = ("http://www.inkscape.org/namespaces/inkscape", v)
|
||||
let sodi v = ("http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd", v)
|
||||
|
@ -98,17 +104,15 @@ let extract_clips xml =
|
|||
| `El_end -> el_end ()
|
||||
do () done;
|
||||
|
||||
List.sort
|
||||
(fun a b -> String.compare a.name b.name)
|
||||
s.clips
|
||||
|
||||
let gen_sprite_map ic oc =
|
||||
let sprite_map =
|
||||
Xmlm.make_input (`Channel ic) |>
|
||||
extract_clips |>
|
||||
List.iter (fun clip ->
|
||||
Format.kasprintf (output_string oc)
|
||||
"%a\n" Sexp.pp (sexp_of_clip clip))
|
||||
|
||||
extract_clips
|
||||
in
|
||||
Format.kasprintf (output_string oc) "%a\n"
|
||||
Sexp.pp_hum (sexp_of_sprite_map sprite_map)
|
||||
|
||||
let () =
|
||||
gen_sprite_map stdin stdout
|
||||
|
|
Loading…
Reference in New Issue