Compare commits

...

3 Commits
master ... dev

Author SHA1 Message Date
npmrun a2977d615d add 9 months ago
npmrun ca7a2ef217 feat: 增加很多功能 9 months ago
npmrun 3ea07e4173 add 9 months ago
  1. BIN
      bun.lockb
  2. 6
      index.html
  3. 1956
      package-lock.json
  4. 1
      package.json
  5. 1197
      pnpm-lock.yaml
  6. BIN
      public/assets/images/arrow_basic_e.png
  7. BIN
      public/assets/images/arrow_basic_e_small.png
  8. BIN
      public/assets/images/arrow_basic_n.png
  9. BIN
      public/assets/images/arrow_basic_n_small.png
  10. BIN
      public/assets/images/arrow_basic_s.png
  11. BIN
      public/assets/images/arrow_basic_s_small.png
  12. BIN
      public/assets/images/arrow_basic_w.png
  13. BIN
      public/assets/images/arrow_basic_w_small.png
  14. BIN
      public/assets/images/arrow_decorative_e.png
  15. BIN
      public/assets/images/arrow_decorative_e_small.png
  16. BIN
      public/assets/images/arrow_decorative_n.png
  17. BIN
      public/assets/images/arrow_decorative_n_small.png
  18. BIN
      public/assets/images/arrow_decorative_s.png
  19. BIN
      public/assets/images/arrow_decorative_s_small.png
  20. BIN
      public/assets/images/arrow_decorative_w.png
  21. BIN
      public/assets/images/arrow_decorative_w_small.png
  22. BIN
      public/assets/images/button_rectangle_border.png
  23. BIN
      public/assets/images/button_rectangle_depth_border.png
  24. BIN
      public/assets/images/button_rectangle_depth_flat.png
  25. BIN
      public/assets/images/button_rectangle_depth_gloss.png
  26. BIN
      public/assets/images/button_rectangle_depth_gradient.png
  27. BIN
      public/assets/images/button_rectangle_depth_line.png
  28. BIN
      public/assets/images/button_rectangle_flat.png
  29. BIN
      public/assets/images/button_rectangle_gloss.png
  30. BIN
      public/assets/images/button_rectangle_gradient.png
  31. BIN
      public/assets/images/button_rectangle_line.png
  32. BIN
      public/assets/images/button_round_border.png
  33. BIN
      public/assets/images/button_round_depth_border.png
  34. BIN
      public/assets/images/button_round_depth_flat.png
  35. BIN
      public/assets/images/button_round_depth_gloss.png
  36. BIN
      public/assets/images/button_round_depth_gradient.png
  37. BIN
      public/assets/images/button_round_depth_line.png
  38. BIN
      public/assets/images/button_round_flat.png
  39. BIN
      public/assets/images/button_round_gloss.png
  40. BIN
      public/assets/images/button_round_gradient.png
  41. BIN
      public/assets/images/button_round_line.png
  42. BIN
      public/assets/images/button_square_border.png
  43. BIN
      public/assets/images/button_square_depth_border.png
  44. BIN
      public/assets/images/button_square_depth_flat.png
  45. BIN
      public/assets/images/button_square_depth_gloss.png
  46. BIN
      public/assets/images/button_square_depth_gradient.png
  47. BIN
      public/assets/images/button_square_depth_line.png
  48. BIN
      public/assets/images/button_square_flat.png
  49. BIN
      public/assets/images/button_square_gloss.png
  50. BIN
      public/assets/images/button_square_gradient.png
  51. BIN
      public/assets/images/button_square_line.png
  52. BIN
      public/assets/images/check_round_color.png
  53. BIN
      public/assets/images/check_round_grey.png
  54. BIN
      public/assets/images/check_round_grey_circle.png
  55. BIN
      public/assets/images/check_round_round_circle.png
  56. BIN
      public/assets/images/check_square_color.png
  57. BIN
      public/assets/images/check_square_color_checkmark.png
  58. BIN
      public/assets/images/check_square_color_cross.png
  59. BIN
      public/assets/images/check_square_color_square.png
  60. BIN
      public/assets/images/check_square_grey.png
  61. BIN
      public/assets/images/check_square_grey_checkmark.png
  62. BIN
      public/assets/images/check_square_grey_cross.png
  63. BIN
      public/assets/images/check_square_grey_square.png
  64. BIN
      public/assets/images/icon_checkmark.png
  65. BIN
      public/assets/images/icon_circle.png
  66. BIN
      public/assets/images/icon_cross.png
  67. BIN
      public/assets/images/icon_outline_checkmark.png
  68. BIN
      public/assets/images/icon_outline_circle.png
  69. BIN
      public/assets/images/icon_outline_cross.png
  70. BIN
      public/assets/images/icon_outline_square.png
  71. BIN
      public/assets/images/icon_square.png
  72. BIN
      public/assets/images/slide_hangle.png
  73. BIN
      public/assets/images/slide_horizontal_color.png
  74. BIN
      public/assets/images/slide_horizontal_color_section.png
  75. BIN
      public/assets/images/slide_horizontal_color_section_wide.png
  76. BIN
      public/assets/images/slide_horizontal_grey.png
  77. BIN
      public/assets/images/slide_horizontal_grey_section.png
  78. BIN
      public/assets/images/slide_horizontal_grey_section_wide.png
  79. BIN
      public/assets/images/slide_vertical_color.png
  80. BIN
      public/assets/images/slide_vertical_color_section.png
  81. BIN
      public/assets/images/slide_vertical_color_section_wide.png
  82. BIN
      public/assets/images/slide_vertical_grey.png
  83. BIN
      public/assets/images/slide_vertical_grey_section.png
  84. BIN
      public/assets/images/slide_vertical_grey_section_wide.png
  85. BIN
      public/assets/images/star.png
  86. BIN
      public/assets/images/star_outline.png
  87. BIN
      public/assets/images/star_outline_depth.png
  88. 46
      src/Game/Game.ts
  89. 26
      src/Game/Position.ts
  90. 24
      src/Game/Sound.ts
  91. 24
      src/Game/Stage.ts
  92. 55
      src/Game/index.ts
  93. 88
      src/components/Button.ts
  94. 15
      src/main.ts
  95. 24
      src/stages/_global/page_0global.ts
  96. 26
      src/stages/page_control.ts
  97. 101
      src/stages/page_init.ts
  98. 64
      src/stages/page_loading.ts
  99. 13
      src/stages/welcome/page_welcome.ts
  100. 18
      src/stages/welcome2/page_welcome2.ts

BIN
bun.lockb

Binary file not shown.

6
index.html

@ -5,6 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <title>Document</title>
<script src="//cdn.bootcdn.net/ajax/libs/eruda/2.3.3/eruda.js"></script>
<script>eruda.init();</script>
<style> <style>
html,body{ html,body{
padding: 0; padding: 0;
@ -12,10 +14,14 @@
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
} }
body{
display: flex;
}
canvas{ canvas{
display: block; display: block;
position: absolute; position: absolute;
inset: 0; inset: 0;
margin: auto;
} }
.loading{ .loading{
height: 100%; height: 100%;

1956
package-lock.json

File diff suppressed because it is too large

1
package.json

@ -4,6 +4,7 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"check": "taze major",
"dev": "vite --host", "dev": "vite --host",
"build": "vite build" "build": "vite build"
}, },

1197
pnpm-lock.yaml

File diff suppressed because it is too large

BIN
public/assets/images/arrow_basic_e.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

BIN
public/assets/images/arrow_basic_e_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

BIN
public/assets/images/arrow_basic_n.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

BIN
public/assets/images/arrow_basic_n_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

BIN
public/assets/images/arrow_basic_s.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

BIN
public/assets/images/arrow_basic_s_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

BIN
public/assets/images/arrow_basic_w.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

BIN
public/assets/images/arrow_basic_w_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

BIN
public/assets/images/arrow_decorative_e.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

BIN
public/assets/images/arrow_decorative_e_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

BIN
public/assets/images/arrow_decorative_n.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

BIN
public/assets/images/arrow_decorative_n_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

BIN
public/assets/images/arrow_decorative_s.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

BIN
public/assets/images/arrow_decorative_s_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

BIN
public/assets/images/arrow_decorative_w.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

BIN
public/assets/images/arrow_decorative_w_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

BIN
public/assets/images/button_rectangle_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

BIN
public/assets/images/button_rectangle_depth_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

BIN
public/assets/images/button_rectangle_depth_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

BIN
public/assets/images/button_rectangle_depth_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

BIN
public/assets/images/button_rectangle_depth_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

BIN
public/assets/images/button_rectangle_depth_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

BIN
public/assets/images/button_rectangle_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

BIN
public/assets/images/button_rectangle_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

BIN
public/assets/images/button_rectangle_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

BIN
public/assets/images/button_rectangle_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

BIN
public/assets/images/button_round_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
public/assets/images/button_round_depth_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
public/assets/images/button_round_depth_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
public/assets/images/button_round_depth_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
public/assets/images/button_round_depth_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
public/assets/images/button_round_depth_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
public/assets/images/button_round_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 B

BIN
public/assets/images/button_round_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

BIN
public/assets/images/button_round_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
public/assets/images/button_round_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
public/assets/images/button_square_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

BIN
public/assets/images/button_square_depth_border.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

BIN
public/assets/images/button_square_depth_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

BIN
public/assets/images/button_square_depth_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

BIN
public/assets/images/button_square_depth_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B

BIN
public/assets/images/button_square_depth_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

BIN
public/assets/images/button_square_flat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

BIN
public/assets/images/button_square_gloss.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

BIN
public/assets/images/button_square_gradient.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 532 B

BIN
public/assets/images/button_square_line.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

BIN
public/assets/images/check_round_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

BIN
public/assets/images/check_round_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

BIN
public/assets/images/check_round_grey_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

BIN
public/assets/images/check_round_round_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

BIN
public/assets/images/check_square_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

BIN
public/assets/images/check_square_color_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

BIN
public/assets/images/check_square_color_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 501 B

BIN
public/assets/images/check_square_color_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

BIN
public/assets/images/check_square_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

BIN
public/assets/images/check_square_grey_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

BIN
public/assets/images/check_square_grey_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

BIN
public/assets/images/check_square_grey_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

BIN
public/assets/images/icon_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

BIN
public/assets/images/icon_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

BIN
public/assets/images/icon_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

BIN
public/assets/images/icon_outline_checkmark.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 377 B

BIN
public/assets/images/icon_outline_circle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

BIN
public/assets/images/icon_outline_cross.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

BIN
public/assets/images/icon_outline_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

BIN
public/assets/images/icon_square.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 B

BIN
public/assets/images/slide_hangle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

BIN
public/assets/images/slide_horizontal_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

BIN
public/assets/images/slide_horizontal_color_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

BIN
public/assets/images/slide_horizontal_color_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

BIN
public/assets/images/slide_horizontal_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

BIN
public/assets/images/slide_horizontal_grey_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

BIN
public/assets/images/slide_horizontal_grey_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

BIN
public/assets/images/slide_vertical_color.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

BIN
public/assets/images/slide_vertical_color_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
public/assets/images/slide_vertical_color_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

BIN
public/assets/images/slide_vertical_grey.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

BIN
public/assets/images/slide_vertical_grey_section.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
public/assets/images/slide_vertical_grey_section_wide.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

BIN
public/assets/images/star.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
public/assets/images/star_outline.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 B

BIN
public/assets/images/star_outline_depth.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

46
src/Game/Game.ts

@ -8,6 +8,7 @@ import {
} from "pixi.js"; } from "pixi.js";
import detectOrient from "./detectOrient"; import detectOrient from "./detectOrient";
import { EDirection } from "@/enmu"; import { EDirection } from "@/enmu";
import TWEEN from "@tweenjs/tween.js";
export default class Game { export default class Game {
constructor() { constructor() {
@ -23,6 +24,7 @@ export default class Game {
} }
private _stage: Container; private _stage: Container;
private _tween: typeof TWEEN;
private _renderer: AbstractRenderer; private _renderer: AbstractRenderer;
private _ticker: Ticker; private _ticker: Ticker;
private _loader: Loader; private _loader: Loader;
@ -34,6 +36,12 @@ export default class Game {
public get stage(): Container { public get stage(): Container {
return this._stage; return this._stage;
} }
public get tween(): typeof TWEEN {
if(!this._tween) {
this._tween = TWEEN
}
return this._tween;
}
public get ticker(): Ticker { public get ticker(): Ticker {
return this._ticker; return this._ticker;
@ -50,6 +58,24 @@ export default class Game {
height: 0, height: 0,
}; };
private screenInfo() {
const curDirection = detectOrient();
if (curDirection === EDirection.Portrait) {
const width = document.documentElement.clientWidth * 1136 / 640
const height = document.documentElement.clientWidth
return {
widght: height,
height: width,
}
}
const width = document.documentElement.clientHeight * 1136 / 640
const height = document.documentElement.clientHeight
return {
widght: width,
height: height,
}
}
getInfo() { getInfo() {
return this.info; return this.info;
} }
@ -60,8 +86,9 @@ export default class Game {
} }
updateView() { updateView() {
let screenWidght = document.documentElement.clientWidth; const screenInfo = this.screenInfo()
let screenHeight = document.documentElement.clientHeight; let screenWidght = screenInfo.widght;
let screenHeight = screenInfo.height;
this.renderer.resize(screenWidght, screenHeight); this.renderer.resize(screenWidght, screenHeight);
let offsetWidth = 0; let offsetWidth = 0;
let offsetHeight = 0; let offsetHeight = 0;
@ -114,28 +141,33 @@ export default class Game {
} }
init() { init() {
let screenWidght = document.documentElement.clientWidth; const screenInfo = this.screenInfo()
let screenHeight = document.documentElement.clientHeight; let screenWidght = screenInfo.widght;
let screenHeight = screenInfo.height;
const stage = new Container(); const stage = new Container();
stage.name = "root"; stage.name = "root";
let renderer = autoDetectRenderer({ let renderer = autoDetectRenderer({
autoDensity: true,
width: screenWidght, width: screenWidght,
height: screenHeight, height: screenHeight,
antialias: true, antialias: true,
backgroundAlpha: 255, backgroundAlpha: 255,
resolution: 1, resolution: 2,
backgroundColor: 0x1d9ce0, backgroundColor: 0x1d9ce0,
forceCanvas: true, forceCanvas: true,
}); });
this._stage = stage; this._stage = stage;
this._renderer = renderer; this._renderer = renderer;
// https://www.cnblogs.com/haqiao/p/12515775.html
this.renderer.resize(screenWidght, screenHeight)
document.body.appendChild(renderer.view); document.body.appendChild(renderer.view);
window.addEventListener("resize", () => { window.addEventListener("resize", () => {
this.updateView(); this.updateView();
}); });
const ticker = new Ticker(); // const ticker = new Ticker();
const ticker = Ticker.shared; // 单例
ticker.autoStart = true; ticker.autoStart = true;
this._ticker = ticker; this._ticker = ticker;

26
src/Game/Position.ts

@ -0,0 +1,26 @@
import { gameManager } from "@/Game";
import { IPointData } from "pixi.js";
class Position {
static instance: Position = null
private constructor() { }
static getInstance() {
if (Position.instance == null) {
Position.instance = new Position
}
return Position.instance
}
get(xType: "center", yType: "center", offset: Partial<IPointData>): IPointData {
let x, y
if (xType === 'center') {
x = gameManager.getInfo().width / 2 + (offset.x ?? 0)
}
if (yType === 'center') {
y = gameManager.getInfo().height / 2 + (offset.y ?? 0)
}
return { x, y }
}
}
export default Position.getInstance()

24
src/Game/Sound.ts

@ -1,13 +1,17 @@
import { sound } from "@pixi/sound"; import { sound } from "@pixi/sound";
import { LoaderResource } from "pixi.js"; // import { LoaderResource } from "pixi.js";
sound.add('my-sound', {
export function addSound(e: LoaderResource) { url: "/bg.mp3",
console.log(e); singleInstance: true,
sound.add(e.name, { autoPlay: false,
source: e.data, });
singleInstance: true, // export function addSound(e: LoaderResource) {
autoPlay: false, // console.log(e);
}); // sound.add(e.name, {
} // source: e.data,
// singleInstance: true,
// autoPlay: false,
// });
// }
export default sound; export default sound;

24
src/Game/Stage.ts

@ -31,7 +31,7 @@ export default class Stage {
initStage(name: string){ initStage(name: string){
if(!this._stages[name]){ if(!this._stages[name]){
throw new Error("不存在该舞台") throw new Error("不存在该舞台: " + name)
} }
let curStage = this._stages[name]; let curStage = this._stages[name];
this.curStage = curStage this.curStage = curStage
@ -47,9 +47,9 @@ export default class Stage {
this._wscb.forEach(v=>v(curStage)) this._wscb.forEach(v=>v(curStage))
} }
changeStage(name: string){ changeStage(name: string, opts?: {isHolderLast?: boolean}){
if(!this._stages[name]){ if(!this._stages[name]){
throw new Error("不存在该舞台") throw new Error("不存在该舞台: " + name)
} }
if(!this.curStage){ if(!this.curStage){
console.warn("请先初始化一个场景") console.warn("请先初始化一个场景")
@ -57,26 +57,34 @@ export default class Stage {
} }
let lastStage = this.curStage let lastStage = this.curStage
if(lastStage&&lastStage.type === EP.Normal){ if(lastStage&&lastStage.type === EP.Normal){
this.gameManager.stage.removeChild(lastStage.stage) if(opts?.isHolderLast) {
lastStage.stage.visible = false
// @ts-ignore
lastStage.stage.$isHolderLast = opts.isHolderLast
} else this.gameManager.stage.removeChild(lastStage.stage)
}else if(lastStage&&lastStage.type === EP.Resident){ }else if(lastStage&&lastStage.type === EP.Resident){
lastStage.stage.visible = false lastStage.stage.visible = false
} }
let curStage = this._stages[name]; let curStage = this._stages[name];
if(curStage && typeof curStage === "string"){ if(curStage && typeof curStage === "string" && curStage === "已销毁"){
this.create(name, EP.Normal) this.create(name, EP.Normal)
curStage = this._stages[name] curStage = this._stages[name]
console.log(curStage); console.log(curStage);
} }
this.curStage = curStage this.curStage = curStage
if(curStage&&curStage.type === EP.Normal){ if(curStage&&curStage.type === EP.Normal){
this.gameManager.stage.addChild(curStage.stage) // @ts-ignore
if(curStage.stage.$isHolderLast) {
curStage.stage.visible = true
} else {
this.gameManager.stage.addChild(curStage.stage)
}
}else if(curStage&&curStage.type === EP.Resident){ }else if(curStage&&curStage.type === EP.Resident){
curStage.stage.visible = true curStage.stage.visible = true
} }
this._wscb.forEach(v=>v(curStage, lastStage)) this._wscb.forEach(v=>v(curStage, lastStage))
if(lastStage&&lastStage.type === EP.Normal){ if(lastStage&&lastStage.type === EP.Normal && !opts?.isHolderLast){
lastStage.stage.destroy() lastStage.stage.destroy()
this._stages[lastStage.name] = "已销毁" as any this._stages[lastStage.name] = "已销毁" as any
} }

55
src/Game/index.ts

@ -1,40 +1,52 @@
import Game from "./Game"; import Game from "./Game";
import Stage from "./Stage"; import Stage from "./Stage";
import { Container, LoaderResource, Loader } from "pixi.js"; import { Container, LoaderResource, Loader } from "pixi.js";
import * as PIXI from "pixi.js";
import { EP } from "@/enmu"; import { EP } from "@/enmu";
import TWEEN from "@tweenjs/tween.js";
const gameManager = Game.getInstance(); const gameManager = Game.getInstance();
const stageManager = Stage.getInstance(); const stageManager = Stage.getInstance();
const windows: Record<string, IWindow>= {} const windows: Record<string, IWindow> = {}
const residentList: IWindow[] = [] const residentList: IWindow[] = []
function defineLoadResource(resources: {name: string, url: string, callback?: LoaderResource.OnCompleteSignal}[]) { function defineLoadResource(resources: { name: string, url: string, callback?: LoaderResource.OnCompleteSignal }[]) {
return resources return resources
} }
function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP) { function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP): any
return { name, abstractClass, type} function defineWindow(abstractClass: Constructor<IWindow>, type?: EP): any
function defineWindow(name: string | Constructor<IWindow>, abstractClass?: Constructor<IWindow> | EP, type?: EP) {
if (typeof name === "string") {
return { name, abstractClass, type }
}
return { abstractClass: name, type: abstractClass }
} }
const t = import.meta.globEager("../stages/**/page_*.ts"); const t = import.meta.globEager("../stages/**/page_*.ts");
for (const tKey in t) { for (const tKey in t) {
const mod = t[tKey].default || t[tKey] const mod = t[tKey].default || t[tKey]
const {name, abstractClass, type} = mod as ReturnType<typeof defineWindow> const [_, tKeyName] = tKey.match(/page_(.*?)\.ts$/)
const stage = stageManager.getStage(name, type); const { name, abstractClass, type } = mod as ReturnType<typeof defineWindow>
const stage = stageManager.getStage(name || tKeyName, type);
const stageClass = new abstractClass(stage) const stageClass = new abstractClass(stage)
if(EP.Resident === type) { stageClass.bindStage(stage)
stageClass._initLayout = false
stageClass.$name = name || tKeyName
if (EP.Resident === type) {
residentList.push(stageClass) residentList.push(stageClass)
} } else windows[name || tKeyName] = stageClass
windows[name] = stageClass
} }
// @ts-ignore
residentList.sort((a, b) => a.$name.localeCompare(b.$name, 'en'))
type Constructor<T> = new (...args: any[]) => T; type Constructor<T> = new (...args: any[]) => T;
interface IWindow { interface IWindow {
_initLayout?: Boolean;
stage: Container; stage: Container;
loader?: Loader; loader?: Loader;
bindStage?(stage: Container): void;
layout?(): void;
onLoad?(): void; onLoad?(): void;
onUnLoad?(): void; onUnLoad?(): void;
lateUpdate?(dt: number, name: string): void; lateUpdate?(dt: number, name: string): void;
@ -50,6 +62,13 @@ function initGame() {
} }
if (stage && stage.type === EP.Normal) { if (stage && stage.type === EP.Normal) {
let curWindow = windows[stage.name]; let curWindow = windows[stage.name];
const isSameStage = curWindow.stage === stage.stage
!isSameStage && curWindow.bindStage(stage.stage)
if(!curWindow._initLayout || !isSameStage) {
// console.log("不同的舞台");
curWindow.layout?.()
curWindow._initLayout = true
}
curWindow.onLoad && curWindow.onLoad(); curWindow.onLoad && curWindow.onLoad();
} }
}); });
@ -57,17 +76,17 @@ function initGame() {
gameManager.ticker.add((dt: number) => { gameManager.ticker.add((dt: number) => {
if (!stageManager.curStage) return; if (!stageManager.curStage) return;
let curWindow = windows[stageManager.curStage.name]; let curWindow = windows[stageManager.curStage.name];
TWEEN.update(); gameManager.tween.update();
residentList.forEach((v) => v.update && v.update(dt, v.stage.name)); residentList.forEach((v) => v.update && v.update(dt, v.stage.name));
stageManager.curStage && stageManager.curStage &&
curWindow && curWindow &&
curWindow.update && curWindow.update &&
curWindow.update(dt, curWindow.stage.name); curWindow.update(dt, curWindow.stage.name);
gameManager.render(); gameManager.render();
stageManager.curStage && stageManager.curStage &&
curWindow && curWindow &&
curWindow.lateUpdate && curWindow.lateUpdate &&
curWindow.lateUpdate(dt, curWindow.stage.name); curWindow.lateUpdate(dt, curWindow.stage.name);
residentList.forEach((v) => v.lateUpdate && v.lateUpdate(dt, v.stage.name)); residentList.forEach((v) => v.lateUpdate && v.lateUpdate(dt, v.stage.name));
}); });
} }

88
src/components/Button.ts

@ -1,28 +1,36 @@
import { Text, Graphics, Container, TextStyle } from "pixi.js"; import { Text, Graphics, Container, TextStyle, NineSlicePlane, Texture } from "pixi.js";
interface IOpts { interface IOpts {
text: string; text: string;
bg: string;
pressBg: string;
position: null | any;
click(): void; click(): void;
} }
const defaultOpts: IOpts = { const defaultOpts: IOpts = {
text: "", text: "",
click() {}, bg: "",
position: null,
pressBg: "",
click() { },
}; };
function getConfig() {
return Object.assign({}, defaultOpts)
}
export default function Button(opts: Partial<IOpts>) { export default function Button(opts: Partial<IOpts>) {
let curOpts: Partial<IOpts> = {}; let curOpts: IOpts = getConfig();
(Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => { ; (Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => {
if (opts[key] != undefined) { if (opts[key] != undefined) {
curOpts[key] = opts[key]; curOpts[key] = opts[key] as any;
} else {
curOpts[key] = defaultOpts[key];
} }
}); });
let textStyle = new TextStyle({ let textStyle = new TextStyle({
fontFamily: "Arial", fontFamily: "Arial",
fontSize: 50, fontSize: 30,
fill: 0xffffff, fill: 0xffffff,
align: "center", align: "center",
}); });
@ -33,34 +41,64 @@ export default function Button(opts: Partial<IOpts>) {
let button = new Container(); let button = new Container();
let width = textStr.width + xPadding; let width = textStr.width + xPadding;
let height = textStr.height + yPadding; let height = textStr.height + yPadding;
// https://www.cnblogs.com/ningmin/p/11412170.html
textStr.x = xPadding / 2; // https://blog.csdn.net/weixin_52919504/article/details/131854745
textStr.y = yPadding / 2; // https://blog.csdn.net/weixin_52919504/article/details/131854745
button.pivot.set(width / 2, height / 2)
const rect = new Graphics(); textStr.x = xPadding / 2;
rect.name = "rect"; textStr.y = yPadding / 2 - 2;
rect.beginFill(0xff0000);
rect.drawRect(0, 0, width, height);
rect.endFill();
rect.interactive = true;
rect.buttonMode = true;
button.addChild(rect); if (!curOpts.bg) {
const rect = new Graphics();
rect.name = "rect";
rect.beginFill(0xff0000);
rect.drawRect(0, 0, width, height);
rect.endFill();
rect.interactive = true;
rect.buttonMode = true;
button.addChild(rect);
} else {
const plane9 = new NineSlicePlane(Texture.from(curOpts.bg), 10, 10, 10, 10);
plane9.name = "nine-pic"
plane9.width = width
plane9.height = height
plane9.interactive = true;
plane9.buttonMode = true;
button.addChild(plane9);
}
button.addChild(textStr); button.addChild(textStr);
button.x = 100;
button.y = 50;
button.interactive = true; button.interactive = true;
if(curOpts.position) {
button.position = curOpts.position
}
button.on("touchstart", () => { button.on("touchstart", () => {
button.alpha = 0.8; if (curOpts.pressBg) {
button.getChildByName<NineSlicePlane>("nine-pic").texture = Texture.from(curOpts.pressBg)
} else {
button.alpha = 0.8;
button.scale = { x: .8, y: .8 }
}
}); });
button.on("touchend", () => { button.on("touchend", () => {
// 点击成功 // 点击成功
console.log("success"); console.log("touchend success");
if (curOpts.pressBg) {
button.getChildByName<NineSlicePlane>("nine-pic").texture = Texture.from(curOpts.bg)
} else {
button.alpha = 1;
button.scale = { x: 1, y: 1 }
}
curOpts.click(); curOpts.click();
button.alpha = 1;
}); });
button.on("touchendoutside", () => { button.on("touchendoutside", () => {
button.alpha = 1; console.log("touchendoutside success");
if (curOpts.pressBg) {
button.getChildByName<NineSlicePlane>("nine-pic").texture = Texture.from(curOpts.bg)
} else {
button.alpha = 1;
button.scale = { x: 1, y: 1 }
}
}); });
return button; return button;
} }

15
src/main.ts

@ -2,19 +2,20 @@ import { EDirection } from "./enmu";
import { gameManager, initGame, stageManager, windows } from "./Game"; import { gameManager, initGame, stageManager, windows } from "./Game";
import { addSound } from "./Game/Sound"; import { addSound } from "./Game/Sound";
console.log();
gameManager.loader gameManager.loader
.add("my-sound", "/bg.mp3", (e) => addSound(e)) // .add("my-sound", "/bg.mp3", (e) => addSound(e)) // 背景音乐
.add("bg", "/bg.png") .add("bg", "/bg.png") // 背景图片
.add("dnf", "https://www.kkkk1000.com/images/learnPixiJS-AnimatedSprite/dnf.png") // 背景图片
.add("btn-bg", "/assets/images/button_square_depth_gloss.png") // 背景图片
.add("btn-bg-press", "/assets/images/button_square_depth_gradient.png") // 背景图片
.load(); .load();
gameManager.loader.onProgress.add((loader) => { gameManager.loader.onProgress.add((loader) => {
console.log(loader.progress); console.log(loader.progress);
}); });
gameManager.loader.onComplete.once((loader) => { gameManager.loader.onComplete.once((loader) => {
console.log(loader.resources); console.log(loader.resources);
initGame(); initGame();
gameManager.setDirection(EDirection.Portrait); gameManager.setDirection(EDirection.Landscape);
stageManager.initStage("loading"); stageManager.initStage("init");
}); });

24
src/stages/_global/page_0global.ts

@ -0,0 +1,24 @@
import { EP } from "@/enmu";
import { defineWindow } from "@/Game";
import { Container } from "pixi.js";
export default defineWindow(
class {
stage: Container = null;
constructor(stage: Container) {
this.stage = stage;
}
bindStage(stage: Container){
this.stage = stage;
}
onLoad() {
console.log("global page loaded");
}
onUnLoad() {
}
},
EP.Resident
);

26
src/stages/page_control.ts

@ -1,26 +0,0 @@
import { EP } from "@/enmu";
import { defineWindow } from "@/Game";
import { Container, Loader } from "pixi.js";
import { addSound } from "@/Game/Sound";
const loader = new Loader().add("my-sound", "/bg.mp3", (e) => addSound(e));
export default defineWindow("control", class {
stage: Container = null;
loader: Loader = loader;
constructor(stage: Container) {
this.stage = stage;
}
onLoad() {
console.log("onLoad control");
}
onUnLoad() {
console.log("onUnLoad control");
}
update() {
}
}, EP.Resident);

101
src/stages/page_init.ts

@ -0,0 +1,101 @@
import Button from "@/components/Button";
import { gameManager, defineWindow, stageManager } from "@/Game";
import Position from "@/Game/Position";
import Sound from "@/Game/Sound";
import { Container, Sprite, Text, NineSlicePlane, Texture, AnimatedSprite, Rectangle, utils } from "pixi.js";
// defineLoadResource([
// { name: "my-sound", url: "/bg.mp3", callback: (e) => addSound(e) },
// { name: "bg", url: "/bg.png" },
// ])
export default defineWindow(
class {
stage: Container = null;
title: Text; // 标题
pixie: AnimatedSprite; // 标题
bindStage(stage: Container) {
this.stage = stage;
}
layout() {
const bg = new Sprite(Texture.from("bg"));
bg.width = gameManager.getInfo().width
bg.height = gameManager.getInfo().height
this.stage.addChild(bg)
this.title = new Text("时间魔法", {
fontSize: 80,
fill: "red",
});
this.title.x = gameManager.getInfo().width / 2;
this.title.y = gameManager.getInfo().height / 2 - 200;
this.title.position = Position.get("center", "center", { y: -200, x: 0 })
this.title.anchor.set(0.5, 0.5);
this.stage.addChild(this.title);
const plane9 = new NineSlicePlane(Texture.from("btn-bg"), 10, 10, 10, 10);
plane9.width = 100
plane9.height = 50
this.stage.addChild(plane9);
const btn = Button({
text: "开始游戏",
position: Position.get("center", "center", { y: 200, x: 0 }),
bg: "btn-bg",
pressBg: "btn-bg-press",
click: () => {
Sound.play("my-sound")
// new gameManager.tween.Tween(btn.position).interpolation(gameManager.tween.Interpolation.Bezier)
// .to({ alpha: .2, x: btn.width / 2, y: btn.height / 2 }, 1300)
// .onComplete(() => {
// stageManager.changeStage("welcome", { isHolderLast: true })
//播放动画精灵
this.pixie.gotoAndPlay(0);
// })
// .start()
},
});
this.stage.addChild(btn);
console.log(this.stage);
let TextureCache = utils.TextureCache;
let base = TextureCache["dnf"];
//第一个纹理
let texture0 = new Texture(base as any)
texture0.frame = new Rectangle(0, 0, 80, 143);
//第二个纹理
let texture1 = new Texture(base as any)
texture1.frame = new Rectangle(80, 0, 80, 143);
//第三个纹理
let texture2 = new Texture(base as any)
texture2.frame = new Rectangle(160, 0, 80, 143);
//第四个纹理
let texture3 = new Texture(base as any)
texture3.frame = new Rectangle(240, 0, 80, 143);
//创建纹理数组
let textures = [texture0, texture1, texture2, texture3];
//创建动画精灵
this.pixie = new AnimatedSprite(textures, false);
//设置动画精灵的速度
this.pixie.animationSpeed = 0.1;
this.pixie.loop = true;
this.stage.addChild(this.pixie)
this.pixie.y = 200
}
onLoad() {
console.log("onLoad init");
}
onUnLoad() {
Sound.stop("my-sound");
console.log("onUnLoad loading");
}
update(dt: number) {
this.pixie.update(dt)
this.title.rotation -= 0.01 * dt;
}
},
);

64
src/stages/page_loading.ts

@ -1,64 +0,0 @@
import Button from "@/components/Button";
import { gameManager, defineWindow, stageManager } from "@/Game";
import Sound from "@/Game/Sound";
import { Container, Sprite, Text, NineSlicePlane, Texture } from "pixi.js";
import TWEEN from "@tweenjs/tween.js";
// defineLoadResource([
// { name: "my-sound", url: "/bg.mp3", callback: (e) => addSound(e) },
// { name: "bg", url: "/bg.png" },
// ])
export default defineWindow(
"loading",
class {
stage: Container = null;
title: Text; // 标题
constructor(stage: Container) {
this.stage = stage;
}
onLoad() {
console.log("onLoad loading");
this.title = new Text("时间魔法", {
fontSize: 80,
fill: "red",
});
this.title.x = gameManager.getInfo().width / 2;
this.title.y = gameManager.getInfo().height / 2 - 200;
this.title.anchor.set(0.5, 0.5);
this.stage.addChild(this.title);
const plane9 = new NineSlicePlane(Texture.from("bg"), 100, 100, 100, 100);
plane9.width = 300
plane9.height = 300
this.stage.addChild(plane9);
const btn = Button({
text: "开始游戏",
click: () => {
stageManager.changeStage("welcome")
// Sound.play("my-sound")
// new TWEEN.Tween(btn).interpolation( TWEEN.Interpolation.Bezier )
// .to({ alpha: .2,x:100, y:100 }, 1300)
// .start()
},
});
btn.x = gameManager.getInfo().width / 2 - btn.width / 2;
btn.y = gameManager.getInfo().height / 2 - btn.height / 2 + 200;
this.stage.addChild(btn);
}
onUnLoad() {
Sound.stop("my-sound");
console.log("onUnLoad loading");
}
update(dt: number) {
this.title.rotation -= 0.01 * dt;
}
},
);

13
src/stages/welcome/page_welcome.ts

@ -10,12 +10,10 @@ export default defineWindow("welcome", class{
stage:Container = null stage:Container = null
elements: Record<string, Graphics> = {} elements: Record<string, Graphics> = {}
text: any text: any
bindStage(stage: Container){
constructor(stage: Container){ this.stage = stage;
this.stage = stage
} }
onLoad(){ layout(){
console.log("onLoad 1");
const circle = Circle.render() const circle = Circle.render()
this.stage.addChild(circle) this.stage.addChild(circle)
circle.on("touchend", ()=>{ circle.on("touchend", ()=>{
@ -27,10 +25,13 @@ export default defineWindow("welcome", class{
const btn = Button({text: "修仙人生日常"}) const btn = Button({text: "修仙人生日常"})
btn.on("touchend", ()=>{ btn.on("touchend", ()=>{
// Sound.play('my-sound'); // Sound.play('my-sound');
stageManager.changeStage("loading") stageManager.changeStage("init")
}) })
this.stage.addChild(btn) this.stage.addChild(btn)
} }
onLoad(){
console.log("onLoad 1");
}
onUnLoad(){ onUnLoad(){
Sound.stop("my-sound") Sound.stop("my-sound")
console.log("onUnLoad 1"); console.log("onUnLoad 1");

18
src/stages/welcome2/page_welcome2.ts

@ -16,18 +16,20 @@ circle.on("touchend", () => {
stageManager.changeStage("welcome") stageManager.changeStage("welcome")
}) })
export default defineWindow("welcome2", class{ export default defineWindow("welcome2", class {
stage:Container = null stage: Container = null
constructor(stage: Container){ bindStage(stage: Container) {
this.stage = stage this.stage = stage;
} }
onLoad(){ layout() {
console.log("onLoad 2");
this.stage.addChild(circle) this.stage.addChild(circle)
} }
onUnLoad(){ onLoad() {
console.log("onLoad 2");
}
onUnLoad() {
console.log("onUnLoad 2"); console.log("onUnLoad 2");
} }
update(){ update() {
} }
}) })
Loading…
Cancel
Save