script-engine-lib 0.4.3 → 1.0.0-rc1
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.mts +191 -0
- package/dist/index.d.ts +191 -5
- package/dist/index.js +21 -29
- package/dist/index.mjs +21 -0
- package/package.json +56 -52
- package/src/index.ts +10 -0
- package/dist/decorators/action-before-testing.d.ts +0 -2
- package/dist/decorators/action-before-testing.js +0 -23
- package/dist/decorators/action-before-testing.test.d.ts +0 -1
- package/dist/decorators/action-before-testing.test.js +0 -82
- package/dist/engine/script-engine.d.ts +0 -35
- package/dist/engine/script-engine.js +0 -175
- package/dist/engine/script-engine.test.d.ts +0 -1
- package/dist/engine/script-engine.test.js +0 -1277
- package/dist/engine/story-engine.d.ts +0 -35
- package/dist/engine/story-engine.js +0 -175
- package/dist/engine/story-engine.test.d.ts +0 -1
- package/dist/engine/story-engine.test.js +0 -1277
- package/dist/interfaces.d.ts +0 -51
- package/dist/interfaces.js +0 -27
- package/dist/simulator/decorators.d.ts +0 -2
- package/dist/simulator/decorators.js +0 -23
- package/dist/simulator/decorators.test.d.ts +0 -1
- package/dist/simulator/decorators.test.js +0 -81
- package/dist/simulator/event-branches-map.d.ts +0 -16
- package/dist/simulator/event-branches-map.js +0 -114
- package/dist/simulator/event-branches-map.test.d.ts +0 -1
- package/dist/simulator/event-branches-map.test.js +0 -120
- package/dist/simulator/event-test-simulator.d.ts +0 -42
- package/dist/simulator/event-test-simulator.js +0 -373
- package/dist/simulator/event-test-simulator.test.d.ts +0 -1
- package/dist/simulator/event-test-simulator.test.js +0 -1960
- package/dist/simulator/execution-history.d.ts +0 -6
- package/dist/simulator/execution-history.js +0 -22
- package/dist/simulator/helpers/event-branches-map.d.ts +0 -16
- package/dist/simulator/helpers/event-branches-map.js +0 -114
- package/dist/simulator/helpers/event-branches-map.test.d.ts +0 -1
- package/dist/simulator/helpers/event-branches-map.test.js +0 -120
- package/dist/simulator/helpers/execution-history.d.ts +0 -6
- package/dist/simulator/helpers/execution-history.js +0 -22
- package/dist/simulator/helpers/script-branches-map.d.ts +0 -16
- package/dist/simulator/helpers/script-branches-map.js +0 -114
- package/dist/simulator/helpers/script-branches-map.test.d.ts +0 -1
- package/dist/simulator/helpers/script-branches-map.test.js +0 -120
- package/dist/simulator/script-test-simulator.d.ts +0 -42
- package/dist/simulator/script-test-simulator.js +0 -373
- package/dist/simulator/script-test-simulator.test.d.ts +0 -1
- package/dist/simulator/script-test-simulator.test.js +0 -2013
- package/dist/structured-text/index.d.ts +0 -9
- package/dist/structured-text/index.js +0 -8
- package/dist/structured-text/rich-text-separator.d.ts +0 -48
- package/dist/structured-text/rich-text-separator.js +0 -146
- package/dist/structured-text/rich-text-separator.test.d.ts +0 -1
- package/dist/structured-text/rich-text-separator.test.js +0 -166
- package/dist/structured-text/rich-text-validator.d.ts +0 -19
- package/dist/structured-text/rich-text-validator.js +0 -73
- package/dist/structured-text/rich-text-validator.test.d.ts +0 -1
- package/dist/structured-text/rich-text-validator.test.js +0 -59
- package/dist/test.spec.d.ts +0 -0
- package/dist/test.spec.js +0 -7
- package/dist/test.test.d.ts +0 -1
- package/dist/test.test.js +0 -9
package/dist/interfaces.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export type ScriptActionType = 'command' | 'dialog' | 'jumpTo' | 'branchByCondition' | 'branchByPlayerChoice' | 'branchByChance';
|
|
2
|
-
export interface DialogItemDefinition {
|
|
3
|
-
readonly text: string;
|
|
4
|
-
readonly speaker: string;
|
|
5
|
-
}
|
|
6
|
-
export interface BranchByConditionItemDefinition {
|
|
7
|
-
readonly condition?: string;
|
|
8
|
-
readonly actions: readonly ScriptActionDefinition[];
|
|
9
|
-
}
|
|
10
|
-
export interface BranchByPlayerChoiceItemDefinition {
|
|
11
|
-
readonly text: string;
|
|
12
|
-
readonly condition?: string;
|
|
13
|
-
readonly actions: readonly ScriptActionDefinition[];
|
|
14
|
-
}
|
|
15
|
-
export interface BranchByChanceItemDefinition {
|
|
16
|
-
readonly label?: string;
|
|
17
|
-
readonly weight: number | string;
|
|
18
|
-
readonly condition?: string;
|
|
19
|
-
readonly actions: readonly ScriptActionDefinition[];
|
|
20
|
-
}
|
|
21
|
-
export interface ScriptActionDefinition {
|
|
22
|
-
readonly type: ScriptActionType;
|
|
23
|
-
readonly value: string | DialogItemDefinition | readonly BranchByConditionItemDefinition[] | readonly BranchByPlayerChoiceItemDefinition[] | readonly BranchByChanceItemDefinition[];
|
|
24
|
-
}
|
|
25
|
-
export interface ScriptDefinition {
|
|
26
|
-
readonly id: string;
|
|
27
|
-
readonly actions: readonly ScriptActionDefinition[];
|
|
28
|
-
}
|
|
29
|
-
export type VisitableScriptBranchDefinition = ScriptDefinition | BranchByConditionItemDefinition | BranchByPlayerChoiceItemDefinition | BranchByChanceItemDefinition;
|
|
30
|
-
export interface ExecutionLocation {
|
|
31
|
-
readonly scriptId: string;
|
|
32
|
-
readonly path: readonly string[];
|
|
33
|
-
}
|
|
34
|
-
export type ActionBeforeTestType = 'command' | 'runScript';
|
|
35
|
-
export interface ScriptTestActionDefinition {
|
|
36
|
-
readonly type: ActionBeforeTestType;
|
|
37
|
-
readonly value: string;
|
|
38
|
-
}
|
|
39
|
-
export declare class SimulationError extends Error {
|
|
40
|
-
readonly location: ExecutionLocation;
|
|
41
|
-
constructor(message: string, location: ExecutionLocation);
|
|
42
|
-
}
|
|
43
|
-
export declare class ActionsBeforeTestingError extends Error {
|
|
44
|
-
readonly actionIndex: number;
|
|
45
|
-
constructor(message: string, actionIndex: number);
|
|
46
|
-
}
|
|
47
|
-
export declare class BranchingBeforeTestingError extends Error {
|
|
48
|
-
readonly actionIndex: number;
|
|
49
|
-
readonly location: ExecutionLocation;
|
|
50
|
-
constructor(message: string, actionIndex: number, location: ExecutionLocation);
|
|
51
|
-
}
|
package/dist/interfaces.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BranchingBeforeTestingError = exports.ActionsBeforeTestingError = exports.SimulationError = void 0;
|
|
4
|
-
// --------------- Script Simulation Errors ---------------
|
|
5
|
-
class SimulationError extends Error {
|
|
6
|
-
constructor(message, location) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.location = location;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.SimulationError = SimulationError;
|
|
12
|
-
class ActionsBeforeTestingError extends Error {
|
|
13
|
-
constructor(message, actionIndex) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.actionIndex = actionIndex;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ActionsBeforeTestingError = ActionsBeforeTestingError;
|
|
19
|
-
class BranchingBeforeTestingError extends Error {
|
|
20
|
-
constructor(message, actionIndex, location) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.actionIndex = actionIndex;
|
|
23
|
-
this.location = location;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.BranchingBeforeTestingError = BranchingBeforeTestingError;
|
|
27
|
-
//# sourceMappingURL=interfaces.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionBeforeTesting = exports.ActionBeforeTestingFlag = void 0;
|
|
4
|
-
const helpers_lib_1 = require("helpers-lib");
|
|
5
|
-
exports.ActionBeforeTestingFlag = 'actionsBeforeTesting';
|
|
6
|
-
function ActionBeforeTesting() {
|
|
7
|
-
return function (_, propertyKey, descriptor) {
|
|
8
|
-
let originalFunction = descriptor.value;
|
|
9
|
-
helpers_lib_1.JSEngine.setAsJSEngineFunction(originalFunction);
|
|
10
|
-
descriptor.value = function (...args) {
|
|
11
|
-
let hasFlag = Reflect.getOwnMetadata(exports.ActionBeforeTestingFlag, this);
|
|
12
|
-
if (hasFlag) {
|
|
13
|
-
return originalFunction.apply(this, args);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
throw new Error(`"${String(propertyKey)}(...)" can only be called at "actions before testing".`);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
helpers_lib_1.MetaDataHelper.carryMetaDataOfFunction(originalFunction, descriptor.value);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
exports.ActionBeforeTesting = ActionBeforeTesting;
|
|
23
|
-
//# sourceMappingURL=decorators.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const helpers_lib_1 = require("helpers-lib");
|
|
13
|
-
const vitest_1 = require("vitest");
|
|
14
|
-
const story_engine_1 = require("../engine/story-engine");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
16
|
-
const event_test_simulator_1 = require("./event-test-simulator");
|
|
17
|
-
let SampleFunctions = class SampleFunctions extends story_engine_1.StoryEngineFunctions {
|
|
18
|
-
onPlayerChoice(choices) { }
|
|
19
|
-
onEnd() { }
|
|
20
|
-
exclusive() { }
|
|
21
|
-
sayHi(message) { }
|
|
22
|
-
};
|
|
23
|
-
__decorate([
|
|
24
|
-
(0, decorators_1.ActionBeforeTesting)(),
|
|
25
|
-
__metadata("design:type", Function),
|
|
26
|
-
__metadata("design:paramtypes", []),
|
|
27
|
-
__metadata("design:returntype", void 0)
|
|
28
|
-
], SampleFunctions.prototype, "exclusive", null);
|
|
29
|
-
__decorate([
|
|
30
|
-
(0, decorators_1.ActionBeforeTesting)(),
|
|
31
|
-
__metadata("design:type", Function),
|
|
32
|
-
__metadata("design:paramtypes", [String]),
|
|
33
|
-
__metadata("design:returntype", void 0)
|
|
34
|
-
], SampleFunctions.prototype, "sayHi", null);
|
|
35
|
-
SampleFunctions = __decorate([
|
|
36
|
-
(0, helpers_lib_1.AutoValidate)({ allowReadingNonExistantProperties: true })
|
|
37
|
-
], SampleFunctions);
|
|
38
|
-
(0, vitest_1.describe)('EventTestSimulator', () => {
|
|
39
|
-
let functions;
|
|
40
|
-
(0, vitest_1.beforeEach)(() => {
|
|
41
|
-
functions = new SampleFunctions();
|
|
42
|
-
});
|
|
43
|
-
(0, vitest_1.test)('sample 1 - valid call', () => {
|
|
44
|
-
let actionsBeforeTesting = [{ type: 'command', value: 'exclusive()' }];
|
|
45
|
-
let events = [
|
|
46
|
-
{
|
|
47
|
-
id: 'event1',
|
|
48
|
-
actions: [{ type: 'command', value: 'a = 1' }]
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
52
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
53
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, actionsBeforeTesting)).not.toThrow();
|
|
54
|
-
});
|
|
55
|
-
(0, vitest_1.test)('sample 2 - call during execution error', () => {
|
|
56
|
-
let events = [
|
|
57
|
-
{
|
|
58
|
-
id: 'event1',
|
|
59
|
-
actions: [{ type: 'command', value: 'exclusive()' }]
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
63
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
64
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrow('"exclusive(...)" can only be called at "actions before testing"');
|
|
65
|
-
});
|
|
66
|
-
(0, vitest_1.test)('sample 3 - wrong parameter count error', () => {
|
|
67
|
-
let events = [
|
|
68
|
-
{
|
|
69
|
-
id: 'event1',
|
|
70
|
-
actions: [{ type: 'command', value: 'exclusive("a")' }]
|
|
71
|
-
}
|
|
72
|
-
];
|
|
73
|
-
let simulator = new event_test_simulator_1.EventTestSimulator(events);
|
|
74
|
-
let jsEngine = new helpers_lib_1.JSEngine(functions, {});
|
|
75
|
-
(0, vitest_1.expect)(() => simulator.simulateEvent(events[0], jsEngine, [])).toThrow('Error: Unexpected argument has sent to exclusive. Expected: 0, Received: 1');
|
|
76
|
-
});
|
|
77
|
-
(0, vitest_1.test)('sample 4 - preserve parameter count', () => {
|
|
78
|
-
(0, vitest_1.expect)(functions.sayHi.length).toBe(1);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
//# sourceMappingURL=decorators.test.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { EventActionDefinition, EventDefinition, ExecutionLocation, VisitableEventBranchDefinition } from '../interfaces';
|
|
2
|
-
export declare class EventBranchesMap {
|
|
3
|
-
private idToEventMap;
|
|
4
|
-
private unvisitedBranches;
|
|
5
|
-
private branchToInfoMap;
|
|
6
|
-
private actionToInfoMap;
|
|
7
|
-
constructor(eventDefinitions: EventDefinition[]);
|
|
8
|
-
getEvent(id: string): EventDefinition;
|
|
9
|
-
getRootBranchLocation(branch: VisitableEventBranchDefinition): ExecutionLocation;
|
|
10
|
-
getBranchLocation(branch: VisitableEventBranchDefinition): ExecutionLocation;
|
|
11
|
-
getActionLocation(action: EventActionDefinition): ExecutionLocation;
|
|
12
|
-
setVisited(branch: VisitableEventBranchDefinition): void;
|
|
13
|
-
getUnvisitedBranchLocations(): ExecutionLocation[];
|
|
14
|
-
private registerBranch;
|
|
15
|
-
private checkBranchesToRegisterInActions;
|
|
16
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventBranchesMap = void 0;
|
|
4
|
-
var VisitableEventBranchType;
|
|
5
|
-
(function (VisitableEventBranchType) {
|
|
6
|
-
VisitableEventBranchType["event"] = "event";
|
|
7
|
-
VisitableEventBranchType["branchByCondition"] = "branchByCondition";
|
|
8
|
-
VisitableEventBranchType["branchByPlayerChoice"] = "branchByPlayerChoice";
|
|
9
|
-
VisitableEventBranchType["branchByChance"] = "branchByChance";
|
|
10
|
-
})(VisitableEventBranchType || (VisitableEventBranchType = {}));
|
|
11
|
-
class EventBranchesMap {
|
|
12
|
-
constructor(eventDefinitions) {
|
|
13
|
-
this.idToEventMap = new Map();
|
|
14
|
-
this.unvisitedBranches = new Set();
|
|
15
|
-
this.branchToInfoMap = new Map();
|
|
16
|
-
this.actionToInfoMap = new Map();
|
|
17
|
-
eventDefinitions.forEach(eventDefinition => {
|
|
18
|
-
this.idToEventMap.set(eventDefinition.id, eventDefinition);
|
|
19
|
-
this.registerBranch(eventDefinition, VisitableEventBranchType.event, eventDefinition.id, undefined, []);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
getEvent(id) {
|
|
23
|
-
let event = this.idToEventMap.get(id);
|
|
24
|
-
if (!event) {
|
|
25
|
-
throw new Error(`Event with id ${id} not found.`);
|
|
26
|
-
}
|
|
27
|
-
return event;
|
|
28
|
-
}
|
|
29
|
-
getRootBranchLocation(branch) {
|
|
30
|
-
let branchInfo = this.branchToInfoMap.get(branch);
|
|
31
|
-
if (!branchInfo) {
|
|
32
|
-
throw new Error('Branch not found.');
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
eventId: branchInfo.rootEventId,
|
|
36
|
-
path: []
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
getBranchLocation(branch) {
|
|
40
|
-
let branchInfo = this.branchToInfoMap.get(branch);
|
|
41
|
-
if (!branchInfo) {
|
|
42
|
-
throw new Error('Branch not found.');
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
eventId: branchInfo.rootEventId,
|
|
46
|
-
path: branchInfo.path
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
getActionLocation(action) {
|
|
50
|
-
let actionInfo = this.actionToInfoMap.get(action);
|
|
51
|
-
if (!actionInfo) {
|
|
52
|
-
throw new Error('Branch not found.');
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
eventId: actionInfo.rootEventId,
|
|
56
|
-
path: actionInfo.path
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
setVisited(branch) {
|
|
60
|
-
this.unvisitedBranches.delete(branch);
|
|
61
|
-
}
|
|
62
|
-
getUnvisitedBranchLocations() {
|
|
63
|
-
return Array.from(this.unvisitedBranches)
|
|
64
|
-
.map(branch => this.branchToInfoMap.get(branch))
|
|
65
|
-
.filter(branchInfo => !branchInfo.parentBranchInfo || !this.unvisitedBranches.has(branchInfo.parentBranchInfo.branch))
|
|
66
|
-
.map(branchInfo => ({ eventId: branchInfo.rootEventId, path: branchInfo.path }));
|
|
67
|
-
}
|
|
68
|
-
registerBranch(branch, type, rootEventId, parentBranchInfo, path) {
|
|
69
|
-
let branchInfo = {
|
|
70
|
-
branch,
|
|
71
|
-
type,
|
|
72
|
-
parentBranchInfo,
|
|
73
|
-
rootEventId,
|
|
74
|
-
path
|
|
75
|
-
};
|
|
76
|
-
this.unvisitedBranches.add(branch);
|
|
77
|
-
this.branchToInfoMap.set(branch, branchInfo);
|
|
78
|
-
this.checkBranchesToRegisterInActions(branch.actions, rootEventId, branchInfo, path);
|
|
79
|
-
}
|
|
80
|
-
checkBranchesToRegisterInActions(actions, rootEventId, parentBranchInfo, path) {
|
|
81
|
-
actions.forEach((action, index) => {
|
|
82
|
-
let actionPath = [...path, 'actions', `${index}`];
|
|
83
|
-
let actionInfo = {
|
|
84
|
-
action,
|
|
85
|
-
rootEventId,
|
|
86
|
-
path: actionPath
|
|
87
|
-
};
|
|
88
|
-
this.actionToInfoMap.set(action, actionInfo);
|
|
89
|
-
if (action.type === 'branchByCondition') {
|
|
90
|
-
let definiton = action.value;
|
|
91
|
-
definiton.forEach((branchByConditionItem, branchIndex) => {
|
|
92
|
-
let newPath = [...actionPath, 'branchByCondition', `${branchIndex}`];
|
|
93
|
-
this.registerBranch(branchByConditionItem, VisitableEventBranchType.branchByCondition, rootEventId, parentBranchInfo, newPath);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
else if (action.type === 'branchByPlayerChoice') {
|
|
97
|
-
let definiton = action.value;
|
|
98
|
-
definiton.forEach((branchByPlayerChoiceItem, branchIndex) => {
|
|
99
|
-
let newPath = [...actionPath, 'branchByPlayerChoice', `${branchIndex}`];
|
|
100
|
-
this.registerBranch(branchByPlayerChoiceItem, VisitableEventBranchType.branchByPlayerChoice, rootEventId, parentBranchInfo, newPath);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
else if (action.type === 'branchByChance') {
|
|
104
|
-
let definiton = action.value;
|
|
105
|
-
definiton.forEach((branchByChanceItem, branchIndex) => {
|
|
106
|
-
let newPath = [...actionPath, 'branchByChance', `${branchIndex}`];
|
|
107
|
-
this.registerBranch(branchByChanceItem, VisitableEventBranchType.branchByChance, rootEventId, parentBranchInfo, newPath);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.EventBranchesMap = EventBranchesMap;
|
|
114
|
-
//# sourceMappingURL=event-branches-map.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const vitest_1 = require("vitest");
|
|
4
|
-
const event_branches_map_1 = require("./event-branches-map");
|
|
5
|
-
(0, vitest_1.describe)('EventTestSimulator', () => {
|
|
6
|
-
(0, vitest_1.test)('error case', () => {
|
|
7
|
-
let events = [{ id: 'eventbasic', actions: [{ type: 'command', value: 'gameOver()' }] }];
|
|
8
|
-
let visitedBranchesMap = new event_branches_map_1.EventBranchesMap(events);
|
|
9
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([
|
|
10
|
-
{
|
|
11
|
-
eventId: 'eventbasic',
|
|
12
|
-
path: []
|
|
13
|
-
}
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
(0, vitest_1.test)('visiting branch', () => {
|
|
17
|
-
let events = [{ id: 'eventbasic', actions: [{ type: 'command', value: 'gameOver()' }] }];
|
|
18
|
-
let visitedBranchesMap = new event_branches_map_1.EventBranchesMap(events);
|
|
19
|
-
visitedBranchesMap.setVisited(events[0]);
|
|
20
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([]);
|
|
21
|
-
});
|
|
22
|
-
(0, vitest_1.test)('when an error being shown, ignore children errors', () => {
|
|
23
|
-
let childBranch = {
|
|
24
|
-
condition: 'getPlayerCredits() >= 2000',
|
|
25
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
26
|
-
};
|
|
27
|
-
let events = [
|
|
28
|
-
{
|
|
29
|
-
id: 'eventbasic',
|
|
30
|
-
actions: [
|
|
31
|
-
{
|
|
32
|
-
type: 'branchByCondition',
|
|
33
|
-
value: [childBranch]
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
let visitedBranchesMap = new event_branches_map_1.EventBranchesMap(events);
|
|
39
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([
|
|
40
|
-
{
|
|
41
|
-
eventId: 'eventbasic',
|
|
42
|
-
path: []
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
45
|
-
});
|
|
46
|
-
(0, vitest_1.test)('child error', () => {
|
|
47
|
-
let childBranch = {
|
|
48
|
-
condition: 'getPlayerCredits() >= 2000',
|
|
49
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
50
|
-
};
|
|
51
|
-
let events = [
|
|
52
|
-
{
|
|
53
|
-
id: 'eventbasic',
|
|
54
|
-
actions: [
|
|
55
|
-
{
|
|
56
|
-
type: 'branchByCondition',
|
|
57
|
-
value: [childBranch]
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
let visitedBranchesMap = new event_branches_map_1.EventBranchesMap(events);
|
|
63
|
-
visitedBranchesMap.setVisited(events[0]);
|
|
64
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([
|
|
65
|
-
{
|
|
66
|
-
eventId: 'eventbasic',
|
|
67
|
-
path: ['actions', '0', 'branchByCondition', '0']
|
|
68
|
-
}
|
|
69
|
-
]);
|
|
70
|
-
});
|
|
71
|
-
(0, vitest_1.test)('get branch path', () => {
|
|
72
|
-
let childBranch = {
|
|
73
|
-
condition: 'getPlayerCredits() >= 2000',
|
|
74
|
-
actions: [{ type: 'command', value: 'gameOver()' }]
|
|
75
|
-
};
|
|
76
|
-
let events = [
|
|
77
|
-
{
|
|
78
|
-
id: 'eventbasic',
|
|
79
|
-
actions: [
|
|
80
|
-
{
|
|
81
|
-
type: 'branchByCondition',
|
|
82
|
-
value: [childBranch]
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
let visitedBranchesMap = new event_branches_map_1.EventBranchesMap(events);
|
|
88
|
-
visitedBranchesMap.setVisited(events[0]);
|
|
89
|
-
(0, vitest_1.expect)(visitedBranchesMap.getBranchLocation(childBranch)).toEqual({
|
|
90
|
-
eventId: 'eventbasic',
|
|
91
|
-
path: ['actions', '0', 'branchByCondition', '0']
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
(0, vitest_1.test)('get branch path', () => {
|
|
95
|
-
let childAction = { type: 'command', value: 'gameOver()' };
|
|
96
|
-
let events = [
|
|
97
|
-
{
|
|
98
|
-
id: 'eventbasic',
|
|
99
|
-
actions: [
|
|
100
|
-
{
|
|
101
|
-
type: 'branchByCondition',
|
|
102
|
-
value: [
|
|
103
|
-
{
|
|
104
|
-
condition: 'getPlayerCredits() >= 2000',
|
|
105
|
-
actions: [childAction]
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
];
|
|
112
|
-
let visitedBranchesMap = new event_branches_map_1.EventBranchesMap(events);
|
|
113
|
-
visitedBranchesMap.setVisited(events[0]);
|
|
114
|
-
(0, vitest_1.expect)(visitedBranchesMap.getActionLocation(childAction)).toEqual({
|
|
115
|
-
eventId: 'eventbasic',
|
|
116
|
-
path: ['actions', '0', 'branchByCondition', '0', 'actions', '0']
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
//# sourceMappingURL=event-branches-map.test.js.map
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { JSEngine } from 'helpers-lib';
|
|
2
|
-
import { EventDefinition, EventTestActionDefinition, ExecutionLocation } from '../interfaces';
|
|
3
|
-
export declare abstract class StoryEngineSimulatorFunctions {
|
|
4
|
-
abstract onDialog(text: string, speaker: string): void;
|
|
5
|
-
abstract onPlayerChoice(choices: readonly string[]): void;
|
|
6
|
-
abstract onEnd(): void;
|
|
7
|
-
abstract onEventBranchingEnd(): void;
|
|
8
|
-
}
|
|
9
|
-
export interface EventTestSimulatorOptions {
|
|
10
|
-
readonly preventTypeChanges?: boolean;
|
|
11
|
-
readonly richTextTags?: Set<string>;
|
|
12
|
-
}
|
|
13
|
-
export declare class EventTestSimulator<T extends StoryEngineSimulatorFunctions> {
|
|
14
|
-
private eventDefinitions;
|
|
15
|
-
private options;
|
|
16
|
-
private eventBranchesMap;
|
|
17
|
-
private globalNameSpace?;
|
|
18
|
-
private visitedBranchStates;
|
|
19
|
-
constructor(eventDefinitions: EventDefinition[], options?: EventTestSimulatorOptions);
|
|
20
|
-
/**
|
|
21
|
-
* @throws SimulationError, ActionsBeforeTestingError, BranchingBeforeTestingError
|
|
22
|
-
*/
|
|
23
|
-
simulateEvent(eventDefinition: EventDefinition, jsEngine: JSEngine<T>, actionsBeforeTesting: readonly EventTestActionDefinition[]): void;
|
|
24
|
-
getUnvisitedBranchLocations(): ExecutionLocation[];
|
|
25
|
-
private processActionsBeforeTesting;
|
|
26
|
-
private executeActionBeforeTesting;
|
|
27
|
-
private branchOutFromEvent;
|
|
28
|
-
private executeEvent;
|
|
29
|
-
private executeBranch;
|
|
30
|
-
private executeAction;
|
|
31
|
-
private executeActionCommand;
|
|
32
|
-
private executeDialogCommand;
|
|
33
|
-
private executeActionJumpToEvent;
|
|
34
|
-
private executeActionBranchByCondition;
|
|
35
|
-
private executeActionBranchByChance;
|
|
36
|
-
private executeActionBranchByPlayerChoice;
|
|
37
|
-
private checkBranchCondition;
|
|
38
|
-
private removeDuplicateEndings;
|
|
39
|
-
private isBranchVisitedAndRegister;
|
|
40
|
-
private duplicateContext;
|
|
41
|
-
private prepareErrorMessage;
|
|
42
|
-
}
|