@starktma/minecraft-utils 1.2.81 → 1.3.11
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/LICENSE +674 -674
- package/README.md +82 -26
- package/dist/database/database.d.ts.map +1 -1
- package/dist/database/database.js +6 -8
- package/dist/database/database.js.map +1 -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 +54 -0
- package/dist/game-state-machine/stateMachine.d.ts.map +1 -0
- package/dist/game-state-machine/stateMachine.js +337 -0
- package/dist/game-state-machine/stateMachine.js.map +1 -0
- package/package.json +54 -50
package/README.md
CHANGED
|
@@ -1,26 +1,82 @@
|
|
|
1
|
-
# @starktma/minecraft-utils — utilities for Minecraft scripting
|
|
2
|
-
|
|
3
|
-
This package provides a small collection of TypeScript utilities. The code is split into focused modules; this README gives a short summary and points to the source files for details.
|
|
4
|
-
|
|
5
|
-
## Quick summary
|
|
6
|
-
|
|
7
|
-
- **database** — lightweight JSON storage helpers for Minecraft's dynamic properties. Implements a `DatabaseManager` (low-level serialization/partitioning) and `SimpleDatabase` (convenience base class for storing objects by id). See `src/database` for full details and examples.
|
|
8
|
-
- **math** — common math utilities used across the packages. See `src/math`.
|
|
9
|
-
- **minecraft** — helpers for Minecraft-specific operations and types. See `src/minecraft`.
|
|
10
|
-
- **player-event** — convenience helpers to handle player-related events and payloads. See `src/player-event`.
|
|
11
|
-
|
|
12
|
-
## Short database note
|
|
13
|
-
|
|
14
|
-
The database utilities are intentionally small: `DatabaseManager` handles serializing/partitioning JSON so it can be stored within Minecraft dynamic property limits, and `SimpleDatabase` provides a straightforward API for storing objects keyed by `id`. For full API and examples, open `src/database`.
|
|
15
|
-
|
|
16
|
-
## Installation & quick dev
|
|
17
|
-
|
|
18
|
-
- **To use the published package**: `npm install @starktma/minecraft-utils` (if published to npm or a registry).
|
|
19
|
-
|
|
20
|
-
## Where to look next
|
|
21
|
-
|
|
22
|
-
- See the module source for exact types, exported functions, and examples:
|
|
23
|
-
- `src/database` — database manager, simple database base class, and interfaces
|
|
24
|
-
- `src/math` — math helpers
|
|
25
|
-
- `src/minecraft` — Minecraft helpers
|
|
26
|
-
- `src/player-event` — player event helpers
|
|
1
|
+
# @starktma/minecraft-utils — utilities for Minecraft scripting
|
|
2
|
+
|
|
3
|
+
This package provides a small collection of TypeScript utilities. The code is split into focused modules; this README gives a short summary and points to the source files for details.
|
|
4
|
+
|
|
5
|
+
## Quick summary
|
|
6
|
+
|
|
7
|
+
- **database** — lightweight JSON storage helpers for Minecraft's dynamic properties. Implements a `DatabaseManager` (low-level serialization/partitioning) and `SimpleDatabase` (convenience base class for storing objects by id). See `src/database` for full details and examples.
|
|
8
|
+
- **math** — common math utilities used across the packages. See `src/math`.
|
|
9
|
+
- **minecraft** — helpers for Minecraft-specific operations and types. See `src/minecraft`.
|
|
10
|
+
- **player-event** — convenience helpers to handle player-related events and payloads. See `src/player-event`.
|
|
11
|
+
|
|
12
|
+
## Short database note
|
|
13
|
+
|
|
14
|
+
The database utilities are intentionally small: `DatabaseManager` handles serializing/partitioning JSON so it can be stored within Minecraft dynamic property limits, and `SimpleDatabase` provides a straightforward API for storing objects keyed by `id`. For full API and examples, open `src/database`.
|
|
15
|
+
|
|
16
|
+
## Installation & quick dev
|
|
17
|
+
|
|
18
|
+
- **To use the published package**: `npm install @starktma/minecraft-utils` (if published to npm or a registry).
|
|
19
|
+
|
|
20
|
+
## Where to look next
|
|
21
|
+
|
|
22
|
+
- See the module source for exact types, exported functions, and examples:
|
|
23
|
+
- `src/database` — database manager, simple database base class, and interfaces
|
|
24
|
+
- `src/math` — math helpers
|
|
25
|
+
- `src/minecraft` — Minecraft 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.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/database/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/database/database.ts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+
if (target instanceof Entity) {
|
|
14
|
+
this.target = target;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.target = world;
|
|
18
|
+
}
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
21
|
* Checks if a JSON database with the given name exists.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/database/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAS,MAAM,mBAAmB,CAAC;AAGzD,YAAY;AACZ,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,MAAM,eAAe;IACZ,MAAM,CAAU,uBAAuB,GAAG,KAAK,CAAC;IAChD,MAAM,CAAU,SAAS,GAAG,WAAW,CAAC;IAExC,MAAM,
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/database/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAS,MAAM,mBAAmB,CAAC;AAGzD,YAAY;AACZ,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,MAAM,eAAe;IACZ,MAAM,CAAU,uBAAuB,GAAG,KAAK,CAAC;IAChD,MAAM,CAAU,SAAS,GAAG,WAAW,CAAC;IAExC,MAAM,CAAiB;IAE/B,YAAY,MAA0B;QACrC,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACtB,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACrB,CAAC;IACF,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,YAAoB;QACnC,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,SAAS,GAAG,GAAG,GAAG,YAAY,CAAC,KA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EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,aAAa;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,eAAe;QACd,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,QAAuD;QAC9D,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAClE,CAAC;CACD"}
|
|
@@ -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,OAA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W,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,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,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,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,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,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,uBAAuB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM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