resource.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. let resource_bundled: map_t<string, gpu_texture_t> = map_create();
  2. function resource_load(names: string[]) {
  3. for (let i: i32 = 0; i < names.length; ++i) {
  4. let s: string = names[i];
  5. let image: gpu_texture_t = data_get_image(s);
  6. map_set(resource_bundled, s, image);
  7. }
  8. }
  9. function resource_get(name: string): gpu_texture_t {
  10. return map_get(resource_bundled, name);
  11. }
  12. function resource_tile50(img: gpu_texture_t, x: i32, y: i32): rect_t {
  13. let size: i32 = config_raw.window_scale > 1 ? 100 : 50;
  14. let r: rect_t = { x: x * size, y: y * size, w: size, h: size };
  15. return r;
  16. }
  17. function resource_tile25(img: gpu_texture_t, x: i32, y: i32): rect_t {
  18. let size: i32 = config_raw.window_scale > 1 ? 50 : 25;
  19. let r: rect_t = { x: x * size, y: y * size, w: size, h: size };
  20. return r;
  21. }
  22. function resource_tile18(img: gpu_texture_t, x: i32, y: i32): rect_t {
  23. let size: i32 = config_raw.window_scale > 1 ? 36 : 18;
  24. let r: rect_t = { x: x * size, y: img.height - (y + 1) * size, w: size, h: size };
  25. return r;
  26. }
  27. type rect_t = {
  28. x?: i32;
  29. y?: i32;
  30. w?: i32;
  31. h?: i32;
  32. };