package demonchime import "core:image" import "core:image/qoi" import "core:log" import "fw" Tiled_Property :: union { string, i32, f32, bool, } Image_Resource :: struct { texture: fw.Texture, anim: Animation_Id, data: []u8, } Tag_Resource :: struct { from: i32, to: i32, } Animation_Resource :: struct { frame_count: i32, frame_durations: []i32, tags: map[string]Tag_Resource, } Object_Resource :: struct { type: Object_Type, tile_id: Maybe(u32), pos: Vec2, size: Vec2, parallax: Vec2, properties: map[string]Tiled_Property, } Backgrond_Image :: struct { image_id: Image_Id, parallax: Vec2, } Room_Resource :: struct { width: i32, height: i32, tile_width: i32, tile_height: i32, layers: [][]u32, objects: []Object_Resource, background_color: Color, background_images: []Backgrond_Image, } Tile_Resource :: struct { image: Image_Id, rect: Rect, id: u32, collisions: []Rect, } Tileset_Resource :: struct { tiles: []u32, image: Image_Id, } Room_Position_Resource :: struct { id: Room_Id, x: i32, y: i32, width: i32, height: i32, } get_image :: proc(id: Image_Id) -> fw.Texture { img_res := &images[id] if img_res.texture.handle == 0 { img, qoi_err := qoi.load_from_bytes(img_res.data) defer image.destroy(img) img_res.texture = fw.create_texture_from_image(img) log.debug(img_res.texture.size) } return img_res.texture } get_room :: proc(id: Room_Id) -> Room_Resource { return rooms[id] } convert_path_to_resource :: proc( obj: Object_Resource, property: string, ) -> Resource_Id { path, has_path := obj.properties[property].(string) if !has_path { log.warnf("Property '%v' must be a path or string", property) return nil } return path_to_resource_id[path] }