[ts] More refactoring for greater code reuse

This commit is contained in:
badlogic 2016-08-16 10:41:28 +02:00
parent e72c9030eb
commit 847bd2a76c
14 changed files with 2914 additions and 381 deletions

View File

@ -384,7 +384,7 @@ declare module spine {
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
declare module spine.webgl { declare module spine {
class AssetManager implements Disposable { class AssetManager implements Disposable {
private _textureLoader; private _textureLoader;
private _assets; private _assets;
@ -1282,6 +1282,20 @@ declare module spine {
ClampToEdge = 33071, ClampToEdge = 33071,
Repeat = 10497, Repeat = 10497,
} }
class TextureRegion {
renderObject: any;
u: number;
v: number;
u2: number;
v2: number;
width: number;
height: number;
rotate: boolean;
offsetX: number;
offsetY: number;
originalWidth: number;
originalHeight: number;
}
} }
/****************************************************************************** /******************************************************************************
* Spine Runtimes Software License * Spine Runtimes Software License
@ -1313,7 +1327,7 @@ declare module spine {
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
declare module spine.webgl { declare module spine {
class TextureAtlas implements Disposable { class TextureAtlas implements Disposable {
pages: TextureAtlasPage[]; pages: TextureAtlasPage[];
regions: TextureAtlasRegion[]; regions: TextureAtlasRegion[];
@ -1905,52 +1919,6 @@ declare module spine {
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>; updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
} }
} }
/******************************************************************************
* Spine Runtimes Software License
* Version 2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
declare module spine {
class TextureRegion {
renderObject: any;
u: number;
v: number;
u2: number;
v2: number;
width: number;
height: number;
rotate: boolean;
offsetX: number;
offsetY: number;
originalWidth: number;
originalHeight: number;
}
}
/****************************************************************************** /******************************************************************************
* Spine Runtimes Software License * Spine Runtimes Software License
* Version 2.5 * Version 2.5

View File

@ -1147,8 +1147,6 @@ var spine;
*****************************************************************************/ *****************************************************************************/
var spine; var spine;
(function (spine) { (function (spine) {
var webgl;
(function (webgl) {
var AssetManager = (function () { var AssetManager = (function () {
function AssetManager(textureLoader) { function AssetManager(textureLoader) {
this._assets = {}; this._assets = {};
@ -1242,8 +1240,7 @@ var spine;
}; };
return AssetManager; return AssetManager;
}()); }());
webgl.AssetManager = AssetManager; spine.AssetManager = AssetManager;
})(webgl = spine.webgl || (spine.webgl = {}));
})(spine || (spine = {})); })(spine || (spine = {}));
/****************************************************************************** /******************************************************************************
* Spine Runtimes Software License * Spine Runtimes Software License
@ -4175,6 +4172,23 @@ var spine;
TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat"; // WebGLRenderingContext.REPEAT TextureWrap[TextureWrap["Repeat"] = 10497] = "Repeat"; // WebGLRenderingContext.REPEAT
})(spine.TextureWrap || (spine.TextureWrap = {})); })(spine.TextureWrap || (spine.TextureWrap = {}));
var TextureWrap = spine.TextureWrap; var TextureWrap = spine.TextureWrap;
var TextureRegion = (function () {
function TextureRegion() {
this.u = 0;
this.v = 0;
this.u2 = 0;
this.v2 = 0;
this.width = 0;
this.height = 0;
this.rotate = false;
this.offsetX = 0;
this.offsetY = 0;
this.originalWidth = 0;
this.originalHeight = 0;
}
return TextureRegion;
}());
spine.TextureRegion = TextureRegion;
})(spine || (spine = {})); })(spine || (spine = {}));
/****************************************************************************** /******************************************************************************
* Spine Runtimes Software License * Spine Runtimes Software License
@ -4208,8 +4222,6 @@ var spine;
*****************************************************************************/ *****************************************************************************/
var spine; var spine;
(function (spine) { (function (spine) {
var webgl;
(function (webgl) {
var TextureAtlas = (function () { var TextureAtlas = (function () {
function TextureAtlas(atlasText, textureLoader) { function TextureAtlas(atlasText, textureLoader) {
this.pages = new Array(); this.pages = new Array();
@ -4313,7 +4325,7 @@ var spine;
}; };
return TextureAtlas; return TextureAtlas;
}()); }());
webgl.TextureAtlas = TextureAtlas; spine.TextureAtlas = TextureAtlas;
var TextureAtlasReader = (function () { var TextureAtlasReader = (function () {
function TextureAtlasReader(text) { function TextureAtlasReader(text) {
this.index = 0; this.index = 0;
@ -4354,7 +4366,7 @@ var spine;
} }
return TextureAtlasPage; return TextureAtlasPage;
}()); }());
webgl.TextureAtlasPage = TextureAtlasPage; spine.TextureAtlasPage = TextureAtlasPage;
var TextureAtlasRegion = (function (_super) { var TextureAtlasRegion = (function (_super) {
__extends(TextureAtlasRegion, _super); __extends(TextureAtlasRegion, _super);
function TextureAtlasRegion() { function TextureAtlasRegion() {
@ -4362,8 +4374,7 @@ var spine;
} }
return TextureAtlasRegion; return TextureAtlasRegion;
}(spine.TextureRegion)); }(spine.TextureRegion));
webgl.TextureAtlasRegion = TextureAtlasRegion; spine.TextureAtlasRegion = TextureAtlasRegion;
})(webgl = spine.webgl || (spine.webgl = {}));
})(spine || (spine = {})); })(spine || (spine = {}));
/****************************************************************************** /******************************************************************************
* Spine Runtimes Software License * Spine Runtimes Software License
@ -5429,56 +5440,6 @@ var spine;
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
var spine; var spine;
(function (spine) {
var TextureRegion = (function () {
function TextureRegion() {
this.u = 0;
this.v = 0;
this.u2 = 0;
this.v2 = 0;
this.width = 0;
this.height = 0;
this.rotate = false;
this.offsetX = 0;
this.offsetY = 0;
this.originalWidth = 0;
this.originalHeight = 0;
}
return TextureRegion;
}());
spine.TextureRegion = TextureRegion;
})(spine || (spine = {}));
/******************************************************************************
* Spine Runtimes Software License
* Version 2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
var spine;
(function (spine) { (function (spine) {
var webgl; var webgl;
(function (webgl) { (function (webgl) {

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,195 @@
spineboy.png
size: 1024,1024
format: RGBA8888
filter: Linear,Linear
repeat: none
eye_indifferent
rotate: false
xy: 550, 694
size: 93, 89
orig: 93, 89
offset: 0, 0
index: -1
eye_surprised
rotate: false
xy: 834, 856
size: 93, 89
orig: 93, 89
offset: 0, 0
index: -1
front_bracer
rotate: false
xy: 678, 774
size: 58, 80
orig: 58, 80
offset: 0, 0
index: -1
front_fist_closed
rotate: true
xy: 466, 593
size: 75, 82
orig: 75, 82
offset: 0, 0
index: -1
front_fist_open
rotate: false
xy: 550, 605
size: 86, 87
orig: 86, 87
offset: 0, 0
index: -1
front_foot
rotate: false
xy: 550, 785
size: 126, 69
orig: 126, 69
offset: 0, 0
index: -1
front_foot_bend1
rotate: true
xy: 375, 492
size: 128, 70
orig: 128, 70
offset: 0, 0
index: -1
front_foot_bend2
rotate: true
xy: 275, 330
size: 108, 93
orig: 108, 93
offset: 0, 0
index: -1
front_shin
rotate: false
xy: 466, 670
size: 82, 184
orig: 82, 184
offset: 0, 0
index: -1
front_thigh
rotate: false
xy: 214, 208
size: 48, 112
orig: 48, 112
offset: 0, 0
index: -1
front_upper_arm
rotate: false
xy: 214, 109
size: 54, 97
orig: 54, 97
offset: 0, 0
index: -1
goggles
rotate: false
xy: 466, 856
size: 261, 166
orig: 261, 166
offset: 0, 0
index: -1
gun
rotate: false
xy: 2, 117
size: 210, 203
orig: 210, 203
offset: 0, 0
index: -1
head
rotate: false
xy: 2, 322
size: 271, 298
orig: 271, 298
offset: 0, 0
index: -1
mouth_grind
rotate: false
xy: 929, 896
size: 93, 59
orig: 93, 59
offset: 0, 0
index: -1
mouth_oooo
rotate: false
xy: 929, 835
size: 93, 59
orig: 93, 59
offset: 0, 0
index: -1
mouth_smile
rotate: false
xy: 447, 532
size: 93, 59
orig: 93, 59
offset: 0, 0
index: -1
muzzle
rotate: false
xy: 2, 622
size: 462, 400
orig: 462, 400
offset: 0, 0
index: -1
neck
rotate: false
xy: 796, 819
size: 36, 41
orig: 36, 41
offset: 0, 0
index: -1
rear_bracer
rotate: false
xy: 738, 788
size: 56, 72
orig: 56, 72
offset: 0, 0
index: -1
rear_foot
rotate: true
xy: 2, 2
size: 113, 60
orig: 113, 60
offset: 0, 0
index: -1
rear_foot_bend1
rotate: false
xy: 64, 49
size: 117, 66
orig: 117, 66
offset: 0, 0
index: -1
rear_foot_bend2
rotate: false
xy: 729, 862
size: 103, 83
orig: 103, 83
offset: 0, 0
index: -1
rear_shin
rotate: true
xy: 729, 947
size: 75, 178
orig: 75, 178
offset: 0, 0
index: -1
rear_thigh
rotate: true
xy: 909, 957
size: 65, 104
orig: 65, 104
offset: 0, 0
index: -1
rear_upper_arm
rotate: true
xy: 447, 483
size: 47, 87
orig: 47, 87
offset: 0, 0
index: -1
torso
rotate: false
xy: 275, 440
size: 98, 180
orig: 98, 180
offset: 0, 0
index: -1

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 KiB

View File

@ -8,5 +8,20 @@
</body> </body>
<script> <script>
var lastFrameTime = Date.now() / 1000;
var canvas;
var assetManager;
var skeletonRenderer;
function init () {
assetManager = new spine.AssetManager(function(image) {
return CanvasTexture(image);
});
}
(function() {
init();
}());
</script> </script>
</html> </html>

View File

@ -0,0 +1,11 @@
module spine.canvas {
export class CanvasTexture extends Texture {
constructor (image: HTMLImageElement) {
super(image);
}
setFilters (minFilter: TextureFilter, magFilter: TextureFilter) { }
setWraps (uWrap: TextureWrap, vWrap: TextureWrap) { }
dispose () { }
}
}

View File

@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
module spine.webgl { module spine {
export class AssetManager implements Disposable { export class AssetManager implements Disposable {
private _textureLoader: (image: HTMLImageElement) => any; private _textureLoader: (image: HTMLImageElement) => any;
private _assets: Map<any> = {}; private _assets: Map<any> = {};

View File

@ -53,4 +53,14 @@ module spine {
ClampToEdge = 33071, // WebGLRenderingContext.CLAMP_TO_EDGE ClampToEdge = 33071, // WebGLRenderingContext.CLAMP_TO_EDGE
Repeat = 10497 // WebGLRenderingContext.REPEAT Repeat = 10497 // WebGLRenderingContext.REPEAT
} }
export class TextureRegion {
renderObject: any;
u = 0; v = 0;
u2 = 0; v2 = 0;
width = 0; height = 0;
rotate = false;
offsetX = 0; offsetY = 0;
originalWidth = 0; originalHeight = 0;
}
} }

View File

@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
module spine.webgl { module spine {
export class TextureAtlas implements Disposable { export class TextureAtlas implements Disposable {
pages = new Array<TextureAtlasPage>(); pages = new Array<TextureAtlasPage>();
regions = new Array<TextureAtlasRegion>(); regions = new Array<TextureAtlasRegion>();

View File

@ -1,42 +0,0 @@
/******************************************************************************
* Spine Runtimes Software License
* Version 2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
module spine {
export class TextureRegion {
renderObject: any;
u = 0; v = 0;
u2 = 0; v2 = 0;
width = 0; height = 0;
rotate = false;
offsetX = 0; offsetY = 0;
originalWidth = 0; originalHeight = 0;
}
}

View File

@ -36,7 +36,9 @@ function init () {
batcher = new spine.webgl.PolygonBatcher(gl); batcher = new spine.webgl.PolygonBatcher(gl);
mvp.ortho2d(0, 0, 639, 479); mvp.ortho2d(0, 0, 639, 479);
skeletonRenderer = new spine.webgl.SkeletonRenderer(gl); skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
assetManager = new spine.webgl.AssetManager(gl); assetManager = new spine.AssetManager(function(image) {
return new spine.webgl.GLTexture(gl, image);
});
// Tell AssetManager to load the resources for each model, including the exported .json file, the .atlas file and the .png // Tell AssetManager to load the resources for each model, including the exported .json file, the .atlas file and the .png
// file for the atlas. We then wait until all resources are loaded in the load() method. // file for the atlas. We then wait until all resources are loaded in the load() method.
@ -78,10 +80,11 @@ function loadSkeleton (name, scale, initialAnimation, positionX, positionY, prem
// Load the texture atlas using name.atlas and name.png from the AssetManager. // Load the texture atlas using name.atlas and name.png from the AssetManager.
// The function passed to TextureAtlas is used to resolve relative paths. // The function passed to TextureAtlas is used to resolve relative paths.
atlas = new spine.webgl.TextureAtlas(assetManager.get("assets/" + name + ".atlas"), function(path, minFilter, magFilter, uWrap, vWrap) { atlas = new spine.TextureAtlas(assetManager.get("assets/" + name + ".atlas"), function(path, minFilter, magFilter, uWrap, vWrap) {
var texture = assetManager.get("assets/" + path); var texture = assetManager.get("assets/" + path);
texture.setFilters(minFilter, magFilter); texture.setFilters(minFilter, magFilter);
texture.setWraps(uWrap, vWrap); texture.setWraps(uWrap, vWrap);
return texture;
}); });
// Create a TextureAtlasAttachmentLoader, which is specific to the WebGL backend. // Create a TextureAtlasAttachmentLoader, which is specific to the WebGL backend.