Files
armorpaint/Sources/arm/Res.hx
T

42 lines
975 B
Haxe
Raw Normal View History

2019-05-10 19:28:59 +02:00
package arm;
2019-06-20 11:23:01 +02:00
import kha.Image;
import iron.data.Data;
2019-05-10 19:28:59 +02:00
class Res {
2019-12-09 00:28:10 +01:00
static var bundled: Map<String, Image> = new Map();
2019-05-10 19:28:59 +02:00
2019-12-09 00:28:10 +01:00
public static function load(names: Array<String>, done: Void->Void) {
2019-05-10 19:28:59 +02:00
var loaded = 0;
for (s in names) {
2019-12-09 00:28:10 +01:00
Data.getImage(s, function(image: Image) {
2019-05-10 19:28:59 +02:00
bundled.set(s, image);
loaded++;
if (loaded == names.length) done();
});
}
}
2019-12-09 00:28:10 +01:00
public static inline function get(name: String): Image {
2019-05-10 19:28:59 +02:00
return bundled.get(name);
}
2019-11-19 14:25:22 +01:00
2019-12-09 00:28:10 +01:00
public static function tile50(img: kha.Image, x: Int, y: Int): TRect {
2020-03-18 20:26:28 +01:00
var size = arm.ui.UISidebar.inst.ui.SCALE() > 1 ? 100 : 50;
2019-11-19 14:25:22 +01:00
return { x: x * size, y: y * size, w: size, h: size };
}
2019-12-09 00:28:10 +01:00
public static function tile18(img: kha.Image, x: Int, y: Int): TRect {
2020-03-18 20:26:28 +01:00
var size = arm.ui.UISidebar.inst.ui.SCALE() > 1 ? 36 : 18;
2019-11-19 14:25:22 +01:00
return { x: x * size, y: img.height - (y + 1) * size, w: size, h: size };
}
}
typedef TRect = {
2019-12-09 00:28:10 +01:00
public var x: Int;
public var y: Int;
public var w: Int;
public var h: Int;
2019-05-10 19:28:59 +02:00
}