aboutsummaryrefslogtreecommitdiff
path: root/src/resources.odin
blob: 7051fcfe0755bfbe695b9cb29968fa138d6195d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package demonchime

import "core:log"

import rl "vendor:raylib"

Tiled_Property :: union {
  string,
  i32,
  f32,
  bool,
}

Image_Resource :: struct {
  texture: rl.Texture2D,
  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,
  pos: Vec2,
  size: Vec2,
  parallax: Vec2,
  properties: map[string]Tiled_Property,
}

Room_Resource :: struct {
  width: i32,
  height: i32,
  tile_width: i32,
  tile_height: i32,
  layers: [][]u32,
  objects: []Object_Resource,
  background_image: Maybe(Image_Id),
}

Tile_Resource :: struct {
  tileset: Tileset_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) -> rl.Texture2D {
  img_res := &images[id]

  if !rl.IsTextureValid(img_res.texture) {
    rl_img := rl.LoadImageFromMemory(
      ".qoi",
      raw_data(img_res.data),
      i32(len(img_res.data)),
    )
    if !rl.IsImageValid(rl_img) {
      log.warnf("Could not load asset %v", id)
    }

    img_res.texture = rl.LoadTextureFromImage(rl_img)
    rl.UnloadImage(rl_img)
  }

  return img_res.texture
}

get_room :: proc(id: Room_Id) -> Room_Resource {
  return rooms[id]
}