lyb-pixi-js 1.2.4 → 1.3.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.
package/README.md CHANGED
@@ -142,6 +142,8 @@ app.stage.addChild(box);
142
142
 
143
143
  \- [LibPixiSlideInput-滑块选择值](#LibPixiSlideInput-滑块选择值)
144
144
 
145
+ \- [LibGlobalUpdater-事件实例汇总](#LibGlobalUpdater-事件实例汇总)
146
+
145
147
  ## Base-基础
146
148
 
147
149
  ### LibPixiText-文本
@@ -262,11 +264,11 @@ import { LibPixiButtonHover } from "lyb-pixi-js";
262
264
 
263
265
  //创建按钮实例
264
266
  const button = new LibPixiButtonHover({
265
- texture: PIXI.Texture.from('path/to/normal.png'),
266
- hoverTexture: PIXI.Texture.from('path/to/hover.png'),
267
+ texture: PIXI.Texture.from("path/to/normal.png"),
268
+ hoverTexture: PIXI.Texture.from("path/to/hover.png"),
267
269
  tintColor: "#ff0000", //默认颜色
268
270
  hoverTintColor: "#00ff00", //悬浮颜色
269
- disabledColor: "#cccccc" //禁用颜色
271
+ disabledColor: "#cccccc", //禁用颜色
270
272
  });
271
273
 
272
274
  //启用/禁用按钮
@@ -275,8 +277,8 @@ button.setDisabled(true); //禁用
275
277
 
276
278
  //切换按钮材质
277
279
  button.toggleTexture(
278
- PIXI.Texture.from('path/to/new_normal.png'),
279
- PIXI.Texture.from('path/to/new_hover.png')
280
+ PIXI.Texture.from("path/to/new_normal.png"),
281
+ PIXI.Texture.from("path/to/new_hover.png")
280
282
  );
281
283
 
282
284
  //添加到Pixi舞台
@@ -492,17 +494,17 @@ const betControl = new LibPixiSubAddMinMax({
492
494
  } else if (type === "max") {
493
495
  maxButton.tint = 0x999999; //禁用最大按钮
494
496
  } else {
495
- minButton.tint = 0xFFFFFF; //启用最小按钮
496
- maxButton.tint = 0xFFFFFF; //启用最大按钮
497
+ minButton.tint = 0xffffff; //启用最小按钮
498
+ maxButton.tint = 0xffffff; //启用最大按钮
497
499
  }
498
- }
500
+ },
499
501
  });
500
502
 
501
503
  //设置初始状态
502
- betControl.min(); //设置为最小值
503
- betControl.max(); //设置为最大值
504
- betControl.sub(); //减少下注
505
- betControl.add(); //增加下注
504
+ betControl.min(); //设置为最小值
505
+ betControl.max(); //设置为最大值
506
+ betControl.sub(); //减少下注
507
+ betControl.add(); //增加下注
506
508
 
507
509
  //添加到Pixi舞台
508
510
  app.stage.addChild(minButton, maxButton, subButton, addButton);
@@ -652,7 +654,6 @@ stopInterval();
652
654
  > 点击容器外或入口按钮时隐藏
653
655
 
654
656
  ```ts
655
-
656
657
  let removeEventListener: () => void;
657
658
  const btn = new Sprite(Assets.get("btnIcon"));
658
659
  const optionList = new Container();
@@ -680,7 +681,7 @@ libPixiEvent(btn, "pointertap", () => {
680
681
  const mask = libPixiOverflowHidden(container); //为容器创建并应用矩形蒙版
681
682
  ```
682
683
 
683
- ### LibPixiPromiseTickerTimeout-TickerPromise定时器
684
+ ### LibPixiPromiseTickerTimeout-TickerPromise 定时器
684
685
 
685
686
  > 基于 Ticker 和 Promise 的定时器
686
687
 
@@ -714,7 +715,7 @@ libPixiShadow(container, {
714
715
  });
715
716
  ```
716
717
 
717
- ### LibPixiTickerTimeout-Ticker定时器
718
+ ### LibPixiTickerTimeout-Ticker 定时器
718
719
 
719
720
  > 基于 Ticker 的定时器
720
721
 
@@ -761,3 +762,32 @@ const slideInput = new LibPixiSlideInput({
761
762
  slideInput.setValue(0.5);
762
763
  ```
763
764
 
765
+ ### LibGlobalUpdater-事件实例汇总
766
+
767
+ > 将组件实例化后,将涉及通过事件总线更新的实例进行存储,用于事件总线统一在一个位置监听并通过从实例汇总中获取实例调用实例的方法进行更新
768
+
769
+ ```ts
770
+ //app.ts
771
+ this.gameUI = new GameUI();
772
+ this.addChild(this.gameUI);
773
+ globalUpdater.setInstance("GameUI", this.gameUI);
774
+
775
+ this.toolbarUI = new ToolbarUI();
776
+ this.addChild(this.toolbarUI);
777
+ globalUpdater.setInstance("ToolbarUI", this.toolbarUI);
778
+
779
+ //globalUpdater.ts
780
+ import type { GameUI } from "@/app/ui/GameUI";
781
+ import type { ToolbarUI } from "@/app/ui/ToolbarUI";
782
+
783
+ type Instances = "GameUI" | "ToolbarUI"
784
+ const globalUpdater = new GlobalUpdater<Instances>();
785
+ export { globalUpdater };
786
+
787
+ //开始游戏
788
+ $bus.on("play", () => {
789
+ globalUpdater.getInstance<GameUI>("GameUI").play();
790
+ globalUpdater.getInstance<ToolbarUI>("ToolbarUI").play();
791
+ });
792
+ ```
793
+
@@ -0,0 +1,15 @@
1
+ import type { Container } from "pixi.js";
2
+ /** @description 事件总线更新实例汇总 */
3
+ export declare class LibGlobalUpdater<Instances> {
4
+ /** 实例列表 */
5
+ private instances;
6
+ /** @description 存储实例
7
+ * @param key 实例key
8
+ * @param instance 实例
9
+ */
10
+ setInstance(key: Instances, instance: Container): void;
11
+ /** @description 获取实例
12
+ * @param key 实例key
13
+ */
14
+ getInstance<T>(key: Instances): T;
15
+ }
@@ -0,0 +1,21 @@
1
+ /** @description 事件总线更新实例汇总 */
2
+ export class LibGlobalUpdater {
3
+ constructor() {
4
+ /** 实例列表 */
5
+ this.instances = new Map();
6
+ }
7
+ /** @description 存储实例
8
+ * @param key 实例key
9
+ * @param instance 实例
10
+ */
11
+ setInstance(key, instance) {
12
+ this.instances.has(key) && this.instances.delete(key);
13
+ this.instances.set(key, instance);
14
+ }
15
+ /** @description 获取实例
16
+ * @param key 实例key
17
+ */
18
+ getInstance(key) {
19
+ return this.instances.get(key);
20
+ }
21
+ }
@@ -118,9 +118,11 @@ export class LibPixiAudio {
118
118
  }
119
119
  /** @description 继续播放音乐 */
120
120
  resumeMusic() {
121
- var _a;
121
+ var _a, _b;
122
122
  this._isMusicPaused = false;
123
- (_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.play();
123
+ if ((_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.playing())
124
+ return;
125
+ (_b = this._musicPlayer) === null || _b === void 0 ? void 0 : _b.play();
124
126
  }
125
127
  /** @description 停止播放指定音效
126
128
  * @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
package/libPixiJs.d.ts CHANGED
@@ -16,6 +16,7 @@ import { LibPixiSubAddMinMax } from "./Components/Custom/LibPixiSubAddMinMax";
16
16
  import { LibPixiTable } from "./Components/Custom/LibPixiTable";
17
17
  import { LibPixiAudio } from "./Utils/LibPixiAudio";
18
18
  import { LibPixiSlideInput } from "./Utils/LibPixiSlideInput";
19
+ import { LibGlobalUpdater } from "./Utils/LibGlobalUpdater";
19
20
  /** @description 组件 */
20
21
  export declare const Components: {
21
22
  Base: {
@@ -165,4 +166,8 @@ export declare const Utils: {
165
166
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlideInput-滑动选择值
166
167
  */
167
168
  LibPixiSlideInput: typeof LibPixiSlideInput;
169
+ /** @description 事件总线更新实例汇总
170
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibGlobalUpdater-事件实例汇总
171
+ */
172
+ LibGlobalUpdater: typeof LibGlobalUpdater;
168
173
  };
package/libPixiJs.js CHANGED
@@ -27,6 +27,7 @@ import { libPixiFilter } from "./Utils/LibPixiFilter";
27
27
  import { libPixiShadow } from "./Utils/LibPixiShadow";
28
28
  import { libPixiTickerTimeout } from "./Utils/LibPixiTickerTimeout";
29
29
  import { LibPixiSlideInput } from "./Utils/LibPixiSlideInput";
30
+ import { LibGlobalUpdater } from "./Utils/LibGlobalUpdater";
30
31
  /** @description 组件 */
31
32
  export const Components = {
32
33
  Base: {
@@ -176,4 +177,8 @@ export const Utils = {
176
177
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlideInput-滑动选择值
177
178
  */
178
179
  LibPixiSlideInput,
180
+ /** @description 事件总线更新实例汇总
181
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibGlobalUpdater-事件实例汇总
182
+ */
183
+ LibGlobalUpdater,
179
184
  };