lyb-pixi-js 1.0.22 → 1.1.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.
Files changed (61) hide show
  1. package/README.md +484 -1
  2. package/dist/Components/Custom/LibPixiButtonHover/index.d.ts +32 -0
  3. package/dist/Components/Custom/LibPixiButtonHover/index.js +44 -0
  4. package/dist/Components/Custom/LibPixiCloseBtn/index.d.ts +14 -0
  5. package/dist/Components/Custom/LibPixiCloseBtn/index.js +35 -0
  6. package/dist/Components/Custom/LibPixiDrawer/index.d.ts +16 -0
  7. package/dist/Components/Custom/LibPixiDrawer/index.js +59 -0
  8. package/dist/Components/Custom/LibPixiPerforMon/index.d.ts +31 -0
  9. package/dist/Components/Custom/LibPixiPerforMon/index.js +107 -0
  10. package/dist/Components/Custom/LibPixiProgress/index.d.ts +29 -0
  11. package/dist/Components/Custom/LibPixiProgress/index.js +36 -0
  12. package/dist/Components/Custom/LibPixiScrollContainer/index.d.ts +57 -0
  13. package/dist/Components/Custom/LibPixiScrollContainer/index.js +166 -0
  14. package/dist/Components/Custom/LibPixiScrollNum/index.d.ts +62 -0
  15. package/dist/Components/Custom/LibPixiScrollNum/index.js +146 -0
  16. package/dist/Components/Custom/LibPixiSlider/index.d.ts +45 -0
  17. package/dist/Components/Custom/LibPixiSlider/index.js +111 -0
  18. package/dist/Components/Custom/LibPixiSubAddMinMax/index.d.ts +49 -0
  19. package/dist/Components/Custom/LibPixiSubAddMinMax/index.js +75 -0
  20. package/dist/Components/Custom/LibPixiTable/index.d.ts +52 -0
  21. package/dist/Components/Custom/LibPixiTable/index.js +70 -0
  22. package/dist/Utils/LibPixiAudio/index.d.ts +34 -0
  23. package/dist/Utils/LibPixiAudio/index.js +140 -0
  24. package/dist/Utils/LibPixiCreateNineGrid/index.d.ts +15 -0
  25. package/dist/Utils/LibPixiCreateNineGrid/index.js +19 -0
  26. package/dist/Utils/LibPixiEvent/index.d.ts +9 -0
  27. package/dist/Utils/LibPixiEvent/index.js +22 -0
  28. package/dist/Utils/LibPixiEventControlled/index.d.ts +8 -0
  29. package/dist/Utils/LibPixiEventControlled/index.js +21 -0
  30. package/dist/Utils/LibPixiFilter/index.d.ts +9 -0
  31. package/dist/Utils/LibPixiFilter/index.js +30 -0
  32. package/dist/Utils/LibPixiIntervalTrigger/index.d.ts +6 -0
  33. package/dist/Utils/LibPixiIntervalTrigger/index.js +33 -0
  34. package/dist/Utils/LibPixiOutsideClick/index.d.ts +8 -0
  35. package/dist/Utils/LibPixiOutsideClick/index.js +22 -0
  36. package/dist/Utils/LibPixiOverflowHidden/index.d.ts +6 -0
  37. package/dist/Utils/LibPixiOverflowHidden/index.js +14 -0
  38. package/dist/Utils/LibPixiPromiseTickerTimeout/index.d.ts +6 -0
  39. package/dist/Utils/LibPixiPromiseTickerTimeout/index.js +22 -0
  40. package/dist/Utils/LibPixiScaleContainer/index.d.ts +8 -0
  41. package/dist/Utils/LibPixiScaleContainer/index.js +14 -0
  42. package/dist/Utils/LibPixiShadow/index.d.ts +17 -0
  43. package/dist/Utils/LibPixiShadow/index.js +18 -0
  44. package/dist/Utils/LibPixiTickerTimeout/index.d.ts +6 -0
  45. package/dist/Utils/LibPixiTickerTimeout/index.js +28 -0
  46. package/dist/libPixiJs.d.ts +155 -25
  47. package/dist/libPixiJs.js +166 -25
  48. package/package.json +6 -1
  49. package/umd/lyb-pixi.js +222 -128
  50. /package/dist/{Base → Components/Base}/LibPixiBitText/index.d.ts +0 -0
  51. /package/dist/{Base → Components/Base}/LibPixiBitText/index.js +0 -0
  52. /package/dist/{Base → Components/Base}/LibPixiContainer/index.d.ts +0 -0
  53. /package/dist/{Base → Components/Base}/LibPixiContainer/index.js +0 -0
  54. /package/dist/{Base → Components/Base}/LibPixiParticleMove/index.d.ts +0 -0
  55. /package/dist/{Base → Components/Base}/LibPixiParticleMove/index.js +0 -0
  56. /package/dist/{Base → Components/Base}/LibPixiRectBgColor/index.d.ts +0 -0
  57. /package/dist/{Base → Components/Base}/LibPixiRectBgColor/index.js +0 -0
  58. /package/dist/{Base → Components/Base}/LibPixiSpine/index.d.ts +0 -0
  59. /package/dist/{Base → Components/Base}/LibPixiSpine/index.js +0 -0
  60. /package/dist/{Base → Components/Base}/LibPixiText/index.d.ts +0 -0
  61. /package/dist/{Base → Components/Base}/LibPixiText/index.js +0 -0
@@ -0,0 +1,111 @@
1
+ import gsap from "gsap";
2
+ import { LibPixiContainer } from "../../Base/LibPixiContainer";
3
+ import { libPixiOverflowHidden } from "../../../Utils/LibPixiOverflowHidden";
4
+ /** @description 类似轮播图,但是不会自动轮播
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
6
+ */
7
+ export class LibPixiSlider extends LibPixiContainer {
8
+ /**
9
+ * @param width 宽度
10
+ * @param height 高度
11
+ * @param content 内容
12
+ * @param slideCallback 滑动结束回调
13
+ */
14
+ constructor(width, height, content, slideCallback) {
15
+ super(width, height);
16
+ /** 当前幻灯片索引 */
17
+ this._currentIndex = 0;
18
+ /** 滑动区域宽度 */
19
+ this._slideWidth = 0;
20
+ /** 记录拖动开始时的X坐标 */
21
+ this._startX = 0;
22
+ /** 偏移量 */
23
+ this._offsetX = 0;
24
+ /** 最大索引 */
25
+ this._pageNum = 0;
26
+ /** 记录开始时间 */
27
+ this._startTime = new Date().getTime();
28
+ /* 是否正在拖动 */
29
+ this._isDragging = false;
30
+ libPixiOverflowHidden(this);
31
+ this._slideWidth = width;
32
+ this._slideArea = content;
33
+ this.slideCallback = slideCallback;
34
+ this._pageNum = Math.floor(content.width / this._slideWidth) - 1;
35
+ this.addChild(content);
36
+ // 监听拖动事件
37
+ this.eventMode = "static";
38
+ this.cursor = "pointer";
39
+ this.on("pointerdown", this._onDragStart);
40
+ window.addEventListener("pointermove", this._onDragMove.bind(this));
41
+ window.addEventListener("pointerup", this._onDragEnd.bind(this));
42
+ }
43
+ /** @description 上一页 */
44
+ prev() {
45
+ this._slideTo(this._currentIndex - 1);
46
+ }
47
+ /** @description 下一页 */
48
+ next() {
49
+ this._slideTo(this._currentIndex + 1);
50
+ }
51
+ /** @description 滑动到指定索引
52
+ * @param index 索引
53
+ */
54
+ _slideTo(index) {
55
+ if (index < 0) {
56
+ // 回弹到第一张
57
+ gsap.to(this._slideArea, { x: 0, duration: 0.25 });
58
+ this._currentIndex = 0;
59
+ }
60
+ else if (index > this._pageNum) {
61
+ // 回弹到最后一张
62
+ gsap.to(this._slideArea, {
63
+ x: -this._pageNum * this._slideWidth,
64
+ duration: 0.5,
65
+ });
66
+ this._currentIndex = this._pageNum;
67
+ }
68
+ else {
69
+ // 正常滑动
70
+ this._currentIndex = index;
71
+ gsap.to(this._slideArea, {
72
+ x: -this._currentIndex * this._slideWidth,
73
+ duration: 0.25,
74
+ });
75
+ }
76
+ this.slideCallback(this._currentIndex, this._pageNum);
77
+ }
78
+ /** @description 开始拖动 */
79
+ _onDragStart(event) {
80
+ this._isDragging = true;
81
+ this._startX = event.global.x;
82
+ this._offsetX = this._slideArea.x;
83
+ gsap.killTweensOf(this._slideArea);
84
+ this._startTime = new Date().getTime();
85
+ }
86
+ /** @description 拖动中 */
87
+ _onDragMove(event) {
88
+ if (!this._isDragging)
89
+ return;
90
+ const moveX = event.pageX - this._startX;
91
+ this._slideArea.x = this._offsetX + moveX;
92
+ }
93
+ /** @description 结束拖动 */
94
+ _onDragEnd(event) {
95
+ if (!this._isDragging)
96
+ return;
97
+ this._isDragging = false;
98
+ const endTime = new Date().getTime() - this._startTime;
99
+ const slide = this._startX - event.pageX;
100
+ const slideSpeed = Math.abs(slide) / endTime;
101
+ //滑动距离阈值,滑动到一半以上必定翻页
102
+ const slideThreshold = this._slideWidth / 2;
103
+ //滑动速度阈值,滑动速度大于这个值,必定翻页
104
+ const speedThreshold = 0.275;
105
+ //如果滑动距离大于阈值,或速度大于阈值翻页
106
+ if (Math.abs(slide) > slideThreshold || slideSpeed > speedThreshold) {
107
+ slide > 0 ? this._currentIndex++ : this._currentIndex--;
108
+ }
109
+ this._slideTo(this._currentIndex);
110
+ }
111
+ }
@@ -0,0 +1,49 @@
1
+ import type { Container } from "pixi.js";
2
+ export interface LibPixiSubAddMinMaxParams {
3
+ /** 最小按钮 */
4
+ minBtn: Container;
5
+ /** 最大按钮 */
6
+ maxBtn: Container;
7
+ /** 增加按钮 */
8
+ subBtn: Container;
9
+ /** 减少按钮 */
10
+ addBtn: Container;
11
+ /** 初始下注索引 */
12
+ initialBetIndex: number;
13
+ /** 下注金额列表 */
14
+ betAmountListLength: number;
15
+ /** 金额更新回调 */
16
+ onAmountIndex: (index: number) => void;
17
+ }
18
+ /** @description 最小、最大按钮和增减按钮功能及置灰逻辑
19
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
20
+ */
21
+ export declare class LibPixiSubAddMinMax {
22
+ /** 步进器 */
23
+ private baseNumSteper;
24
+ /** 最大最小按钮 */
25
+ private minBtn;
26
+ private maxBtn;
27
+ /** 增加减少按钮 */
28
+ private subBtn;
29
+ private addBtn;
30
+ /** 金额列表数量 */
31
+ private betAmountListLength;
32
+ /** 金额更新回调 */
33
+ onAmountIndex: (index: number) => void;
34
+ constructor(params: LibPixiSubAddMinMaxParams);
35
+ /** @description 点击最小按钮 */
36
+ min(): void;
37
+ /** @description 点击最大按钮 */
38
+ max(): void;
39
+ /** @description 点击减少按钮 */
40
+ sub(): void;
41
+ /** @description 点击增加按钮 */
42
+ add(): void;
43
+ /** @description 改变最小最大按钮状态及回调
44
+ * @param index 索引
45
+ */
46
+ minMaxUpdateIndex(index: number): void;
47
+ /** @description 设置最大最小按钮置灰及恢复 */
48
+ private _setGrey;
49
+ }
@@ -0,0 +1,75 @@
1
+ import { LibJsNumerStepper } from "lyb-js/dist/Misc/LibJsNumerStepper";
2
+ import { libPixiFilter } from '../../../Utils/LibPixiFilter';
3
+ /** @description 最小、最大按钮和增减按钮功能及置灰逻辑
4
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
5
+ */
6
+ export class LibPixiSubAddMinMax {
7
+ constructor(params) {
8
+ /** 金额列表数量 */
9
+ this.betAmountListLength = 0;
10
+ const { minBtn, maxBtn, addBtn, subBtn, initialBetIndex, betAmountListLength, onAmountIndex, } = params;
11
+ this.minBtn = minBtn;
12
+ this.maxBtn = maxBtn;
13
+ this.subBtn = subBtn;
14
+ this.addBtn = addBtn;
15
+ this.onAmountIndex = onAmountIndex;
16
+ this.betAmountListLength = betAmountListLength;
17
+ //金额增减步进器
18
+ this.baseNumSteper = new LibJsNumerStepper(betAmountListLength, (index) => {
19
+ this.onAmountIndex(index);
20
+ this.minMaxUpdateIndex(index);
21
+ });
22
+ //设置初始状态
23
+ this.minMaxUpdateIndex(initialBetIndex);
24
+ this.baseNumSteper.updateIndex(initialBetIndex);
25
+ }
26
+ /** @description 点击最小按钮 */
27
+ min() {
28
+ this.minMaxUpdateIndex(0);
29
+ this.onAmountIndex(0);
30
+ }
31
+ /** @description 点击最大按钮 */
32
+ max() {
33
+ const index = this.betAmountListLength - 1;
34
+ this.minMaxUpdateIndex(index);
35
+ this.onAmountIndex(index);
36
+ }
37
+ /** @description 点击减少按钮 */
38
+ sub() {
39
+ this.baseNumSteper.down("sub");
40
+ }
41
+ /** @description 点击增加按钮 */
42
+ add() {
43
+ this.baseNumSteper.down("add");
44
+ }
45
+ /** @description 改变最小最大按钮状态及回调
46
+ * @param index 索引
47
+ */
48
+ minMaxUpdateIndex(index) {
49
+ if (index === 0) {
50
+ this._setGrey("min");
51
+ }
52
+ else if (index === this.betAmountListLength - 1) {
53
+ this._setGrey("max");
54
+ }
55
+ else {
56
+ this._setGrey();
57
+ }
58
+ this.baseNumSteper.updateIndex(index);
59
+ }
60
+ /** @description 设置最大最小按钮置灰及恢复 */
61
+ _setGrey(type) {
62
+ this.minBtn.filters = [];
63
+ this.maxBtn.filters = [];
64
+ this.subBtn.filters = [];
65
+ this.addBtn.filters = [];
66
+ if (type === "min") {
67
+ this.minBtn.filters = [libPixiFilter("desaturate")];
68
+ this.subBtn.filters = [libPixiFilter("desaturate")];
69
+ }
70
+ else if (type === "max") {
71
+ this.maxBtn.filters = [libPixiFilter("desaturate")];
72
+ this.addBtn.filters = [libPixiFilter("desaturate")];
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,52 @@
1
+ /** @description 表格绘制并填入数字 */
2
+ import { Container } from "pixi.js";
3
+ export interface LibPixiTableParams {
4
+ /** 表格数据 */
5
+ data: (number | string)[][];
6
+ /** 单元格宽度 */
7
+ cellWidth?: number;
8
+ /** 单元格高度 */
9
+ cellHeight?: number;
10
+ /** 字体大小 */
11
+ fontSize?: number;
12
+ /** 字体颜色 */
13
+ fontColor?: string;
14
+ /** 线条厚度 */
15
+ lineWidth?: number;
16
+ /** 线条颜色 */
17
+ lineColor?: string;
18
+ }
19
+ /** @description 绘制表格并填充数字
20
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
21
+ */
22
+ export declare class LibPixiTable extends Container {
23
+ /** 行数 */
24
+ private _rows;
25
+ /** 列数 */
26
+ private _cols;
27
+ /** 单元格宽度 */
28
+ private _cellWidth;
29
+ /** 单元格高度 */
30
+ private _cellHeight;
31
+ /** 字体大小 */
32
+ private _fontSize;
33
+ /** 线条宽度 */
34
+ private _lineWidth;
35
+ /** 字体颜色 */
36
+ private _fontColor;
37
+ /** 线条颜色 */
38
+ private _lineColor;
39
+ /** 二维数字数组 */
40
+ private _data;
41
+ constructor(params: LibPixiTableParams);
42
+ /** @description 绘制表格 */
43
+ private _drawTable;
44
+ /** @description 填充数字 */
45
+ private fillNumbers;
46
+ /** @description 创建数字文本
47
+ * @param number 数字
48
+ * @param col 列索引
49
+ * @param row 行索引
50
+ */
51
+ private _createNumberText;
52
+ }
@@ -0,0 +1,70 @@
1
+ /** @description 表格绘制并填入数字 */
2
+ import { Text, Container, Graphics } from "pixi.js";
3
+ import { libPixiScaleContainer } from "../../../Utils/LibPixiScaleContainer";
4
+ /** @description 绘制表格并填充数字
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiTable-数字表格
6
+ */
7
+ export class LibPixiTable extends Container {
8
+ constructor(params) {
9
+ super();
10
+ const { data, cellWidth = 130, cellHeight = 100, fontColor = "#B4B4B8", fontSize = 24, lineWidth = 3, lineColor = "#B4B4B8", } = params;
11
+ this._data = data;
12
+ this._rows = data.length;
13
+ this._cols = data[0].length;
14
+ this._cellWidth = cellWidth;
15
+ this._cellHeight = cellHeight;
16
+ this._fontColor = fontColor;
17
+ this._fontSize = fontSize;
18
+ this._lineWidth = lineWidth;
19
+ this._lineColor = lineColor;
20
+ this._drawTable();
21
+ this.fillNumbers();
22
+ }
23
+ /** @description 绘制表格 */
24
+ _drawTable() {
25
+ const tableWidth = this._cellWidth * this._cols;
26
+ const tableHeight = this._cellHeight * this._rows;
27
+ const graphics = new Graphics();
28
+ graphics.lineStyle(this._lineWidth, this._lineColor);
29
+ // 绘制表格外框
30
+ graphics.drawRect(0, 0, tableWidth, tableHeight);
31
+ // 绘制横线
32
+ for (let i = 1; i < this._rows; i++) {
33
+ graphics.moveTo(0, i * this._cellHeight);
34
+ graphics.lineTo(tableWidth, i * this._cellHeight);
35
+ }
36
+ // 绘制竖线
37
+ for (let j = 1; j < this._cols; j++) {
38
+ graphics.moveTo(j * this._cellWidth, 0);
39
+ graphics.lineTo(j * this._cellWidth, tableHeight);
40
+ }
41
+ this.addChild(graphics);
42
+ }
43
+ /** @description 填充数字 */
44
+ fillNumbers() {
45
+ for (let row = 0; row < this._rows; row++) {
46
+ for (let col = 0; col < this._cols; col++) {
47
+ const number = this._data[row][col];
48
+ this._createNumberText(number, col, row);
49
+ }
50
+ }
51
+ }
52
+ /** @description 创建数字文本
53
+ * @param number 数字
54
+ * @param col 列索引
55
+ * @param row 行索引
56
+ */
57
+ _createNumberText(number, col, row) {
58
+ const text = new Text(number.toString(), {
59
+ _fontSize: this._fontSize,
60
+ fill: this._fontColor,
61
+ });
62
+ // 计算文本的居中位置
63
+ const x = col * this._cellWidth + this._cellWidth / 2;
64
+ const y = row * this._cellHeight + this._cellHeight / 2;
65
+ this.addChild(text);
66
+ text.anchor.set(0.5);
67
+ text.position.set(x, y);
68
+ libPixiScaleContainer(text, this._cellWidth * 0.9);
69
+ }
70
+ }
@@ -0,0 +1,34 @@
1
+ /** @description 音频播放器
2
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
3
+ */
4
+ export declare class LibPixiAudio {
5
+ /** 是否启用音效 */
6
+ effectEnabled: boolean;
7
+ /** 是否启用音乐 */
8
+ musicEnabled: boolean;
9
+ /** 音乐是否处于暂停状态 */
10
+ private _isMusicPaused;
11
+ /** 是否已切换后台 */
12
+ private _isBackground;
13
+ /** 当前音乐播放器 */
14
+ private _musicPlayer;
15
+ /** 当前正在播放的音效列表 */
16
+ private _playingList;
17
+ constructor();
18
+ /** @description 播放音效 */
19
+ playEffect(link: string): Promise<void>;
20
+ /** @description 播放音乐 */
21
+ playMusic(link: string): Promise<void>;
22
+ /** @description 暂停音乐,一般是为了停止音乐后播放指定的音效,音效结束后调用 resumeMusic */
23
+ pauseMusic(): void;
24
+ /** @description 继续播放音乐,调用 pauseMusic 之后调用 */
25
+ resumeMusic(): void;
26
+ /** @description 停止播放指定音效 */
27
+ stopEffect(link: string): void;
28
+ /** @description 设置启用音效 */
29
+ setEffectEnabled(enabled: boolean): void;
30
+ /** @description 设置启用音乐 */
31
+ setMusicEnabled(enabled: boolean): void;
32
+ /** @description 设置音效和音乐播放状态 */
33
+ private _setPlayStatus;
34
+ }
@@ -0,0 +1,140 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { Assets } from "pixi.js";
11
+ /** @description 音频播放器
12
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
13
+ */
14
+ export class LibPixiAudio {
15
+ constructor() {
16
+ /** 是否启用音效 */
17
+ this.effectEnabled = true;
18
+ /** 是否启用音乐 */
19
+ this.musicEnabled = true;
20
+ /** 音乐是否处于暂停状态 */
21
+ this._isMusicPaused = false;
22
+ /** 是否已切换后台 */
23
+ this._isBackground = false;
24
+ /** 当前正在播放的音效列表 */
25
+ this._playingList = [];
26
+ this._musicPlayer = new Audio();
27
+ document.addEventListener("visibilitychange", () => {
28
+ this._isBackground = document.hidden;
29
+ this._setPlayStatus(!document.hidden);
30
+ });
31
+ }
32
+ /** @description 播放音效 */
33
+ playEffect(link) {
34
+ return new Promise((resolve) => {
35
+ const id = new Date().getTime();
36
+ const url = Assets.get(link).url;
37
+ const audio = new Audio(url);
38
+ audio.muted = this._isBackground || !this.effectEnabled;
39
+ audio.addEventListener("ended", () => {
40
+ this._playingList = this._playingList.filter((item) => item.id !== id);
41
+ resolve();
42
+ });
43
+ audio
44
+ .play()
45
+ .then(() => {
46
+ this._playingList.push({
47
+ id,
48
+ audio,
49
+ url,
50
+ });
51
+ })
52
+ .catch(() => { });
53
+ });
54
+ }
55
+ /** @description 播放音乐 */
56
+ playMusic(link) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ //如果有音乐正在播放,则停止
59
+ if (this._musicPlayer) {
60
+ gsap.killTweensOf(this._musicPlayer);
61
+ yield gsap.to(this._musicPlayer, {
62
+ volume: 0,
63
+ duration: 1,
64
+ ease: "linear",
65
+ });
66
+ this._musicPlayer.pause();
67
+ }
68
+ const url = Assets.get(link).url;
69
+ this._musicPlayer.src = url;
70
+ this._musicPlayer.loop = true;
71
+ this._musicPlayer.volume = 0;
72
+ const play = () => {
73
+ this._musicPlayer
74
+ .play()
75
+ .then(() => {
76
+ this._isMusicPaused = false;
77
+ gsap.killTweensOf(this._musicPlayer);
78
+ gsap.to(this._musicPlayer, {
79
+ volume: 1,
80
+ duration: 1,
81
+ ease: "linear",
82
+ });
83
+ })
84
+ .catch(() => {
85
+ requestAnimationFrame(play.bind(this));
86
+ });
87
+ };
88
+ play();
89
+ });
90
+ }
91
+ /** @description 暂停音乐,一般是为了停止音乐后播放指定的音效,音效结束后调用 resumeMusic */
92
+ pauseMusic() {
93
+ this._isMusicPaused = true;
94
+ this._musicPlayer.pause();
95
+ }
96
+ /** @description 继续播放音乐,调用 pauseMusic 之后调用 */
97
+ resumeMusic() {
98
+ this._isMusicPaused = false;
99
+ this._musicPlayer.play();
100
+ }
101
+ /** @description 停止播放指定音效 */
102
+ stopEffect(link) {
103
+ const url = Assets.get(link).url;
104
+ this._playingList.forEach((item) => {
105
+ if (item.url === url) {
106
+ item.audio.pause();
107
+ }
108
+ });
109
+ this._playingList = this._playingList.filter((item) => item.url !== url);
110
+ }
111
+ /** @description 设置启用音效 */
112
+ setEffectEnabled(enabled) {
113
+ this.effectEnabled = enabled;
114
+ this._playingList.forEach((item) => {
115
+ item.audio.muted = !enabled;
116
+ });
117
+ }
118
+ /** @description 设置启用音乐 */
119
+ setMusicEnabled(enabled) {
120
+ this.musicEnabled = enabled;
121
+ this._musicPlayer.muted = !enabled;
122
+ }
123
+ /** @description 设置音效和音乐播放状态 */
124
+ _setPlayStatus(status) {
125
+ if (status) {
126
+ !this._isMusicPaused && this._musicPlayer.play();
127
+ }
128
+ else {
129
+ this._musicPlayer.pause();
130
+ }
131
+ this._playingList.forEach((item) => {
132
+ if (status) {
133
+ item.audio.play();
134
+ }
135
+ else {
136
+ item.audio.pause();
137
+ }
138
+ });
139
+ }
140
+ }
@@ -0,0 +1,15 @@
1
+ import { NineSlicePlane, type Texture } from "pixi.js";
2
+ export interface LibPixiCreateNineGridParams {
3
+ /** 九宫格图片 */
4
+ texture: Texture;
5
+ /** 四个角的宽度 */
6
+ dotWidth: number | [number, number, number, number];
7
+ /** 宽度 */
8
+ width: number;
9
+ /** 高度 */
10
+ height: number;
11
+ }
12
+ /** @description 九宫格图
13
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCreateNineGrid-九宫格图
14
+ */
15
+ export declare const libPixiCreateNineGrid: (params: LibPixiCreateNineGridParams) => NineSlicePlane;
@@ -0,0 +1,19 @@
1
+ import { NineSlicePlane } from "pixi.js";
2
+ /** @description 九宫格图
3
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCreateNineGrid-九宫格图
4
+ */
5
+ export const libPixiCreateNineGrid = (params) => {
6
+ const { texture, dotWidth, width, height } = params;
7
+ let slice_width = [];
8
+ // 四个角的宽度
9
+ if (Array.isArray(dotWidth)) {
10
+ slice_width = dotWidth;
11
+ }
12
+ else {
13
+ slice_width = [dotWidth, dotWidth, dotWidth, dotWidth];
14
+ }
15
+ const nineSlicePlane = new NineSlicePlane(texture, slice_width[0], slice_width[1], slice_width[2], slice_width[3]);
16
+ nineSlicePlane.width = width;
17
+ nineSlicePlane.height = height;
18
+ return nineSlicePlane;
19
+ };
@@ -0,0 +1,9 @@
1
+ import type { Container, DisplayObjectEvents } from "pixi.js";
2
+ /** @description 事件注册
3
+ * @param v 事件容器
4
+ * @param eventName 事件名称
5
+ * @param callback 回调函数
6
+ * @param once 是否只执行一次
7
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
8
+ */
9
+ export declare const libPixiEvent: (v: Container, eventName: keyof DisplayObjectEvents, callback: (...args: any) => void, once?: boolean) => void;
@@ -0,0 +1,22 @@
1
+ /** @description 事件注册
2
+ * @param v 事件容器
3
+ * @param eventName 事件名称
4
+ * @param callback 回调函数
5
+ * @param once 是否只执行一次
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
7
+ */
8
+ export const libPixiEvent = (v, eventName, callback, once = false) => {
9
+ v.cursor = "pointer";
10
+ v.eventMode = "static";
11
+ const fn = (e) => {
12
+ if (e.button === 2)
13
+ return;
14
+ callback(e);
15
+ };
16
+ if (once) {
17
+ v.once(eventName, fn);
18
+ }
19
+ else {
20
+ v.on(eventName, fn);
21
+ }
22
+ };
@@ -0,0 +1,8 @@
1
+ import type { Container, DisplayObjectEvents } from "pixi.js";
2
+ /** @description 设置可关闭的事件监听,调用自身后不再触发
3
+ * @param container 事件容器
4
+ * @param eventName 事件名称
5
+ * @param callback 事件回调
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEventControlled-可关闭的事件
7
+ */
8
+ export declare const libPixiEventControlled: (container: Container, eventName: keyof DisplayObjectEvents, callback: (...args: any) => void) => () => void;
@@ -0,0 +1,21 @@
1
+ /** @description 设置可关闭的事件监听,调用自身后不再触发
2
+ * @param container 事件容器
3
+ * @param eventName 事件名称
4
+ * @param callback 事件回调
5
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEventControlled-可关闭的事件
6
+ */
7
+ export const libPixiEventControlled = (container, eventName, callback) => {
8
+ let isDestroy = false;
9
+ container.cursor = "pointer";
10
+ container.eventMode = "static";
11
+ container.on(eventName, (e) => {
12
+ if (isDestroy)
13
+ return;
14
+ if (e.button === 2)
15
+ return;
16
+ callback(e);
17
+ });
18
+ return () => {
19
+ isDestroy = true;
20
+ };
21
+ };
@@ -0,0 +1,9 @@
1
+ /** @description 设置滤镜 */
2
+ import { ColorMatrixFilter, BlurFilter } from "pixi.js";
3
+ export type LibPixiSetFilterFilterName = "brightness" | "blur" | "desaturate" | "contrast";
4
+ /** @description 滤镜
5
+ * @param filterName 滤镜名称
6
+ * @param v 滤镜值
7
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiFilter-滤镜
8
+ */
9
+ export declare const libPixiFilter: (filterName: LibPixiSetFilterFilterName, v?: number) => ColorMatrixFilter | BlurFilter;
@@ -0,0 +1,30 @@
1
+ /** @description 设置滤镜 */
2
+ import { ColorMatrixFilter, BlurFilter } from "pixi.js";
3
+ /** @description 滤镜
4
+ * @param filterName 滤镜名称
5
+ * @param v 滤镜值
6
+ * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiFilter-滤镜
7
+ */
8
+ export const libPixiFilter = (filterName, v) => {
9
+ let filter;
10
+ if (filterName === "brightness") {
11
+ filter = new ColorMatrixFilter();
12
+ filter.brightness(v, false); // 设置亮度
13
+ }
14
+ else if (filterName === "blur") {
15
+ filter = new BlurFilter();
16
+ }
17
+ else if (filterName === "desaturate") {
18
+ filter = new ColorMatrixFilter();
19
+ filter.desaturate();
20
+ }
21
+ else if (filterName === "contrast") {
22
+ filter = new ColorMatrixFilter();
23
+ filter.contrast(v, false);
24
+ }
25
+ else {
26
+ throw new Error("未知滤镜名称");
27
+ }
28
+ filter.resolution = window.devicePixelRatio || 1;
29
+ return filter;
30
+ };