@safe-engine/pixi 1.0.0 → 1.0.1

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.
@@ -1,4 +1,4 @@
1
- import { Size, Vec2 } from '..';
1
+ import { Point } from 'pixi.js';
2
2
  import { Color4B } from '../core/Color';
3
3
  import { ComponentX, NoRenderComponentX } from '../core/decorator';
4
4
  import { LoadingBarMode } from '../core/LoadingBar';
@@ -46,7 +46,7 @@ export declare class ProgressTimerComp extends ComponentX {
46
46
  spriteFrame: string;
47
47
  fillType: Values;
48
48
  fillRange: number;
49
- fillCenter: Vec2;
49
+ fillCenter: Point;
50
50
  isReverse: boolean;
51
51
  getFillRange(): void;
52
52
  setFillStart(val: number): void;
@@ -66,7 +66,7 @@ export declare class LabelOutlineComp extends NoRenderComponentX {
66
66
  export declare class LabelShadowComp extends NoRenderComponentX {
67
67
  color: typeof Color4B;
68
68
  blur: number;
69
- offset: Size;
69
+ offset: Point;
70
70
  }
71
71
  export {};
72
72
  //# sourceMappingURL=GUIComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GUIComponent.d.ts","sourceRoot":"","sources":["../../src/components/GUIComponent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAc,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAI/D,eAAO,MAAM,QAAQ;;;;CAIpB,CAAA;AACD,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,CAAA;AACjC,KAAK,MAAM,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAA;AAErC,qBAAa,UAAW,SAAQ,kBAAkB;IAChD,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,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,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,KAAK,CAAA;CACd"}
package/dist/index.d.ts CHANGED
@@ -5,7 +5,6 @@ export * from './components/RenderComponent';
5
5
  export { ComponentX, NoRenderComponentX } from './core/decorator';
6
6
  export { SceneComponent } from './core/Scene';
7
7
  export * from './core/Size';
8
- export { Vec2 } from './core/Vec2';
9
8
  export { GameWorld } from './gworld';
10
9
  export { instantiate, registerSystem } from './helper/utils';
11
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,SAAS,EAAC,eAAe,EAAE,MAAM,OAAO,CAAA;AACvE,cAAc,2BAA2B,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAG,IAAI,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,SAAS,EAAC,eAAe,EAAE,MAAM,OAAO,CAAA;AACvE,cAAc,2BAA2B,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,cAAc,8BAA8B,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.registerSystem = exports.instantiate = exports.GameWorld = exports.Vec2 = exports.SceneComponent = exports.NoRenderComponentX = exports.ComponentX = exports.NodeComp = exports.setupResolution = exports.initWorld = exports.app = exports.addGameCanvasTo = void 0;
17
+ exports.registerSystem = exports.instantiate = exports.GameWorld = exports.SceneComponent = exports.NoRenderComponentX = exports.ComponentX = exports.NodeComp = exports.setupResolution = exports.initWorld = exports.app = exports.addGameCanvasTo = void 0;
18
18
  var app_1 = require("./app");
19
19
  Object.defineProperty(exports, "addGameCanvasTo", { enumerable: true, get: function () { return app_1.addGameCanvasTo; } });
20
20
  Object.defineProperty(exports, "app", { enumerable: true, get: function () { return app_1.app; } });
@@ -30,8 +30,6 @@ Object.defineProperty(exports, "NoRenderComponentX", { enumerable: true, get: fu
30
30
  var Scene_1 = require("./core/Scene");
31
31
  Object.defineProperty(exports, "SceneComponent", { enumerable: true, get: function () { return Scene_1.SceneComponent; } });
32
32
  __exportStar(require("./core/Size"), exports);
33
- var Vec2_1 = require("./core/Vec2");
34
- Object.defineProperty(exports, "Vec2", { enumerable: true, get: function () { return Vec2_1.Vec2; } });
35
33
  var gworld_1 = require("./gworld");
36
34
  Object.defineProperty(exports, "GameWorld", { enumerable: true, get: function () { return gworld_1.GameWorld; } });
37
35
  var utils_1 = require("./helper/utils");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@safe-engine/pixi",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,147 +1,146 @@
1
- import { Assets, Text } from 'pixi.js'
2
-
3
- import { Size, Vec2 } from '..'
4
- import { Color4B } from '../core/Color'
5
- import { ComponentX, NoRenderComponentX } from '../core/decorator'
6
- import { LoadingBar, LoadingBarMode } from '../core/LoadingBar'
7
- import { HtmlTextParser } from '../helper/html-text-parser'
8
-
9
- const _htmlTextParser = new HtmlTextParser()
10
- export const FillType = {
11
- HORIZONTAL: 0,
12
- VERTICAL: 1,
13
- RADIAL: 2,
14
- }
15
- type Keys = keyof typeof FillType
16
- type Values = (typeof FillType)[Keys]
17
-
18
- export class ButtonComp extends NoRenderComponentX {
19
- normalImage: string
20
- selectedImage: string
21
- disableImage: string
22
- zoomScale: number
23
- onPress: (target: ButtonComp) => void
24
-
25
- setOnPress(cb: (target: ButtonComp) => void) {
26
- this.onPress = cb
27
- }
28
-
29
- set enabled(val) {
30
- this.node.instance.interactive = val
31
- }
32
- }
33
-
34
- export class ProgressBarComp extends NoRenderComponentX {
35
- mode = LoadingBarMode.BAR
36
- private _progress: number
37
- isReverse: boolean
38
-
39
- get progress() {
40
- return this._progress
41
- }
42
-
43
- set progress(val: number) {
44
- this._progress = val
45
- ;(this.node.instance as LoadingBar).progress = val
46
- }
47
- }
48
-
49
- export class LabelComp extends ComponentX {
50
- font: string
51
- string: string
52
- size = 64
53
-
54
- getString() {
55
- if (this.node.instance instanceof Text) {
56
- return this.node.instance.text
57
- }
58
- }
59
-
60
- setString(val: string) {
61
- if (this.node.instance instanceof Text) {
62
- this.node.instance.text = val
63
- }
64
- }
65
-
66
- getSize() {
67
- if (this.node.instance instanceof Text) {
68
- return this.node.instance.style.fontSize
69
- }
70
- }
71
- setSize(val) {
72
- if (this.node.instance instanceof Text) {
73
- this.node.instance.style.fontSize = val
74
- }
75
- }
76
-
77
- getFont() {
78
- if (this.node.instance instanceof Text) {
79
- return this.node.instance.style.fontFamily as string
80
- }
81
- }
82
-
83
- setFont(val: string) {
84
- // console.log('set font', val, Assets.get(val))
85
- if (this.node.instance instanceof Text) {
86
- if (Assets.get(val)) this.node.instance.style.fontFamily = Assets.get(val).family
87
- }
88
- }
89
- }
90
-
91
- export class ScrollView extends ComponentX {
92
- width: number
93
- height: number
94
- }
95
-
96
- export class BlockInputEventsComp extends NoRenderComponentX {}
97
-
98
- export class ProgressTimerComp extends ComponentX {
99
- spriteFrame: string
100
- fillType: Values
101
- fillRange: number
102
- fillCenter: Vec2
103
- isReverse: boolean
104
-
105
- getFillRange() {
106
- // if (this.node.instance instanceof cc.ProgressTimer) {
107
- // return this.node.instance.getPercentage() * 0.01
108
- // }
109
- }
110
-
111
- setFillStart(val: number) {
112
- // if (this.node.instance instanceof cc.ProgressTimer) {
113
- // this.node.instance.setMidpoint(Vec2(val, val))
114
- // }
115
- }
116
-
117
- setFillRange(val: number) {
118
- // if (this.node.instance instanceof cc.ProgressTimer) {
119
- // this.node.instance.setPercentage(val * 100)
120
- // }
121
- }
122
- }
123
-
124
- export class RichTextComp extends ComponentX {
125
- protected font: string
126
- protected string: string
127
- protected size: number
128
-
129
- getString() {
130
- return this.string
131
- }
132
-
133
- setString(val: string) {
134
- this.string = val
135
- }
136
- }
137
-
138
- export class LabelOutlineComp extends NoRenderComponentX {
139
- color: typeof Color4B
140
- width: number
141
- }
142
-
143
- export class LabelShadowComp extends NoRenderComponentX {
144
- color: typeof Color4B
145
- blur: number
146
- offset: Size
1
+ import { Assets, Point, Text } from 'pixi.js'
2
+
3
+ import { Color4B } from '../core/Color'
4
+ import { ComponentX, NoRenderComponentX } from '../core/decorator'
5
+ import { LoadingBar, LoadingBarMode } from '../core/LoadingBar'
6
+ import { HtmlTextParser } from '../helper/html-text-parser'
7
+
8
+ const _htmlTextParser = new HtmlTextParser()
9
+ export const FillType = {
10
+ HORIZONTAL: 0,
11
+ VERTICAL: 1,
12
+ RADIAL: 2,
13
+ }
14
+ type Keys = keyof typeof FillType
15
+ type Values = (typeof FillType)[Keys]
16
+
17
+ export class ButtonComp extends NoRenderComponentX {
18
+ normalImage: string
19
+ selectedImage: string
20
+ disableImage: string
21
+ zoomScale: number
22
+ onPress: (target: ButtonComp) => void
23
+
24
+ setOnPress(cb: (target: ButtonComp) => void) {
25
+ this.onPress = cb
26
+ }
27
+
28
+ set enabled(val) {
29
+ this.node.instance.interactive = val
30
+ }
31
+ }
32
+
33
+ export class ProgressBarComp extends NoRenderComponentX {
34
+ mode = LoadingBarMode.BAR
35
+ private _progress: number
36
+ isReverse: boolean
37
+
38
+ get progress() {
39
+ return this._progress
40
+ }
41
+
42
+ set progress(val: number) {
43
+ this._progress = val
44
+ ;(this.node.instance as LoadingBar).progress = val
45
+ }
46
+ }
47
+
48
+ export class LabelComp extends ComponentX {
49
+ font: string
50
+ string: string
51
+ size = 64
52
+
53
+ getString() {
54
+ if (this.node.instance instanceof Text) {
55
+ return this.node.instance.text
56
+ }
57
+ }
58
+
59
+ setString(val: string) {
60
+ if (this.node.instance instanceof Text) {
61
+ this.node.instance.text = val
62
+ }
63
+ }
64
+
65
+ getSize() {
66
+ if (this.node.instance instanceof Text) {
67
+ return this.node.instance.style.fontSize
68
+ }
69
+ }
70
+ setSize(val) {
71
+ if (this.node.instance instanceof Text) {
72
+ this.node.instance.style.fontSize = val
73
+ }
74
+ }
75
+
76
+ getFont() {
77
+ if (this.node.instance instanceof Text) {
78
+ return this.node.instance.style.fontFamily as string
79
+ }
80
+ }
81
+
82
+ setFont(val: string) {
83
+ // console.log('set font', val, Assets.get(val))
84
+ if (this.node.instance instanceof Text) {
85
+ if (Assets.get(val)) this.node.instance.style.fontFamily = Assets.get(val).family
86
+ }
87
+ }
88
+ }
89
+
90
+ export class ScrollView extends ComponentX {
91
+ width: number
92
+ height: number
93
+ }
94
+
95
+ export class BlockInputEventsComp extends NoRenderComponentX {}
96
+
97
+ export class ProgressTimerComp extends ComponentX {
98
+ spriteFrame: string
99
+ fillType: Values
100
+ fillRange: number
101
+ fillCenter: Point
102
+ isReverse: boolean
103
+
104
+ getFillRange() {
105
+ // if (this.node.instance instanceof cc.ProgressTimer) {
106
+ // return this.node.instance.getPercentage() * 0.01
107
+ // }
108
+ }
109
+
110
+ setFillStart(val: number) {
111
+ // if (this.node.instance instanceof cc.ProgressTimer) {
112
+ // this.node.instance.setMidpoint(Vec2(val, val))
113
+ // }
114
+ }
115
+
116
+ setFillRange(val: number) {
117
+ // if (this.node.instance instanceof cc.ProgressTimer) {
118
+ // this.node.instance.setPercentage(val * 100)
119
+ // }
120
+ }
121
+ }
122
+
123
+ export class RichTextComp extends ComponentX {
124
+ protected font: string
125
+ protected string: string
126
+ protected size: number
127
+
128
+ getString() {
129
+ return this.string
130
+ }
131
+
132
+ setString(val: string) {
133
+ this.string = val
134
+ }
135
+ }
136
+
137
+ export class LabelOutlineComp extends NoRenderComponentX {
138
+ color: typeof Color4B
139
+ width: number
140
+ }
141
+
142
+ export class LabelShadowComp extends NoRenderComponentX {
143
+ color: typeof Color4B
144
+ blur: number
145
+ offset: Point
147
146
  }
package/src/index.ts CHANGED
@@ -1,10 +1,9 @@
1
- export { addGameCanvasTo, app, initWorld,setupResolution } from './app'
2
- export * from './components/GUIComponent'
3
- export { NodeComp } from './components/NodeComp'
4
- export * from './components/RenderComponent'
5
- export { ComponentX, NoRenderComponentX } from './core/decorator'
6
- export { SceneComponent } from './core/Scene'
7
- export * from './core/Size'
8
- export { Vec2 } from './core/Vec2'
9
- export { GameWorld } from './gworld'
10
- export { instantiate, registerSystem } from './helper/utils'
1
+ export { addGameCanvasTo, app, initWorld,setupResolution } from './app'
2
+ export * from './components/GUIComponent'
3
+ export { NodeComp } from './components/NodeComp'
4
+ export * from './components/RenderComponent'
5
+ export { ComponentX, NoRenderComponentX } from './core/decorator'
6
+ export { SceneComponent } from './core/Scene'
7
+ export * from './core/Size'
8
+ export { GameWorld } from './gworld'
9
+ export { instantiate, registerSystem } from './helper/utils'
package/src/core/Vec2.ts DELETED
@@ -1,52 +0,0 @@
1
- import clamp from 'lodash/clamp';
2
- import { Point } from 'pixi.js'
3
-
4
- class _Vec2 extends Point {
5
- x: number
6
- y: number
7
- static ZERO
8
-
9
- equals(other: Point) {
10
- return this.x === other.x && this.y === other.y
11
- }
12
-
13
- addSelf(value: Point): Point {
14
- const nor = value.add(new Point(this.x, this.y))
15
- this.x = nor.x
16
- this.y = nor.y
17
- return nor
18
- }
19
-
20
- public cross(other: Vec2) {
21
- return this.x * other.y - this.y * other.x
22
- }
23
- public signAngle(other: Vec2) {
24
- const angle = this.angle(other)
25
- return this.cross(other) < 0 ? -angle : angle
26
- }
27
- public lengthSqr() {
28
- return this.x * this.x + this.y * this.y
29
- }
30
- public dot(other: Vec2) {
31
- return this.x * other.x + this.y * other.y
32
- }
33
- public angle(other: Vec2) {
34
- const magSqr1 = this.lengthSqr()
35
- const magSqr2 = other.lengthSqr()
36
-
37
- if (magSqr1 === 0 || magSqr2 === 0) {
38
- console.warn('Cant get angle between zero vector')
39
- return 0.0
40
- }
41
-
42
- const dot = this.dot(other)
43
- let theta = dot / Math.sqrt(magSqr1 * magSqr2)
44
- theta = clamp(theta, -1.0, 1.0)
45
- return Math.acos(theta)
46
- }
47
- }
48
- export type Vec2 = _Vec2
49
- export function Vec2(x = 0, y = 0): Vec2 {
50
- return new _Vec2(x, y)
51
- }
52
- Vec2.ZERO = Object.freeze(Vec2(0, 0))