| 37 | |
| 38 | export class Texture extends Native("PiuTextureDelete") { |
| 39 | constructor(it, alphaBitmap, colorBitmap) { |
| 40 | super(); |
| 41 | if (alphaBitmap || colorBitmap) { |
| 42 | native("PiuTexture_create").call(this, alphaBitmap, colorBitmap); |
| 43 | return; |
| 44 | } |
| 45 | let archive; |
| 46 | if (typeof(it) == "object") { |
| 47 | archive = it.archive |
| 48 | if (it.alpha && it.color) { |
| 49 | alphaBitmap = parseBMP(new Resource(it.alpha, archive)); |
| 50 | colorBitmap = parseBMP(new Resource(it.color, archive)); |
| 51 | native("PiuTexture_create").call(this, alphaBitmap, colorBitmap); |
| 52 | return; |
| 53 | } |
| 54 | it = it.path; |
| 55 | } |
| 56 | if (it.endsWith(".png")) { |
| 57 | let name = it.slice(0, -4); |
| 58 | let path = name + "-alpha.bm4"; |
| 59 | if (Resource.exists(path, archive)) { |
| 60 | alphaBitmap = parseRLE(new Resource(path, archive)); |
| 61 | } |
| 62 | else { |
| 63 | path = name + "-alpha.bmp"; |
| 64 | if (Resource.exists(path, archive)) { |
| 65 | alphaBitmap = parseBMP(new Resource(path, archive)); |
| 66 | } |
| 67 | } |
| 68 | path = name + "-color.bm4"; |
| 69 | if (Resource.exists(path, archive)) { |
| 70 | colorBitmap = parseRLE(new Resource(path, archive)); |
| 71 | } |
| 72 | else { |
| 73 | path = name + "-color.bmp"; |
| 74 | if (Resource.exists(path, archive)) { |
| 75 | colorBitmap = parseBMP(new Resource(path, archive)); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | else if (it.endsWith("-alpha.bmp")) |
| 80 | alphaBitmap = parseBMP(new Resource(it, archive)); |
| 81 | else if (it.endsWith("-color.bmp")) |
| 82 | colorBitmap = parseBMP(new Resource(it, archive)); |
| 83 | if (alphaBitmap || colorBitmap) |
| 84 | native("PiuTexture_create").call(this, alphaBitmap, colorBitmap); |
| 85 | else |
| 86 | throw new URIError("Texture " + it + " not found!"); |
| 87 | } |
| 88 | get width() { return native("PiuTexture_get_width").call(this); } |
| 89 | get height() { return native("PiuTexture_get_height").call(this); } |
| 90 | static template(i) { |