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
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExecutionHistory = void 0;
|
|
4
|
-
class ExecutionHistory {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.entries = [];
|
|
7
|
-
}
|
|
8
|
-
addEntry(entry) {
|
|
9
|
-
this.entries.push(entry);
|
|
10
|
-
return this;
|
|
11
|
-
}
|
|
12
|
-
toString() {
|
|
13
|
-
return this.entries.join('\n');
|
|
14
|
-
}
|
|
15
|
-
duplicate() {
|
|
16
|
-
let copy = new ExecutionHistory();
|
|
17
|
-
copy.entries = [...this.entries];
|
|
18
|
-
return copy;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ExecutionHistory = ExecutionHistory;
|
|
22
|
-
//# sourceMappingURL=execution-history.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,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExecutionHistory = void 0;
|
|
4
|
-
class ExecutionHistory {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.entries = [];
|
|
7
|
-
}
|
|
8
|
-
addEntry(entry) {
|
|
9
|
-
this.entries.push(entry);
|
|
10
|
-
return this;
|
|
11
|
-
}
|
|
12
|
-
toString() {
|
|
13
|
-
return this.entries.join('\n');
|
|
14
|
-
}
|
|
15
|
-
duplicate() {
|
|
16
|
-
let copy = new ExecutionHistory();
|
|
17
|
-
copy.entries = [...this.entries];
|
|
18
|
-
return copy;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ExecutionHistory = ExecutionHistory;
|
|
22
|
-
//# sourceMappingURL=execution-history.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ExecutionLocation, ScriptActionDefinition, ScriptDefinition, VisitableScriptBranchDefinition } from '../../interfaces';
|
|
2
|
-
export declare class ScriptBranchesMap {
|
|
3
|
-
private idToScriptMap;
|
|
4
|
-
private unvisitedBranches;
|
|
5
|
-
private branchToInfoMap;
|
|
6
|
-
private actionToInfoMap;
|
|
7
|
-
constructor(scriptDefinitions: ScriptDefinition[]);
|
|
8
|
-
getScript(id: string): ScriptDefinition;
|
|
9
|
-
getRootBranchLocation(branch: VisitableScriptBranchDefinition): ExecutionLocation;
|
|
10
|
-
getBranchLocation(branch: VisitableScriptBranchDefinition): ExecutionLocation;
|
|
11
|
-
getActionLocation(action: ScriptActionDefinition): ExecutionLocation;
|
|
12
|
-
setVisited(branch: VisitableScriptBranchDefinition): 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.ScriptBranchesMap = void 0;
|
|
4
|
-
var VisitableScriptBranchType;
|
|
5
|
-
(function (VisitableScriptBranchType) {
|
|
6
|
-
VisitableScriptBranchType["script"] = "script";
|
|
7
|
-
VisitableScriptBranchType["branchByCondition"] = "branchByCondition";
|
|
8
|
-
VisitableScriptBranchType["branchByPlayerChoice"] = "branchByPlayerChoice";
|
|
9
|
-
VisitableScriptBranchType["branchByChance"] = "branchByChance";
|
|
10
|
-
})(VisitableScriptBranchType || (VisitableScriptBranchType = {}));
|
|
11
|
-
class ScriptBranchesMap {
|
|
12
|
-
constructor(scriptDefinitions) {
|
|
13
|
-
this.idToScriptMap = new Map();
|
|
14
|
-
this.unvisitedBranches = new Set();
|
|
15
|
-
this.branchToInfoMap = new Map();
|
|
16
|
-
this.actionToInfoMap = new Map();
|
|
17
|
-
scriptDefinitions.forEach(scriptDefinition => {
|
|
18
|
-
this.idToScriptMap.set(scriptDefinition.id, scriptDefinition);
|
|
19
|
-
this.registerBranch(scriptDefinition, VisitableScriptBranchType.script, scriptDefinition.id, undefined, []);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
getScript(id) {
|
|
23
|
-
let script = this.idToScriptMap.get(id);
|
|
24
|
-
if (!script) {
|
|
25
|
-
throw new Error(`Script with id ${id} not found.`);
|
|
26
|
-
}
|
|
27
|
-
return script;
|
|
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
|
-
scriptId: branchInfo.rootScriptId,
|
|
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
|
-
scriptId: branchInfo.rootScriptId,
|
|
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
|
-
scriptId: actionInfo.rootScriptId,
|
|
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 => ({ scriptId: branchInfo.rootScriptId, path: branchInfo.path }));
|
|
67
|
-
}
|
|
68
|
-
registerBranch(branch, type, rootScriptId, parentBranchInfo, path) {
|
|
69
|
-
let branchInfo = {
|
|
70
|
-
branch,
|
|
71
|
-
type,
|
|
72
|
-
parentBranchInfo,
|
|
73
|
-
rootScriptId,
|
|
74
|
-
path
|
|
75
|
-
};
|
|
76
|
-
this.unvisitedBranches.add(branch);
|
|
77
|
-
this.branchToInfoMap.set(branch, branchInfo);
|
|
78
|
-
this.checkBranchesToRegisterInActions(branch.actions, rootScriptId, branchInfo, path);
|
|
79
|
-
}
|
|
80
|
-
checkBranchesToRegisterInActions(actions, rootScriptId, parentBranchInfo, path) {
|
|
81
|
-
actions.forEach((action, index) => {
|
|
82
|
-
let actionPath = [...path, 'actions', `${index}`];
|
|
83
|
-
let actionInfo = {
|
|
84
|
-
action,
|
|
85
|
-
rootScriptId,
|
|
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, VisitableScriptBranchType.branchByCondition, rootScriptId, 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, VisitableScriptBranchType.branchByPlayerChoice, rootScriptId, 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, VisitableScriptBranchType.branchByChance, rootScriptId, parentBranchInfo, newPath);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
exports.ScriptBranchesMap = ScriptBranchesMap;
|
|
114
|
-
//# sourceMappingURL=script-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 script_branches_map_1 = require("./script-branches-map");
|
|
5
|
-
(0, vitest_1.describe)('ScriptTestSimulator', () => {
|
|
6
|
-
(0, vitest_1.test)('error case', () => {
|
|
7
|
-
let scripts = [{ id: 'scriptbasic', actions: [{ type: 'command', value: 'gameOver()' }] }];
|
|
8
|
-
let visitedBranchesMap = new script_branches_map_1.ScriptBranchesMap(scripts);
|
|
9
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([
|
|
10
|
-
{
|
|
11
|
-
scriptId: 'scriptbasic',
|
|
12
|
-
path: []
|
|
13
|
-
}
|
|
14
|
-
]);
|
|
15
|
-
});
|
|
16
|
-
(0, vitest_1.test)('visiting branch', () => {
|
|
17
|
-
let scripts = [{ id: 'scriptbasic', actions: [{ type: 'command', value: 'gameOver()' }] }];
|
|
18
|
-
let visitedBranchesMap = new script_branches_map_1.ScriptBranchesMap(scripts);
|
|
19
|
-
visitedBranchesMap.setVisited(scripts[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 scripts = [
|
|
28
|
-
{
|
|
29
|
-
id: 'scriptbasic',
|
|
30
|
-
actions: [
|
|
31
|
-
{
|
|
32
|
-
type: 'branchByCondition',
|
|
33
|
-
value: [childBranch]
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
let visitedBranchesMap = new script_branches_map_1.ScriptBranchesMap(scripts);
|
|
39
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([
|
|
40
|
-
{
|
|
41
|
-
scriptId: 'scriptbasic',
|
|
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 scripts = [
|
|
52
|
-
{
|
|
53
|
-
id: 'scriptbasic',
|
|
54
|
-
actions: [
|
|
55
|
-
{
|
|
56
|
-
type: 'branchByCondition',
|
|
57
|
-
value: [childBranch]
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}
|
|
61
|
-
];
|
|
62
|
-
let visitedBranchesMap = new script_branches_map_1.ScriptBranchesMap(scripts);
|
|
63
|
-
visitedBranchesMap.setVisited(scripts[0]);
|
|
64
|
-
(0, vitest_1.expect)(visitedBranchesMap.getUnvisitedBranchLocations()).toEqual([
|
|
65
|
-
{
|
|
66
|
-
scriptId: 'scriptbasic',
|
|
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 scripts = [
|
|
77
|
-
{
|
|
78
|
-
id: 'scriptbasic',
|
|
79
|
-
actions: [
|
|
80
|
-
{
|
|
81
|
-
type: 'branchByCondition',
|
|
82
|
-
value: [childBranch]
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
let visitedBranchesMap = new script_branches_map_1.ScriptBranchesMap(scripts);
|
|
88
|
-
visitedBranchesMap.setVisited(scripts[0]);
|
|
89
|
-
(0, vitest_1.expect)(visitedBranchesMap.getBranchLocation(childBranch)).toEqual({
|
|
90
|
-
scriptId: 'scriptbasic',
|
|
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 scripts = [
|
|
97
|
-
{
|
|
98
|
-
id: 'scriptbasic',
|
|
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 script_branches_map_1.ScriptBranchesMap(scripts);
|
|
113
|
-
visitedBranchesMap.setVisited(scripts[0]);
|
|
114
|
-
(0, vitest_1.expect)(visitedBranchesMap.getActionLocation(childAction)).toEqual({
|
|
115
|
-
scriptId: 'scriptbasic',
|
|
116
|
-
path: ['actions', '0', 'branchByCondition', '0', 'actions', '0']
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
//# sourceMappingURL=script-branches-map.test.js.map
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { JSEngine } from 'helpers-lib';
|
|
2
|
-
import { ExecutionLocation, ScriptDefinition, ScriptTestActionDefinition } from '../interfaces';
|
|
3
|
-
export declare abstract class ScriptEngineSimulatorFunctions {
|
|
4
|
-
abstract onDialog(text: string, speaker: string): void;
|
|
5
|
-
abstract onPlayerChoice(choices: readonly string[]): void;
|
|
6
|
-
abstract onEnd(): void;
|
|
7
|
-
abstract onScriptBranchingEnd(): void;
|
|
8
|
-
}
|
|
9
|
-
export interface ScriptTestSimulatorOptions {
|
|
10
|
-
readonly prscriptTypeChanges?: boolean;
|
|
11
|
-
readonly richTextTags?: Set<string>;
|
|
12
|
-
}
|
|
13
|
-
export declare class ScriptTestSimulator<T extends ScriptEngineSimulatorFunctions> {
|
|
14
|
-
private scriptDefinitions;
|
|
15
|
-
private options;
|
|
16
|
-
private scriptBranchesMap;
|
|
17
|
-
private globalNameSpace?;
|
|
18
|
-
private visitedBranchStates;
|
|
19
|
-
constructor(scriptDefinitions: ScriptDefinition[], options?: ScriptTestSimulatorOptions);
|
|
20
|
-
/**
|
|
21
|
-
* @throws SimulationError, ActionsBeforeTestingError, BranchingBeforeTestingError
|
|
22
|
-
*/
|
|
23
|
-
simulateScript(scriptDefinition: ScriptDefinition, jsEngine: JSEngine<T>, actionsBeforeTesting: readonly ScriptTestActionDefinition[]): void;
|
|
24
|
-
getUnvisitedBranchLocations(): ExecutionLocation[];
|
|
25
|
-
private processActionsBeforeTesting;
|
|
26
|
-
private executeActionBeforeTesting;
|
|
27
|
-
private branchOutFromScript;
|
|
28
|
-
private executeScript;
|
|
29
|
-
private executeBranch;
|
|
30
|
-
private executeAction;
|
|
31
|
-
private executeActionCommand;
|
|
32
|
-
private executeDialogCommand;
|
|
33
|
-
private executeActionjumpTo;
|
|
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
|
-
}
|