| 828 |
}; |
}; |
| 829 |
return Trigger; |
return Trigger; |
| 830 |
})(); |
})(); |
| 831 |
var Resource = (function () { |
var ResourceLoader = (function () { |
| 832 |
function Resource() { |
function ResourceLoader(resource) { |
| 833 |
this.requests = []; |
this.resource = resource; |
|
this.loaded = new Trigger(); |
|
|
this.images = { |
|
|
}; |
|
|
this.scripts = { |
|
|
}; |
|
| 834 |
} |
} |
| 835 |
Resource.instance = null; |
ResourceLoader.prototype.load = function (url, identifier) { |
| 836 |
Resource.getInstance = function getInstance() { |
}; |
| 837 |
return (function () { |
return ResourceLoader; |
| 838 |
if(!Resource.instance) { |
})(); |
| 839 |
Resource.instance = new Resource(); |
var ImageResourceLoader = (function (_super) { |
| 840 |
} |
__extends(ImageResourceLoader, _super); |
| 841 |
return Resource.instance; |
function ImageResourceLoader() { |
| 842 |
})(); |
_super.apply(this, arguments); |
| 843 |
|
|
| 844 |
} |
} |
| 845 |
Resource.prototype.get = function (name) { |
ImageResourceLoader.prototype.load = function (url, identifier) { |
| 846 |
return this.images[name]; |
var image = new Image(); |
| 847 |
|
image.src = "img/" + url; |
| 848 |
|
var caller = this; |
| 849 |
|
var callback = this.completed; |
| 850 |
|
image.onerror = function () { |
| 851 |
|
callback.call(caller, identifier, image, false); |
| 852 |
|
}; |
| 853 |
|
image.onload = function () { |
| 854 |
|
callback.call(caller, identifier, image, true); |
| 855 |
|
}; |
| 856 |
}; |
}; |
| 857 |
Resource.prototype.loadScript = function (url, identifier, caller, callback) { |
ImageResourceLoader.prototype.completed = function (name, image, is_success) { |
| 858 |
|
if(!is_success) { |
| 859 |
|
console.log("error: " + name); |
| 860 |
|
} else { |
| 861 |
|
this.resource.images[name] = image; |
| 862 |
|
} |
| 863 |
|
this.resource.requestCompleted(name); |
| 864 |
|
}; |
| 865 |
|
return ImageResourceLoader; |
| 866 |
|
})(ResourceLoader); |
| 867 |
|
var ScriptResourceLoader = (function (_super) { |
| 868 |
|
__extends(ScriptResourceLoader, _super); |
| 869 |
|
function ScriptResourceLoader() { |
| 870 |
|
_super.apply(this, arguments); |
| 871 |
|
|
| 872 |
|
} |
| 873 |
|
ScriptResourceLoader.prototype.load = function (url, identifier) { |
| 874 |
var script = document.createElement("script"); |
var script = document.createElement("script"); |
| 875 |
var heads = document.getElementsByTagName("head"); |
var heads = document.getElementsByTagName("head"); |
| 876 |
if(heads.length == 0) { |
if(heads.length == 0) { |
| 877 |
throw "can not find head tag"; |
throw "can not find head tag"; |
| 878 |
} |
} |
| 879 |
script.src = url + "?" + (new Date()).getTime(); |
script.src = url + "?" + (new Date()).getTime(); |
| 880 |
|
var caller = this; |
| 881 |
|
var callback = this.completed; |
| 882 |
script.onload = function () { |
script.onload = function () { |
| 883 |
callback.call(caller, identifier, script, true); |
callback.call(caller, identifier, script, true); |
| 884 |
}; |
}; |
| 887 |
}; |
}; |
| 888 |
heads[0].appendChild(script); |
heads[0].appendChild(script); |
| 889 |
}; |
}; |
| 890 |
Resource.prototype.loadScriptComplete = function (name, script, is_success) { |
ScriptResourceLoader.prototype.completed = function (name, script, is_success) { |
| 891 |
if(!is_success) { |
if(!is_success) { |
| 892 |
console.log("error: " + name); |
console.log("error: " + name); |
| 893 |
} else { |
} else { |
| 894 |
this.scripts[name] = script; |
this.resource.scripts[name] = script; |
|
} |
|
|
for(var i = 0; i < this.requests.length; i++) { |
|
|
if(this.requests[i] == name) { |
|
|
this.requests.splice(i, 1); |
|
|
break; |
|
|
} |
|
| 895 |
} |
} |
| 896 |
this.loaded.fire(this.requests.length); |
this.resource.requestCompleted(name); |
| 897 |
}; |
}; |
| 898 |
Resource.prototype.loadImage = function (url, identifier, caller, callback) { |
return ScriptResourceLoader; |
| 899 |
var image = new Image(); |
})(ResourceLoader); |
| 900 |
image.src = "img/" + url; |
var Resource = (function () { |
| 901 |
image.onerror = function () { |
function Resource() { |
| 902 |
callback.call(caller, identifier, image, false); |
this.requests = []; |
| 903 |
|
this.loaded = new Trigger(); |
| 904 |
|
this.images = { |
| 905 |
}; |
}; |
| 906 |
image.onload = function () { |
this.scripts = { |
| 907 |
callback.call(caller, identifier, image, true); |
}; |
| 908 |
|
this.loaders = { |
| 909 |
}; |
}; |
| 910 |
|
this.loaders["js"] = new ScriptResourceLoader(this); |
| 911 |
|
this.loaders["default"] = new ImageResourceLoader(this); |
| 912 |
|
} |
| 913 |
|
Resource.instance = null; |
| 914 |
|
Resource.getInstance = function getInstance() { |
| 915 |
|
return (function () { |
| 916 |
|
if(!Resource.instance) { |
| 917 |
|
Resource.instance = new Resource(); |
| 918 |
|
} |
| 919 |
|
return Resource.instance; |
| 920 |
|
})(); |
| 921 |
|
} |
| 922 |
|
Resource.prototype.get = function (name) { |
| 923 |
|
return this.images[name]; |
| 924 |
}; |
}; |
| 925 |
Resource.prototype.loadImageComplete = function (name, image, is_success) { |
Resource.prototype.requestCompleted = function (name) { |
|
if(!is_success) { |
|
|
console.log("error: " + name); |
|
|
} else { |
|
|
this.images[name] = image; |
|
|
} |
|
| 926 |
for(var i = 0; i < this.requests.length; i++) { |
for(var i = 0; i < this.requests.length; i++) { |
| 927 |
if(this.requests[i] == name) { |
if(this.requests[i] == name) { |
| 928 |
this.requests.splice(i, 1); |
this.requests.splice(i, 1); |
| 936 |
url = name; |
url = name; |
| 937 |
} |
} |
| 938 |
this.requests.push(name); |
this.requests.push(name); |
| 939 |
if(url.length > 3 && url.substr(-3).toLowerCase() == ".js") { |
var dot = url.split(/\./g); |
| 940 |
this.loadScript(url, name, this, this.loadScriptComplete); |
var ext; |
| 941 |
|
if(dot.length == 0) { |
| 942 |
|
ext = ""; |
| 943 |
|
} else { |
| 944 |
|
ext = dot[dot.length - 1]; |
| 945 |
|
} |
| 946 |
|
ext = ext.toLowerCase(); |
| 947 |
|
if(this.loaders[ext]) { |
| 948 |
|
this.loaders[ext].load(url, name); |
| 949 |
} else { |
} else { |
| 950 |
this.loadImage(url, name, this, this.loadImageComplete); |
this.loaders["default"].load(url, name); |
| 951 |
} |
} |
| 952 |
}; |
}; |
| 953 |
return Resource; |
return Resource; |
| 1095 |
this.width = width; |
this.width = width; |
| 1096 |
this.height = height; |
this.height = height; |
| 1097 |
this.image = image; |
this.image = image; |
|
this.image.style["image-rendering"] = "-o-crisp-edges"; |
|
| 1098 |
this.sep = Math.floor(this.image.width / this.width); |
this.sep = Math.floor(this.image.width / this.width); |
| 1099 |
this.frame = [ |
this.frame = [ |
| 1100 |
0 |
0 |