resource.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. let resource_bundled: map_t<string, image_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: image_t = data_get_image(s);
  6. map_set(resource_bundled, s, image);
  7. }
  8. }
  9. function resource_get(name: string): image_t {
  10. return map_get(resource_bundled, name);
  11. }
  12. function resource_tile50(img: image_t, x: i32, y: i32): rect_t {
  13. let size: i32 = config_raw.window_scale > 1 ? 100 : 50;
  14. return { x: x * size, y: y * size, w: size, h: size };
  15. }
  16. function resource_tile25(img: image_t, x: i32, y: i32): rect_t {
  17. let size: i32 = config_raw.window_scale > 1 ? 50 : 25;
  18. return { x: x * size, y: y * size, w: size, h: size };
  19. }
  20. function resource_tile18(img: image_t, x: i32, y: i32): rect_t {
  21. let size: i32 = config_raw.window_scale > 1 ? 36 : 18;
  22. return { x: x * size, y: img.height - (y + 1) * size, w: size, h: size };
  23. }
  24. ///if arm_snapshot
  25. function resource_embed_raw(handle: string, name: string, file: buffer_t) {
  26. map_set(data_cached_blobs, name, file);
  27. data_get_scene_raw(handle);
  28. map_delete(data_cached_blobs, name);
  29. }
  30. function resource_embed_blob(name: string, file: buffer_t) {
  31. map_set(data_cached_blobs, name, file);
  32. }
  33. function resource_embed_font(name: string, file: buffer_t) {
  34. map_set(data_cached_fonts, name, g2_font_create(file));
  35. }
  36. ///end
  37. type rect_t = {
  38. x?: i32;
  39. y?: i32;
  40. w?: i32;
  41. h?: i32;
  42. };