| 1149 |
}; |
}; |
| 1150 |
return SimpleSound; |
return SimpleSound; |
| 1151 |
})(); |
})(); |
| 1152 |
|
var ResourceStructure = (function () { |
| 1153 |
|
function ResourceStructure(img, sound) { |
| 1154 |
|
this.img = img; |
| 1155 |
|
this.sound = sound; |
| 1156 |
|
} |
| 1157 |
|
ResourceStructure.Default = new ResourceStructure("img/", "sound/"); |
| 1158 |
|
ResourceStructure.Plain = new ResourceStructure("", ""); |
| 1159 |
|
ResourceStructure.prototype.isAbsolute = function (url) { |
| 1160 |
|
var white = [ |
| 1161 |
|
".", |
| 1162 |
|
"/" |
| 1163 |
|
]; |
| 1164 |
|
if(white.indexOf(url.charAt(0)) >= 0 || url.match(/^(http:|https:|data:)/)) { |
| 1165 |
|
return url; |
| 1166 |
|
} |
| 1167 |
|
}; |
| 1168 |
|
ResourceStructure.prototype.imageUrl = function (url) { |
| 1169 |
|
if(this.isAbsolute(url)) { |
| 1170 |
|
return url; |
| 1171 |
|
} |
| 1172 |
|
return this.img + url; |
| 1173 |
|
}; |
| 1174 |
|
ResourceStructure.prototype.soundUrl = function (url) { |
| 1175 |
|
if(this.isAbsolute(url)) { |
| 1176 |
|
return url; |
| 1177 |
|
} |
| 1178 |
|
return this.sound + url; |
| 1179 |
|
}; |
| 1180 |
|
return ResourceStructure; |
| 1181 |
|
})(); |
| 1182 |
var ResourceLoader = (function () { |
var ResourceLoader = (function () { |
| 1183 |
function ResourceLoader(resource) { |
function ResourceLoader(resource) { |
| 1184 |
this.resource = resource; |
this.resource = resource; |
| 1195 |
} |
} |
| 1196 |
ImageResourceLoader.prototype.load = function (url, identifier) { |
ImageResourceLoader.prototype.load = function (url, identifier) { |
| 1197 |
var image = new Image(); |
var image = new Image(); |
| 1198 |
image.src = "img/" + url; |
image.src = this.resource.structure.imageUrl(url); |
| 1199 |
var caller = this; |
var caller = this; |
| 1200 |
var callback = this.completed; |
var callback = this.completed; |
| 1201 |
image.onerror = function () { |
image.onerror = function () { |
| 1257 |
SoundResourceLoader.prototype.load = function (url, identifier) { |
SoundResourceLoader.prototype.load = function (url, identifier) { |
| 1258 |
var _this = this; |
var _this = this; |
| 1259 |
var request = new XMLHttpRequest(); |
var request = new XMLHttpRequest(); |
| 1260 |
request.open("GET", "sound/" + url, true); |
request.open("GET", this.resource.structure.soundUrl(url), true); |
| 1261 |
request.responseType = "arraybuffer"; |
request.responseType = "arraybuffer"; |
| 1262 |
var callback = this.completed; |
var callback = this.completed; |
| 1263 |
request.onload = function () { |
request.onload = function () { |
| 1301 |
this.loaders["ogg"] = this.loaders["mp3"]; |
this.loaders["ogg"] = this.loaders["mp3"]; |
| 1302 |
this.loaders["wav"] = this.loaders["mp3"]; |
this.loaders["wav"] = this.loaders["mp3"]; |
| 1303 |
this.loaders["mid"] = this.loaders["mp3"]; |
this.loaders["mid"] = this.loaders["mp3"]; |
| 1304 |
|
this.structure = ResourceStructure.Default; |
| 1305 |
} |
} |
| 1306 |
Resource.getInstance = function getInstance() { |
Resource.getInstance = function getInstance() { |
| 1307 |
return (function () { |
return (function () { |