Compare commits

...

4 Commits

Author SHA1 Message Date
npmrun 1f0a7280f3 add 9 months ago
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. 15
      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. BIN
      public/controller_prompt_bg.png
  89. 29
      public/manifest.json
  90. 45
      src/Game/Assets.ts
  91. 75
      src/Game/Game.ts
  92. 26
      src/Game/Position.ts
  93. 24
      src/Game/Sound.ts
  94. 56
      src/Game/Stage.ts
  95. 157
      src/Game/index.ts
  96. 21
      src/Game/type.ts
  97. 191
      src/components/Button.ts
  98. 44
      src/main.ts
  99. 44
      src/stages/_global/page_0global.ts
  100. 26
      src/stages/page_control.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 name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <script src="//cdn.bootcdn.net/ajax/libs/eruda/2.3.3/eruda.js"></script>
<script>eruda.init();</script> -->
<style>
html,body{
padding: 0;
@ -12,10 +14,14 @@
height: 100vh;
width: 100vw;
}
body{
display: flex;
}
canvas{
display: block;
position: absolute;
inset: 0;
margin: auto;
}
.loading{
height: 100%;

1956
package-lock.json

File diff suppressed because it is too large

15
package.json

@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"check": "taze major",
"dev": "vite --host",
"build": "vite build"
},
@ -11,13 +12,15 @@
"author": "",
"license": "ISC",
"dependencies": {
"@pixi/sound": "^4.3.0",
"@tweenjs/tween.js": "^18.6.4",
"pixi.js": "^6.5.3",
"vite": "^2.9.15",
"vite-tsconfig-paths": "^3.5.0"
"@pixi/sound": "^6.0.1",
"@pixi/ui": "^2.1.2",
"@tweenjs/tween.js": "^25.0.0",
"pixi.js": "^8.2.5",
"vite": "^5.3.5",
"vite-tsconfig-paths": "^4.3.2"
},
"devDependencies": {
"typescript": "^4.8.3"
"@pixi/devtools": "^2.0.1",
"typescript": "^5.5.4"
}
}

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

BIN
public/controller_prompt_bg.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

29
public/manifest.json

@ -0,0 +1,29 @@
{
"bundles":[
{
"name":"load-screen",
"assets":[
{
"alias":"cbg",
"src":"/controller_prompt_bg.png"
},
{
"alias":"bg",
"src":"/bg.png"
},
{
"alias":"dnf",
"src":"https://www.kkkk1000.com/images/learnPixiJS-AnimatedSprite/dnf.png"
},
{
"alias":"btn-bg",
"src":"/assets/images/button_square_depth_gloss.png"
},
{
"alias":"btn-bg-press",
"src":"/assets/images/button_square_depth_gradient.png"
}
]
}
]
}

45
src/Game/Assets.ts

@ -0,0 +1,45 @@
import { Assets } from "pixi.js";
export async function initAssets() {
await Assets.init({ manifest: "/manifest.json" })
}
const catchMap = new Map()
export async function loadAsset(name: string, cb?: (progress: number) => void) {
const check = () => {
if (catchMap.has(name)) {
const rr = catchMap.get(name)
rr.count++
console.log(2211);
catchMap.set(name, rr)
cb?.(1)
return rr.data
}
}
check()
const res = await Assets.loadBundle(name, (progress: number) => {
cb?.(progress)
})
let r = check()
if (r) return r
catchMap.set(name, {
data: res,
count: 1
})
return res
}
/**
*
*/
export async function unLoadAsset(name: string) {
if (catchMap.has(name)) {
const rr = catchMap.get(name)
rr.count--
if (rr.count == 0) {
await Assets.unloadBundle(name)
catchMap.delete(name)
}
}
}

75
src/Game/Game.ts

@ -1,17 +1,17 @@
import {
autoDetectRenderer,
Container,
AbstractRenderer,
Renderer,
Ticker,
Loader,
utils, Graphics,
} from "pixi.js";
import detectOrient from "./detectOrient";
import { EDirection } from "@/enmu";
import { initDevtools } from '@pixi/devtools';
export default class Game {
constructor() {
this.init()
// this.init()
}
private static instance: Game = new Game();
@ -23,33 +23,59 @@ export default class Game {
}
private _stage: Container;
private _renderer: AbstractRenderer;
private _renderer: Renderer;
private _ticker: Ticker;
private _loader: Loader;
private direction: EDirection = EDirection.Portrait;
public get renderer(): AbstractRenderer {
public get renderer(): Renderer {
return this._renderer;
}
public get stage(): Container {
return this._stage;
}
public get ticker(): Ticker {
return this._ticker;
}
public get loader(): Loader {
return this._loader;
}
public get utils() {
return utils;
}
public info = {
width: 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.clientWidth
const height = document.documentElement.clientHeight
return {
widght: width,
height: height,
}
}
// const width = document.documentElement.clientHeight * 1136 / 640
// const height = document.documentElement.clientHeight
// return {
// widght: width,
// height: height,
// }
const width = document.documentElement.clientWidth
const height = document.documentElement.clientHeight
return {
widght: width,
height: height,
}
}
getInfo() {
return this.info;
}
@ -60,8 +86,9 @@ export default class Game {
}
updateView() {
let screenWidght = document.documentElement.clientWidth;
let screenHeight = document.documentElement.clientHeight;
const screenInfo = this.screenInfo()
let screenWidght = screenInfo.widght;
let screenHeight = screenInfo.height;
this.renderer.resize(screenWidght, screenHeight);
let offsetWidth = 0;
let offsetHeight = 0;
@ -113,34 +140,40 @@ export default class Game {
}
}
init() {
let screenWidght = document.documentElement.clientWidth;
let screenHeight = document.documentElement.clientHeight;
async init() {
const screenInfo = this.screenInfo()
let screenWidght = screenInfo.widght;
let screenHeight = screenInfo.height;
const stage = new Container();
stage.name = "root";
let renderer = autoDetectRenderer({
stage.label = "root";
let renderer = await autoDetectRenderer({
autoDensity: true,
width: screenWidght,
height: screenHeight,
antialias: true,
backgroundAlpha: 255,
resolution: 1,
resolution: 2,
backgroundColor: 0x1d9ce0,
forceCanvas: true,
});
this._stage = stage;
this._renderer = renderer;
document.body.appendChild(renderer.view);
// https://www.cnblogs.com/haqiao/p/12515775.html
this.renderer.resize(screenWidght, screenHeight)
document.body.appendChild(renderer.canvas);
window.addEventListener("resize", () => {
this.updateView();
});
const ticker = new Ticker();
// const ticker = new Ticker();
const ticker = Ticker.shared; // 单例
ticker.autoStart = true;
this._ticker = ticker;
const loader = new Loader();
this._loader = loader;
initDevtools({ stage, renderer });
}
render() {

26
src/Game/Position.ts

@ -0,0 +1,26 @@
import { gameManager } from "@/Game";
import { PointData } 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<PointData>): PointData {
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 { LoaderResource } from "pixi.js";
// import { LoaderResource } from "pixi.js";
export function addSound(e: LoaderResource) {
console.log(e);
sound.add(e.name, {
source: e.data,
singleInstance: true,
autoPlay: false,
});
}
sound.add('my-sound', {
url: "/bg.mp3",
singleInstance: true,
autoPlay: false,
});
// export function addSound(e: LoaderResource) {
// console.log(e);
// sound.add(e.name, {
// source: e.data,
// singleInstance: true,
// autoPlay: false,
// });
// }
export default sound;

56
src/Game/Stage.ts

@ -1,6 +1,7 @@
import { EP } from "@/enmu";
import { Container } from "pixi.js";
import Game from "./Game";
import { windows } from ".";
type TStage = {
type: EP,
@ -28,10 +29,16 @@ export default class Stage {
watchStageChange(cb: (stage: TStage, lastStage?:TStage)=>void){
this._wscb.push(cb)
}
async runStageChange(stage: TStage, lastStage?: TStage){
for (let i = 0; i < this._wscb.length; i++) {
const cb = this._wscb[i];
await cb(stage, lastStage)
}
}
initStage(name: string){
if(!this._stages[name]){
throw new Error("不存在该舞台")
throw new Error("不存在该舞台: " + name)
}
let curStage = this._stages[name];
this.curStage = curStage
@ -44,12 +51,12 @@ export default class Stage {
}else if(curStage&&curStage.type === EP.Resident){
curStage.stage.visible = true
}
this._wscb.forEach(v=>v(curStage))
this.runStageChange(curStage)
}
changeStage(name: string){
changeStage(name: string, opts?: {isHolderLast?: boolean}){
if(!this._stages[name]){
throw new Error("不存在该舞台")
throw new Error("不存在该舞台: " + name)
}
if(!this.curStage){
console.warn("请先初始化一个场景")
@ -57,32 +64,55 @@ export default class Stage {
}
let lastStage = this.curStage
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 {
lastStage.stage.destroy({
children: true
})
this.gameManager.stage.removeChild(lastStage.stage)
}
}else if(lastStage&&lastStage.type === EP.Resident){
lastStage.stage.visible = false
}
let curStage = this._stages[name];
if(curStage && typeof curStage === "string"){
if(curStage && typeof curStage === "string" && curStage === "已销毁"){
this.create(name, EP.Normal)
curStage = this._stages[name]
console.log(curStage);
}
this.curStage = curStage
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){
curStage.stage.visible = true
}
this._wscb.forEach(v=>v(curStage, lastStage))
this.runStageChange(curStage, lastStage)
if(lastStage&&lastStage.type === EP.Normal){
if(lastStage&&lastStage.type === EP.Normal && !opts?.isHolderLast){
lastStage.stage.destroy()
this._stages[lastStage.name] = "已销毁" as any
}
}
getStage(name: string): Container{
return this._stages[name].stage
}
checkStageMustExist(name: string, type: EP = EP.Normal){
if(!this._stages[name]){
this.create(name, type)
}
}
getStage(name: string, type: EP = EP.Normal): Container{
getInitStage(name: string, type: EP = EP.Normal): Container{
if(name === "root"){
throw new Error("最好换过一个名字")
}
@ -97,14 +127,14 @@ export default class Stage {
private create(name: string, type: EP = EP.Normal): Container{
const stage = new Container();
stage.name = name
stage.label = name
this._stages[name] = {
type: type,
stage: stage,
name: name
}
if(type === EP.Resident){
stage.visible = false
stage.visible = true
this.gameManager.stage.addChild(stage)
}
return stage

157
src/Game/index.ts

@ -1,74 +1,150 @@
import Game from "./Game";
import Stage from "./Stage";
import { Container, LoaderResource, Loader } from "pixi.js";
import { Container, Ticker } from "pixi.js";
import * as PIXI from "pixi.js";
import { EP } from "@/enmu";
import TWEEN from "@tweenjs/tween.js";
const gameManager = Game.getInstance();
const stageManager = Stage.getInstance();
const windows: Record<string, IWindow>= {}
const windows: Record<string, IWindow> = {}
const residentList: IWindow[] = []
function defineLoadResource(resources: {name: string, url: string, callback?: LoaderResource.OnCompleteSignal}[]) {
return resources
}
function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP) {
return { name, abstractClass, type}
function defineWindow(name: string, abstractClass: Constructor<IWindow>, type?: EP): any
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");
for (const tKey in t) {
const mod = t[tKey].default || t[tKey]
const {name, abstractClass, type} = mod as ReturnType<typeof defineWindow>
const stage = stageManager.getStage(name, type);
const stageClass = new abstractClass(stage)
if(EP.Resident === type) {
residentList.push(stageClass)
function initStage() {
const t = import.meta.glob("../stages/**/page_*.ts", { eager: true });
for (const tKey in t) {
const mod = (t[tKey] as any).default || t[tKey]
const [_, tKeyName] = tKey.match(/page_(.*?)\.ts$/)
const { name, abstractClass, type } = mod as ReturnType<typeof defineWindow>
// stageManager.getInitStage(name || tKeyName, type);
const stageClass = new abstractClass()
if ((name || tKeyName) == "init") {
setTimeout(() => {
// 延迟,等其他逻辑完成之后再执行
stageManager.checkStageMustExist(name || tKeyName, type)
stageManager.initStage(name || tKeyName)
}, 0);
}
stageClass.changeStage = (name: string, opts?: { isHolderLast?: boolean }) => {
stageManager.checkStageMustExist(name, type)
stageManager.changeStage(name, opts)
}
stageClass._type = type
stageClass._initLayout = false
stageClass.$name = name || tKeyName
if (EP.Resident === type) {
stageClass.stage = stageManager.getInitStage(name || tKeyName, type)
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;
interface IWindow {
export interface IWindow {
_type?: EP;
_initLayout?: Boolean;
_initAssets?: Boolean;
stage: Container;
loader?: Loader;
components: Record<string, any>;
changeStage?(name: string, opts?: { isHolderLast?: boolean }): void;
loadBundle?(): void;
unLoadBundle?(): void;
layout?(): void;
onLoad?(): void;
onUnLoad?(): void;
lateUpdate?(dt: number, name: string): void;
update?(dt: number, name: string): void;
lateUpdate?(dt: number, name: string, ticker: Ticker): void;
update?(dt: number, name: string, ticker: Ticker): void;
}
export function GG(name: string){
console.log(windows);
console.log(residentList);
const win = windows[name]
return win
}
function initGame() {
initStage()
// 场景切换监听
stageManager.watchStageChange((stage, lastStage) => {
if (lastStage && lastStage.type === EP.Normal) {
let lastWindow = windows[lastStage.name];
lastWindow.onUnLoad && lastWindow.onUnLoad();
}
stageManager.watchStageChange(async (stage, lastStage) => {
if (stage && stage.type === EP.Normal) {
let curWindow = windows[stage.name];
curWindow.onLoad && curWindow.onLoad();
if (lastStage && lastStage.type === EP.Normal) {
let lastWindow = windows[lastStage.name];
// @ts-ignore
if (lastWindow._initAssets && lastWindow.stage && !lastWindow.stage.$isHolderLast) {
await lastWindow.unLoadBundle?.()
lastWindow._initAssets = false
}
lastWindow.onUnLoad && await lastWindow.onUnLoad();
lastWindow.stage = stageManager.getStage(lastStage.name)
}
const isSameStage = curWindow.stage === stage.stage
!isSameStage && (curWindow.stage = stage.stage)
if (!curWindow._initAssets) {
await curWindow.loadBundle?.()
curWindow._initAssets = true
}
if (!curWindow._initLayout || !isSameStage) {
// console.log("不同的舞台");
await curWindow.layout?.()
curWindow._initLayout = true
}
curWindow.onLoad && await curWindow.onLoad();
console.log(curWindow);
console.log(windows);
console.log(stageManager);
}
});
residentList.forEach((v) => v.onLoad && v.onLoad());
gameManager.ticker.add((dt: number) => {
(async () => {
for (let i = 0; i < residentList.length; i++) {
const v = residentList[i];
if (!v._initAssets) {
await v.loadBundle?.()
v._initAssets = true
}
if (!v._initLayout) {
await v.layout?.()
v._initLayout = true
}
v.onLoad && await v.onLoad()
}
})()
gameManager.ticker.add(async (ticker: Ticker) => {
const dt = ticker.deltaTime
if (!stageManager.curStage) return;
let curWindow = windows[stageManager.curStage.name];
TWEEN.update();
residentList.forEach((v) => v.update && v.update(dt, v.stage.name));
if (!curWindow.stage) return;
for (let i = 0; i < residentList.length; i++) {
const v = residentList[i];
v.update && await v.update(dt, v.stage.label, ticker)
}
stageManager.curStage &&
curWindow &&
curWindow.update &&
curWindow.update(dt, curWindow.stage.name);
curWindow &&
curWindow.update &&
await curWindow.update(dt, curWindow.stage.label, ticker);
gameManager.render();
stageManager.curStage &&
curWindow &&
curWindow.lateUpdate &&
curWindow.lateUpdate(dt, curWindow.stage.name);
residentList.forEach((v) => v.lateUpdate && v.lateUpdate(dt, v.stage.name));
curWindow &&
curWindow.lateUpdate &&
await curWindow.lateUpdate(dt, curWindow.stage.label, ticker);
for (let i = 0; i < residentList.length; i++) {
const v = residentList[i];
v.update && await v.lateUpdate && v.lateUpdate(dt, v.stage.label, ticker)
}
});
}
@ -76,7 +152,6 @@ export {
initGame,
gameManager,
stageManager,
defineLoadResource,
defineWindow,
windows,
residentList,

21
src/Game/type.ts

@ -0,0 +1,21 @@
import { EP } from "@/enmu";
import { IWindow } from ".";
import { Container, Ticker } from "pixi.js";
export abstract class PWindow implements IWindow {
components: Record<string, any>;
_type?: EP;
_initLayout?: Boolean;
_initAssets?: Boolean;
_layoutChild?: void | any[];
stage: Container;
loader?: Loader;
changeStage?(name: string, opts?: {isHolderLast?: boolean}): void;
loadBundle?(): void;
unLoadBundle?(): void;
layout?(): void;
onLoad?(): void;
onUnLoad?(): void;
lateUpdate?(dt: number, name: string, ticker: Ticker): void;
update?(dt: number, name: string, ticker: Ticker): void;
}

191
src/components/Button.ts

@ -1,66 +1,159 @@
import { Text, Graphics, Container, TextStyle } from "pixi.js";
import { Text, Graphics, Container, TextStyle, NineSlicePlane, Texture, NineSliceSprite, Ticker } from "pixi.js";
interface IOpts {
text: string;
autoUpdate: Boolean;
bg: Texture;
pressBg: Texture;
position: null | any;
click(): void;
}
const defaultOpts: IOpts = {
autoUpdate: true,
text: "",
click() {},
bg: null,
position: null,
pressBg: null,
click() { },
};
export default function Button(opts: Partial<IOpts>) {
let curOpts: Partial<IOpts> = {};
(Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => {
if (opts[key] != undefined) {
curOpts[key] = opts[key];
function getConfig() {
return Object.assign({}, defaultOpts)
}
export class Button {
config: IOpts
_comp: Container
textObj: Text
bgRect: Graphics
bgNine: NineSliceSprite
padding = { x: 60, y: 40 }
getComp(){
return this._comp
}
constructor(opts: Partial<IOpts>) {
this.config = getConfig();
; (Object.keys(defaultOpts) as (keyof IOpts)[]).forEach((key) => {
if (opts[key] != undefined) {
this.config[key] = opts[key] as any;
}
});
this._comp = new Container();
this._comp.cursor = 'pointer';
this._comp.interactive = true;
if (!this.config.bg) {
this.createRect()
this._comp.addChild(this.bgRect)
} else {
curOpts[key] = defaultOpts[key];
this.createNine()
this._comp.addChild(this.bgNine)
}
this.createText()
this._comp.addChild(this.textObj)
if (this.config.autoUpdate) {
const update = () => {
this.updateView()
}
Ticker.shared.add(update)
this._comp.on("destroyed", ()=>{
console.log("销毁了");
Ticker.shared.remove(update, this)
})
}
const downFN = () => {
if (this.config.pressBg && this.bgNine) {
this.bgNine.texture = this.config.pressBg
} else {
this._comp.alpha = 0.8;
this._comp.scale = { x: .8, y: .8 }
}
}
this._comp.on("mousedown", downFN);
this._comp.on("touchstart", downFN);
const upFN = () => {
if (this.config.pressBg && this.bgNine) {
this.bgNine.texture = this.config.bg
} else {
this._comp.alpha = 1;
this._comp.scale = { x: 1, y: 1 }
}
this.config.click();
}
});
this._comp.on('mouseup', upFN);
this._comp.on('touchend', upFN);
const upOutsideFN = () => {
if (this.config.pressBg) {
this.bgNine.texture = this.config.bg
} else {
this._comp.alpha = 1;
this._comp.scale = { x: 1, y: 1 }
}
}
this._comp.on("mouseupoutside", upOutsideFN);
this._comp.on("touchendoutside", upOutsideFN);
}
let textStyle = new TextStyle({
fontFamily: "Arial",
fontSize: 50,
fill: 0xffffff,
align: "center",
});
let textStr = new Text(curOpts.text, textStyle);
let xPadding = 60;
let yPadding = 40;
updateView() {
if(this._comp.destroyed) return
let width = this.textObj.width + this.padding.x;
let height = this.textObj.height + this.padding.y;
this._comp.pivot.set(width / 2, height / 2)
this.textObj.x = this.padding.x / 2;
this.textObj.y = this.padding.y / 2 - 2;
let button = new Container();
let width = textStr.width + xPadding;
let height = textStr.height + yPadding;
textStr.x = xPadding / 2;
textStr.y = yPadding / 2;
if (this.bgRect) {
this.bgRect.rect(0, 0, width, height);
this.bgRect.fill(0xff0000);
}
if (this.bgNine) {
this.bgNine.width = width
this.bgNine.height = height
}
const rect = new Graphics();
rect.name = "rect";
rect.beginFill(0xff0000);
rect.drawRect(0, 0, width, height);
rect.endFill();
rect.interactive = true;
rect.buttonMode = true;
if (this.config.position) {
this._comp.position = this.config.position()
}
}
button.addChild(rect);
button.addChild(textStr);
button.x = 100;
button.y = 50;
button.interactive = true;
button.on("touchstart", () => {
button.alpha = 0.8;
});
button.on("touchend", () => {
// 点击成功
console.log("success");
curOpts.click();
button.alpha = 1;
});
button.on("touchendoutside", () => {
button.alpha = 1;
});
return button;
createNine() {
this.bgNine = new NineSliceSprite({
texture: this.config.bg,
leftWidth: 10,
topHeight: 10,
rightWidth: 10,
bottomHeight: 10,
});
this.bgNine.cursor = 'pointer';
this.bgNine.label = "nine-pic"
this.bgNine.interactive = true;
// plane9.buttonMode = true;
}
createRect() {
this.bgRect = new Graphics();
this.bgRect.label = "rect";
this.bgRect.interactive = true;
this.bgRect.cursor = 'pointer';
// rect.buttonMode = true;
}
createText() {
let textStyle = new TextStyle({
fontFamily: "Arial",
fontSize: 30,
fill: 0xffffff,
align: "center",
});
this.textObj = new Text({
text: this.config.text,
style: textStyle
});
this.textObj.cursor = 'pointer';
this.textObj.label = "text"
}
}
export default Button

44
src/main.ts

@ -1,20 +1,32 @@
import { Assets } from "pixi.js";
import { EDirection } from "./enmu";
import { gameManager, initGame, stageManager, windows } from "./Game";
import { addSound } from "./Game/Sound";
import { gameManager, initGame, stageManager } from "./Game";
import Game from "./Game/Game";
import { initAssets } from "./Game/Assets";
console.log();
// gameManager.loader
// // .add("my-sound", "/bg.mp3", (e) => addSound(e)) // 背景音乐
// .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();
gameManager.loader
.add("my-sound", "/bg.mp3", (e) => addSound(e))
.add("bg", "/bg.png")
.load();
gameManager.loader.onProgress.add((loader) => {
console.log(loader.progress);
});
gameManager.loader.onComplete.once((loader) => {
console.log(loader.resources);
initGame();
gameManager.setDirection(EDirection.Portrait);
stageManager.initStage("loading");
// gameManager.loader.onProgress.add((loader) => {
// console.log(loader.progress);
// });
// gameManager.loader.onComplete.once((loader) => {
// console.log(loader.resources);
// initGame();
// gameManager.setDirection(EDirection.Landscape);
// stageManager.initStage("init");
// });
});
setTimeout(() => {
;(async ()=>{
await initAssets();
await Game.getInstance().init()
initGame();
gameManager.setDirection(EDirection.Landscape);
})()
}, 200);

44
src/stages/_global/page_0global.ts

@ -0,0 +1,44 @@
import { Button } from "@/components/Button";
import { EP } from "@/enmu";
import { defineWindow } from "@/Game";
import { loadAsset } from "@/Game/Assets";
import Position from "@/Game/Position";
import { PWindow } from "@/Game/type";
import { Assets, Container } from "pixi.js";
export default defineWindow(
class extends PWindow {
btn: Button;
async loadBundle() {
console.log(this.stage);
console.log("加载资源");
Assets.add({ alias: 'btn-bgaa', src: '/assets/images/button_square_depth_gloss.png' })
Assets.add({ alias: 'btn-bg-pressaa', src: '/assets/images/button_square_depth_gradient.png' })
const aa = await Assets.load('btn-bgaa')
console.log(aa);
}
async layout() {
this.stage.zIndex = 9999
this.btn = new Button({
text: "全局",
bg: await Assets.load('btn-bgaa'),
pressBg: await Assets.load("btn-bg-pressaa"),
position: () => Position.get("center", "center", { y: 100, x: 0 })
})
this.stage.addChild(this.btn._comp)
}
onLoad() {
console.log("global page loaded");
}
hide() {
// this.btn._comp.visible = false
}
show() {
// this.btn._comp.visible = true
}
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);

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save