diff options
Diffstat (limited to 'src/draw/animation.odin')
| -rw-r--r-- | src/draw/animation.odin | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/draw/animation.odin b/src/draw/animation.odin deleted file mode 100644 index a59fe5f..0000000 --- a/src/draw/animation.odin +++ /dev/null @@ -1,86 +0,0 @@ -package draw - -import "core:encoding/json" -import "core:log" -import "core:os" -import "core:path/filepath" -import "core:strings" - -FrameRect :: struct { - x: i32 `json:"x"`, - y: i32 `json:"y"`, - w: i32 `json:"w"`, - h: i32 `json:"h"`, -} - -Frame :: struct { - rect: FrameRect `json:"frame"`, - duration: i32 `json:"duration"`, -} - -Tag :: struct { - name: string `json:"name"`, - from: i32 `json:"from"`, - to: i32 `json:"to"`, - direction: string `json:"direction"`, -} - -AnimationMeta :: struct { - image_path: string `json:"image"`, - frame_tags: []Tag `json:"frameTags"`, - frame_tags_indices: map[string]u32, -} - -Animation :: struct { - frames: []Frame `json:"frames"`, - using meta: AnimationMeta `json:"meta"`, -} - -@(require_results) -init_anim_data :: proc(anim: ^Animation, path: string) -> bool { - data, ok := os.read_entire_file(path) - if !ok { - return false - } - defer delete(data) - - json_err := json.unmarshal(data, anim) - if json_err != nil { - log.error("could not unmarshal data") - return false - } - - for tag, i in anim.frame_tags { - anim.frame_tags_indices[tag.name] = u32(i) - } - - partial_img_path := anim.image_path - defer delete(partial_img_path) - anim_dir := filepath.dir(path) - defer delete(anim_dir) - - anim.image_path = strings.concatenate({anim_dir, "/", partial_img_path}) - - log.debugf("loaded animation '%v'", path) - - return true -} - -delete_anim_data :: proc(anim: Animation) { - delete(anim.frames) - - for tag in anim.frame_tags { - delete(tag.name) - delete(tag.direction) - } - - // sg.destroy_image(anim.image) - - delete(anim.frame_tags) - delete(anim.frame_tags_indices) - delete(anim.image_path) -} - -get_anim_tag :: proc(anim: Animation, tag_name: string) -> Tag { - return anim.frame_tags[anim.frame_tags_indices[tag_name]] -} |
