-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathres.dart
101 lines (100 loc) · 3.03 KB
/
res.dart
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
92
93
94
95
96
97
98
99
100
101
part of BigIsland;
// Big Island video game source code file
// Copyright (C) 2012 Severin Ibarluzea
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
class res {
static final int TILE_TYPES = 18;
static loadImage(name,[callback=null]){
name = "resources/$name";
html.ImageElement img = new html.Element.tag("img");
img.onLoad.listen((e){
callback(img);
});
img.onError.listen((e){
//img.src = "resources/error.png";
callback(new html.ImageElement());
});
callback = (callback == null)?(a){}:callback;
img.src = name;
return img;
}
static loadFile(String name,[callback=null]){
name = "resources/$name";
callback = (callback == null)?(a){}:callback;
web.load(name,callback);
}
static List<html.ImageElement> loadSplitImage(name,callback,{int px : 32,int py : 32}){
name = "resources/$name";
html.ImageElement img = new html.Element.tag("img");
img.onLoad.listen((e){
HiddenCanvas.split(img,px,py,callback);
});
img.src = name;
}
/*static List<html.ImageElement> loadSpriteSheet(name,tx,ty,callback){
List<html.ImageElement> list = new List<html.ImageElement>();
loadImage(name,(img){
int tix = img.width;
int tiy = img.height;
for (var i = 0;i<tix;i+=tx){
for (var u = 0;u<tiy;u++){
HiddenCanvas hc = new HiddenCanvas(tx,ty);
CanvasRenderingContext2d context = hc.context;
context.drawImage(img,-i,-u);
hc.getImage((img){
list.add(img);
});
}
}
});
}*/
static loadTile(name,callback){
name = "tiles/$name";
List ar = new List(TILE_TYPES);
int loadsCompleted = 0;
void loadComplete(no){
return (img){
ar[no] = img;
loadsCompleted --;
if (loadsCompleted <= 0){
callback(ar);
}
};
}
loadsCompleted = TILE_TYPES + 1;
for (int i = 0;i<TILE_TYPES;i++){
loadImage("${name}_${i}.png",loadComplete(i));
}
loadsCompleted -= 1;
}
static batchLoadImage(ar,callback_image,callback_complete){
int completed = 0;
void loadComplete(name){
return (img){
completed ++;
callback_image(name,img);
if (completed>=ar.length){
callback_complete();
}
};
}
for (var i = 0;i<ar.length;i++){
loadImage(ar[i],loadComplete(ar[i]));
}
}
static testImage(html.ImageElement img){
html.window.open(img.src,"Derp");
}
}