Эх сурвалжийг харах

[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.

badlogic 5 жил өмнө
parent
commit
b81f77b993

+ 1 - 0
CHANGELOG.md

@@ -554,6 +554,7 @@ This will automatically:
   * Support for stretchy IK
   * 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).
+  * 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
 * 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.

+ 4 - 3
spine-ts/build/spine-all.d.ts

@@ -384,13 +384,14 @@ declare module spine {
 		private errors;
 		private toLoad;
 		private loaded;
+		private rawDataUris;
 		constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
-		private static downloadText;
-		private static downloadBinary;
+		private downloadText;
+		private downloadBinary;
+		setRawDataURI(path: string, data: string): 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;
 		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;
 		get(path: string): any;
 		remove(path: string): void;

+ 19 - 32
spine-ts/build/spine-all.js

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
spine-ts/build/spine-all.js.map


+ 4 - 3
spine-ts/build/spine-canvas.d.ts

@@ -384,13 +384,14 @@ declare module spine {
 		private errors;
 		private toLoad;
 		private loaded;
+		private rawDataUris;
 		constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
-		private static downloadText;
-		private static downloadBinary;
+		private downloadText;
+		private downloadBinary;
+		setRawDataURI(path: string, data: string): 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;
 		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;
 		get(path: string): any;
 		remove(path: string): void;

+ 19 - 32
spine-ts/build/spine-canvas.js

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
spine-ts/build/spine-canvas.js.map


+ 4 - 3
spine-ts/build/spine-core.d.ts

@@ -384,13 +384,14 @@ declare module spine {
 		private errors;
 		private toLoad;
 		private loaded;
+		private rawDataUris;
 		constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
-		private static downloadText;
-		private static downloadBinary;
+		private downloadText;
+		private downloadBinary;
+		setRawDataURI(path: string, data: string): 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;
 		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;
 		get(path: string): any;
 		remove(path: string): void;

+ 19 - 32
spine-ts/build/spine-core.js

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
spine-ts/build/spine-core.js.map


+ 4 - 3
spine-ts/build/spine-player.d.ts

@@ -384,13 +384,14 @@ declare module spine {
 		private errors;
 		private toLoad;
 		private loaded;
+		private rawDataUris;
 		constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
-		private static downloadText;
-		private static downloadBinary;
+		private downloadText;
+		private downloadBinary;
+		setRawDataURI(path: string, data: string): 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;
 		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;
 		get(path: string): any;
 		remove(path: string): void;

+ 19 - 32
spine-ts/build/spine-player.js

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
spine-ts/build/spine-player.js.map


+ 4 - 3
spine-ts/build/spine-threejs.d.ts

@@ -384,13 +384,14 @@ declare module spine {
 		private errors;
 		private toLoad;
 		private loaded;
+		private rawDataUris;
 		constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
-		private static downloadText;
-		private static downloadBinary;
+		private downloadText;
+		private downloadBinary;
+		setRawDataURI(path: string, data: string): 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;
 		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;
 		get(path: string): any;
 		remove(path: string): void;

+ 19 - 32
spine-ts/build/spine-threejs.js

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
spine-ts/build/spine-threejs.js.map


+ 4 - 3
spine-ts/build/spine-webgl.d.ts

@@ -384,13 +384,14 @@ declare module spine {
 		private errors;
 		private toLoad;
 		private loaded;
+		private rawDataUris;
 		constructor(textureLoader: (image: HTMLImageElement) => any, pathPrefix?: string);
-		private static downloadText;
-		private static downloadBinary;
+		private downloadText;
+		private downloadBinary;
+		setRawDataURI(path: string, data: string): 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;
 		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;
 		get(path: string): any;
 		remove(path: string): void;

+ 19 - 32
spine-ts/build/spine-webgl.js

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

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
spine-ts/build/spine-webgl.js.map


+ 17 - 30
spine-ts/core/src/AssetManager.ts

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

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно