[ts] Added AssetManager#setRawDataURI(path, data). Allows to set raw data URIs for a specific path, which in turn enables embedding assets into JavaScript/HTML. See #1535.

This commit is contained in:
badlogic 2019-10-31 19:27:33 +01:00
parent 4e96ebcda2
commit b81f77b993
20 changed files with 162 additions and 246 deletions

View File

@ -554,6 +554,7 @@ This will automatically:
* Support for stretchy IK * Support for stretchy IK
* Support for audio events, see `audioPath`, `volume` and `balance` fields on event (data). * Support for audio events, see `audioPath`, `volume` and `balance` fields on event (data).
* `TrackEntry` has an additional field called `holdPrevious`. It can be used to counter act a limitation of `AnimationState` resulting in "dipping" of parts of the animation. For a full discussion of the problem and the solution we've implemented, see this [forum thread](http://esotericsoftware.com/forum/Probably-Easy-Animation-mixing-with-multiple-tracks-10682?p=48130&hilit=holdprevious#p48130). * `TrackEntry` has an additional field called `holdPrevious`. It can be used to counter act a limitation of `AnimationState` resulting in "dipping" of parts of the animation. For a full discussion of the problem and the solution we've implemented, see this [forum thread](http://esotericsoftware.com/forum/Probably-Easy-Animation-mixing-with-multiple-tracks-10682?p=48130&hilit=holdprevious#p48130).
* Added `AssetManager#setRawDataURI(path, data)`. Allows to set raw data URIs for a specific path, which in turn enables embedding assets into JavaScript/HTML.
### WebGL backend ### WebGL backend
* Added `VertexEffect` interface, instances of which can be set on `SkeletonRenderer`. Allows to modify vertices before submitting them to GPU. See `SwirlEffect`, `JitterEffect`, and the example which allows to set effects. * Added `VertexEffect` interface, instances of which can be set on `SkeletonRenderer`. Allows to modify vertices before submitting them to GPU. See `SwirlEffect`, `JitterEffect`, and the example which allows to set effects.

View File

@ -384,13 +384,14 @@ declare module spine {
private errors; private errors;
private toLoad; private toLoad;
private loaded; private loaded;
private rawDataUris;
constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string); constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
private static downloadText; private downloadText;
private static downloadBinary; private downloadBinary;
setRawDataURI(path: string, data: string): void;
loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void; loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void;
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void; loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void; loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureData(path: string, data: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void; loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void;
get(path: string): any; get(path: string): any;
remove(path: string): void; remove(path: string): void;

View File

@ -2161,11 +2161,14 @@ var spine;
this.errors = {}; this.errors = {};
this.toLoad = 0; this.toLoad = 0;
this.loaded = 0; this.loaded = 0;
this.rawDataUris = {};
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
AssetManager.downloadText = function (url, success, error) { AssetManager.prototype.downloadText = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = function () { request.onload = function () {
if (request.status == 200) { if (request.status == 200) {
@ -2180,8 +2183,10 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.downloadBinary = function (url, success, error) { AssetManager.prototype.downloadBinary = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = function () { request.onload = function () {
@ -2197,13 +2202,16 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.prototype.setRawDataURI = function (path, data) {
this.rawDataUris[this.pathPrefix + path] = data;
};
AssetManager.prototype.loadBinary = function (path, success, error) { AssetManager.prototype.loadBinary = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, function (data) { this.downloadBinary(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2223,7 +2231,7 @@ var spine;
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (data) { this.downloadText(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2242,12 +2250,13 @@ var spine;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
var storagePath = path;
this.toLoad++; this.toLoad++;
var img = new Image(); var img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = function (ev) { img.onload = function (ev) {
var texture = _this.textureLoader(img); var texture = _this.textureLoader(img);
_this.assets[path] = texture; _this.assets[storagePath] = texture;
_this.toLoad--; _this.toLoad--;
_this.loaded++; _this.loaded++;
if (success) if (success)
@ -2260,32 +2269,10 @@ var spine;
if (error) if (error)
error(path, "Couldn't load image " + path); error(path, "Couldn't load image " + path);
}; };
if (this.rawDataUris[path])
path = this.rawDataUris[path];
img.src = path; img.src = path;
}; };
AssetManager.prototype.loadTextureData = function (path, data, success, error) {
var _this = this;
if (success === void 0) { success = null; }
if (error === void 0) { error = null; }
path = this.pathPrefix + path;
this.toLoad++;
var img = new Image();
img.onload = function (ev) {
var texture = _this.textureLoader(img);
_this.assets[path] = texture;
_this.toLoad--;
_this.loaded++;
if (success)
success(path, img);
};
img.onerror = function (ev) {
_this.errors[path] = "Couldn't load image " + path;
_this.toLoad--;
_this.loaded++;
if (error)
error(path, "Couldn't load image " + path);
};
img.src = data;
};
AssetManager.prototype.loadTextureAtlas = function (path, success, error) { AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
@ -2293,12 +2280,12 @@ var spine;
var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (atlasData) { this.downloadText(path, function (atlasData) {
var pagesLoaded = { count: 0 }; var pagesLoaded = { count: 0 };
var atlasPages = new Array(); var atlasPages = new Array();
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
var image = document.createElement("img"); var image = document.createElement("img");
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -2322,7 +2309,7 @@ var spine;
if (!pageLoadError) { if (!pageLoadError) {
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
return _this.get(parent + "/" + path); return _this.get(parent == "" ? path : parent + "/" + path);
}); });
_this.assets[path] = atlas; _this.assets[path] = atlas;
if (success) if (success)

File diff suppressed because one or more lines are too long

View File

@ -384,13 +384,14 @@ declare module spine {
private errors; private errors;
private toLoad; private toLoad;
private loaded; private loaded;
private rawDataUris;
constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string); constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
private static downloadText; private downloadText;
private static downloadBinary; private downloadBinary;
setRawDataURI(path: string, data: string): void;
loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void; loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void;
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void; loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void; loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureData(path: string, data: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void; loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void;
get(path: string): any; get(path: string): any;
remove(path: string): void; remove(path: string): void;

View File

@ -2161,11 +2161,14 @@ var spine;
this.errors = {}; this.errors = {};
this.toLoad = 0; this.toLoad = 0;
this.loaded = 0; this.loaded = 0;
this.rawDataUris = {};
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
AssetManager.downloadText = function (url, success, error) { AssetManager.prototype.downloadText = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = function () { request.onload = function () {
if (request.status == 200) { if (request.status == 200) {
@ -2180,8 +2183,10 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.downloadBinary = function (url, success, error) { AssetManager.prototype.downloadBinary = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = function () { request.onload = function () {
@ -2197,13 +2202,16 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.prototype.setRawDataURI = function (path, data) {
this.rawDataUris[this.pathPrefix + path] = data;
};
AssetManager.prototype.loadBinary = function (path, success, error) { AssetManager.prototype.loadBinary = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, function (data) { this.downloadBinary(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2223,7 +2231,7 @@ var spine;
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (data) { this.downloadText(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2242,12 +2250,13 @@ var spine;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
var storagePath = path;
this.toLoad++; this.toLoad++;
var img = new Image(); var img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = function (ev) { img.onload = function (ev) {
var texture = _this.textureLoader(img); var texture = _this.textureLoader(img);
_this.assets[path] = texture; _this.assets[storagePath] = texture;
_this.toLoad--; _this.toLoad--;
_this.loaded++; _this.loaded++;
if (success) if (success)
@ -2260,32 +2269,10 @@ var spine;
if (error) if (error)
error(path, "Couldn't load image " + path); error(path, "Couldn't load image " + path);
}; };
if (this.rawDataUris[path])
path = this.rawDataUris[path];
img.src = path; img.src = path;
}; };
AssetManager.prototype.loadTextureData = function (path, data, success, error) {
var _this = this;
if (success === void 0) { success = null; }
if (error === void 0) { error = null; }
path = this.pathPrefix + path;
this.toLoad++;
var img = new Image();
img.onload = function (ev) {
var texture = _this.textureLoader(img);
_this.assets[path] = texture;
_this.toLoad--;
_this.loaded++;
if (success)
success(path, img);
};
img.onerror = function (ev) {
_this.errors[path] = "Couldn't load image " + path;
_this.toLoad--;
_this.loaded++;
if (error)
error(path, "Couldn't load image " + path);
};
img.src = data;
};
AssetManager.prototype.loadTextureAtlas = function (path, success, error) { AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
@ -2293,12 +2280,12 @@ var spine;
var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (atlasData) { this.downloadText(path, function (atlasData) {
var pagesLoaded = { count: 0 }; var pagesLoaded = { count: 0 };
var atlasPages = new Array(); var atlasPages = new Array();
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
var image = document.createElement("img"); var image = document.createElement("img");
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -2322,7 +2309,7 @@ var spine;
if (!pageLoadError) { if (!pageLoadError) {
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
return _this.get(parent + "/" + path); return _this.get(parent == "" ? path : parent + "/" + path);
}); });
_this.assets[path] = atlas; _this.assets[path] = atlas;
if (success) if (success)

File diff suppressed because one or more lines are too long

View File

@ -384,13 +384,14 @@ declare module spine {
private errors; private errors;
private toLoad; private toLoad;
private loaded; private loaded;
private rawDataUris;
constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string); constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
private static downloadText; private downloadText;
private static downloadBinary; private downloadBinary;
setRawDataURI(path: string, data: string): void;
loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void; loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void;
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void; loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void; loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureData(path: string, data: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void; loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void;
get(path: string): any; get(path: string): any;
remove(path: string): void; remove(path: string): void;

View File

@ -2161,11 +2161,14 @@ var spine;
this.errors = {}; this.errors = {};
this.toLoad = 0; this.toLoad = 0;
this.loaded = 0; this.loaded = 0;
this.rawDataUris = {};
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
AssetManager.downloadText = function (url, success, error) { AssetManager.prototype.downloadText = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = function () { request.onload = function () {
if (request.status == 200) { if (request.status == 200) {
@ -2180,8 +2183,10 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.downloadBinary = function (url, success, error) { AssetManager.prototype.downloadBinary = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = function () { request.onload = function () {
@ -2197,13 +2202,16 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.prototype.setRawDataURI = function (path, data) {
this.rawDataUris[this.pathPrefix + path] = data;
};
AssetManager.prototype.loadBinary = function (path, success, error) { AssetManager.prototype.loadBinary = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, function (data) { this.downloadBinary(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2223,7 +2231,7 @@ var spine;
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (data) { this.downloadText(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2242,12 +2250,13 @@ var spine;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
var storagePath = path;
this.toLoad++; this.toLoad++;
var img = new Image(); var img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = function (ev) { img.onload = function (ev) {
var texture = _this.textureLoader(img); var texture = _this.textureLoader(img);
_this.assets[path] = texture; _this.assets[storagePath] = texture;
_this.toLoad--; _this.toLoad--;
_this.loaded++; _this.loaded++;
if (success) if (success)
@ -2260,32 +2269,10 @@ var spine;
if (error) if (error)
error(path, "Couldn't load image " + path); error(path, "Couldn't load image " + path);
}; };
if (this.rawDataUris[path])
path = this.rawDataUris[path];
img.src = path; img.src = path;
}; };
AssetManager.prototype.loadTextureData = function (path, data, success, error) {
var _this = this;
if (success === void 0) { success = null; }
if (error === void 0) { error = null; }
path = this.pathPrefix + path;
this.toLoad++;
var img = new Image();
img.onload = function (ev) {
var texture = _this.textureLoader(img);
_this.assets[path] = texture;
_this.toLoad--;
_this.loaded++;
if (success)
success(path, img);
};
img.onerror = function (ev) {
_this.errors[path] = "Couldn't load image " + path;
_this.toLoad--;
_this.loaded++;
if (error)
error(path, "Couldn't load image " + path);
};
img.src = data;
};
AssetManager.prototype.loadTextureAtlas = function (path, success, error) { AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
@ -2293,12 +2280,12 @@ var spine;
var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (atlasData) { this.downloadText(path, function (atlasData) {
var pagesLoaded = { count: 0 }; var pagesLoaded = { count: 0 };
var atlasPages = new Array(); var atlasPages = new Array();
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
var image = document.createElement("img"); var image = document.createElement("img");
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -2322,7 +2309,7 @@ var spine;
if (!pageLoadError) { if (!pageLoadError) {
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
return _this.get(parent + "/" + path); return _this.get(parent == "" ? path : parent + "/" + path);
}); });
_this.assets[path] = atlas; _this.assets[path] = atlas;
if (success) if (success)

File diff suppressed because one or more lines are too long

View File

@ -384,13 +384,14 @@ declare module spine {
private errors; private errors;
private toLoad; private toLoad;
private loaded; private loaded;
private rawDataUris;
constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string); constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
private static downloadText; private downloadText;
private static downloadBinary; private downloadBinary;
setRawDataURI(path: string, data: string): void;
loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void; loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void;
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void; loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void; loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureData(path: string, data: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void; loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void;
get(path: string): any; get(path: string): any;
remove(path: string): void; remove(path: string): void;

View File

@ -2161,11 +2161,14 @@ var spine;
this.errors = {}; this.errors = {};
this.toLoad = 0; this.toLoad = 0;
this.loaded = 0; this.loaded = 0;
this.rawDataUris = {};
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
AssetManager.downloadText = function (url, success, error) { AssetManager.prototype.downloadText = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = function () { request.onload = function () {
if (request.status == 200) { if (request.status == 200) {
@ -2180,8 +2183,10 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.downloadBinary = function (url, success, error) { AssetManager.prototype.downloadBinary = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = function () { request.onload = function () {
@ -2197,13 +2202,16 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.prototype.setRawDataURI = function (path, data) {
this.rawDataUris[this.pathPrefix + path] = data;
};
AssetManager.prototype.loadBinary = function (path, success, error) { AssetManager.prototype.loadBinary = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, function (data) { this.downloadBinary(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2223,7 +2231,7 @@ var spine;
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (data) { this.downloadText(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2242,12 +2250,13 @@ var spine;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
var storagePath = path;
this.toLoad++; this.toLoad++;
var img = new Image(); var img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = function (ev) { img.onload = function (ev) {
var texture = _this.textureLoader(img); var texture = _this.textureLoader(img);
_this.assets[path] = texture; _this.assets[storagePath] = texture;
_this.toLoad--; _this.toLoad--;
_this.loaded++; _this.loaded++;
if (success) if (success)
@ -2260,32 +2269,10 @@ var spine;
if (error) if (error)
error(path, "Couldn't load image " + path); error(path, "Couldn't load image " + path);
}; };
if (this.rawDataUris[path])
path = this.rawDataUris[path];
img.src = path; img.src = path;
}; };
AssetManager.prototype.loadTextureData = function (path, data, success, error) {
var _this = this;
if (success === void 0) { success = null; }
if (error === void 0) { error = null; }
path = this.pathPrefix + path;
this.toLoad++;
var img = new Image();
img.onload = function (ev) {
var texture = _this.textureLoader(img);
_this.assets[path] = texture;
_this.toLoad--;
_this.loaded++;
if (success)
success(path, img);
};
img.onerror = function (ev) {
_this.errors[path] = "Couldn't load image " + path;
_this.toLoad--;
_this.loaded++;
if (error)
error(path, "Couldn't load image " + path);
};
img.src = data;
};
AssetManager.prototype.loadTextureAtlas = function (path, success, error) { AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
@ -2293,12 +2280,12 @@ var spine;
var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (atlasData) { this.downloadText(path, function (atlasData) {
var pagesLoaded = { count: 0 }; var pagesLoaded = { count: 0 };
var atlasPages = new Array(); var atlasPages = new Array();
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
var image = document.createElement("img"); var image = document.createElement("img");
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -2322,7 +2309,7 @@ var spine;
if (!pageLoadError) { if (!pageLoadError) {
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
return _this.get(parent + "/" + path); return _this.get(parent == "" ? path : parent + "/" + path);
}); });
_this.assets[path] = atlas; _this.assets[path] = atlas;
if (success) if (success)

File diff suppressed because one or more lines are too long

View File

@ -384,13 +384,14 @@ declare module spine {
private errors; private errors;
private toLoad; private toLoad;
private loaded; private loaded;
private rawDataUris;
constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string); constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
private static downloadText; private downloadText;
private static downloadBinary; private downloadBinary;
setRawDataURI(path: string, data: string): void;
loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void; loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void;
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void; loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void; loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureData(path: string, data: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void; loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void;
get(path: string): any; get(path: string): any;
remove(path: string): void; remove(path: string): void;

View File

@ -2161,11 +2161,14 @@ var spine;
this.errors = {}; this.errors = {};
this.toLoad = 0; this.toLoad = 0;
this.loaded = 0; this.loaded = 0;
this.rawDataUris = {};
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
AssetManager.downloadText = function (url, success, error) { AssetManager.prototype.downloadText = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = function () { request.onload = function () {
if (request.status == 200) { if (request.status == 200) {
@ -2180,8 +2183,10 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.downloadBinary = function (url, success, error) { AssetManager.prototype.downloadBinary = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = function () { request.onload = function () {
@ -2197,13 +2202,16 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.prototype.setRawDataURI = function (path, data) {
this.rawDataUris[this.pathPrefix + path] = data;
};
AssetManager.prototype.loadBinary = function (path, success, error) { AssetManager.prototype.loadBinary = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, function (data) { this.downloadBinary(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2223,7 +2231,7 @@ var spine;
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (data) { this.downloadText(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2242,12 +2250,13 @@ var spine;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
var storagePath = path;
this.toLoad++; this.toLoad++;
var img = new Image(); var img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = function (ev) { img.onload = function (ev) {
var texture = _this.textureLoader(img); var texture = _this.textureLoader(img);
_this.assets[path] = texture; _this.assets[storagePath] = texture;
_this.toLoad--; _this.toLoad--;
_this.loaded++; _this.loaded++;
if (success) if (success)
@ -2260,32 +2269,10 @@ var spine;
if (error) if (error)
error(path, "Couldn't load image " + path); error(path, "Couldn't load image " + path);
}; };
if (this.rawDataUris[path])
path = this.rawDataUris[path];
img.src = path; img.src = path;
}; };
AssetManager.prototype.loadTextureData = function (path, data, success, error) {
var _this = this;
if (success === void 0) { success = null; }
if (error === void 0) { error = null; }
path = this.pathPrefix + path;
this.toLoad++;
var img = new Image();
img.onload = function (ev) {
var texture = _this.textureLoader(img);
_this.assets[path] = texture;
_this.toLoad--;
_this.loaded++;
if (success)
success(path, img);
};
img.onerror = function (ev) {
_this.errors[path] = "Couldn't load image " + path;
_this.toLoad--;
_this.loaded++;
if (error)
error(path, "Couldn't load image " + path);
};
img.src = data;
};
AssetManager.prototype.loadTextureAtlas = function (path, success, error) { AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
@ -2293,12 +2280,12 @@ var spine;
var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (atlasData) { this.downloadText(path, function (atlasData) {
var pagesLoaded = { count: 0 }; var pagesLoaded = { count: 0 };
var atlasPages = new Array(); var atlasPages = new Array();
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
var image = document.createElement("img"); var image = document.createElement("img");
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -2322,7 +2309,7 @@ var spine;
if (!pageLoadError) { if (!pageLoadError) {
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
return _this.get(parent + "/" + path); return _this.get(parent == "" ? path : parent + "/" + path);
}); });
_this.assets[path] = atlas; _this.assets[path] = atlas;
if (success) if (success)

File diff suppressed because one or more lines are too long

View File

@ -384,13 +384,14 @@ declare module spine {
private errors; private errors;
private toLoad; private toLoad;
private loaded; private loaded;
private rawDataUris;
constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string); constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
private static downloadText; private downloadText;
private static downloadBinary; private downloadBinary;
setRawDataURI(path: string, data: string): void;
loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void; loadBinary(path: string, success?: (path: string, binary: Uint8Array) => void, error?: (path: string, error: string) => void): void;
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void; loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void; loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureData(path: string, data: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void; loadTextureAtlas(path: string, success?: (path: string, atlas: TextureAtlas) => void, error?: (path: string, error: string) => void): void;
get(path: string): any; get(path: string): any;
remove(path: string): void; remove(path: string): void;

View File

@ -2161,11 +2161,14 @@ var spine;
this.errors = {}; this.errors = {};
this.toLoad = 0; this.toLoad = 0;
this.loaded = 0; this.loaded = 0;
this.rawDataUris = {};
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
AssetManager.downloadText = function (url, success, error) { AssetManager.prototype.downloadText = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = function () { request.onload = function () {
if (request.status == 200) { if (request.status == 200) {
@ -2180,8 +2183,10 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.downloadBinary = function (url, success, error) { AssetManager.prototype.downloadBinary = function (url, success, error) {
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
if (this.rawDataUris[url])
url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = function () { request.onload = function () {
@ -2197,13 +2202,16 @@ var spine;
}; };
request.send(); request.send();
}; };
AssetManager.prototype.setRawDataURI = function (path, data) {
this.rawDataUris[this.pathPrefix + path] = data;
};
AssetManager.prototype.loadBinary = function (path, success, error) { AssetManager.prototype.loadBinary = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, function (data) { this.downloadBinary(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2223,7 +2231,7 @@ var spine;
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (data) { this.downloadText(path, function (data) {
_this.assets[path] = data; _this.assets[path] = data;
if (success) if (success)
success(path, data); success(path, data);
@ -2242,12 +2250,13 @@ var spine;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
if (error === void 0) { error = null; } if (error === void 0) { error = null; }
path = this.pathPrefix + path; path = this.pathPrefix + path;
var storagePath = path;
this.toLoad++; this.toLoad++;
var img = new Image(); var img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = function (ev) { img.onload = function (ev) {
var texture = _this.textureLoader(img); var texture = _this.textureLoader(img);
_this.assets[path] = texture; _this.assets[storagePath] = texture;
_this.toLoad--; _this.toLoad--;
_this.loaded++; _this.loaded++;
if (success) if (success)
@ -2260,32 +2269,10 @@ var spine;
if (error) if (error)
error(path, "Couldn't load image " + path); error(path, "Couldn't load image " + path);
}; };
if (this.rawDataUris[path])
path = this.rawDataUris[path];
img.src = path; img.src = path;
}; };
AssetManager.prototype.loadTextureData = function (path, data, success, error) {
var _this = this;
if (success === void 0) { success = null; }
if (error === void 0) { error = null; }
path = this.pathPrefix + path;
this.toLoad++;
var img = new Image();
img.onload = function (ev) {
var texture = _this.textureLoader(img);
_this.assets[path] = texture;
_this.toLoad--;
_this.loaded++;
if (success)
success(path, img);
};
img.onerror = function (ev) {
_this.errors[path] = "Couldn't load image " + path;
_this.toLoad--;
_this.loaded++;
if (error)
error(path, "Couldn't load image " + path);
};
img.src = data;
};
AssetManager.prototype.loadTextureAtlas = function (path, success, error) { AssetManager.prototype.loadTextureAtlas = function (path, success, error) {
var _this = this; var _this = this;
if (success === void 0) { success = null; } if (success === void 0) { success = null; }
@ -2293,12 +2280,12 @@ var spine;
var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : ""; var parent = path.lastIndexOf("/") >= 0 ? path.substring(0, path.lastIndexOf("/")) : "";
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, function (atlasData) { this.downloadText(path, function (atlasData) {
var pagesLoaded = { count: 0 }; var pagesLoaded = { count: 0 };
var atlasPages = new Array(); var atlasPages = new Array();
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
var image = document.createElement("img"); var image = document.createElement("img");
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -2322,7 +2309,7 @@ var spine;
if (!pageLoadError) { if (!pageLoadError) {
try { try {
var atlas = new spine.TextureAtlas(atlasData, function (path) { var atlas = new spine.TextureAtlas(atlasData, function (path) {
return _this.get(parent + "/" + path); return _this.get(parent == "" ? path : parent + "/" + path);
}); });
_this.assets[path] = atlas; _this.assets[path] = atlas;
if (success) if (success)

File diff suppressed because one or more lines are too long

View File

@ -35,14 +35,16 @@ module spine {
private errors: Map<string> = {}; private errors: Map<string> = {};
private toLoad = 0; private toLoad = 0;
private loaded = 0; private loaded = 0;
private rawDataUris: Map<string> = {};
constructor (textureLoader: (image: HTMLImageElement) => any, pathPrefix: string = "") { constructor (textureLoader: (image: HTMLImageElement) => any, pathPrefix: string = "") {
this.textureLoader = textureLoader; this.textureLoader = textureLoader;
this.pathPrefix = pathPrefix; this.pathPrefix = pathPrefix;
} }
private static downloadText (url: string, success: (data: string) => void, error: (status: number, responseText: string) => void) { private downloadText (url: string, success: (data: string) => void, error: (status: number, responseText: string) => void) {
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
if (this.rawDataUris[url]) url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.onload = () => { request.onload = () => {
if (request.status == 200) { if (request.status == 200) {
@ -57,8 +59,9 @@ module spine {
request.send(); request.send();
} }
private static downloadBinary (url: string, success: (data: Uint8Array) => void, error: (status: number, responseText: string) => void) { private downloadBinary (url: string, success: (data: Uint8Array) => void, error: (status: number, responseText: string) => void) {
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
if (this.rawDataUris[url]) url = this.rawDataUris[url];
request.open("GET", url, true); request.open("GET", url, true);
request.responseType = "arraybuffer"; request.responseType = "arraybuffer";
request.onload = () => { request.onload = () => {
@ -74,13 +77,17 @@ module spine {
request.send(); request.send();
} }
setRawDataURI(path: string, data: string) {
this.rawDataUris[this.pathPrefix + path] = data;
}
loadBinary(path: string, loadBinary(path: string,
success: (path: string, binary: Uint8Array) => void = null, success: (path: string, binary: Uint8Array) => void = null,
error: (path: string, error: string) => void = null) { error: (path: string, error: string) => void = null) {
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadBinary(path, (data: Uint8Array): void => { this.downloadBinary(path, (data: Uint8Array): void => {
this.assets[path] = data; this.assets[path] = data;
if (success) success(path, data); if (success) success(path, data);
this.toLoad--; this.toLoad--;
@ -99,7 +106,7 @@ module spine {
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, (data: string): void => { this.downloadText(path, (data: string): void => {
this.assets[path] = data; this.assets[path] = data;
if (success) success(path, data); if (success) success(path, data);
this.toLoad--; this.toLoad--;
@ -116,12 +123,13 @@ module spine {
success: (path: string, image: HTMLImageElement) => void = null, success: (path: string, image: HTMLImageElement) => void = null,
error: (path: string, error: string) => void = null) { error: (path: string, error: string) => void = null) {
path = this.pathPrefix + path; path = this.pathPrefix + path;
let storagePath = path;
this.toLoad++; this.toLoad++;
let img = new Image(); let img = new Image();
img.crossOrigin = "anonymous"; img.crossOrigin = "anonymous";
img.onload = (ev) => { img.onload = (ev) => {
let texture = this.textureLoader(img); let texture = this.textureLoader(img);
this.assets[path] = texture; this.assets[storagePath] = texture;
this.toLoad--; this.toLoad--;
this.loaded++; this.loaded++;
if (success) success(path, img); if (success) success(path, img);
@ -132,31 +140,10 @@ module spine {
this.loaded++; this.loaded++;
if (error) error(path, `Couldn't load image ${path}`); if (error) error(path, `Couldn't load image ${path}`);
} }
if (this.rawDataUris[path]) path = this.rawDataUris[path];
img.src = path; img.src = path;
} }
loadTextureData(path: string, data: string,
success: (path: string, image: HTMLImageElement) => void = null,
error: (path: string, error: string) => void = null) {
path = this.pathPrefix + path;
this.toLoad++;
let img = new Image();
img.onload = (ev) => {
let texture = this.textureLoader(img);
this.assets[path] = texture;
this.toLoad--;
this.loaded++;
if (success) success(path, img);
}
img.onerror = (ev) => {
this.errors[path] = `Couldn't load image ${path}`;
this.toLoad--;
this.loaded++;
if (error) error(path, `Couldn't load image ${path}`);
}
img.src = data;
}
loadTextureAtlas (path: string, loadTextureAtlas (path: string,
success: (path: string, atlas: TextureAtlas) => void = null, success: (path: string, atlas: TextureAtlas) => void = null,
error: (path: string, error: string) => void = null error: (path: string, error: string) => void = null
@ -165,12 +152,12 @@ module spine {
path = this.pathPrefix + path; path = this.pathPrefix + path;
this.toLoad++; this.toLoad++;
AssetManager.downloadText(path, (atlasData: string): void => { this.downloadText(path, (atlasData: string): void => {
let pagesLoaded: any = { count: 0 }; let pagesLoaded: any = { count: 0 };
let atlasPages = new Array<string>(); let atlasPages = new Array<string>();
try { try {
let atlas = new TextureAtlas(atlasData, (path: string) => { let atlas = new TextureAtlas(atlasData, (path: string) => {
atlasPages.push(parent + "/" + path); atlasPages.push(parent == "" ? path : parent + "/" + path);
let image = document.createElement("img") as HTMLImageElement; let image = document.createElement("img") as HTMLImageElement;
image.width = 16; image.width = 16;
image.height = 16; image.height = 16;
@ -194,7 +181,7 @@ module spine {
if (!pageLoadError) { if (!pageLoadError) {
try { try {
let atlas = new TextureAtlas(atlasData, (path: string) => { let atlas = new TextureAtlas(atlasData, (path: string) => {
return this.get(parent + "/" + path); return this.get(parent == "" ? path : parent + "/" + path);
}); });
this.assets[path] = atlas; this.assets[path] = atlas;
if (success) success(path, atlas); if (success) success(path, atlas);