@nativescript/canvas-phaser-ce 1.0.0-beta.0 → 1.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/game.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export default function Game({ canvas, width, height, renderer, preventLoop, onRender, title, state, transparent, antialias, physicsConfig }: {
2
+ canvas: any;
3
+ width?: any;
4
+ height?: any;
5
+ renderer?: number;
6
+ preventLoop?: any;
7
+ onRender?: any;
8
+ title?: any;
9
+ state?: any;
10
+ transparent?: any;
11
+ antialias?: any;
12
+ physicsConfig?: any;
13
+ }): any;
package/game.js CHANGED
@@ -1,44 +1,27 @@
1
1
  import Phaser from './phaser';
2
-
3
- export default function Game({
4
- canvas,
5
- width = null,
6
- height = null,
7
- renderer = 2,
8
- preventLoop = null,
9
- onRender = null,
10
- title = null,
11
- state = null,
12
- transparent = null,
13
- antialias = null,
14
- physicsConfig = null,
15
- }) {
16
- const realWidth = canvas.width || 1;
17
- const realHeight = canvas.height || 1;
18
-
19
- global.document.readyState = 'complete';
20
-
21
- const config = {
22
- width: width || realWidth,
23
- height: height || realHeight,
24
- renderer: renderer || 2,
25
- title: title || 'tns-phaser-game',
26
- state: state || null,
27
- transparent: transparent || false,
28
- antialias: antialias || true,
29
- physicsConfig: physicsConfig || null,
30
- canvas
31
- }
32
-
33
- const game = new Phaser.Game(config);
34
-
35
- const render = () => {
36
- requestAnimationFrame(render);
37
- onRender && onRender();
38
- };
39
- if (!preventLoop) {
40
- render();
41
- }
42
-
43
- return game;
2
+ export default function Game({ canvas, width = null, height = null, renderer = 2, preventLoop = null, onRender = null, title = null, state = null, transparent = null, antialias = null, physicsConfig = null }) {
3
+ const realWidth = canvas.width || 1;
4
+ const realHeight = canvas.height || 1;
5
+ global.document.readyState = 'complete';
6
+ const config = {
7
+ width: width || realWidth,
8
+ height: height || realHeight,
9
+ renderer: renderer || 2,
10
+ title: title || 'tns-phaser-game',
11
+ state: state || null,
12
+ transparent: transparent || false,
13
+ antialias: antialias || true,
14
+ physicsConfig: physicsConfig || null,
15
+ canvas,
16
+ };
17
+ const game = new Phaser.Game(config);
18
+ const render = () => {
19
+ requestAnimationFrame(render);
20
+ onRender && onRender();
21
+ };
22
+ if (!preventLoop) {
23
+ render();
24
+ }
25
+ return game;
44
26
  }
27
+ //# sourceMappingURL=game.js.map
package/game.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"game.js","sourceRoot":"","sources":["../../../packages/canvas-phaser-ce/game.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,QAAQ,GAAG,CAAC,EAAE,WAAW,GAAG,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,EAAE,aAAa,GAAG,IAAI,EAAE;IAC9M,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IAErC,MAAc,CAAC,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IAEjD,MAAM,MAAM,GAAG;QACd,KAAK,EAAE,KAAK,IAAI,SAAS;QACzB,MAAM,EAAE,MAAM,IAAI,UAAU;QAC5B,QAAQ,EAAE,QAAQ,IAAI,CAAC;QACvB,KAAK,EAAE,KAAK,IAAI,iBAAiB;QACjC,KAAK,EAAE,KAAK,IAAI,IAAI;QACpB,WAAW,EAAE,WAAW,IAAI,KAAK;QACjC,SAAS,EAAE,SAAS,IAAI,IAAI;QAC5B,aAAa,EAAE,aAAa,IAAI,IAAI;QACpC,MAAM;KACN,CAAC;IAEF,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAErC,MAAM,MAAM,GAAG,GAAG,EAAE;QACnB,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC9B,QAAQ,IAAI,QAAQ,EAAE,CAAC;IACxB,CAAC,CAAC;IACF,IAAI,CAAC,WAAW,EAAE;QACjB,MAAM,EAAE,CAAC;KACT;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './tns-phaser';
2
+ import * as TNSPhaser from './tns-phaser';
3
+ export default TNSPhaser;
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './tns-phaser';
2
2
  import * as TNSPhaser from './tns-phaser';
3
3
  export default TNSPhaser;
4
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/canvas-phaser-ce/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAC1C,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@nativescript/canvas-phaser-ce",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.12",
4
4
  "description": "Tools for using Phaser-ce to build native 2D games in NativeScript 👾",
5
- "main": "index.js",
5
+ "main": "index",
6
6
  "typings": "index.d.ts",
7
7
  "nativescript": {
8
8
  "platforms": {
@@ -32,8 +32,11 @@
32
32
  "homepage": "https://github.com/NativeScript/canvas",
33
33
  "readmeFilename": "README.md",
34
34
  "bootstrapper": "@nativescript/plugin-seed",
35
+ "dependencies": {
36
+ "@nativescript/canvas-polyfill": "beta",
37
+ "@nativescript/canvas": "1.0.0-alpha.17"
38
+ },
35
39
  "peerDependencies": {
36
- "@nativescript/canvas": "alpha",
37
40
  "phaser-ce": "2.15.0"
38
41
  }
39
- }
42
+ }
package/phaser.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ interface TNSPhaserCe {
2
+ PIXI: any;
3
+ Phaser: any;
4
+ }
5
+ export declare var global: TNSPhaserCe;
6
+ declare const _default: any;
7
+ export default _default;
package/phaser.js CHANGED
@@ -1,84 +1,47 @@
1
- import '@nativescript/canvas-polyfill';
2
-
1
+ require('@nativescript/canvas-polyfill');
3
2
  function initPhaser() {
4
- global.PIXI = global.window.PIXI = global.PIXI || require('phaser-ce/build/custom/pixi');
5
- global.p2 = global.window.p2 = global.p2 || require('phaser-ce/build/custom/p2');
6
- global.Phaser = global.window.Phaser = global.Phaser || require('phaser-ce/build/phaser');
7
-
8
- global.PIXI.WebGLRenderer.prototype.updateTexture = function (texture) {
9
- if (!texture.hasLoaded || texture.source.nodeName === 'CANVAS') {
10
- return false;
11
- }
12
- if (texture.source.compressionAlgorithm) {
13
- return this.updateCompressedTexture(texture);
14
- }
15
-
16
- var gl = this.gl;
17
-
18
- if (!texture._glTextures[gl.id]) {
19
- texture._glTextures[gl.id] = gl.createTexture();
20
- }
21
- gl.activeTexture(gl.TEXTURE0 + texture.textureIndex);
22
-
23
- gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
24
-
25
-
26
- gl.pixelStorei(
27
- gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,
28
- texture.premultipliedAlpha
29
- );
30
-
31
- gl.texImage2D(
32
- gl.TEXTURE_2D,
33
- 0,
34
- gl.RGBA,
35
- gl.RGBA,
36
- gl.UNSIGNED_BYTE,
37
- texture.source
38
- );
39
-
40
- gl.texParameteri(
41
- gl.TEXTURE_2D,
42
- gl.TEXTURE_MAG_FILTER,
43
- texture.scaleMode === global.PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST
44
- );
45
-
46
- if (
47
- texture.mipmap &&
48
- global.Phaser.Math.isPowerOfTwo(texture.width, texture.height)
49
- ) {
50
- gl.texParameteri(
51
- gl.TEXTURE_2D,
52
- gl.TEXTURE_MIN_FILTER,
53
- texture.scaleMode === global.PIXI.scaleModes.LINEAR
54
- ? gl.LINEAR_MIPMAP_LINEAR
55
- : gl.NEAREST_MIPMAP_NEAREST
56
- );
57
- gl.generateMipmap(gl.TEXTURE_2D);
58
- } else {
59
- gl.texParameteri(
60
- gl.TEXTURE_2D,
61
- gl.TEXTURE_MIN_FILTER,
62
- texture.scaleMode === global.PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST
63
- );
64
- }
65
-
66
- if (!texture._powerOf2) {
67
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
68
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
69
- } else {
70
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
71
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
72
- }
73
-
74
- texture._dirty[gl.id] = false;
75
-
76
- // return texture._glTextures[gl.id];
77
- return true;
78
- };
79
-
80
-
81
- return global.Phaser;
3
+ global.PIXI = global.window.PIXI = global.PIXI || require('phaser-ce/build/custom/pixi');
4
+ global.p2 = global.window.p2 = global.p2 || require('phaser-ce/build/custom/p2');
5
+ global.Phaser = global.window.Phaser = global.Phaser || require('phaser-ce/build/phaser');
6
+ global.PIXI.WebGLRenderer.prototype.updateTexture = function (texture) {
7
+ if (!texture.hasLoaded || texture.source.nodeName === 'CANVAS') {
8
+ return false;
9
+ }
10
+ if (texture.source.compressionAlgorithm) {
11
+ return this.updateCompressedTexture(texture);
12
+ }
13
+ var gl = this.gl;
14
+ if (!texture._glTextures[gl.id]) {
15
+ texture._glTextures[gl.id] = gl.createTexture();
16
+ }
17
+ gl.activeTexture(gl.TEXTURE0 + texture.textureIndex);
18
+ gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
19
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha);
20
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source);
21
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === global.PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
22
+ if (texture.mipmap &&
23
+ global.Phaser.Math.isPowerOfTwo(texture.width, texture.height)) {
24
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === global.PIXI.scaleModes.LINEAR
25
+ ? gl.LINEAR_MIPMAP_LINEAR
26
+ : gl.NEAREST_MIPMAP_NEAREST);
27
+ gl.generateMipmap(gl.TEXTURE_2D);
28
+ }
29
+ else {
30
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === global.PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST);
31
+ }
32
+ if (!texture._powerOf2) {
33
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
34
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
35
+ }
36
+ else {
37
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
38
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
39
+ }
40
+ texture._dirty[gl.id] = false;
41
+ // return texture._glTextures[gl.id];
42
+ return true;
43
+ };
44
+ return global.Phaser;
82
45
  }
83
-
84
46
  export default initPhaser();
47
+ //# sourceMappingURL=phaser.js.map
package/phaser.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phaser.js","sourceRoot":"","sources":["../../../packages/canvas-phaser-ce/phaser.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,+BAA+B,CAAC,CAA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AE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC;SACrE;aAAM;YACN,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;YAC9D,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC;SAC9D;QAED,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;QAE9B,qCAAqC;QACrC,OAAO,IAAI,CAAC;IACb,CAAC,CAAC;IAGF,OAAQ,MAAc,CAAC,MAAM,CAAC;AAC/B,CAAC;AAED,eAAe,UAAU,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default as Phaser } from './phaser';
2
+ export { default as Game } from './game';
package/tns-phaser.js CHANGED
@@ -1,2 +1,3 @@
1
- export {default as Phaser} from './phaser';
2
- export {default as Game} from './game';
1
+ export { default as Phaser } from './phaser';
2
+ export { default as Game } from './game';
3
+ //# sourceMappingURL=tns-phaser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tns-phaser.js","sourceRoot":"","sources":["../../../packages/canvas-phaser-ce/tns-phaser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAC,OAAO,IAAI,IAAI,EAAC,MAAM,QAAQ,CAAC"}