labag 2.0.2 → 2.1.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/index.d.ts +3 -1
- package/dist/index.js +7 -42
- package/dist/labag.d.ts +1 -1
- package/dist/mode.d.ts +3 -3
- package/dist/modes/greenwei.d.ts +1 -1
- package/dist/modes/index.d.ts +8 -0
- package/dist/modes/index.js +17 -0
- package/dist/modes/normal.d.ts +1 -1
- package/dist/modes/pikachu.d.ts +1 -1
- package/dist/modes/superhhh.d.ts +1 -1
- package/dist/test.js +10 -13
- package/package.json +1 -1
- package/src/index.ts +15 -10
- package/src/mode.ts +3 -3
- package/src/modes/index.ts +15 -0
- package/src/test.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { LaBaG } from "./labag";
|
|
2
|
+
import { ModeName } from "./modes";
|
|
3
|
+
import { LaBaGEvent, Pattern, PatternName } from "./types";
|
|
2
4
|
declare const labag: LaBaG;
|
|
3
|
-
export
|
|
5
|
+
export { labag, type LaBaGEvent, type Pattern, type PatternName, type ModeName, };
|
package/dist/index.js
CHANGED
|
@@ -1,51 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.labag = void 0;
|
|
36
4
|
const labag_1 = require("./labag");
|
|
37
|
-
const
|
|
38
|
-
const superhhh = __importStar(require("./modes/superhhh"));
|
|
39
|
-
const greenwei = __importStar(require("./modes/greenwei"));
|
|
40
|
-
const pikachu = __importStar(require("./modes/pikachu"));
|
|
5
|
+
const modes_1 = require("./modes");
|
|
41
6
|
const labag = new labag_1.LaBaG();
|
|
42
|
-
|
|
7
|
+
exports.labag = labag;
|
|
8
|
+
modes_1.modeList.forEach((mode) => {
|
|
43
9
|
console.log(mode);
|
|
44
|
-
if (mode.
|
|
45
|
-
labag.modes.push(mode
|
|
10
|
+
if (mode.active) {
|
|
11
|
+
labag.modes.push(mode);
|
|
46
12
|
}
|
|
47
13
|
else {
|
|
48
|
-
labag.addMode(mode
|
|
14
|
+
labag.addMode(mode);
|
|
49
15
|
}
|
|
50
16
|
});
|
|
51
|
-
exports.default = labag;
|
package/dist/labag.d.ts
CHANGED
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 {
|
|
6
|
+
export declare class Mode<N extends string = string> {
|
|
7
7
|
/** 模式是否啟用 */
|
|
8
8
|
active: boolean;
|
|
9
9
|
/** 模式名稱 */
|
|
10
|
-
name:
|
|
10
|
+
name: N;
|
|
11
11
|
/** 各圖案出現的機率 */
|
|
12
12
|
rates: Record<PatternName, number>;
|
|
13
13
|
ranges: {
|
|
@@ -26,5 +26,5 @@ export declare class Mode {
|
|
|
26
26
|
* @param rates - 各圖案的機率設定。
|
|
27
27
|
* @param eventListener - 事件監聽器。
|
|
28
28
|
*/
|
|
29
|
-
constructor(active: boolean, name:
|
|
29
|
+
constructor(active: boolean, name: N, rates: Record<PatternName, number>, eventListener?: Partial<Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>>, variable?: Record<string, any>);
|
|
30
30
|
}
|
package/dist/modes/greenwei.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const modes: {
|
|
2
|
+
readonly greenwei: import("../mode").Mode<"greenwei">;
|
|
3
|
+
readonly normal: import("../mode").Mode<"normal">;
|
|
4
|
+
readonly pikachu: import("../mode").Mode<"pikachu">;
|
|
5
|
+
readonly superhhh: import("../mode").Mode<"superhhh">;
|
|
6
|
+
};
|
|
7
|
+
export type ModeName = typeof modes[keyof typeof modes]["name"];
|
|
8
|
+
export declare const modeList: (import("../mode").Mode<"greenwei"> | import("../mode").Mode<"normal"> | import("../mode").Mode<"pikachu"> | import("../mode").Mode<"superhhh">)[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.modeList = exports.modes = void 0;
|
|
7
|
+
const greenwei_1 = __importDefault(require("./greenwei"));
|
|
8
|
+
const normal_1 = __importDefault(require("./normal"));
|
|
9
|
+
const pikachu_1 = __importDefault(require("./pikachu"));
|
|
10
|
+
const superhhh_1 = __importDefault(require("./superhhh"));
|
|
11
|
+
exports.modes = {
|
|
12
|
+
greenwei: greenwei_1.default,
|
|
13
|
+
normal: normal_1.default,
|
|
14
|
+
pikachu: pikachu_1.default,
|
|
15
|
+
superhhh: superhhh_1.default,
|
|
16
|
+
};
|
|
17
|
+
exports.modeList = Object.values(exports.modes);
|
package/dist/modes/normal.d.ts
CHANGED
package/dist/modes/pikachu.d.ts
CHANGED
package/dist/modes/superhhh.d.ts
CHANGED
package/dist/test.js
CHANGED
|
@@ -1,35 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_1 =
|
|
7
|
-
index_1.
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
index_1.labag.addEventListener("gameStart", (game) => {
|
|
8
5
|
console.log("Game Started!");
|
|
9
6
|
console.log(`Total Rounds: ${game.times}\n`);
|
|
10
7
|
});
|
|
11
|
-
index_1.
|
|
8
|
+
index_1.labag.addEventListener("roundStart", (game) => {
|
|
12
9
|
console.log(`--- Round ${game.rounds} Start ---`);
|
|
13
10
|
});
|
|
14
|
-
index_1.
|
|
11
|
+
index_1.labag.addEventListener("rollSlots", (game) => {
|
|
15
12
|
const { modes, ranges } = game.getCurrentConfig();
|
|
16
13
|
console.log(`Active Modes: ${modes.map((m) => m.name).join(", ")}`);
|
|
17
14
|
console.log(`Probability Ranges: ${ranges
|
|
18
15
|
.map((r) => `${r.pattern.name}<=${r.threshold}`)
|
|
19
16
|
.join(", ")}`);
|
|
20
17
|
});
|
|
21
|
-
index_1.
|
|
18
|
+
index_1.labag.addEventListener("roundEnd", (game) => {
|
|
22
19
|
console.log(game.patterns.map((p) => (p ? p.name : "null")).join(" | "));
|
|
23
20
|
console.log(`Margin Score: ${game.marginScore}`);
|
|
24
21
|
console.log(`Score: ${game.score}\n`);
|
|
25
22
|
});
|
|
26
|
-
index_1.
|
|
27
|
-
while (index_1.
|
|
28
|
-
index_1.
|
|
23
|
+
index_1.labag.init();
|
|
24
|
+
while (index_1.labag.isRunning()) {
|
|
25
|
+
index_1.labag.play();
|
|
29
26
|
}
|
|
30
27
|
console.log("Game Over");
|
|
31
|
-
console.log(`Final Score: ${index_1.
|
|
32
|
-
console.log(`Active Modes at end: ${index_1.
|
|
28
|
+
console.log(`Final Score: ${index_1.labag.score}`);
|
|
29
|
+
console.log(`Active Modes at end: ${index_1.labag
|
|
33
30
|
.getCurrentConfig()
|
|
34
31
|
.modes.map((m) => m.name)
|
|
35
32
|
.join(", ")}`);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { LaBaG } from "./labag";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as greenwei from "./modes/greenwei";
|
|
5
|
-
import * as pikachu from "./modes/pikachu";
|
|
2
|
+
import { modeList, ModeName } from "./modes";
|
|
3
|
+
import { LaBaGEvent, Pattern, PatternName } from "./types";
|
|
6
4
|
|
|
7
5
|
const labag = new LaBaG();
|
|
8
|
-
|
|
9
|
-
console.log(mode)
|
|
10
|
-
if (mode.
|
|
11
|
-
labag.modes.push(mode
|
|
6
|
+
modeList.forEach((mode) => {
|
|
7
|
+
console.log(mode);
|
|
8
|
+
if (mode.active) {
|
|
9
|
+
labag.modes.push(mode);
|
|
12
10
|
} else {
|
|
13
|
-
labag.addMode(mode
|
|
11
|
+
labag.addMode(mode);
|
|
14
12
|
}
|
|
15
13
|
});
|
|
16
|
-
export
|
|
14
|
+
export {
|
|
15
|
+
labag,
|
|
16
|
+
type LaBaGEvent,
|
|
17
|
+
type Pattern,
|
|
18
|
+
type PatternName,
|
|
19
|
+
type ModeName,
|
|
20
|
+
|
|
21
|
+
};
|
package/src/mode.ts
CHANGED
|
@@ -5,11 +5,11 @@ import { LaBaGEvent, Pattern, PatternName } from "./types";
|
|
|
5
5
|
/**
|
|
6
6
|
* 代表遊戲的一種模式,包含機率設定和事件監聽器。
|
|
7
7
|
*/
|
|
8
|
-
export class Mode {
|
|
8
|
+
export class Mode<N extends string = string> {
|
|
9
9
|
/** 模式是否啟用 */
|
|
10
10
|
active: boolean;
|
|
11
11
|
/** 模式名稱 */
|
|
12
|
-
name:
|
|
12
|
+
name: N;
|
|
13
13
|
/** 各圖案出現的機率 */
|
|
14
14
|
rates: Record<PatternName, number>;
|
|
15
15
|
// 預先計算的區間,用於高效查找
|
|
@@ -30,7 +30,7 @@ export class Mode {
|
|
|
30
30
|
*/
|
|
31
31
|
constructor(
|
|
32
32
|
active: boolean,
|
|
33
|
-
name:
|
|
33
|
+
name: N,
|
|
34
34
|
rates: Record<PatternName, number>,
|
|
35
35
|
eventListener?: Partial<
|
|
36
36
|
Record<LaBaGEvent, (game: LaBaG, mode: Mode) => void>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import greenwei from "./greenwei";
|
|
2
|
+
import normal from "./normal";
|
|
3
|
+
import pikachu from "./pikachu";
|
|
4
|
+
import superhhh from "./superhhh";
|
|
5
|
+
|
|
6
|
+
export const modes = {
|
|
7
|
+
greenwei,
|
|
8
|
+
normal,
|
|
9
|
+
pikachu,
|
|
10
|
+
superhhh,
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export type ModeName = typeof modes[keyof typeof modes]["name"];
|
|
14
|
+
|
|
15
|
+
export const modeList = Object.values(modes);
|
package/src/test.ts
CHANGED