@starktma/minecraft-utils 1.2.9 → 1.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/README.md +57 -1
- package/dist/game-state-machine/branch.d.ts +45 -0
- package/dist/game-state-machine/branch.d.ts.map +1 -0
- package/dist/game-state-machine/branch.js +134 -0
- package/dist/game-state-machine/branch.js.map +1 -0
- package/dist/game-state-machine/constants.d.ts +2 -0
- package/dist/game-state-machine/constants.d.ts.map +1 -0
- package/dist/game-state-machine/constants.js +2 -0
- package/dist/game-state-machine/constants.js.map +1 -0
- package/dist/game-state-machine/database.d.ts +13 -0
- package/dist/game-state-machine/database.d.ts.map +1 -0
- package/dist/game-state-machine/database.js +26 -0
- package/dist/game-state-machine/database.js.map +1 -0
- package/dist/game-state-machine/index.d.ts +3 -0
- package/dist/game-state-machine/index.d.ts.map +1 -0
- package/dist/game-state-machine/index.js +3 -0
- package/dist/game-state-machine/index.js.map +1 -0
- package/dist/game-state-machine/interfaces.d.ts +24 -0
- package/dist/game-state-machine/interfaces.d.ts.map +1 -0
- package/dist/game-state-machine/interfaces.js +13 -0
- package/dist/game-state-machine/interfaces.js.map +1 -0
- package/dist/game-state-machine/level.d.ts +50 -0
- package/dist/game-state-machine/level.d.ts.map +1 -0
- package/dist/game-state-machine/level.js +133 -0
- package/dist/game-state-machine/level.js.map +1 -0
- package/dist/game-state-machine/stateMachine.d.ts +52 -0
- package/dist/game-state-machine/stateMachine.d.ts.map +1 -0
- package/dist/game-state-machine/stateMachine.js +318 -0
- package/dist/game-state-machine/stateMachine.js.map +1 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -23,4 +23,60 @@ The database utilities are intentionally small: `DatabaseManager` handles serial
|
|
|
23
23
|
- `src/database` — database manager, simple database base class, and interfaces
|
|
24
24
|
- `src/math` — math helpers
|
|
25
25
|
- `src/minecraft` — Minecraft helpers
|
|
26
|
-
- `src/player-event` — player event helpers
|
|
26
|
+
- `src/player-event` — player event helpers
|
|
27
|
+
|
|
28
|
+
# StateMachine for Minecraft Add-on
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
The StateMachine module is a comprehensive Minecraft system designed for dynamically managing game states, player interactions, and level progression within custom Minecraft maps and add-ons. It leverages the Minecraft scripting API to offer a robust framework for creating complex gameplay mechanics.
|
|
33
|
+
|
|
34
|
+
The StateMachine is still under development.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- **Branch Management:** Facilitates the creation and management of multiple game branches, each representing a unique pathway or storyline within the game world.
|
|
39
|
+
- **Level Progression:** Each branch can contain multiple levels, with a system to manage player progression through these levels.
|
|
40
|
+
- **Dynamic Player State Handling:** Tracks and updates player states based on their interactions and progress within the game.
|
|
41
|
+
- **Event-Driven Architecture:** Utilizes custom events for player actions like joining/leaving the server, respawning, or dying, and level-specific events such as level load, loop, and exit.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
1. Ensure you have the Minecraft server set up with the appropriate scripting API support.
|
|
46
|
+
2. Clone or download this repository.
|
|
47
|
+
3. Place the StateMachine module in your server's script directory or in the assets/javascript directory if you're using Anvil.
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
Import the StateMachine at the beginning of your server script:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { stateMachine, mainBranch, mainLevel0 } from "@starktma/minecraft-utils/game-state-machine";
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Use the provided methods to create and manage branches and levels, and to handle player states and events.
|
|
58
|
+
|
|
59
|
+
### Example
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
// Create a new branch
|
|
63
|
+
const myBranch = stateMachine.createBranch("myCustomBranch");
|
|
64
|
+
|
|
65
|
+
// Add levels to the branch
|
|
66
|
+
const level1 = myBranch.addLevel();
|
|
67
|
+
const level2 = myBranch.addLevel();
|
|
68
|
+
|
|
69
|
+
// Set up event listeners for player actions
|
|
70
|
+
level1.events.onPlayerJoinLevel((player) => {
|
|
71
|
+
// Custom logic when a player joins level 1
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
Detailed documentation of classes, methods, and their usage can be found in the respective TypeScript files within the module.
|
|
78
|
+
|
|
79
|
+
- **StateMachine**: Core class for managing branches, levels, and player states.
|
|
80
|
+
- **Branch**: Class representing a game branch, capable of holding multiple levels.
|
|
81
|
+
- **Level**: Class for individual levels within a branch, with its own lifecycle and events.
|
|
82
|
+
- **PlayerDatabase & StateMachineDatabase**: Classes for managing persistent data related to players and game states.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BranchDatabase } from "./database";
|
|
2
|
+
import { Level } from "./level";
|
|
3
|
+
import { levelState } from "./interfaces";
|
|
4
|
+
declare class BranchManager {
|
|
5
|
+
protected branchDatabase: BranchDatabase;
|
|
6
|
+
protected levels: Map<string, Level>;
|
|
7
|
+
protected defaultActiveLevel: string | undefined;
|
|
8
|
+
identifier: string;
|
|
9
|
+
activeLevel: string | undefined;
|
|
10
|
+
levelState: levelState;
|
|
11
|
+
levelTick: number;
|
|
12
|
+
stateTick: number;
|
|
13
|
+
protected updateBranchState(): void;
|
|
14
|
+
resetBranch(): void;
|
|
15
|
+
protected getBranchState(): void;
|
|
16
|
+
constructor(name: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class Branch extends BranchManager {
|
|
19
|
+
constructor(name: string);
|
|
20
|
+
/**
|
|
21
|
+
* Get the level object by name
|
|
22
|
+
* @param levelName - The name of the level
|
|
23
|
+
* @returns The level object
|
|
24
|
+
* @example
|
|
25
|
+
* const level = branch.getLevel("level1");
|
|
26
|
+
*/
|
|
27
|
+
getLevel(levelName: string): Level | undefined;
|
|
28
|
+
getLevels(): Map<string, Level>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the active level object
|
|
31
|
+
* @returns The active level object
|
|
32
|
+
*/
|
|
33
|
+
getActiveLevel(): Level | undefined;
|
|
34
|
+
jumpToLevel(levelIndex: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Add a level to the branch
|
|
37
|
+
* @param name - The name of the level
|
|
38
|
+
* @param activate - Whether to activate the level
|
|
39
|
+
* @returns The level object
|
|
40
|
+
*/
|
|
41
|
+
addLevel(name: string, default_active?: boolean): Level;
|
|
42
|
+
tick(): void;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=branch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,cAAM,aAAa;IAClB,SAAS,CAAC,cAAc,EAAE,cAAc,CAAgC;IACxE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAa;IAEjD,SAAS,CAAC,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IAE1C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAG,UAAU,CAAC;IAExB,SAAS,EAAG,MAAM,CAAC;IACnB,SAAS,EAAG,MAAM,CAAC;IAE1B,SAAS,CAAC,iBAAiB;IAUpB,WAAW;IAQlB,SAAS,CAAC,cAAc;gBAeZ,IAAI,EAAE,MAAM;CAIxB;AAED,qBAAa,MAAO,SAAQ,aAAa;gBAC5B,IAAI,EAAE,MAAM;IAIxB;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAS9C,SAAS;IAIT;;;OAGG;IACH,cAAc,IAAI,KAAK,GAAG,SAAS;IAQnC,WAAW,CAAC,UAAU,EAAE,MAAM;IAe9B;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,GAAE,OAAe;IAYtD,IAAI;CAwBJ"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { BranchDatabase } from "./database";
|
|
2
|
+
import { Level } from "./level";
|
|
3
|
+
import { levelState } from "./interfaces";
|
|
4
|
+
import { NAMESPACE } from "./constants";
|
|
5
|
+
class BranchManager {
|
|
6
|
+
branchDatabase = BranchDatabase.getInstance();
|
|
7
|
+
levels = new Map();
|
|
8
|
+
defaultActiveLevel;
|
|
9
|
+
identifier;
|
|
10
|
+
activeLevel;
|
|
11
|
+
levelState;
|
|
12
|
+
levelTick;
|
|
13
|
+
stateTick;
|
|
14
|
+
updateBranchState() {
|
|
15
|
+
this.branchDatabase.updateObject({
|
|
16
|
+
id: this.identifier,
|
|
17
|
+
activeLevel: this.activeLevel,
|
|
18
|
+
levelState: this.levelState,
|
|
19
|
+
levelTick: this.levelTick,
|
|
20
|
+
stateTick: this.stateTick,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
resetBranch() {
|
|
24
|
+
this.activeLevel = this.defaultActiveLevel;
|
|
25
|
+
this.levelState = levelState.INIT_LEVEL;
|
|
26
|
+
this.levelTick = 0;
|
|
27
|
+
this.stateTick = 0;
|
|
28
|
+
this.updateBranchState();
|
|
29
|
+
}
|
|
30
|
+
getBranchState() {
|
|
31
|
+
const branchState = this.branchDatabase.getObject(this.identifier);
|
|
32
|
+
if (!branchState) {
|
|
33
|
+
this.resetBranch();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.activeLevel = branchState.activeLevel;
|
|
37
|
+
this.levelState = branchState.levelState;
|
|
38
|
+
this.levelTick = branchState.levelTick;
|
|
39
|
+
this.stateTick = branchState.stateTick;
|
|
40
|
+
this.updateBranchState();
|
|
41
|
+
}
|
|
42
|
+
constructor(name) {
|
|
43
|
+
this.identifier = `${NAMESPACE}:${name}`;
|
|
44
|
+
this.getBranchState();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class Branch extends BranchManager {
|
|
48
|
+
constructor(name) {
|
|
49
|
+
super(name);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the level object by name
|
|
53
|
+
* @param levelName - The name of the level
|
|
54
|
+
* @returns The level object
|
|
55
|
+
* @example
|
|
56
|
+
* const level = branch.getLevel("level1");
|
|
57
|
+
*/
|
|
58
|
+
getLevel(levelName) {
|
|
59
|
+
const level = this.levels.get(levelName);
|
|
60
|
+
if (level) {
|
|
61
|
+
return level;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.warn(`Level not found, Error at Branch.getLevel(), ${levelName}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
getLevels() {
|
|
68
|
+
return this.levels;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the active level object
|
|
72
|
+
* @returns The active level object
|
|
73
|
+
*/
|
|
74
|
+
getActiveLevel() {
|
|
75
|
+
if (this.activeLevel) {
|
|
76
|
+
return this.levels.get(this.activeLevel);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.warn("Active level is not set");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
jumpToLevel(levelIndex) {
|
|
83
|
+
const levelId = this.identifier + "_" + levelIndex;
|
|
84
|
+
const level = this.levels.get(levelId);
|
|
85
|
+
if (level) {
|
|
86
|
+
this.activeLevel = level.identifier;
|
|
87
|
+
this.levelState = levelState.INIT_LEVEL;
|
|
88
|
+
this.levelTick = 0;
|
|
89
|
+
this.stateTick = 0;
|
|
90
|
+
this.updateBranchState();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.warn("Level not found: " + levelId);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Add a level to the branch
|
|
98
|
+
* @param name - The name of the level
|
|
99
|
+
* @param activate - Whether to activate the level
|
|
100
|
+
* @returns The level object
|
|
101
|
+
*/
|
|
102
|
+
addLevel(name, default_active = false) {
|
|
103
|
+
const levelId = `${this.identifier}_${name}`;
|
|
104
|
+
const level = new Level(name, this.identifier, this.levels.size);
|
|
105
|
+
this.levels.set(levelId, level);
|
|
106
|
+
if (default_active) {
|
|
107
|
+
this.defaultActiveLevel = levelId;
|
|
108
|
+
this.updateBranchState();
|
|
109
|
+
}
|
|
110
|
+
return level;
|
|
111
|
+
}
|
|
112
|
+
tick() {
|
|
113
|
+
if (this.activeLevel) {
|
|
114
|
+
const level = this.levels.get(this.activeLevel);
|
|
115
|
+
level.tick();
|
|
116
|
+
this.getBranchState();
|
|
117
|
+
this.levelTick++;
|
|
118
|
+
this.stateTick++;
|
|
119
|
+
// Progresses to the next level if it exists, the actual level states are handled in the level class
|
|
120
|
+
if (this.levelState == levelState.COMPLETED) {
|
|
121
|
+
const levelIDs = Array.from(this.levels.keys());
|
|
122
|
+
const nextLevelID = levelIDs[levelIDs.indexOf(level.identifier) + 1];
|
|
123
|
+
const nextLevel = this.levels.get(nextLevelID);
|
|
124
|
+
this.activeLevel = nextLevelID ? nextLevelID : undefined;
|
|
125
|
+
this.levelState = nextLevel ? levelState.INIT_LEVEL : levelState.COMPLETED;
|
|
126
|
+
this.levelTick = 0;
|
|
127
|
+
this.stateTick = 0;
|
|
128
|
+
}
|
|
129
|
+
this.updateBranchState();
|
|
130
|
+
}
|
|
131
|
+
this.getBranchState();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=branch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/game-state-machine/branch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAA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AAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;gBACrE,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;gBAE/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;gBACzD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;gBAC3E,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;gBACnB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;YACpB,CAAC;YACD,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;IACvB,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/game-state-machine/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PlayerObject, BranchObject } from "./interfaces";
|
|
2
|
+
import { SimpleDatabase } from "../database";
|
|
3
|
+
export declare class BranchDatabase extends SimpleDatabase<BranchObject> {
|
|
4
|
+
protected static instance: BranchDatabase;
|
|
5
|
+
private constructor();
|
|
6
|
+
static getInstance(): BranchDatabase;
|
|
7
|
+
}
|
|
8
|
+
export declare class PlayerDatabase extends SimpleDatabase<PlayerObject> {
|
|
9
|
+
protected static instance: PlayerDatabase;
|
|
10
|
+
private constructor();
|
|
11
|
+
static getInstance(): PlayerDatabase;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,qBAAa,cAAe,SAAQ,cAAc,CAAC,YAAY,CAAC;IAC/D,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC1C,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,cAAc;CAMpC;AAED,qBAAa,cAAe,SAAQ,cAAc,CAAC,YAAY,CAAC;IAC/D,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC1C,OAAO;IAIP,MAAM,CAAC,WAAW,IAAI,cAAc;CAMpC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SimpleDatabase } from "../database";
|
|
2
|
+
export class BranchDatabase extends SimpleDatabase {
|
|
3
|
+
static instance;
|
|
4
|
+
constructor() {
|
|
5
|
+
super("branchDatabase", undefined);
|
|
6
|
+
}
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!BranchDatabase.instance) {
|
|
9
|
+
BranchDatabase.instance = new BranchDatabase();
|
|
10
|
+
}
|
|
11
|
+
return BranchDatabase.instance;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class PlayerDatabase extends SimpleDatabase {
|
|
15
|
+
static instance;
|
|
16
|
+
constructor() {
|
|
17
|
+
super("playerDatabase", undefined);
|
|
18
|
+
}
|
|
19
|
+
static getInstance() {
|
|
20
|
+
if (!PlayerDatabase.instance) {
|
|
21
|
+
PlayerDatabase.instance = new PlayerDatabase();
|
|
22
|
+
}
|
|
23
|
+
return PlayerDatabase.instance;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/game-state-machine/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,cAAe,SAAQ,cAA4B;IACrD,MAAM,CAAC,QAAQ,CAAiB;IAC1C;QACC,KAAK,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,WAAW;QACjB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC9B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QAChD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IAChC,CAAC;CACD;AAED,MAAM,OAAO,cAAe,SAAQ,cAA4B;IACrD,MAAM,CAAC,QAAQ,CAAiB;IAC1C;QACC,KAAK,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,WAAW;QACjB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC9B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QAChD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IAChC,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/game-state-machine/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare enum levelState {
|
|
2
|
+
INIT_LEVEL = "INIT_LEVEL",
|
|
3
|
+
LOOP = "LOOP",
|
|
4
|
+
END_LEVEL = "END_LEVEL",
|
|
5
|
+
COMPLETED = "COMPLETED"
|
|
6
|
+
}
|
|
7
|
+
export declare enum playerState {
|
|
8
|
+
SETUP_PLAYER = "SETUP_PLAYER",
|
|
9
|
+
EXIT_PLAYER = "EXIT_PLAYER"
|
|
10
|
+
}
|
|
11
|
+
export interface BranchObject {
|
|
12
|
+
id: string;
|
|
13
|
+
activeLevel: string | undefined;
|
|
14
|
+
levelState: levelState;
|
|
15
|
+
levelTick: number;
|
|
16
|
+
stateTick: number;
|
|
17
|
+
}
|
|
18
|
+
export interface PlayerObject {
|
|
19
|
+
id: string;
|
|
20
|
+
branch: string;
|
|
21
|
+
playerLevel: string;
|
|
22
|
+
playerState: playerState;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/interfaces.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACrB,UAAU,eAAe;IACzB,IAAI,SAAS;IACb,SAAS,cAAc;IACvB,SAAS,cAAc;CACvB;AAED,oBAAY,WAAW;IACtB,YAAY,iBAAiB;IAC7B,WAAW,gBAAgB;CAC3B;AAED,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;CACzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export var levelState;
|
|
2
|
+
(function (levelState) {
|
|
3
|
+
levelState["INIT_LEVEL"] = "INIT_LEVEL";
|
|
4
|
+
levelState["LOOP"] = "LOOP";
|
|
5
|
+
levelState["END_LEVEL"] = "END_LEVEL";
|
|
6
|
+
levelState["COMPLETED"] = "COMPLETED";
|
|
7
|
+
})(levelState || (levelState = {}));
|
|
8
|
+
export var playerState;
|
|
9
|
+
(function (playerState) {
|
|
10
|
+
playerState["SETUP_PLAYER"] = "SETUP_PLAYER";
|
|
11
|
+
playerState["EXIT_PLAYER"] = "EXIT_PLAYER";
|
|
12
|
+
})(playerState || (playerState = {}));
|
|
13
|
+
//# sourceMappingURL=interfaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/game-state-machine/interfaces.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,uCAAyB,CAAA;IACzB,2BAAa,CAAA;IACb,qCAAuB,CAAA;IACvB,qCAAuB,CAAA;AACxB,CAAC,EALW,UAAU,KAAV,UAAU,QAKrB;AAED,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACtB,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;AAC5B,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as mc from "@minecraft/server";
|
|
2
|
+
declare class Events {
|
|
3
|
+
onLevelLoad: (() => void)[];
|
|
4
|
+
levelLoop: (() => void)[];
|
|
5
|
+
onLevelExit: (() => void)[];
|
|
6
|
+
onPlayerJoinLevel: ((player: mc.Player) => void)[];
|
|
7
|
+
onPlayerRespawn: ((player: mc.Player) => void)[];
|
|
8
|
+
onPlayerDeath: ((player: mc.Player) => void)[];
|
|
9
|
+
onPlayerLeaveLevel: ((player: mc.Player) => void)[];
|
|
10
|
+
onPlayerJoinServer: ((player: mc.Player) => void)[];
|
|
11
|
+
onPlayerLeaveServer: ((player: mc.Player) => void)[];
|
|
12
|
+
constructor();
|
|
13
|
+
triggerLevelLoad(): void;
|
|
14
|
+
triggerLevelLoop(): void;
|
|
15
|
+
triggerLevelExit(): void;
|
|
16
|
+
triggerPlayerJoinServer(player: mc.Player): void;
|
|
17
|
+
triggerPlayerLeaveServer(player: mc.Player): void;
|
|
18
|
+
triggerPlayerJoinLevel(player: mc.Player): void;
|
|
19
|
+
triggerPlayerLeaveLevel(player: mc.Player): void;
|
|
20
|
+
triggerPlayerRespawn(player: mc.Player): void;
|
|
21
|
+
triggerPlayerDeath(player: mc.Player): void;
|
|
22
|
+
}
|
|
23
|
+
declare class EventsRegistry {
|
|
24
|
+
private events;
|
|
25
|
+
constructor(events: Events);
|
|
26
|
+
onLevelLoad(callback: () => void): void;
|
|
27
|
+
onLevelLoop(callback: () => void): void;
|
|
28
|
+
onLevelExit(callback: () => void): void;
|
|
29
|
+
onPlayerJoinServer(callback: (player: mc.Player) => void): void;
|
|
30
|
+
onPlayerLeaveServer(callback: (player: mc.Player) => void): void;
|
|
31
|
+
onPlayerJoinLevel(callback: (player: mc.Player) => void): void;
|
|
32
|
+
onPlayerLeaveLevel(callback: (player: mc.Player) => void): void;
|
|
33
|
+
onPlayerRespawn(callback: (player: mc.Player) => void): void;
|
|
34
|
+
onPlayerDeath(callback: (player: mc.Player) => void): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class Level {
|
|
37
|
+
private branchIdentifier;
|
|
38
|
+
private branchDatabase;
|
|
39
|
+
identifier: string;
|
|
40
|
+
levelIndex: number;
|
|
41
|
+
levelTick: number;
|
|
42
|
+
stateTick: number;
|
|
43
|
+
eventTrigger: Events;
|
|
44
|
+
events: EventsRegistry;
|
|
45
|
+
constructor(identifier: string, branchIdentifier: string, levelIndex: number);
|
|
46
|
+
nextState(): void;
|
|
47
|
+
tick(): void;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=level.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/level.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAExC,cAAM,MAAM;IACJ,WAAW,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAC5B,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAC1B,WAAW,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAE5B,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;IACnD,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;IACjD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;IAC/C,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;IAEpD,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;IACpD,mBAAmB,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,IAAI,CAAC,EAAE,CAAC;;IAgB5D,gBAAgB;IAIhB,gBAAgB;IAIhB,gBAAgB;IAIhB,uBAAuB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;IAIzC,wBAAwB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;IAI1C,sBAAsB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;IAIxC,u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}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { BranchDatabase } from "./database";
|
|
2
|
+
import { levelState } from "./interfaces";
|
|
3
|
+
class Events {
|
|
4
|
+
onLevelLoad;
|
|
5
|
+
levelLoop;
|
|
6
|
+
onLevelExit;
|
|
7
|
+
onPlayerJoinLevel;
|
|
8
|
+
onPlayerRespawn;
|
|
9
|
+
onPlayerDeath;
|
|
10
|
+
onPlayerLeaveLevel;
|
|
11
|
+
onPlayerJoinServer;
|
|
12
|
+
onPlayerLeaveServer;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.onLevelLoad = [];
|
|
15
|
+
this.levelLoop = [];
|
|
16
|
+
this.onLevelExit = [];
|
|
17
|
+
this.onPlayerJoinLevel = [];
|
|
18
|
+
this.onPlayerRespawn = [];
|
|
19
|
+
this.onPlayerDeath = [];
|
|
20
|
+
this.onPlayerLeaveLevel = [];
|
|
21
|
+
this.onPlayerJoinServer = [];
|
|
22
|
+
this.onPlayerLeaveServer = [];
|
|
23
|
+
}
|
|
24
|
+
triggerLevelLoad() {
|
|
25
|
+
this.onLevelLoad.forEach((func) => func());
|
|
26
|
+
}
|
|
27
|
+
triggerLevelLoop() {
|
|
28
|
+
this.levelLoop.forEach((func) => func());
|
|
29
|
+
}
|
|
30
|
+
triggerLevelExit() {
|
|
31
|
+
this.onLevelExit.forEach((func) => func());
|
|
32
|
+
}
|
|
33
|
+
triggerPlayerJoinServer(player) {
|
|
34
|
+
this.onPlayerJoinServer.forEach((func) => func(player));
|
|
35
|
+
}
|
|
36
|
+
triggerPlayerLeaveServer(player) {
|
|
37
|
+
this.onPlayerLeaveServer.forEach((func) => func(player));
|
|
38
|
+
}
|
|
39
|
+
triggerPlayerJoinLevel(player) {
|
|
40
|
+
this.onPlayerJoinLevel.forEach((func) => func(player));
|
|
41
|
+
}
|
|
42
|
+
triggerPlayerLeaveLevel(player) {
|
|
43
|
+
this.onPlayerLeaveLevel.forEach((func) => func(player));
|
|
44
|
+
}
|
|
45
|
+
triggerPlayerRespawn(player) {
|
|
46
|
+
this.onPlayerRespawn.forEach((func) => func(player));
|
|
47
|
+
}
|
|
48
|
+
triggerPlayerDeath(player) {
|
|
49
|
+
this.onPlayerDeath.forEach((func) => func(player));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class EventsRegistry {
|
|
53
|
+
events;
|
|
54
|
+
constructor(events) {
|
|
55
|
+
this.events = events;
|
|
56
|
+
}
|
|
57
|
+
onLevelLoad(callback) {
|
|
58
|
+
this.events.onLevelLoad.push(callback);
|
|
59
|
+
}
|
|
60
|
+
onLevelLoop(callback) {
|
|
61
|
+
this.events.levelLoop.push(callback);
|
|
62
|
+
}
|
|
63
|
+
onLevelExit(callback) {
|
|
64
|
+
this.events.onLevelExit.push(callback);
|
|
65
|
+
}
|
|
66
|
+
onPlayerJoinServer(callback) {
|
|
67
|
+
this.events.onPlayerJoinServer.push(callback);
|
|
68
|
+
}
|
|
69
|
+
onPlayerLeaveServer(callback) {
|
|
70
|
+
this.events.onPlayerLeaveServer.push(callback);
|
|
71
|
+
}
|
|
72
|
+
onPlayerJoinLevel(callback) {
|
|
73
|
+
this.events.onPlayerJoinLevel.push(callback);
|
|
74
|
+
}
|
|
75
|
+
onPlayerLeaveLevel(callback) {
|
|
76
|
+
this.events.onPlayerLeaveLevel.push(callback);
|
|
77
|
+
}
|
|
78
|
+
onPlayerRespawn(callback) {
|
|
79
|
+
this.events.onPlayerRespawn.push(callback);
|
|
80
|
+
}
|
|
81
|
+
onPlayerDeath(callback) {
|
|
82
|
+
this.events.onPlayerDeath.push(callback);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export class Level {
|
|
86
|
+
branchIdentifier;
|
|
87
|
+
branchDatabase;
|
|
88
|
+
identifier;
|
|
89
|
+
levelIndex;
|
|
90
|
+
levelTick;
|
|
91
|
+
stateTick;
|
|
92
|
+
eventTrigger;
|
|
93
|
+
events;
|
|
94
|
+
constructor(identifier, branchIdentifier, levelIndex) {
|
|
95
|
+
this.identifier = `${branchIdentifier}_${identifier}`;
|
|
96
|
+
this.branchIdentifier = branchIdentifier;
|
|
97
|
+
this.branchDatabase = BranchDatabase.getInstance();
|
|
98
|
+
this.levelIndex = levelIndex;
|
|
99
|
+
this.levelTick = 0;
|
|
100
|
+
this.stateTick = 0;
|
|
101
|
+
this.eventTrigger = new Events();
|
|
102
|
+
this.events = new EventsRegistry(this.eventTrigger);
|
|
103
|
+
}
|
|
104
|
+
nextState() {
|
|
105
|
+
let branch = this.branchDatabase.getObject(this.branchIdentifier);
|
|
106
|
+
if (branch.levelState == levelState.END_LEVEL) {
|
|
107
|
+
branch.levelState = levelState.COMPLETED;
|
|
108
|
+
}
|
|
109
|
+
else if (branch.levelState == levelState.LOOP) {
|
|
110
|
+
branch.levelState = levelState.END_LEVEL;
|
|
111
|
+
}
|
|
112
|
+
else if (branch.levelState == levelState.INIT_LEVEL) {
|
|
113
|
+
branch.levelState = levelState.LOOP;
|
|
114
|
+
}
|
|
115
|
+
branch.stateTick = 0;
|
|
116
|
+
this.branchDatabase.updateObject(branch);
|
|
117
|
+
}
|
|
118
|
+
tick() {
|
|
119
|
+
let branch = this.branchDatabase.getObject(this.branchIdentifier);
|
|
120
|
+
if (branch.levelState == levelState.INIT_LEVEL) {
|
|
121
|
+
this.eventTrigger.triggerLevelLoad();
|
|
122
|
+
}
|
|
123
|
+
else if (branch.levelState == levelState.LOOP) {
|
|
124
|
+
this.eventTrigger.triggerLevelLoop();
|
|
125
|
+
}
|
|
126
|
+
else if (branch.levelState == levelState.END_LEVEL) {
|
|
127
|
+
this.eventTrigger.triggerLevelExit();
|
|
128
|
+
}
|
|
129
|
+
this.levelTick = branch.levelTick;
|
|
130
|
+
this.stateTick = branch.stateTick;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=level.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"level.js","sourceRoot":"","sources":["../../src/game-state-machine/level.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GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,CAAC;CACD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Level } from "./level";
|
|
2
|
+
import { Branch } from "./branch";
|
|
3
|
+
declare class StateMachineEvents {
|
|
4
|
+
resetFunctions: (() => void)[];
|
|
5
|
+
tickFunctions: (() => void)[];
|
|
6
|
+
constructor();
|
|
7
|
+
triggerReset(): void;
|
|
8
|
+
triggerTick(): void;
|
|
9
|
+
}
|
|
10
|
+
declare class StateMachineEventRegister {
|
|
11
|
+
private events;
|
|
12
|
+
constructor(events: StateMachineEvents);
|
|
13
|
+
onReset(callback: () => void): void;
|
|
14
|
+
onTick(callback: () => void): void;
|
|
15
|
+
}
|
|
16
|
+
declare class StateMachine {
|
|
17
|
+
private static instance;
|
|
18
|
+
private eventTrigger;
|
|
19
|
+
events: StateMachineEventRegister;
|
|
20
|
+
private playersManager;
|
|
21
|
+
private branches;
|
|
22
|
+
private activeBranches;
|
|
23
|
+
private defaultActiveBranches;
|
|
24
|
+
/**
|
|
25
|
+
* Debug function to display the branches' state in the action bar.
|
|
26
|
+
*/
|
|
27
|
+
private debugBranches;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new branch.
|
|
30
|
+
* @param name The branch name to create.
|
|
31
|
+
* @param activate Whether to activate the branch or not.
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
createBranch(name: string, activate?: boolean): Branch;
|
|
35
|
+
/**
|
|
36
|
+
* Activates a branch.
|
|
37
|
+
* @param branch The branch to activate.
|
|
38
|
+
*/
|
|
39
|
+
activateBranch(branch: Branch): void;
|
|
40
|
+
/**
|
|
41
|
+
* Deactivates a branch.
|
|
42
|
+
* @param branch The branch to deactivate.
|
|
43
|
+
*/
|
|
44
|
+
deactivateBranch(branch: Branch): void;
|
|
45
|
+
static getInstance(): StateMachine;
|
|
46
|
+
private constructor();
|
|
47
|
+
}
|
|
48
|
+
export declare const stateMachine: StateMachine;
|
|
49
|
+
export declare const mainBranch: Branch;
|
|
50
|
+
export declare const mainLevel0: Level;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=stateMachine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateMachine.d.ts","sourceRoot":"","sources":["../../src/game-state-machine/stateMachine.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMlC,cAAM,kBAAkB;IAChB,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAC/B,aAAa,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;;IAOrC,YAAY;IAMZ,WAAW;CAKX;AAED,cAAM,yBAAyB;IAC9B,OAAO,CAAC,MAAM,CAAqB;gBAEvB,MAAM,EAAE,kBAAkB;IAItC,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI;IAI5B,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI;CAG3B;AAqLD,cAAM,YAAY;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IAEtC,OAAO,CAAC,YAAY,CAAgD;IAC7D,MAAM,EAAE,yBAAyB,CAAoD;IAE5F,OAAO,CAAC,cAAc,CAAsC;IAE5D,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,cAAc,CAA0B;IAChD,OAAO,CAAC,qBAAqB,CAA0B;IAEvD;;OAEG;IACH,OAAO,CAAC,aAAa;IA2BrB;;;;;OAKG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,MAAM;IAepE;;;OAGG;IACI,cAAc,CAAC,MAAM,EAAE,MAAM;IAIpC;;;OAGG;IACI,gBAAgB,CAAC,MAAM,EAAE,MAAM;WAIxB,WAAW,IAAI,YAAY;IAOzC,OAAO;CA2DP;AAED,eAAO,MAAM,YAAY,cAA6B,CAAC;AACvD,eAAO,MAAM,UAAU,QAAgD,CAAC;AACxE,eAAO,MAAM,UAAU,OAA0C,CAAC"}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import * as mc from "@minecraft/server";
|
|
2
|
+
import { PlayerDatabase } from "./database";
|
|
3
|
+
import { playerState } from "./interfaces";
|
|
4
|
+
import { Branch } from "./branch";
|
|
5
|
+
import { NAMESPACE } from "./constants";
|
|
6
|
+
const RESET_EVENT = `${NAMESPACE}:reset`;
|
|
7
|
+
const JUMP_EVENT = `${NAMESPACE}:jump`;
|
|
8
|
+
class StateMachineEvents {
|
|
9
|
+
resetFunctions; // Functions to call when the state machine is reset
|
|
10
|
+
tickFunctions; // Functions to call when the state machine ticks
|
|
11
|
+
constructor() {
|
|
12
|
+
this.resetFunctions = [];
|
|
13
|
+
this.tickFunctions = [];
|
|
14
|
+
}
|
|
15
|
+
triggerReset() {
|
|
16
|
+
this.resetFunctions.forEach((callback) => {
|
|
17
|
+
callback();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
triggerTick() {
|
|
21
|
+
this.tickFunctions.forEach((callback) => {
|
|
22
|
+
callback();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class StateMachineEventRegister {
|
|
27
|
+
events;
|
|
28
|
+
constructor(events) {
|
|
29
|
+
this.events = events;
|
|
30
|
+
}
|
|
31
|
+
onReset(callback) {
|
|
32
|
+
this.events.resetFunctions.push(callback);
|
|
33
|
+
}
|
|
34
|
+
onTick(callback) {
|
|
35
|
+
this.events.tickFunctions.push(callback);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
class PlayerManager {
|
|
39
|
+
playerDatabase = PlayerDatabase.getInstance();
|
|
40
|
+
players = new Map();
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* Debug function to display the players' state in the action bar.
|
|
44
|
+
*/
|
|
45
|
+
debugPlayers() {
|
|
46
|
+
let data = [];
|
|
47
|
+
let longestPlayerName = 0;
|
|
48
|
+
let longestBranchName = 0;
|
|
49
|
+
let longestLevelName = 0;
|
|
50
|
+
const players = mc.world.getAllPlayers();
|
|
51
|
+
for (const player of players) {
|
|
52
|
+
const playerObject = this.playerDatabase.getObject(player.id);
|
|
53
|
+
data.push({
|
|
54
|
+
playerName: player.nameTag,
|
|
55
|
+
branch: playerObject.branch,
|
|
56
|
+
level: playerObject.playerLevel,
|
|
57
|
+
state: playerObject.playerState,
|
|
58
|
+
});
|
|
59
|
+
longestPlayerName = Math.max(longestPlayerName, player.nameTag.length);
|
|
60
|
+
longestBranchName = Math.max(longestBranchName, playerObject.branch.length);
|
|
61
|
+
longestLevelName = Math.max(longestLevelName, playerObject.playerLevel.length);
|
|
62
|
+
}
|
|
63
|
+
let formattedData = data.map((player) => {
|
|
64
|
+
return `${player.playerName.padEnd(longestPlayerName)} | §a${player.branch.padEnd(longestBranchName)}§r | §6${player.level.padEnd(longestLevelName)}§r | §3${player.state}§r`;
|
|
65
|
+
});
|
|
66
|
+
return formattedData;
|
|
67
|
+
}
|
|
68
|
+
registerNewPlayer(player) {
|
|
69
|
+
if (!this.playerDatabase.hasObject(player.id)) {
|
|
70
|
+
this.playerDatabase.addObject({
|
|
71
|
+
id: player.id,
|
|
72
|
+
branch: mainBranch.identifier,
|
|
73
|
+
playerLevel: mainLevel0.identifier,
|
|
74
|
+
playerState: playerState.SETUP_PLAYER,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
updatePlayerState(currentLevel, player, playerObject, branch) {
|
|
79
|
+
if (playerObject.playerLevel === currentLevel.identifier && playerObject.playerState === playerState.SETUP_PLAYER) {
|
|
80
|
+
currentLevel.eventTrigger.triggerPlayerJoinLevel(player);
|
|
81
|
+
playerObject.playerState = playerState.EXIT_PLAYER;
|
|
82
|
+
}
|
|
83
|
+
else if (playerObject.playerLevel !== currentLevel.identifier) {
|
|
84
|
+
const levels = Array.from(branch.getLevels());
|
|
85
|
+
const currentIndex = currentLevel.levelIndex;
|
|
86
|
+
const playerIndex = levels.findIndex((level) => level[0] === playerObject.playerLevel);
|
|
87
|
+
if (currentIndex > playerIndex) {
|
|
88
|
+
for (let i = playerIndex; i < currentIndex; i++) {
|
|
89
|
+
const levelToExit = branch.getLevel(levels[i][0]);
|
|
90
|
+
const levelToEnter = branch.getLevel(levels[i + 1][0]);
|
|
91
|
+
levelToExit?.eventTrigger.triggerPlayerLeaveLevel(player);
|
|
92
|
+
levelToEnter?.eventTrigger.triggerPlayerJoinLevel(player);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (currentIndex < playerIndex) {
|
|
96
|
+
const levelToExit = branch.getLevel(levels[playerIndex][0]);
|
|
97
|
+
const levelToEnter = branch.getLevel(levels[currentIndex][0]);
|
|
98
|
+
levelToExit?.eventTrigger.triggerPlayerLeaveLevel(player);
|
|
99
|
+
levelToEnter?.eventTrigger.triggerPlayerJoinLevel(player);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
currentLevel.eventTrigger.triggerPlayerLeaveLevel(player);
|
|
103
|
+
}
|
|
104
|
+
playerObject.playerState = playerState.SETUP_PLAYER;
|
|
105
|
+
playerObject.playerLevel = currentLevel.identifier;
|
|
106
|
+
}
|
|
107
|
+
this.playerDatabase.updateObject(playerObject);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Resets the player database.
|
|
111
|
+
*/
|
|
112
|
+
reset() {
|
|
113
|
+
this.playerDatabase.eraseAllObjects();
|
|
114
|
+
mc.world.getAllPlayers().forEach((player) => {
|
|
115
|
+
this.registerNewPlayer(player);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Called when a player joins the server.
|
|
120
|
+
* If a player does not exist on the database, it will be added to the main branch.
|
|
121
|
+
* @param player The player that joined the server.
|
|
122
|
+
*/
|
|
123
|
+
onPlayerJoinServer(player, branches) {
|
|
124
|
+
this.registerNewPlayer(player);
|
|
125
|
+
this.players.set(player.id, player);
|
|
126
|
+
const playerObject = this.playerDatabase.getObject(player.id);
|
|
127
|
+
const branch = branches.branches.get(playerObject.branch);
|
|
128
|
+
const currentLevel = branch.getActiveLevel();
|
|
129
|
+
if (!currentLevel || !branches.activeBranches.has(branch)) {
|
|
130
|
+
playerObject.branch = mainBranch.identifier;
|
|
131
|
+
playerObject.playerLevel = mainLevel0.identifier;
|
|
132
|
+
playerObject.playerState = playerState.SETUP_PLAYER;
|
|
133
|
+
mainLevel0.eventTrigger.triggerPlayerJoinServer(player);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
currentLevel.eventTrigger.triggerPlayerJoinServer(player);
|
|
137
|
+
this.updatePlayerState(currentLevel, player, playerObject, branch);
|
|
138
|
+
}
|
|
139
|
+
this.playerDatabase.updateObject(playerObject);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Called when a player respawns.
|
|
143
|
+
* @param player The player that respawned.
|
|
144
|
+
*/
|
|
145
|
+
onPlayerRespawn(player, branches) {
|
|
146
|
+
const playerObject = this.playerDatabase.getObject(player.id);
|
|
147
|
+
const branch = branches.branches.get(playerObject.branch);
|
|
148
|
+
const level = branch.getActiveLevel();
|
|
149
|
+
if (level) {
|
|
150
|
+
level.eventTrigger.triggerPlayerRespawn(player);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Called when a player leaves the server.
|
|
155
|
+
* @param player The player that left the server.
|
|
156
|
+
*/
|
|
157
|
+
onPlayerLeaveServer(player, branches) {
|
|
158
|
+
this.players.delete(player.id);
|
|
159
|
+
const playerObject = this.playerDatabase.getObject(player.id);
|
|
160
|
+
const branch = branches.branches.get(playerObject.branch);
|
|
161
|
+
const level = branch.getActiveLevel();
|
|
162
|
+
if (level) {
|
|
163
|
+
level.eventTrigger.triggerPlayerLeaveServer(player);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Called when a player dies.
|
|
168
|
+
* @param player The player that died.
|
|
169
|
+
*/
|
|
170
|
+
onPlayerDeath(player, branches) {
|
|
171
|
+
const playerObject = this.playerDatabase.getObject(player.id);
|
|
172
|
+
const branch = branches.branches.get(playerObject.branch);
|
|
173
|
+
const level = branch.getActiveLevel();
|
|
174
|
+
if (level) {
|
|
175
|
+
level.eventTrigger.triggerPlayerDeath(player);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
tick(activeBranches) {
|
|
179
|
+
activeBranches.forEach((branch) => {
|
|
180
|
+
this.playerDatabase
|
|
181
|
+
.getAllObjects()
|
|
182
|
+
.filter((player) => player.branch === branch.identifier)
|
|
183
|
+
.forEach((player) => {
|
|
184
|
+
const p = this.players.get(player.id);
|
|
185
|
+
if (p) {
|
|
186
|
+
this.updatePlayerState(branch.getActiveLevel(), p, player, branch);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
class StateMachine {
|
|
193
|
+
static instance;
|
|
194
|
+
eventTrigger = new StateMachineEvents();
|
|
195
|
+
events = new StateMachineEventRegister(this.eventTrigger);
|
|
196
|
+
playersManager = new PlayerManager();
|
|
197
|
+
branches = new Map();
|
|
198
|
+
activeBranches = new Set();
|
|
199
|
+
defaultActiveBranches = new Set();
|
|
200
|
+
/**
|
|
201
|
+
* Debug function to display the branches' state in the action bar.
|
|
202
|
+
*/
|
|
203
|
+
debugBranches() {
|
|
204
|
+
let data = [];
|
|
205
|
+
let longestBranchName = 0;
|
|
206
|
+
let longestLevelName = 0;
|
|
207
|
+
this.branches.forEach((branch) => {
|
|
208
|
+
const level = branch.getActiveLevel();
|
|
209
|
+
data.push({
|
|
210
|
+
branch: branch.identifier,
|
|
211
|
+
level: level?.identifier ?? "No active levels",
|
|
212
|
+
state: branch.levelState,
|
|
213
|
+
isActive: this.activeBranches.has(branch),
|
|
214
|
+
});
|
|
215
|
+
longestBranchName = Math.max(longestBranchName, branch.identifier.length);
|
|
216
|
+
longestLevelName = Math.max(longestLevelName, level?.identifier.length ?? 0);
|
|
217
|
+
});
|
|
218
|
+
let formattedData = data.map((branch) => {
|
|
219
|
+
return `§a${branch.branch.padEnd(longestBranchName)}§r | §6${branch.level.padEnd(longestLevelName)}§r | §3${branch.state}§r | ${branch.isActive}§r`;
|
|
220
|
+
});
|
|
221
|
+
return formattedData;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Creates a new branch.
|
|
225
|
+
* @param name The branch name to create.
|
|
226
|
+
* @param activate Whether to activate the branch or not.
|
|
227
|
+
* @returns
|
|
228
|
+
*/
|
|
229
|
+
createBranch(name, activate = false) {
|
|
230
|
+
const branchIdentifier = `${NAMESPACE}:${name}`;
|
|
231
|
+
if (this.branches.has(branchIdentifier)) {
|
|
232
|
+
throw new Error(`Branch with name ${branchIdentifier} already exists. Error at StateMachine.createBranch`);
|
|
233
|
+
}
|
|
234
|
+
const branch = new Branch(name);
|
|
235
|
+
this.branches.set(branchIdentifier, branch);
|
|
236
|
+
if (activate) {
|
|
237
|
+
this.activateBranch(branch);
|
|
238
|
+
this.defaultActiveBranches.add(branch);
|
|
239
|
+
}
|
|
240
|
+
return branch;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Activates a branch.
|
|
244
|
+
* @param branch The branch to activate.
|
|
245
|
+
*/
|
|
246
|
+
activateBranch(branch) {
|
|
247
|
+
this.activeBranches.add(branch);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Deactivates a branch.
|
|
251
|
+
* @param branch The branch to deactivate.
|
|
252
|
+
*/
|
|
253
|
+
deactivateBranch(branch) {
|
|
254
|
+
this.activeBranches.delete(branch);
|
|
255
|
+
}
|
|
256
|
+
static getInstance() {
|
|
257
|
+
if (!StateMachine.instance) {
|
|
258
|
+
StateMachine.instance = new StateMachine();
|
|
259
|
+
}
|
|
260
|
+
return StateMachine.instance;
|
|
261
|
+
}
|
|
262
|
+
constructor() {
|
|
263
|
+
mc.world.afterEvents.playerSpawn.subscribe((event) => {
|
|
264
|
+
if (event.initialSpawn) {
|
|
265
|
+
this.playersManager.onPlayerJoinServer(event.player, { branches: this.branches, activeBranches: this.activeBranches });
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.playersManager.onPlayerRespawn(event.player, { branches: this.branches, activeBranches: this.activeBranches });
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
mc.world.beforeEvents.playerLeave.subscribe((event) => {
|
|
272
|
+
this.playersManager.onPlayerLeaveServer(event.player, { branches: this.branches, activeBranches: this.activeBranches });
|
|
273
|
+
});
|
|
274
|
+
mc.world.afterEvents.entityDie.subscribe((event) => {
|
|
275
|
+
this.playersManager.onPlayerDeath(event.deadEntity, { branches: this.branches, activeBranches: this.activeBranches });
|
|
276
|
+
}, { entityTypes: ["minecraft:player"] });
|
|
277
|
+
mc.system.afterEvents.scriptEventReceive.subscribe((event) => {
|
|
278
|
+
if (event.id === RESET_EVENT) {
|
|
279
|
+
this.eventTrigger.triggerReset();
|
|
280
|
+
}
|
|
281
|
+
else if (event.id === JUMP_EVENT) {
|
|
282
|
+
this.activeBranches.forEach((branch) => {
|
|
283
|
+
branch.jumpToLevel(event.message);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
mc.system.runInterval(() => this.eventTrigger.triggerTick());
|
|
288
|
+
this.events.onReset(() => {
|
|
289
|
+
this.activeBranches.clear();
|
|
290
|
+
this.branches.forEach((branch) => {
|
|
291
|
+
branch.resetBranch();
|
|
292
|
+
});
|
|
293
|
+
this.defaultActiveBranches.forEach((branch) => {
|
|
294
|
+
this.activateBranch(branch);
|
|
295
|
+
});
|
|
296
|
+
this.playersManager.reset();
|
|
297
|
+
});
|
|
298
|
+
this.events.onTick(() => {
|
|
299
|
+
this.activeBranches.forEach((branch) => {
|
|
300
|
+
if (!branch.getActiveLevel()) {
|
|
301
|
+
this.deactivateBranch(branch);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
branch.tick();
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
this.playersManager.tick(this.activeBranches);
|
|
308
|
+
//let playerData = this.playersManager.debugPlayers();
|
|
309
|
+
//let levelData = this.debugBranches();
|
|
310
|
+
//let combinedData = [...playerData, ...levelData];
|
|
311
|
+
//mc.world.getDimension(mc.MinecraftDimensionTypes.overworld).runCommand(`title @a actionbar ${combinedData.join("\n")}`);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export const stateMachine = StateMachine.getInstance();
|
|
316
|
+
export const mainBranch = stateMachine.createBranch("mainBranch", true);
|
|
317
|
+
export const mainLevel0 = mainBranch.addLevel("mainLevel0", true);
|
|
318
|
+
//# sourceMappingURL=stateMachine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateMachine.js","sourceRoot":"","sources":["../../src/game-state-machine/stateMachine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAgB,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,GAAG,GAAG,SAAS,QAAQ,CAAC;AACzC,MAAM,UAAU,GAAG,GAAG,SAAS,OAAO,CAAC;AAEvC,MAAM,kBAAkB;IAChB,cAAc,CAAiB,CAAC,oDAAoD;IACpF,aAAa,CAAiB,CAAC,iDAAiD;IAEvF;QACC,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,YAAY;QACX,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC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G,YAAY,CAAC,WAAW,EAAE,CAAC;AACvD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starktma/minecraft-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"./player-events": {
|
|
33
33
|
"import": "./dist/player-event/index.js",
|
|
34
34
|
"types": "./dist/player-event/index.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./game-state-machine": {
|
|
37
|
+
"import": "./dist/game-state-machine/index.js",
|
|
38
|
+
"types": "./dist/game-state-machine/index.d.ts"
|
|
35
39
|
}
|
|
36
40
|
},
|
|
37
41
|
"publishConfig": {
|