labag 2.2.13 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/labag.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Mode } from "./mode";
2
+ import { ModeName } from "./modes";
2
3
  import { Pattern, LaBaGEvent } from "./types";
3
4
  /**
4
5
  * 拉霸遊戲的主要類別。
@@ -58,7 +59,7 @@ export declare class LaBaG {
58
59
  * 取得目前遊戲的相關設定
59
60
  */
60
61
  getCurrentConfig(): {
61
- modes: Mode<string>[];
62
+ modes: Mode[];
62
63
  ranges: {
63
64
  threshold: number;
64
65
  pattern: Pattern;
@@ -83,5 +84,5 @@ export declare class LaBaG {
83
84
  private roundEnd;
84
85
  private gameOver;
85
86
  play(): void;
86
- getMode(modeName: string): Mode | undefined;
87
+ getMode(modeName: ModeName): Mode | undefined;
87
88
  }
package/dist/mode.d.ts CHANGED
@@ -3,11 +3,11 @@ import { LaBaGEvent, Pattern, PatternName } from "./types";
3
3
  /**
4
4
  * 代表遊戲的一種模式,包含機率設定和事件監聽器。
5
5
  */
6
- export declare class Mode<N extends string = string> {
6
+ export declare class Mode {
7
7
  /** 模式是否啟用 */
8
8
  active: boolean;
9
9
  /** 模式名稱 */
10
- name: N;
10
+ name: string;
11
11
  /** 各圖案出現的機率 */
12
12
  rates: Record<PatternName, number>;
13
13
  ranges: {
@@ -26,5 +26,5 @@ export declare class Mode<N extends string = string> {
26
26
  * @param rates - 各圖案的機率設定。
27
27
  * @param eventListener - 事件監聽器。
28
28
  */
29
- constructor(active: boolean, name: N, rates: Record<PatternName, number>, eventListener?: Partial<Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>>, variable?: Record<string, any>);
29
+ constructor(active: boolean, name: string, rates: Record<PatternName, number>, eventListener?: Partial<Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>>, variable?: Record<string, any>);
30
30
  }
@@ -1,3 +1,3 @@
1
1
  import { Mode } from "../mode";
2
- declare const _default: Mode<"greenwei">;
2
+ declare const _default: Mode;
3
3
  export default _default;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const pattern_1 = require("src/pattern");
3
4
  const mode_1 = require("../mode");
4
5
  const randInt_1 = require("../utils/randInt");
5
6
  exports.default = new mode_1.Mode(false, "greenwei", {
@@ -34,7 +35,7 @@ exports.default = new mode_1.Mode(false, "greenwei", {
34
35
  let gssCount = 0;
35
36
  let allGSS = true;
36
37
  for (const p of patterns) {
37
- if (p?.name === mode.variable.bindPattern) {
38
+ if (p?.name === mode.variable.bindPattern.name) {
38
39
  gssCount++;
39
40
  }
40
41
  else {
@@ -64,7 +65,7 @@ exports.default = new mode_1.Mode(false, "greenwei", {
64
65
  if (activated) {
65
66
  mode.active = true;
66
67
  for (let i = 0; i < patterns.length; i++) {
67
- if (patterns[i]?.name === mode.variable.bindPattern) {
68
+ if (patterns[i]?.name === mode.variable.bindPattern.name) {
68
69
  patterns[i] = variable.pattern;
69
70
  }
70
71
  }
@@ -81,7 +82,7 @@ exports.default = new mode_1.Mode(false, "greenwei", {
81
82
  scores: [800, 400, 180],
82
83
  },
83
84
  extendTimes: 2,
84
- bindPattern: "gss",
85
+ bindPattern: pattern_1.patterns[0],
85
86
  bonusTimes: 2,
86
87
  requiredGssCount: 20,
87
88
  mutiplier: 3,
@@ -1,8 +1,8 @@
1
1
  export declare const modes: {
2
- pikachu: import("..").Mode<"pikachu">;
3
- superhhh: import("..").Mode<"superhhh">;
4
- greenwei: import("..").Mode<"greenwei">;
5
- normal: import("..").Mode<"normal">;
2
+ pikachu: import("..").Mode;
3
+ superhhh: import("..").Mode;
4
+ greenwei: import("..").Mode;
5
+ normal: import("..").Mode;
6
6
  };
7
- export type ModeName = (typeof modes)[keyof typeof modes]["name"];
8
- export declare const modeList: (import("..").Mode<"greenwei"> | import("..").Mode<"normal"> | import("..").Mode<"pikachu"> | import("..").Mode<"superhhh">)[];
7
+ export type ModeName = keyof typeof modes;
8
+ export declare const modeList: import("..").Mode[];
@@ -1,3 +1,3 @@
1
1
  import { Mode } from "../mode";
2
- declare const _default: Mode<"normal">;
2
+ declare const _default: Mode;
3
3
  export default _default;
@@ -1,3 +1,3 @@
1
1
  import { Mode } from "../mode";
2
- declare const _default: Mode<"pikachu">;
2
+ declare const _default: Mode;
3
3
  export default _default;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const pattern_1 = require("src/pattern");
3
4
  const mode_1 = require("../mode");
4
5
  exports.default = new mode_1.Mode(false, "pikachu", {
5
6
  gss: 36,
@@ -15,13 +16,13 @@ exports.default = new mode_1.Mode(false, "pikachu", {
15
16
  },
16
17
  roundEnd: (game, mode) => {
17
18
  const { patterns } = game;
18
- const hasBindPattern = patterns.some((p) => p && p.name === mode.variable.bindPattern);
19
+ const hasBindPattern = patterns.some((p) => p && p.name === mode.variable.bindPattern.name);
19
20
  if (!game.isRunning() && hasBindPattern) {
20
21
  mode.active = true;
21
22
  game.played -= mode.variable.bonusRounds;
22
23
  mode.variable.times += 1;
23
24
  patterns.forEach((p, i) => {
24
- if (p?.name === mode.variable.bindPattern) {
25
+ if (p?.name === mode.variable.bindPattern.name) {
25
26
  patterns[i] = mode.variable.pattern;
26
27
  }
27
28
  });
@@ -37,6 +38,6 @@ exports.default = new mode_1.Mode(false, "pikachu", {
37
38
  name: "pikachu",
38
39
  scores: [12000, 8000, 1250],
39
40
  },
40
- bindPattern: "kachu",
41
+ bindPattern: pattern_1.patterns[4],
41
42
  bonusRounds: 5,
42
43
  });
@@ -1,3 +1,3 @@
1
1
  import { Mode } from "../mode";
2
- declare const _default: Mode<"superhhh">;
2
+ declare const _default: Mode;
3
3
  export default _default;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const pattern_1 = require("src/pattern");
3
4
  const mode_1 = require("../mode");
4
5
  const randInt_1 = require("../utils/randInt");
5
6
  exports.default = new mode_1.Mode(false, "superhhh", {
@@ -27,7 +28,7 @@ exports.default = new mode_1.Mode(false, "superhhh", {
27
28
  calculateScore: (game, mode) => {
28
29
  if (mode.active)
29
30
  return;
30
- if (game.patterns.every((p) => p?.name === mode.variable.bindPattern) &&
31
+ if (game.patterns.every((p) => p?.name === mode.variable.bindPattern.name) &&
31
32
  mode.variable.randNum <= mode.variable.rate) {
32
33
  mode.variable.score += Math.round(game.score / 2);
33
34
  game.marginScore += mode.variable.score;
@@ -39,7 +40,7 @@ exports.default = new mode_1.Mode(false, "superhhh", {
39
40
  let hhhCount = 0;
40
41
  let allHHH = true;
41
42
  for (const p of patterns) {
42
- if (p?.name === mode.variable.bindPattern)
43
+ if (p?.name === mode.variable.bindPattern.name)
43
44
  hhhCount++;
44
45
  else
45
46
  allHHH = false;
@@ -57,7 +58,7 @@ exports.default = new mode_1.Mode(false, "superhhh", {
57
58
  mode.active = true;
58
59
  variable.times += variable.bonusTimes;
59
60
  for (let i = 0; i < patterns.length; i++) {
60
- if (patterns[i]?.name === mode.variable.bindPattern) {
61
+ if (patterns[i]?.name === mode.variable.bindPattern.name) {
61
62
  patterns[i] = variable.pattern;
62
63
  }
63
64
  }
@@ -69,7 +70,7 @@ exports.default = new mode_1.Mode(false, "superhhh", {
69
70
  rate: 15,
70
71
  score: 0,
71
72
  randNum: 0,
72
- bindPattern: "hhh",
73
+ bindPattern: pattern_1.patterns[1],
73
74
  bonusTimes: 6,
74
75
  pattern: {
75
76
  name: "superhhh",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labag",
3
- "version": "2.2.13",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/labag.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Mode } from "./mode";
2
+ import { ModeName } from "./modes";
2
3
  import { patterns } from "./pattern";
3
4
  import { Pattern, LaBaGEvent, PatternName } from "./types";
4
5
  import { randInt } from "./utils/randInt";
@@ -250,7 +251,7 @@ export class LaBaG {
250
251
  }
251
252
  }
252
253
 
253
- getMode(modeName: string): Mode | undefined {
254
+ getMode(modeName: ModeName): Mode | undefined {
254
255
  return this.modes.find((mode) => mode.name === modeName);
255
256
  }
256
257
  }
package/src/mode.ts CHANGED
@@ -5,17 +5,19 @@ import { LaBaGEvent, Pattern, PatternName } from "./types";
5
5
  /**
6
6
  * 代表遊戲的一種模式,包含機率設定和事件監聽器。
7
7
  */
8
- export class Mode<N extends string = string> {
8
+ export class Mode{
9
9
  /** 模式是否啟用 */
10
10
  active: boolean;
11
11
  /** 模式名稱 */
12
- name: N;
12
+ name: string;
13
13
  /** 各圖案出現的機率 */
14
14
  rates: Record<PatternName, number>;
15
15
  // 預先計算的區間,用於高效查找
16
16
  ranges: { threshold: number; pattern: Pattern }[];
17
17
  /** 事件監聽器 */
18
- eventListener: Partial<Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>>;
18
+ eventListener: Partial<
19
+ Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>
20
+ >;
19
21
 
20
22
  /** 模式專屬的變數儲存空間 */
21
23
  variable: Record<string, any>;
@@ -30,7 +32,7 @@ export class Mode<N extends string = string> {
30
32
  */
31
33
  constructor(
32
34
  active: boolean,
33
- name: N,
35
+ name: string,
34
36
  rates: Record<PatternName, number>,
35
37
  eventListener?: Partial<
36
38
  Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>
@@ -55,4 +57,4 @@ export class Mode<N extends string = string> {
55
57
  }
56
58
  }
57
59
  }
58
- }
60
+ }
@@ -1,3 +1,4 @@
1
+ import { patterns } from "src/pattern";
1
2
  import { Mode } from "../mode";
2
3
  import { randInt } from "../utils/randInt";
3
4
 
@@ -39,7 +40,7 @@ export default new Mode(
39
40
  let gssCount = 0;
40
41
  let allGSS = true;
41
42
  for (const p of patterns) {
42
- if (p?.name === mode.variable.bindPattern) {
43
+ if (p?.name === mode.variable.bindPattern.name) {
43
44
  gssCount++;
44
45
  } else {
45
46
  allGSS = false;
@@ -69,7 +70,7 @@ export default new Mode(
69
70
  if (activated) {
70
71
  mode.active = true;
71
72
  for (let i = 0; i < patterns.length; i++) {
72
- if (patterns[i]?.name === mode.variable.bindPattern) {
73
+ if (patterns[i]?.name === mode.variable.bindPattern.name) {
73
74
  patterns[i] = variable.pattern;
74
75
  }
75
76
  }
@@ -87,7 +88,7 @@ export default new Mode(
87
88
  scores: [800, 400, 180],
88
89
  },
89
90
  extendTimes: 2,
90
- bindPattern: "gss",
91
+ bindPattern: patterns[0],
91
92
  bonusTimes: 2,
92
93
  requiredGssCount: 20,
93
94
  mutiplier: 3,
@@ -8,8 +8,8 @@ export const modes = {
8
8
  superhhh,
9
9
  greenwei,
10
10
  normal,
11
- }
11
+ };
12
12
 
13
- export type ModeName = (typeof modes)[keyof typeof modes]["name"];
13
+ export type ModeName = keyof typeof modes;
14
14
 
15
15
  export const modeList = Object.values(modes);
@@ -1,3 +1,4 @@
1
+ import { patterns } from "src/pattern";
1
2
  import { Mode } from "../mode";
2
3
 
3
4
  export default new Mode(
@@ -19,7 +20,7 @@ export default new Mode(
19
20
  roundEnd: (game, mode) => {
20
21
  const { patterns } = game;
21
22
  const hasBindPattern = patterns.some(
22
- (p) => p && p.name === mode.variable.bindPattern
23
+ (p) => p && p.name === mode.variable.bindPattern.name
23
24
  );
24
25
 
25
26
  if (!game.isRunning() && hasBindPattern) {
@@ -27,7 +28,7 @@ export default new Mode(
27
28
  game.played -= mode.variable.bonusRounds;
28
29
  mode.variable.times += 1;
29
30
  patterns.forEach((p, i) => {
30
- if (p?.name === mode.variable.bindPattern) {
31
+ if (p?.name === mode.variable.bindPattern.name) {
31
32
  patterns[i] = mode.variable.pattern;
32
33
  }
33
34
  });
@@ -45,7 +46,7 @@ export default new Mode(
45
46
  name: "pikachu",
46
47
  scores: [12000, 8000, 1250],
47
48
  },
48
- bindPattern: "kachu",
49
+ bindPattern: patterns[4],
49
50
  bonusRounds: 5,
50
51
  }
51
52
  );
@@ -1,3 +1,4 @@
1
+ import { patterns } from "src/pattern";
1
2
  import { Mode } from "../mode";
2
3
  import { randInt } from "../utils/randInt";
3
4
 
@@ -29,7 +30,9 @@ export default new Mode(
29
30
  calculateScore: (game, mode) => {
30
31
  if (mode.active) return;
31
32
  if (
32
- game.patterns.every((p) => p?.name === mode.variable.bindPattern) &&
33
+ game.patterns.every(
34
+ (p) => p?.name === mode.variable.bindPattern.name
35
+ ) &&
33
36
  mode.variable.randNum <= mode.variable.rate
34
37
  ) {
35
38
  mode.variable.score += Math.round(game.score / 2);
@@ -43,7 +46,7 @@ export default new Mode(
43
46
  let hhhCount = 0;
44
47
  let allHHH = true;
45
48
  for (const p of patterns) {
46
- if (p?.name === mode.variable.bindPattern) hhhCount++;
49
+ if (p?.name === mode.variable.bindPattern.name) hhhCount++;
47
50
  else allHHH = false;
48
51
  }
49
52
 
@@ -60,7 +63,7 @@ export default new Mode(
60
63
  variable.times += variable.bonusTimes;
61
64
 
62
65
  for (let i = 0; i < patterns.length; i++) {
63
- if (patterns[i]?.name === mode.variable.bindPattern) {
66
+ if (patterns[i]?.name === mode.variable.bindPattern.name) {
64
67
  patterns[i] = variable.pattern;
65
68
  }
66
69
  }
@@ -73,7 +76,7 @@ export default new Mode(
73
76
  rate: 15,
74
77
  score: 0,
75
78
  randNum: 0,
76
- bindPattern: "hhh",
79
+ bindPattern: patterns[1],
77
80
  bonusTimes: 6,
78
81
  pattern: {
79
82
  name: "superhhh",