@bscotch/gcdata 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/GameChanger.js +1 -1
- package/dist/GameChanger.js.map +1 -1
- package/dist/cl2.character.pointers.d.ts +3 -0
- package/dist/cl2.character.pointers.d.ts.map +1 -0
- package/dist/cl2.character.pointers.js +2 -0
- package/dist/cl2.character.pointers.js.map +1 -0
- package/dist/cl2.chat.pointers.d.ts +3 -0
- package/dist/cl2.chat.pointers.d.ts.map +1 -0
- package/dist/cl2.chat.pointers.js +2 -0
- package/dist/cl2.chat.pointers.js.map +1 -0
- package/dist/cl2.comfort.d.ts +4 -0
- package/dist/cl2.comfort.d.ts.map +1 -0
- package/dist/cl2.comfort.js +4 -0
- package/dist/cl2.comfort.js.map +1 -0
- package/dist/cl2.comfort.parse.d.ts +7 -0
- package/dist/cl2.comfort.parse.d.ts.map +1 -0
- package/dist/cl2.comfort.parse.js +109 -0
- package/dist/cl2.comfort.parse.js.map +1 -0
- package/dist/cl2.comfort.pointers.d.ts +3 -0
- package/dist/cl2.comfort.pointers.d.ts.map +1 -0
- package/dist/cl2.comfort.pointers.js +2 -0
- package/dist/cl2.comfort.pointers.js.map +1 -0
- package/dist/cl2.comfort.stringify.d.ts +4 -0
- package/dist/cl2.comfort.stringify.d.ts.map +1 -0
- package/dist/cl2.comfort.stringify.js +25 -0
- package/dist/cl2.comfort.stringify.js.map +1 -0
- package/dist/cl2.comfort.types.d.ts +14 -0
- package/dist/cl2.comfort.types.d.ts.map +1 -0
- package/dist/cl2.comfort.types.js +23 -0
- package/dist/cl2.comfort.types.js.map +1 -0
- package/dist/cl2.quest.d.ts +1 -1
- package/dist/cl2.quest.d.ts.map +1 -1
- package/dist/cl2.quest.js +1 -1
- package/dist/cl2.quest.js.map +1 -1
- package/dist/cl2.quest.parse.d.ts +1 -1
- package/dist/cl2.quest.parse.d.ts.map +1 -1
- package/dist/cl2.quest.parse.js +42 -196
- package/dist/cl2.quest.parse.js.map +1 -1
- package/dist/cl2.quest.types.d.ts +15 -105
- package/dist/cl2.quest.types.d.ts.map +1 -1
- package/dist/cl2.quest.types.js +1 -84
- package/dist/cl2.quest.types.js.map +1 -1
- package/dist/cl2.quest.utils.d.ts +0 -2
- package/dist/cl2.quest.utils.d.ts.map +1 -1
- package/dist/cl2.quest.utils.js +0 -14
- package/dist/cl2.quest.utils.js.map +1 -1
- package/dist/cl2.shared.parse.d.ts +38 -0
- package/dist/cl2.shared.parse.d.ts.map +1 -0
- package/dist/cl2.shared.parse.js +223 -0
- package/dist/cl2.shared.parse.js.map +1 -0
- package/dist/cl2.shared.types.d.ts +126 -0
- package/dist/cl2.shared.types.d.ts.map +1 -0
- package/dist/cl2.shared.types.js +108 -0
- package/dist/cl2.shared.types.js.map +1 -0
- package/dist/cl2.storyline.d.ts +1 -1
- package/dist/cl2.storyline.d.ts.map +1 -1
- package/dist/cl2.storyline.js +1 -1
- package/dist/cl2.storyline.js.map +1 -1
- package/dist/cl2.storyline.parse.d.ts.map +1 -1
- package/dist/cl2.storyline.parse.js +18 -176
- package/dist/cl2.storyline.parse.js.map +1 -1
- package/dist/cl2.storyline.stringify.d.ts +1 -1
- package/dist/cl2.storyline.stringify.d.ts.map +1 -1
- package/dist/cl2.storyline.types.d.ts +5 -28
- package/dist/cl2.storyline.types.d.ts.map +1 -1
- package/dist/cl2.storyline.types.js +1 -65
- package/dist/cl2.storyline.types.js.map +1 -1
- package/dist/cl2.types.auto.d.ts +10635 -10434
- package/dist/cl2.types.auto.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types.editor.d.ts +10 -0
- package/dist/types.editor.d.ts.map +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +3 -0
- package/dist/util.js.map +1 -1
- package/package.json +1 -1
- package/dist/cl2.storyline.utils.d.ts +0 -1
- package/dist/cl2.storyline.utils.d.ts.map +0 -1
- package/dist/cl2.storyline.utils.js +0 -2
- package/dist/cl2.storyline.utils.js.map +0 -1
- package/dist/cl2.types.editor.d.ts +0 -33
- package/dist/cl2.types.editor.d.ts.map +0 -1
- package/dist/cl2.types.editor.js +0 -2
- package/dist/cl2.types.editor.js.map +0 -1
- package/dist/dict.d.ts +0 -3
- package/dist/dict.d.ts.map +0 -1
- package/dist/dict.js +0 -49777
- package/dist/dict.js.map +0 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { assert } from './assert.js';
|
|
3
|
+
import { resolvePointerInSchema } from './util.js';
|
|
4
|
+
export const questSchemaId = 'cl2_quest';
|
|
5
|
+
export const chatSchemaId = 'cl2_chat';
|
|
6
|
+
export const buddySchemaId = 'artisan';
|
|
7
|
+
export const npcSchemaId = 'cl2_npc';
|
|
8
|
+
export const comfortSchemaId = 'cl2_artisan_glads';
|
|
9
|
+
export const storylineSchemaId = 'cl2_storyline';
|
|
10
|
+
export const arrayTagPattern = '(?:#(?<arrayTag>[a-z0-9]+))';
|
|
11
|
+
export const linePartsSchema = z.object({
|
|
12
|
+
indicator: z
|
|
13
|
+
.string()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe('The symbol prefixing the line to indicate what the line type is'),
|
|
16
|
+
arrayTag: z
|
|
17
|
+
.string()
|
|
18
|
+
.regex(/^[a-z0-9]+$/)
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("BsArrayElement identifier (without the '#' prefix)"),
|
|
21
|
+
moteTag: z
|
|
22
|
+
.string()
|
|
23
|
+
.regex(/^[\w_-]+$/)
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("MoteId (without the '@' prefix)"),
|
|
26
|
+
moteName: z.string().optional().describe('Mote Name'),
|
|
27
|
+
emojiGroup: z
|
|
28
|
+
.string()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('The emoji name, including the outer `()`'),
|
|
31
|
+
emojiName: z.string().optional().describe("The emoji's mote name"),
|
|
32
|
+
labelGroup: z.string().optional().describe('The label, including the `:`'),
|
|
33
|
+
label: z.string().optional().describe('For `Label:Value` elements'),
|
|
34
|
+
sep: z
|
|
35
|
+
.string()
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('Separator between the line prefix and content.'),
|
|
38
|
+
text: z
|
|
39
|
+
.string()
|
|
40
|
+
.optional()
|
|
41
|
+
.describe('For dialog and similar, the text content'),
|
|
42
|
+
style: z
|
|
43
|
+
.string()
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('For array elements whose values come in distinct flavors, the identifier indicating which flavor it is'),
|
|
46
|
+
status: z
|
|
47
|
+
.string()
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('For entries that have some kind of "status" concept'),
|
|
50
|
+
});
|
|
51
|
+
export function parseIfMatch(pattern, line, startPosition) {
|
|
52
|
+
const rawMatch = line.match(new RegExp(pattern));
|
|
53
|
+
if (!rawMatch)
|
|
54
|
+
return null;
|
|
55
|
+
const parsedLine = linePartsSchema.parse(rawMatch.groups);
|
|
56
|
+
const result = {
|
|
57
|
+
_: {
|
|
58
|
+
start: startPosition,
|
|
59
|
+
end: { ...startPosition },
|
|
60
|
+
value: line,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
result._.end.character += line.length;
|
|
64
|
+
result._.end.index += line.length;
|
|
65
|
+
for (const [key, value] of Object.entries(parsedLine)) {
|
|
66
|
+
if (typeof value !== 'undefined') {
|
|
67
|
+
// Figure out where this is in the matches so we
|
|
68
|
+
// can get the start and end positions.
|
|
69
|
+
const startChar = line.indexOf(`${value}`);
|
|
70
|
+
const endChar = startChar + `${value}`.length;
|
|
71
|
+
const start = { ...startPosition };
|
|
72
|
+
start.character += startChar;
|
|
73
|
+
start.index += startChar;
|
|
74
|
+
const end = { ...startPosition };
|
|
75
|
+
end.character += endChar;
|
|
76
|
+
end.index += endChar;
|
|
77
|
+
result[key] = {
|
|
78
|
+
start,
|
|
79
|
+
end,
|
|
80
|
+
value: value,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
export function lineIsArrayItem(line) {
|
|
87
|
+
if (line.match(/^(\t|name|stage|storyline|(start|end) (moments|requirements)|log|giver|receiver|description|unlocked description)/i)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
export function getStagingOptions(packed) {
|
|
93
|
+
const stagingSubchema = resolvePointerInSchema(['wip', 'staging'], {
|
|
94
|
+
schema_id: 'cl2_quest',
|
|
95
|
+
data: {
|
|
96
|
+
wip: {
|
|
97
|
+
staging: 'any',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
}, packed);
|
|
101
|
+
return stagingSubchema.enum;
|
|
102
|
+
}
|
|
103
|
+
export function getEmojis(packed) {
|
|
104
|
+
const emojis = packed.listMotesBySchema('cl2_emoji');
|
|
105
|
+
assert(emojis.length > 0, 'Should have at least one emoji mote');
|
|
106
|
+
return emojis;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=cl2.shared.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cl2.shared.types.js","sourceRoot":"","sources":["../src/cl2.shared.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAEnD,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;AAIzC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AAIvC,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAIvC,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAIrC,MAAM,CAAC,MAAM,eAAe,GAAG,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,aAAa,EAAE,CAAC;YACjC,GAAG,CAAC,SAAS,IAAI,OAAO,CAAC;YACzB,GAAG,CAAC,KAAK,IAAI,OAAO,CAAC;YACrB,MAAM,CAAC,GAAuB,CAAC,GAAG;gBAChC,KAAK;gBACL,GAAG;gBACH,KAAK,EAAE,KAAY;aACb,CAAC;QACX,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IACE,IAAI,CAAC,KAAK,CACR,oHAAoH,CACrH,EACD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,eAAe,GAAG,sBAAsB,CAC5C,CAAC,KAAK,EAAE,SAAS,CAAC,EAClB;QACE,SAAS,EAAE,WAAW;QACtB,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,OAAO,EAAE,KAAK;aACf;SACF;KACK,EACR,MAAM,CACQ,CAAC;IACjB,OAAO,eAAe,CAAC,IAAI,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,MAAc;IAEd,MAAM,MAAM,GACV,MAAM,CAAC,iBAAiB,CAAmC,WAAW,CAAC,CAAC;IAC1E,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,qCAAqC,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/cl2.storyline.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { parseStringifiedStoryline, updateChangesFromParsedStoryline, } from './cl2.storyline.parse.js';
|
|
2
2
|
export { stringifyStoryline } from './cl2.storyline.stringify.js';
|
|
3
|
-
export { isStorylineMote, listStorylines,
|
|
3
|
+
export { isStorylineMote, listStorylines, type StorylineUpdateResult, } from './cl2.storyline.types.js';
|
|
4
4
|
//# sourceMappingURL=cl2.storyline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,eAAe,EACf,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"cl2.storyline.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,eAAe,EACf,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,0BAA0B,CAAC"}
|
package/dist/cl2.storyline.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { parseStringifiedStoryline, updateChangesFromParsedStoryline, } from './cl2.storyline.parse.js';
|
|
2
2
|
export { stringifyStoryline } from './cl2.storyline.stringify.js';
|
|
3
|
-
export { isStorylineMote, listStorylines,
|
|
3
|
+
export { isStorylineMote, listStorylines, } from './cl2.storyline.types.js';
|
|
4
4
|
//# sourceMappingURL=cl2.storyline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.js","sourceRoot":"","sources":["../src/cl2.storyline.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,eAAe,EACf,cAAc,
|
|
1
|
+
{"version":3,"file":"cl2.storyline.js","sourceRoot":"","sources":["../src/cl2.storyline.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,eAAe,EACf,cAAc,GAEf,MAAM,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.parse.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"cl2.storyline.parse.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAUpD,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE;IACP,aAAa,CAAC,EAAE,OAAO,CAAC;CACpB,GACL,qBAAqB,CAoEvB;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,qBAAqB,CAAC,QAAQ,CAAC,EACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { assert } from './assert.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { checkWords, includes } from './util.js';
|
|
2
|
+
import { isCommentLine, isStageLine, prepareParserHelpers, updateWipChangesFromParsed, } from './cl2.shared.parse.js';
|
|
3
|
+
import { storylineSchemaId } from './cl2.shared.types.js';
|
|
4
|
+
import { getStorylineSchema, linePatterns, } from './cl2.storyline.types.js';
|
|
6
5
|
export function parseStringifiedStoryline(text, packed, options = {}) {
|
|
7
6
|
const result = {
|
|
8
7
|
diagnostics: [],
|
|
@@ -14,124 +13,25 @@ export function parseStringifiedStoryline(text, packed, options = {}) {
|
|
|
14
13
|
comments: [],
|
|
15
14
|
},
|
|
16
15
|
};
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
'Description',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const stagingOptions = getStagingOptions(packed.working);
|
|
23
|
-
/** Terms from the glossary for use in autocompletes */
|
|
24
|
-
const glossaryTerms = (packed.glossary?.relevantTerms() || []).map((t) => t.text);
|
|
25
|
-
const checkSpelling = (item) => {
|
|
26
|
-
if (!item || !options.checkSpelling)
|
|
27
|
-
return;
|
|
28
|
-
result.words.push(...checkWords(item, packed.glossary));
|
|
29
|
-
};
|
|
30
|
-
const lines = text.split(/(\r?\n)/g);
|
|
31
|
-
let index = 0;
|
|
32
|
-
let lineNumber = 0;
|
|
33
|
-
for (const line of lines) {
|
|
16
|
+
const helpers = prepareParserHelpers(text, packed, {
|
|
17
|
+
...options,
|
|
18
|
+
globalLabels: new Set(['Name', 'Description', 'Stage']),
|
|
19
|
+
}, result);
|
|
20
|
+
for (const line of helpers.lines) {
|
|
34
21
|
const trace = [];
|
|
35
22
|
try {
|
|
36
|
-
// Is this just a newline?
|
|
37
|
-
if (line.match(/\r?\n/)) {
|
|
38
|
-
// Then we just need to increment the index
|
|
39
|
-
index += line.length;
|
|
40
|
-
lineNumber++;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
const lineRange = {
|
|
44
|
-
start: {
|
|
45
|
-
index,
|
|
46
|
-
line: lineNumber,
|
|
47
|
-
character: 0,
|
|
48
|
-
},
|
|
49
|
-
end: {
|
|
50
|
-
index: index + line.length,
|
|
51
|
-
line: lineNumber,
|
|
52
|
-
character: line.length,
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
// Is this just a blank line?
|
|
56
23
|
if (!line) {
|
|
57
|
-
// Add global autocompletes
|
|
58
|
-
result.completions.push({
|
|
59
|
-
type: 'labels',
|
|
60
|
-
start: lineRange.start,
|
|
61
|
-
end: lineRange.end,
|
|
62
|
-
options: availableGlobalLabels,
|
|
63
|
-
});
|
|
64
24
|
continue;
|
|
65
25
|
}
|
|
26
|
+
const lineRange = helpers.currentLineRange;
|
|
66
27
|
// Find the first matching pattern and pull the values from it.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
parsedLine = parseIfMatch(pattern, line, lineRange.start);
|
|
70
|
-
if (parsedLine)
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
if (!parsedLine) {
|
|
74
|
-
// Then this is likely the result of uncommenting something
|
|
75
|
-
// that was commented out, resulting in a line that starts with
|
|
76
|
-
// the comment's array tag. Provide a deletion edit!
|
|
77
|
-
parsedLine = parseIfMatch(`^${arrayTagPattern} +(?<text>.*)$`, line, lineRange.start);
|
|
78
|
-
if (parsedLine) {
|
|
79
|
-
result.edits.push({
|
|
80
|
-
start: lineRange.start,
|
|
81
|
-
end: lineRange.end,
|
|
82
|
-
newText: parsedLine.text.value,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
result.diagnostics.push({
|
|
87
|
-
message: `Unfamiliar syntax: ${line}`,
|
|
88
|
-
...lineRange,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
index += line.length;
|
|
28
|
+
const parsedLine = helpers.parseCurrentLine(linePatterns);
|
|
29
|
+
if (!parsedLine)
|
|
92
30
|
continue;
|
|
93
|
-
}
|
|
94
|
-
// Ensure the array tag. It goes right after the label or indicator.
|
|
95
|
-
if (!parsedLine.arrayTag?.value && lineIsArrayItem(line)) {
|
|
96
|
-
const arrayTag = createBsArrayKey();
|
|
97
|
-
const start = parsedLine.indicator?.end || parsedLine.label?.end;
|
|
98
|
-
result.edits.push({
|
|
99
|
-
start,
|
|
100
|
-
end: start,
|
|
101
|
-
newText: `#${arrayTag}`,
|
|
102
|
-
});
|
|
103
|
-
parsedLine.arrayTag = {
|
|
104
|
-
start,
|
|
105
|
-
end: start,
|
|
106
|
-
value: arrayTag,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
// If this has a label, remove it from the list of available labels
|
|
110
|
-
if (parsedLine.label?.value &&
|
|
111
|
-
availableGlobalLabels.has(parsedLine.label.value)) {
|
|
112
|
-
availableGlobalLabels.delete(parsedLine.label.value);
|
|
113
|
-
}
|
|
114
|
-
// If this has a text section, provide glossary autocompletes
|
|
115
|
-
if ('text' in parsedLine) {
|
|
116
|
-
const start = parsedLine.text.start;
|
|
117
|
-
const end = parsedLine.text.end;
|
|
118
|
-
result.completions.push({
|
|
119
|
-
type: 'glossary',
|
|
120
|
-
start,
|
|
121
|
-
end,
|
|
122
|
-
options: glossaryTerms,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
31
|
// Work through each line type to add diagnostics and completions
|
|
126
32
|
const labelLower = parsedLine.label?.value?.toLowerCase();
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// Then this is a comment/note
|
|
130
|
-
result.parsed.comments.push({
|
|
131
|
-
id: parsedLine.arrayTag?.value?.trim(),
|
|
132
|
-
text: parsedLine.text?.value?.trim(),
|
|
133
|
-
});
|
|
134
|
-
checkSpelling(parsedLine.text);
|
|
33
|
+
if (isCommentLine(parsedLine)) {
|
|
34
|
+
helpers.addComment(parsedLine);
|
|
135
35
|
}
|
|
136
36
|
else if (labelLower === 'name') {
|
|
137
37
|
result.parsed.name = parsedLine.text?.value?.trim();
|
|
@@ -144,26 +44,10 @@ export function parseStringifiedStoryline(text, packed, options = {}) {
|
|
|
144
44
|
}
|
|
145
45
|
else if (labelLower === 'description') {
|
|
146
46
|
result.parsed.description = parsedLine.text?.value?.trim();
|
|
147
|
-
checkSpelling(parsedLine.text);
|
|
47
|
+
helpers.checkSpelling(parsedLine.text);
|
|
148
48
|
}
|
|
149
|
-
else if (
|
|
150
|
-
|
|
151
|
-
if (includes(stagingOptions, stage)) {
|
|
152
|
-
result.parsed.stage = stage;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
result.diagnostics.push({
|
|
156
|
-
message: `Stage must be one of: ${stagingOptions.join(', ')}`,
|
|
157
|
-
...lineRange,
|
|
158
|
-
});
|
|
159
|
-
// Provide autocomplete options
|
|
160
|
-
result.completions.push({
|
|
161
|
-
type: 'stages',
|
|
162
|
-
options: stagingOptions,
|
|
163
|
-
start: parsedLine.labelGroup.end,
|
|
164
|
-
end: lineRange.end,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
49
|
+
else if (isStageLine(parsedLine)) {
|
|
50
|
+
helpers.addStage(parsedLine);
|
|
167
51
|
}
|
|
168
52
|
else {
|
|
169
53
|
// Then we're in an error state on this line!
|
|
@@ -179,7 +63,7 @@ export function parseStringifiedStoryline(text, packed, options = {}) {
|
|
|
179
63
|
}
|
|
180
64
|
throw err;
|
|
181
65
|
}
|
|
182
|
-
index += line.length;
|
|
66
|
+
helpers.index += line.length;
|
|
183
67
|
}
|
|
184
68
|
return result;
|
|
185
69
|
}
|
|
@@ -191,8 +75,6 @@ export async function updateChangesFromParsedStoryline(parsed, moteId, packed) {
|
|
|
191
75
|
// We're always going to be computing ALL changes, so clear whatever
|
|
192
76
|
// we previously had.
|
|
193
77
|
packed.clearMoteChanges(moteId);
|
|
194
|
-
const storylineMoteBase = getStorylineMote(packed.base, moteId);
|
|
195
|
-
const storylineMoteWorking = getStorylineMote(packed.working, moteId);
|
|
196
78
|
const schema = getStorylineSchema(packed.working);
|
|
197
79
|
assert(schema, `${storylineSchemaId} schema not found in working copy`);
|
|
198
80
|
assert(schema.name, 'Quest mote must have a name pointer');
|
|
@@ -201,47 +83,7 @@ export async function updateChangesFromParsedStoryline(parsed, moteId, packed) {
|
|
|
201
83
|
};
|
|
202
84
|
updateMote('data/name/text', parsed.name);
|
|
203
85
|
updateMote('data/description/text', parsed.description);
|
|
204
|
-
|
|
205
|
-
updateMote('data/wip/staging', parsed.stage);
|
|
206
|
-
}
|
|
207
|
-
else if (storylineMoteWorking?.data.wip) {
|
|
208
|
-
updateMote('data/wip/staging', null);
|
|
209
|
-
}
|
|
210
|
-
const parsedComments = parsed.comments.filter((c) => !!c.text);
|
|
211
|
-
//#region COMMENTS
|
|
212
|
-
// Add/Update COMMENTS
|
|
213
|
-
trace(`Updating comments`);
|
|
214
|
-
for (const comment of parsedComments) {
|
|
215
|
-
trace(`Updating comment ${comment.id} with text "${comment.text}"`);
|
|
216
|
-
updateMote(`data/wip/notes/${comment.id}/element/text`, comment.text);
|
|
217
|
-
}
|
|
218
|
-
// Remove deleted comments
|
|
219
|
-
for (const existingComment of bsArrayToArray(storylineMoteBase?.data.wip?.notes || {})) {
|
|
220
|
-
if (!parsedComments.find((c) => c.id === existingComment.id)) {
|
|
221
|
-
trace(`Deleting comment ${existingComment.id}`);
|
|
222
|
-
updateMote(`data/wip/notes/${existingComment.id}`, null);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// Get the BASE order of the comments (if any) and use those
|
|
226
|
-
// as the starting point for an up to date order.
|
|
227
|
-
const comments = parsedComments.map((c) => {
|
|
228
|
-
// Look up the base comment
|
|
229
|
-
let comment = storylineMoteBase?.data.wip?.notes?.[c.id];
|
|
230
|
-
if (!comment) {
|
|
231
|
-
comment = storylineMoteWorking?.data.wip?.notes?.[c.id];
|
|
232
|
-
// @ts-expect-error - order is a required field, but it'll be re-added
|
|
233
|
-
delete comment?.order;
|
|
234
|
-
}
|
|
235
|
-
assert(comment, `Comment ${c.id} not found in base or working mote`);
|
|
236
|
-
return { ...comment, id: c.id };
|
|
237
|
-
});
|
|
238
|
-
trace('Updating comment order');
|
|
239
|
-
updateBsArrayOrder(comments);
|
|
240
|
-
comments.forEach((comment) => {
|
|
241
|
-
trace(`Updating comment ${comment.id} order to ${comment.order}`);
|
|
242
|
-
updateMote(`data/wip/notes/${comment.id}/order`, comment.order);
|
|
243
|
-
});
|
|
244
|
-
//#endregion
|
|
86
|
+
updateWipChangesFromParsed(parsed, moteId, packed, trace);
|
|
245
87
|
trace(`Writing changes`);
|
|
246
88
|
await packed.writeChanges();
|
|
247
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.parse.js","sourceRoot":"","sources":["../src/cl2.storyline.parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"cl2.storyline.parse.js","sourceRoot":"","sources":["../src/cl2.storyline.parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EACL,kBAAkB,EAClB,YAAY,GAEb,MAAM,0BAA0B,CAAC;AAElC,MAAM,UAAU,yBAAyB,CACvC,IAAY,EACZ,MAAmB,EACnB,UAEI,EAAE;IAEN,MAAM,MAAM,GAA0B;QACpC,WAAW,EAAE,EAAE;QACf,MAAM,EAAE,EAAE;QACV,KAAK,EAAE,EAAE;QACT,WAAW,EAAE,EAAE;QACf,KAAK,EAAE,EAAE;QACT,MAAM,EAAE;YACN,QAAQ,EAAE,EAAE;SACb;KACF,CAAC;IAEF,MAAM,OAAO,GAAG,oBAAoB,CAClC,IAAI,EACJ,MAAM,EACN;QACE,GAAG,OAAO;QACV,YAAY,EAAE,IAAI,GAAG,CAAS,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;KAChE,EACD,MAAM,CACP,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QACjC,MAAM,KAAK,GAAU,EAAE,CAAC;QACxB,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YACD,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAE3C,+DAA+D;YAC/D,MAAM,UAAU,GAAG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;QACnB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1B,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;YACzB,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC;QACzB,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { StorylineMote } from './cl2.shared.types.js';
|
|
1
2
|
import type { GameChanger } from './GameChanger.js';
|
|
2
|
-
import { type StorylineMote } from './cl2.storyline.types.js';
|
|
3
3
|
export declare function stringifyStoryline(mote: StorylineMote, packed: GameChanger): string;
|
|
4
4
|
//# sourceMappingURL=cl2.storyline.stringify.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.stringify.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.stringify.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"cl2.storyline.stringify.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.stringify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,WAAW,GAClB,MAAM,CA2BR"}
|
|
@@ -1,36 +1,13 @@
|
|
|
1
1
|
import type { Gcdata } from './GameChanger.js';
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare const storylineSchemaId = "cl2_storyline";
|
|
8
|
-
export type StorylineData = Crashlands2.Schemas['cl2_storyline'];
|
|
9
|
-
export type StorylineMote = Mote<StorylineData>;
|
|
10
|
-
type CompletionsData = {
|
|
11
|
-
type: 'glossary';
|
|
12
|
-
options: string[];
|
|
13
|
-
} | {
|
|
14
|
-
type: 'stages';
|
|
15
|
-
options: string[];
|
|
16
|
-
} | {
|
|
17
|
-
type: 'labels';
|
|
18
|
-
options: Set<string>;
|
|
19
|
-
};
|
|
20
|
-
export interface StorylineUpdateResult extends ParserResult {
|
|
21
|
-
parsed: ParsedBase & {
|
|
22
|
-
description?: string;
|
|
23
|
-
};
|
|
24
|
-
completions: (Range & CompletionsData)[];
|
|
2
|
+
import { ParserResult, StorylineMote } from './cl2.shared.types.js';
|
|
3
|
+
import type { BschemaRoot } from './types.js';
|
|
4
|
+
export interface StorylineUpdateResult extends ParserResult<{
|
|
5
|
+
description?: string;
|
|
6
|
+
}> {
|
|
25
7
|
}
|
|
26
8
|
export declare function listStorylines(gcData: Gcdata): StorylineMote[];
|
|
27
9
|
export declare function isStorylineMote(mote: any): mote is StorylineMote;
|
|
28
10
|
export declare function getStorylineMote(gcData: Gcdata, moteId: string): StorylineMote | undefined;
|
|
29
|
-
export declare function getStorylineMotes(gcData: Gcdata): StorylineMote[];
|
|
30
11
|
export declare function getStorylineSchema(gcData: Gcdata): BschemaRoot | undefined;
|
|
31
|
-
export declare const arrayTagPattern = "(?:#(?<arrayTag>[a-z0-9]+))";
|
|
32
12
|
export declare const linePatterns: string[];
|
|
33
|
-
export declare function parseIfMatch(pattern: string, line: string, startPosition: Position): ParsedLine | null;
|
|
34
|
-
export declare function lineIsArrayItem(line: string): boolean;
|
|
35
|
-
export {};
|
|
36
13
|
//# sourceMappingURL=cl2.storyline.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.types.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cl2.storyline.types.d.ts","sourceRoot":"","sources":["../src/cl2.storyline.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAEL,YAAY,EAEZ,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,qBACf,SAAQ,YAAY,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;CAAG;AAEP,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,CAE9D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,aAAa,CAEhE;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,aAAa,GAAG,SAAS,CAI3B;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAE1E;AAED,eAAO,MAAM,YAAY,UAKxB,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import { assert } from './assert.js';
|
|
3
|
-
|
|
2
|
+
import { arrayTagPattern, storylineSchemaId, } from './cl2.shared.types.js';
|
|
4
3
|
export function listStorylines(gcData) {
|
|
5
4
|
return gcData.listMotesBySchema(storylineSchemaId);
|
|
6
5
|
}
|
|
@@ -12,76 +11,13 @@ export function getStorylineMote(gcData, moteId) {
|
|
|
12
11
|
assert(!mote || isStorylineMote(mote), `Mote ${moteId} is not a storyline`);
|
|
13
12
|
return mote;
|
|
14
13
|
}
|
|
15
|
-
export function getStorylineMotes(gcData) {
|
|
16
|
-
const motes = gcData.listMotesBySchema(storylineSchemaId);
|
|
17
|
-
return motes;
|
|
18
|
-
}
|
|
19
14
|
export function getStorylineSchema(gcData) {
|
|
20
15
|
return gcData.getSchema(storylineSchemaId);
|
|
21
16
|
}
|
|
22
|
-
// PATTERNS
|
|
23
|
-
// Note: These patterns are defined so that they'll work on partial lines
|
|
24
|
-
// as much as possible, so their group names should always be checked for existence.
|
|
25
|
-
const linePartsSchema = z.object({
|
|
26
|
-
indicator: z
|
|
27
|
-
.string()
|
|
28
|
-
.optional()
|
|
29
|
-
.describe('The symbol prefixing the line to indicate what the line type is'),
|
|
30
|
-
arrayTag: z
|
|
31
|
-
.string()
|
|
32
|
-
.regex(/^[a-z0-9]+$/)
|
|
33
|
-
.optional()
|
|
34
|
-
.describe("BsArrayElement identifier (without the '#' prefix)"),
|
|
35
|
-
labelGroup: z.string().optional().describe('The label, including the `:`'),
|
|
36
|
-
label: z.string().optional().describe('For `Label:Value` elements'),
|
|
37
|
-
text: z
|
|
38
|
-
.string()
|
|
39
|
-
.optional()
|
|
40
|
-
.describe('For dialog and similar, the text content'),
|
|
41
|
-
});
|
|
42
|
-
export const arrayTagPattern = '(?:#(?<arrayTag>[a-z0-9]+))';
|
|
43
17
|
export const linePatterns = [
|
|
44
18
|
/** Label:Text */
|
|
45
19
|
`^(?<labelGroup>(?<label>Name|Description|Stage)\\s*:)\\s*(?<text>.*?)\\s*$`,
|
|
46
20
|
/** Comment Line */
|
|
47
21
|
`^(?<indicator>//)\\s*?${arrayTagPattern}?\\s*(?<text>.*?)\\s*$`,
|
|
48
22
|
];
|
|
49
|
-
export function parseIfMatch(pattern, line, startPosition) {
|
|
50
|
-
const rawMatch = line.match(new RegExp(pattern));
|
|
51
|
-
if (!rawMatch)
|
|
52
|
-
return null;
|
|
53
|
-
const parsedLine = linePartsSchema.parse(rawMatch.groups);
|
|
54
|
-
const result = {
|
|
55
|
-
_: {
|
|
56
|
-
start: startPosition,
|
|
57
|
-
end: { ...startPosition },
|
|
58
|
-
value: line,
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
result._.end.character += line.length;
|
|
62
|
-
result._.end.index += line.length;
|
|
63
|
-
for (const [key, value] of Object.entries(parsedLine)) {
|
|
64
|
-
if (typeof value !== 'undefined') {
|
|
65
|
-
// Figure out where this is in the matches so we
|
|
66
|
-
// can get the start and end positions.
|
|
67
|
-
const startChar = line.indexOf(`${value}`);
|
|
68
|
-
const endChar = startChar + `${value}`.length;
|
|
69
|
-
const start = { ...startPosition };
|
|
70
|
-
start.character += startChar;
|
|
71
|
-
start.index += startChar;
|
|
72
|
-
const end = { ...startPosition };
|
|
73
|
-
end.character += endChar;
|
|
74
|
-
end.index += endChar;
|
|
75
|
-
result[key] = {
|
|
76
|
-
start,
|
|
77
|
-
end,
|
|
78
|
-
value: value,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
export function lineIsArrayItem(line) {
|
|
85
|
-
return /^\/\//.test(line);
|
|
86
|
-
}
|
|
87
23
|
//# sourceMappingURL=cl2.storyline.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cl2.storyline.types.js","sourceRoot":"","sources":["../src/cl2.storyline.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cl2.storyline.types.js","sourceRoot":"","sources":["../src/cl2.storyline.types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,eAAe,EAIf,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAQ/B,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,OAAO,MAAM,CAAC,iBAAiB,CAAgB,iBAAiB,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAS;IACvC,OAAO,IAAI,CAAC,SAAS,KAAK,iBAAiB,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,MAAc;IAEd,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAgB,MAAM,CAAC,CAAC;IACnD,MAAM,CAAC,CAAC,IAAI,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,QAAQ,MAAM,qBAAqB,CAAC,CAAC;IAC5E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,OAAO,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAgB,CAAC;AAC5D,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,iBAAiB;IACjB,4EAA4E;IAC5E,mBAAmB;IACnB,yBAAyB,eAAe,wBAAwB;CACjE,CAAC"}
|