@qsp/converters 1.0.0 → 2.0.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/index.cjs +378 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -5
- package/dist/index.js +374 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -30
- package/dist/contracts.d.ts +0 -11
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/qsp-byte-stream.d.ts +0 -19
- package/dist/readers/qsp.d.ts +0 -2
- package/dist/readers/qsp.test.d.ts +0 -1
- package/dist/readers/qsps.d.ts +0 -2
- package/dist/readers/qsps.test.d.ts +0 -1
- package/dist/writers/qsp.d.ts +0 -2
- package/dist/writers/qsp.test.d.ts +0 -1
- package/dist/writers/qsps.d.ts +0 -2
- package/dist/writers/qsps.test.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,378 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const QSP_STRSDELIM = "\r\n";
|
|
3
|
+
const QSP_GAMEID = "QSPGAME";
|
|
4
|
+
const CP1251ToUnicodeTable = [
|
|
5
|
+
1026,
|
|
6
|
+
1027,
|
|
7
|
+
8218,
|
|
8
|
+
1107,
|
|
9
|
+
8222,
|
|
10
|
+
8230,
|
|
11
|
+
8224,
|
|
12
|
+
8225,
|
|
13
|
+
8364,
|
|
14
|
+
8240,
|
|
15
|
+
1033,
|
|
16
|
+
8249,
|
|
17
|
+
1034,
|
|
18
|
+
1036,
|
|
19
|
+
1035,
|
|
20
|
+
1039,
|
|
21
|
+
1106,
|
|
22
|
+
8216,
|
|
23
|
+
8217,
|
|
24
|
+
8220,
|
|
25
|
+
8221,
|
|
26
|
+
8226,
|
|
27
|
+
8211,
|
|
28
|
+
8212,
|
|
29
|
+
32,
|
|
30
|
+
8482,
|
|
31
|
+
1113,
|
|
32
|
+
8250,
|
|
33
|
+
1114,
|
|
34
|
+
1116,
|
|
35
|
+
1115,
|
|
36
|
+
1119,
|
|
37
|
+
160,
|
|
38
|
+
1038,
|
|
39
|
+
1118,
|
|
40
|
+
1032,
|
|
41
|
+
164,
|
|
42
|
+
1168,
|
|
43
|
+
166,
|
|
44
|
+
167,
|
|
45
|
+
1025,
|
|
46
|
+
169,
|
|
47
|
+
1028,
|
|
48
|
+
171,
|
|
49
|
+
172,
|
|
50
|
+
173,
|
|
51
|
+
174,
|
|
52
|
+
1031,
|
|
53
|
+
176,
|
|
54
|
+
177,
|
|
55
|
+
1030,
|
|
56
|
+
1110,
|
|
57
|
+
1169,
|
|
58
|
+
181,
|
|
59
|
+
182,
|
|
60
|
+
183,
|
|
61
|
+
1105,
|
|
62
|
+
8470,
|
|
63
|
+
1108,
|
|
64
|
+
187,
|
|
65
|
+
1112,
|
|
66
|
+
1029,
|
|
67
|
+
1109,
|
|
68
|
+
1111,
|
|
69
|
+
1040,
|
|
70
|
+
1041,
|
|
71
|
+
1042,
|
|
72
|
+
1043,
|
|
73
|
+
1044,
|
|
74
|
+
1045,
|
|
75
|
+
1046,
|
|
76
|
+
1047,
|
|
77
|
+
1048,
|
|
78
|
+
1049,
|
|
79
|
+
1050,
|
|
80
|
+
1051,
|
|
81
|
+
1052,
|
|
82
|
+
1053,
|
|
83
|
+
1054,
|
|
84
|
+
1055,
|
|
85
|
+
1056,
|
|
86
|
+
1057,
|
|
87
|
+
1058,
|
|
88
|
+
1059,
|
|
89
|
+
1060,
|
|
90
|
+
1061,
|
|
91
|
+
1062,
|
|
92
|
+
1063,
|
|
93
|
+
1064,
|
|
94
|
+
1065,
|
|
95
|
+
1066,
|
|
96
|
+
1067,
|
|
97
|
+
1068,
|
|
98
|
+
1069,
|
|
99
|
+
1070,
|
|
100
|
+
1071,
|
|
101
|
+
1072,
|
|
102
|
+
1073,
|
|
103
|
+
1074,
|
|
104
|
+
1075,
|
|
105
|
+
1076,
|
|
106
|
+
1077,
|
|
107
|
+
1078,
|
|
108
|
+
1079,
|
|
109
|
+
1080,
|
|
110
|
+
1081,
|
|
111
|
+
1082,
|
|
112
|
+
1083,
|
|
113
|
+
1084,
|
|
114
|
+
1085,
|
|
115
|
+
1086,
|
|
116
|
+
1087,
|
|
117
|
+
1088,
|
|
118
|
+
1089,
|
|
119
|
+
1090,
|
|
120
|
+
1091,
|
|
121
|
+
1092,
|
|
122
|
+
1093,
|
|
123
|
+
1094,
|
|
124
|
+
1095,
|
|
125
|
+
1096,
|
|
126
|
+
1097,
|
|
127
|
+
1098,
|
|
128
|
+
1099,
|
|
129
|
+
1100,
|
|
130
|
+
1101,
|
|
131
|
+
1102,
|
|
132
|
+
1103
|
|
133
|
+
];
|
|
134
|
+
function convertCP1251(char) {
|
|
135
|
+
return String.fromCharCode(char >= 128 ? CP1251ToUnicodeTable[char - 128] : char);
|
|
136
|
+
}
|
|
137
|
+
var QspByteStream = class {
|
|
138
|
+
cursor = 0;
|
|
139
|
+
content;
|
|
140
|
+
view;
|
|
141
|
+
isUnicode;
|
|
142
|
+
constructor(fromBuffer) {
|
|
143
|
+
this.content = fromBuffer ?? /* @__PURE__ */ new ArrayBuffer(256);
|
|
144
|
+
this.view = new DataView(this.content);
|
|
145
|
+
this.isUnicode = this.view.getUint8(1) === 0;
|
|
146
|
+
}
|
|
147
|
+
ensureSize(size) {
|
|
148
|
+
if (this.content.byteLength >= size) return;
|
|
149
|
+
const newLength = this.content.byteLength * 2;
|
|
150
|
+
const buffer = new ArrayBuffer(newLength);
|
|
151
|
+
new Uint8Array(buffer).set(new Uint8Array(this.content));
|
|
152
|
+
this.content = buffer;
|
|
153
|
+
this.view = new DataView(this.content);
|
|
154
|
+
}
|
|
155
|
+
finalize() {
|
|
156
|
+
this.content = this.content.slice(0, this.cursor);
|
|
157
|
+
return this.content;
|
|
158
|
+
}
|
|
159
|
+
get eof() {
|
|
160
|
+
return this.cursor >= this.content.byteLength;
|
|
161
|
+
}
|
|
162
|
+
read() {
|
|
163
|
+
const position = this.cursor;
|
|
164
|
+
this.cursor += this.isUnicode ? Uint16Array.BYTES_PER_ELEMENT : Uint8Array.BYTES_PER_ELEMENT;
|
|
165
|
+
return this.isUnicode ? this.view.getUint16(position, true) : this.view.getUint8(position);
|
|
166
|
+
}
|
|
167
|
+
readLine(shouldDecode = true) {
|
|
168
|
+
const chars = [];
|
|
169
|
+
while (!this.eof) {
|
|
170
|
+
const char = this.read();
|
|
171
|
+
if (char === 13) {
|
|
172
|
+
this.read();
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
if (shouldDecode) chars.push(char === -5 ? 5 : char + 5);
|
|
176
|
+
else chars.push(char);
|
|
177
|
+
}
|
|
178
|
+
return this.isUnicode ? chars.map((char) => String.fromCharCode(char)).join("") : chars.map(convertCP1251).join("");
|
|
179
|
+
}
|
|
180
|
+
write(value) {
|
|
181
|
+
this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);
|
|
182
|
+
const position = this.cursor;
|
|
183
|
+
this.cursor += Int16Array.BYTES_PER_ELEMENT;
|
|
184
|
+
this.view.setUint16(position, value, true);
|
|
185
|
+
}
|
|
186
|
+
writeString(input, shouldEncode = true) {
|
|
187
|
+
const charCodes = input.split("").map((char) => char.charCodeAt(0));
|
|
188
|
+
for (const point of charCodes.values()) if (shouldEncode) this.write(point === 5 ? -5 : point - 5);
|
|
189
|
+
else this.write(point);
|
|
190
|
+
}
|
|
191
|
+
writeLine(input, shouldEncode = true) {
|
|
192
|
+
if (input) this.writeString(input, shouldEncode);
|
|
193
|
+
this.writeString(QSP_STRSDELIM, false);
|
|
194
|
+
}
|
|
195
|
+
seek(offset) {
|
|
196
|
+
this.cursor = offset;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/readers/qsp.ts
|
|
201
|
+
function readNewFormat(stream) {
|
|
202
|
+
stream.readLine(false);
|
|
203
|
+
stream.readLine();
|
|
204
|
+
const locCount = parseInt(stream.readLine());
|
|
205
|
+
const locations = [];
|
|
206
|
+
for (let i = 0; i < locCount; i++) {
|
|
207
|
+
const name = stream.readLine();
|
|
208
|
+
let description = stream.readLine().split(/\r?\n/);
|
|
209
|
+
if (description.length === 1 && description[0] === "") description = [];
|
|
210
|
+
const code = stream.readLine().split(/\r?\n/);
|
|
211
|
+
const actsCount = parseInt(stream.readLine());
|
|
212
|
+
const actions = [];
|
|
213
|
+
for (let j = 0; j < actsCount; ++j) {
|
|
214
|
+
const image = stream.readLine();
|
|
215
|
+
const actionName = stream.readLine();
|
|
216
|
+
const actionCode = stream.readLine().split(/\r?\n/);
|
|
217
|
+
actions.push({
|
|
218
|
+
image,
|
|
219
|
+
name: actionName,
|
|
220
|
+
code: actionCode
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
locations.push({
|
|
224
|
+
name,
|
|
225
|
+
description,
|
|
226
|
+
code,
|
|
227
|
+
actions
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return locations;
|
|
231
|
+
}
|
|
232
|
+
function readOldFormat(stream) {
|
|
233
|
+
stream.seek(0);
|
|
234
|
+
const locCount = parseInt(stream.readLine(false));
|
|
235
|
+
stream.readLine();
|
|
236
|
+
stream.readLine(false);
|
|
237
|
+
for (let i = 0; i < 27; i++) stream.readLine();
|
|
238
|
+
const locations = [];
|
|
239
|
+
const actsCount = 20;
|
|
240
|
+
for (let i = 0; i < locCount; i++) {
|
|
241
|
+
const name = stream.readLine();
|
|
242
|
+
const description = stream.readLine().split(/\r?\n/);
|
|
243
|
+
const code = stream.readLine().split(/\r?\n/);
|
|
244
|
+
const actions = [];
|
|
245
|
+
for (let j = 0; j < actsCount; ++j) {
|
|
246
|
+
const actionName = stream.readLine();
|
|
247
|
+
const actionCode = stream.readLine().split(/\r?\n/);
|
|
248
|
+
if (actionName) actions.push({
|
|
249
|
+
name: actionName,
|
|
250
|
+
code: actionCode
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
locations.push({
|
|
254
|
+
name,
|
|
255
|
+
description,
|
|
256
|
+
code,
|
|
257
|
+
actions
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return locations;
|
|
261
|
+
}
|
|
262
|
+
function readQsp(buffer) {
|
|
263
|
+
const stream = new QspByteStream(buffer);
|
|
264
|
+
if (stream.readLine(false) === "QSPGAME") return readNewFormat(stream);
|
|
265
|
+
return readOldFormat(stream);
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/readers/qsps.ts
|
|
269
|
+
const QSP_STARTLOC = "#";
|
|
270
|
+
const QSP_ENDLOC = "-";
|
|
271
|
+
const QSP_QUOTES = ["'", "\""];
|
|
272
|
+
const QSP_LCURLY = "{";
|
|
273
|
+
const QSP_RCURLY = "}";
|
|
274
|
+
function readQsps(content) {
|
|
275
|
+
const locations = [];
|
|
276
|
+
let isInLoc = false;
|
|
277
|
+
let curLoc = null;
|
|
278
|
+
let locCode = [];
|
|
279
|
+
const lines = content.split(/\r?\n/);
|
|
280
|
+
let quote = "";
|
|
281
|
+
let quotesCount = 0;
|
|
282
|
+
for (const line of lines) if (isInLoc) {
|
|
283
|
+
if (!quote && !quotesCount) {
|
|
284
|
+
if (line.startsWith(QSP_ENDLOC)) {
|
|
285
|
+
isInLoc = false;
|
|
286
|
+
if (curLoc) {
|
|
287
|
+
curLoc.code = locCode;
|
|
288
|
+
locCode = [];
|
|
289
|
+
locations.push(curLoc);
|
|
290
|
+
curLoc = null;
|
|
291
|
+
}
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
locCode.push(line);
|
|
296
|
+
const chars = line.split("");
|
|
297
|
+
for (let i = 0; i < chars.length; ++i) {
|
|
298
|
+
const char = chars[i];
|
|
299
|
+
if (quote) {
|
|
300
|
+
if (char == quote) {
|
|
301
|
+
if (chars[i + 1] == quote) i++;
|
|
302
|
+
else quote = "";
|
|
303
|
+
}
|
|
304
|
+
} else if (char == QSP_LCURLY) ++quotesCount;
|
|
305
|
+
else if (char == QSP_RCURLY) {
|
|
306
|
+
if (quotesCount) --quotesCount;
|
|
307
|
+
} else if (QSP_QUOTES.includes(char)) quote = char;
|
|
308
|
+
}
|
|
309
|
+
} else if (line.startsWith(QSP_STARTLOC)) {
|
|
310
|
+
isInLoc = true;
|
|
311
|
+
curLoc = {
|
|
312
|
+
name: line.slice(1).trim(),
|
|
313
|
+
description: [],
|
|
314
|
+
code: [],
|
|
315
|
+
actions: []
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
if (isInLoc && curLoc) {
|
|
319
|
+
curLoc.code = locCode;
|
|
320
|
+
locations.push(curLoc);
|
|
321
|
+
}
|
|
322
|
+
return locations;
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/version.ts
|
|
326
|
+
const VERSION = "2.0.0";
|
|
327
|
+
//#endregion
|
|
328
|
+
//#region src/writers/qsp.ts
|
|
329
|
+
function writeQsp(locations) {
|
|
330
|
+
const stream = new QspByteStream();
|
|
331
|
+
stream.writeLine(QSP_GAMEID, false);
|
|
332
|
+
stream.writeLine(`@qsp/converters ${VERSION}`, false);
|
|
333
|
+
stream.writeLine("No");
|
|
334
|
+
stream.writeLine(String(locations.length));
|
|
335
|
+
for (const location of locations) {
|
|
336
|
+
stream.writeLine(location.name);
|
|
337
|
+
stream.writeLine(location.description.join("\r\n"));
|
|
338
|
+
stream.writeLine(location.code.join("\r\n"));
|
|
339
|
+
stream.writeLine(String(location.actions.length));
|
|
340
|
+
for (const action of location.actions) {
|
|
341
|
+
stream.writeLine(action.image ?? "");
|
|
342
|
+
stream.writeLine(action.name);
|
|
343
|
+
stream.writeLine(action.code.join("\r\n"));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return stream.finalize();
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/writers/qsps.ts
|
|
350
|
+
function escapeQspString(input) {
|
|
351
|
+
return input.replace(/'/g, "''");
|
|
352
|
+
}
|
|
353
|
+
function convertDescription(lines, linebreak) {
|
|
354
|
+
return lines.map((line, index) => `${index === lines.length - 1 ? "*p" : "*pl"} '${escapeQspString(line)}'${linebreak}`).join("");
|
|
355
|
+
}
|
|
356
|
+
function convertAction(action, linebreak) {
|
|
357
|
+
return `act '${escapeQspString(action.name)}'${action.image ? `, '${escapeQspString(action.image)}'` : ""}:${linebreak}${action.code.map((line) => ` ${line}${linebreak}`).join("")}end`;
|
|
358
|
+
}
|
|
359
|
+
function convertActions(actions, linebreak) {
|
|
360
|
+
if (!actions.length) return "";
|
|
361
|
+
return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;
|
|
362
|
+
}
|
|
363
|
+
function convertLocation(location, linebreak) {
|
|
364
|
+
const description = convertDescription(location.description, linebreak);
|
|
365
|
+
const code = location.code.length ? location.code.join(linebreak) + linebreak : "";
|
|
366
|
+
const actions = convertActions(location.actions, linebreak);
|
|
367
|
+
return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;
|
|
368
|
+
}
|
|
369
|
+
function writeQsps(locations, linebreak = "\n") {
|
|
370
|
+
return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);
|
|
371
|
+
}
|
|
372
|
+
//#endregion
|
|
373
|
+
exports.readQsp = readQsp;
|
|
374
|
+
exports.readQsps = readQsps;
|
|
375
|
+
exports.writeQsp = writeQsp;
|
|
376
|
+
exports.writeQsps = writeQsps;
|
|
377
|
+
|
|
378
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/qsp-byte-stream.ts","../src/readers/qsps.ts","../src/writers/qsps.ts","../src/readers/qsp.ts","../src/writers/qsp.ts"],"sourcesContent":["export const QSP_CODREMOV = 5;\nconst QSP_STRSDELIM = '\\r\\n';\nexport const QSP_GAMEID = 'QSPGAME';\nexport const QSP_PASSWD = 'No';\n\n// prettier-ignore\nconst CP1251ToUnicodeTable: number[] = [\n 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac,\n 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, 0x0452, 0x2018,\n 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0020, 0x2122, 0x0459,\n 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, 0x00a0, 0x040e, 0x045e, 0x0408,\n 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac,\n 0x00ad, 0x00ae, 0x0407, 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5,\n 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455,\n 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,\n 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420,\n 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429,\n 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,\n 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b,\n 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444,\n 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d,\n 0x044e, 0x044f,\n];\n\nfunction convertCP1251(char: number): string {\n return String.fromCharCode(\n char >= 0x80 ? CP1251ToUnicodeTable[char - 0x80] : char\n );\n}\n\nexport class QspByteStream {\n private cursor = 0;\n private content: ArrayBuffer;\n private view: DataView;\n private isUnicode: boolean;\n\n public constructor(fromBuffer?: ArrayBuffer) {\n this.content = fromBuffer ?? new ArrayBuffer(256);\n this.view = new DataView(this.content);\n this.isUnicode = this.view.getUint8(1) === 0;\n }\n\n private ensureSize(size: number): void {\n if (this.content.byteLength >= size) return;\n const newLength = this.content.byteLength * 2;\n const buffer = new ArrayBuffer(newLength);\n new Uint8Array(buffer).set(new Uint8Array(this.content));\n this.content = buffer;\n this.view = new DataView(this.content);\n }\n\n public finalize(): ArrayBuffer {\n this.content = this.content.slice(0, this.cursor);\n return this.content;\n }\n\n public get eof(): boolean {\n return this.cursor >= this.content.byteLength;\n }\n\n public read(): number {\n const position = this.cursor;\n this.cursor += this.isUnicode\n ? Uint16Array.BYTES_PER_ELEMENT\n : Uint8Array.BYTES_PER_ELEMENT;\n return this.isUnicode\n ? this.view.getUint16(position, true)\n : this.view.getUint8(position);\n }\n\n public readLine(shouldDecode = true): string {\n const chars: number[] = [];\n while (!this.eof) {\n const char = this.read();\n if (char === 0x0d) {\n this.read();\n break;\n }\n if (shouldDecode) {\n chars.push(char === -QSP_CODREMOV ? QSP_CODREMOV : char + QSP_CODREMOV);\n } else {\n chars.push(char);\n }\n }\n return this.isUnicode\n ? // eslint-disable-next-line prefer-spread\n chars.map(char => String.fromCharCode(char)).join('')\n : chars.map(convertCP1251).join('');\n }\n\n public write(value: number): void {\n this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);\n const position = this.cursor;\n this.cursor += Int16Array.BYTES_PER_ELEMENT;\n this.view.setUint16(position, value, true);\n }\n\n public writeString(input: string, shouldEncode = true): void {\n const charCodes = input.split('').map((char): number => char.charCodeAt(0));\n for (const point of charCodes.values()) {\n if (shouldEncode) {\n this.write(\n point === QSP_CODREMOV ? -QSP_CODREMOV : point - QSP_CODREMOV\n );\n } else {\n this.write(point);\n }\n }\n }\n\n public writeLine(input: string, shouldEncode = true): void {\n input && this.writeString(input, shouldEncode);\n this.writeString(QSP_STRSDELIM, false);\n }\n\n public seek(offset: number): void {\n this.cursor = offset;\n }\n}\n","import { QspLocation } from '../contracts';\n\nconst QSP_STARTLOC = '#';\nconst QSP_ENDLOC = '-';\nconst QSP_QUOTES = [\"'\", '\"'];\nconst QSP_LCURLY = '{';\nconst QSP_RCURLY = '}';\n\nexport function readQsps(content: string): QspLocation[] {\n const locations: QspLocation[] = [];\n\n let isInLoc = false;\n let curLoc: QspLocation | null = null;\n let locCode: string[] = [];\n const lines = content.split(/\\r?\\n/);\n let quote = '';\n let quotesCount = 0;\n for (const line of lines) {\n if (isInLoc) {\n if (!quote && !quotesCount) {\n if (line.startsWith(QSP_ENDLOC)) {\n isInLoc = false;\n if (curLoc) {\n curLoc.code = locCode;\n locCode = [];\n locations.push(curLoc);\n curLoc = null;\n }\n continue;\n }\n }\n locCode.push(line);\n const chars = line.split('');\n for (let i = 0; i < chars.length; ++i) {\n const char = chars[i];\n if (quote) {\n if (char == quote) {\n if (chars[i + 1] == quote) {\n i++;\n } else {\n quote = '';\n }\n }\n } else {\n if (char == QSP_LCURLY) ++quotesCount;\n else if (char == QSP_RCURLY) {\n if (quotesCount) --quotesCount;\n } else if (QSP_QUOTES.includes(char)) quote = char;\n }\n }\n } else {\n if (line.startsWith(QSP_STARTLOC)) {\n isInLoc = true;\n curLoc = {\n name: line.slice(QSP_STARTLOC.length).trim(),\n description: [],\n code: [],\n actions: [],\n };\n }\n }\n }\n\n if (isInLoc && curLoc) {\n curLoc.code = locCode;\n locations.push(curLoc);\n }\n\n return locations;\n}\n","import { QspAction, QspLocation } from '../contracts';\n\nfunction escapeQspString(input: string): string {\n return input.replace(/'/g, \"''\");\n}\n\nfunction convertDescription(lines: string[], linebreak: string): string {\n return lines\n .map((line, index) => `${index === lines.length - 1 ? '*p' : '*pl'} '${escapeQspString(line)}'${linebreak}`)\n .join('');\n}\n\nfunction convertAction(action: QspAction, linebreak: string): string {\n const name = escapeQspString(action.name);\n const image = action.image ? `, '${escapeQspString(action.image)}'` : '';\n const code = action.code.map((line) => ` ${line}${linebreak}`).join('');\n return `act '${name}'${image}:${linebreak}${code}end`;\n}\n\nfunction convertActions(actions: QspAction[], linebreak: string): string {\n if (!actions.length) return '';\n return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;\n}\n\nfunction convertLocation(location: QspLocation, linebreak: string): string {\n const description = convertDescription(location.description, linebreak);\n const code = location.code.length ? location.code.join(linebreak) + linebreak : '';\n const actions = convertActions(location.actions, linebreak);\n return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;\n}\n\nexport function writeQsps(locations: QspLocation[], linebreak = '\\n'): string {\n return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);\n}\n","import { QspAction, QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID } from '../qsp-byte-stream';\n\n// format description https://github.com/QSPFoundation/qsp/blob/master/help/gam_desc.txt\n\nfunction readNewFormat(stream: QspByteStream): QspLocation[] {\n stream.readLine(false); // tool version\n stream.readLine(); // password\n const locCount = parseInt(stream.readLine());\n\n const locations: QspLocation[] = [];\n\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actsCount = parseInt(stream.readLine());\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const image = stream.readLine();\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n actions.push({ image, name: actionName, code: actionCode });\n }\n locations.push({ name, description, code, actions });\n }\n return locations;\n}\n\nfunction readOldFormat(stream: QspByteStream): QspLocation[] {\n stream.seek(0);\n const locCount = parseInt(stream.readLine(false));\n stream.readLine(); // password\n stream.readLine(false); // tool version\n for (let i = 0; i < 27; i++) {\n //empty reserved lines\n stream.readLine();\n }\n const locations: QspLocation[] = [];\n const actsCount = 20;\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n if (actionName) {\n actions.push({ name: actionName, code: actionCode });\n }\n }\n locations.push({ name, description, code, actions });\n }\n\n return locations;\n}\n\nexport function readQsp(buffer: ArrayBuffer): QspLocation[] {\n const stream = new QspByteStream(buffer);\n const header = stream.readLine(false);\n if (header === QSP_GAMEID) {\n return readNewFormat(stream);\n }\n\n return readOldFormat(stream);\n}\n","import { QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID, QSP_PASSWD } from '../qsp-byte-stream';\n\nexport function writeQsp(locations: QspLocation[]): ArrayBuffer {\n const stream = new QspByteStream();\n\n stream.writeLine(QSP_GAMEID, false);\n stream.writeLine('@qsp/converters 1.0', false);\n stream.writeLine(QSP_PASSWD);\n stream.writeLine(String(locations.length));\n\n for (const location of locations) {\n stream.writeLine(location.name);\n stream.writeLine(location.description.join('\\r\\n'));\n stream.writeLine(location.code.join('\\r\\n'));\n\n stream.writeLine(String(location.actions.length));\n for (const action of location.actions) {\n stream.writeLine(action.image ?? '');\n stream.writeLine(action.name);\n stream.writeLine(action.code.join('\\r\\n'));\n }\n }\n return stream.finalize();\n}\n"],"names":["CP1251ToUnicodeTable","convertCP1251","char","String","fromCharCode","QspByteStream","fromBuffer","cursor","this","content","view","isUnicode","ArrayBuffer","DataView","getUint8","ensureSize","size","byteLength","buffer","set","Uint8Array","finalize","slice","read","Uint16Array","BYTES_PER_ELEMENT","getUint16","position","readLine","shouldDecode","eof","chars","push","map","join","write","value","Int16Array","setUint16","writeString","input","shouldEncode","_step","_iterator","_createForOfIteratorHelperLoose","split","charCodeAt","values","done","point","writeLine","seek","offset","QSP_QUOTES","escapeQspString","replace","readQsp","stream","locCount","parseInt","locations","i","name","description","code","actsCount","actions","j","image","actionName","actionCode","readNewFormat","readOldFormat","isInLoc","curLoc","locCode","quote","quotesCount","line","startsWith","length","_char","includes","trim","location","_step2","_iterator2","action","_action$image","writeQsps","linebreak","convertLocation","lines","index","convertDescription","convertAction","convertActions"],"mappings":"szBAAO,IAMmBA,EAAa,CACrC,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,GAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,IAAQ,KAAQ,KAAQ,KAChE,IAAQ,KAAQ,IAAQ,IAAQ,KAAQ,IAAQ,KAAQ,IAAQ,IAChE,IAAQ,IAAQ,KAAQ,IAAQ,IAAQ,KAAQ,KAAQ,KAAQ,IAChE,IAAQ,IAAQ,KAAQ,KAAQ,KAAQ,IAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,MAGV,SAASC,EAAcC,GACrB,OAAaC,OAACC,aACZF,GAAQ,IAAOF,EAAqBE,EAAO,KAAQA,GAI1CG,IAAAA,0BAMX,SAAmBC,EAAAA,GALXC,KAAAA,OAAS,EAK0BC,KAJnCC,aACAC,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EAnBnB,SAA4B6B,EAAiBF,GAC3C,OAAOE,EACJ3D,IAAI,SAAC6C,EAAMe,GAAaA,OAAAA,IAAUD,EAAMZ,OAAS,EAAI,KAAO,OAAU1B,KAAAA,EAAgBwB,GAASY,IAAAA,IAC/FxD,KAAK,IAgBY4D,CAAmBV,EAASrB,YAAa2B,GACvD1B,EAAOoB,EAASpB,KAAKgB,OAASI,EAASpB,KAAK9B,KAAKwD,GAAaA,EAAY,GAC1ExB,EARR,SAAwBA,EAAsBwB,GAC5C,OAAKxB,EAAQc,OACCd,EAACjC,IAAI,SAACsD,UATtB,SAAuBA,EAAmBG,GACxC,IAAM5B,EAAOR,EAAgBiC,EAAOzB,MAC9BM,EAAQmB,EAAOnB,MAAP,MAAqBd,EAAgBiC,EAAOnB,OAAY,IAAA,GAC5DJ,EAAGuB,EAAOvB,KAAK/B,IAAI,SAAC6C,GAAD,MAAA,KAAeA,EAAOY,IAAaxD,KAAK,IACrE,cAAe4B,EAAf,IAAuBM,EAAvB,IAAgCsB,EAAY1B,EAA5C,MAK4C+B,CAACR,EAAQG,KAAYxD,KAAKwD,GAAaA,EADvD,GAOZM,CAAeZ,EAASlB,QAASwB,GACjD,WAAYN,EAAStB,KAAO4B,EAAY3B,EAAcG,EAAUF,EAAhE,OAA2EoB,EAAStB,KAApF,qCAA6H4B,EAI1FC,CAAgBP,EAAUM,KAAYxD,KAAKwD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/qsp-byte-stream.ts","../src/readers/qsp.ts","../src/readers/qsps.ts","../src/version.ts","../src/writers/qsp.ts","../src/writers/qsps.ts"],"sourcesContent":["export const QSP_CODREMOV = 5;\nconst QSP_STRSDELIM = '\\r\\n';\nexport const QSP_GAMEID = 'QSPGAME';\nexport const QSP_PASSWD = 'No';\n\n// prettier-ignore\nconst CP1251ToUnicodeTable: number[] = [\n 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac,\n 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, 0x0452, 0x2018,\n 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0020, 0x2122, 0x0459,\n 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, 0x00a0, 0x040e, 0x045e, 0x0408,\n 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac,\n 0x00ad, 0x00ae, 0x0407, 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5,\n 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455,\n 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,\n 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420,\n 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429,\n 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,\n 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b,\n 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444,\n 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d,\n 0x044e, 0x044f,\n];\n\nfunction convertCP1251(char: number): string {\n return String.fromCharCode(char >= 0x80 ? CP1251ToUnicodeTable[char - 0x80] : char);\n}\n\nexport class QspByteStream {\n private cursor = 0;\n private content: ArrayBuffer;\n private view: DataView;\n private isUnicode: boolean;\n\n public constructor(fromBuffer?: ArrayBuffer) {\n this.content = fromBuffer ?? new ArrayBuffer(256);\n this.view = new DataView(this.content);\n this.isUnicode = this.view.getUint8(1) === 0;\n }\n\n private ensureSize(size: number): void {\n if (this.content.byteLength >= size) return;\n const newLength = this.content.byteLength * 2;\n const buffer = new ArrayBuffer(newLength);\n new Uint8Array(buffer).set(new Uint8Array(this.content));\n this.content = buffer;\n this.view = new DataView(this.content);\n }\n\n public finalize(): ArrayBuffer {\n this.content = this.content.slice(0, this.cursor);\n return this.content;\n }\n\n public get eof(): boolean {\n return this.cursor >= this.content.byteLength;\n }\n\n public read(): number {\n const position = this.cursor;\n this.cursor += this.isUnicode ? Uint16Array.BYTES_PER_ELEMENT : Uint8Array.BYTES_PER_ELEMENT;\n return this.isUnicode ? this.view.getUint16(position, true) : this.view.getUint8(position);\n }\n\n public readLine(shouldDecode = true): string {\n const chars: number[] = [];\n while (!this.eof) {\n const char = this.read();\n if (char === 0x0d) {\n this.read();\n break;\n }\n if (shouldDecode) {\n chars.push(char === -QSP_CODREMOV ? QSP_CODREMOV : char + QSP_CODREMOV);\n } else {\n chars.push(char);\n }\n }\n return this.isUnicode ? chars.map((char) => String.fromCharCode(char)).join('') : chars.map(convertCP1251).join('');\n }\n\n public write(value: number): void {\n this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);\n const position = this.cursor;\n this.cursor += Int16Array.BYTES_PER_ELEMENT;\n this.view.setUint16(position, value, true);\n }\n\n public writeString(input: string, shouldEncode = true): void {\n const charCodes = input.split('').map((char): number => char.charCodeAt(0));\n for (const point of charCodes.values()) {\n if (shouldEncode) {\n this.write(point === QSP_CODREMOV ? -QSP_CODREMOV : point - QSP_CODREMOV);\n } else {\n this.write(point);\n }\n }\n }\n\n public writeLine(input: string, shouldEncode = true): void {\n if (input) this.writeString(input, shouldEncode);\n this.writeString(QSP_STRSDELIM, false);\n }\n\n public seek(offset: number): void {\n this.cursor = offset;\n }\n}\n","import { QspAction, QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID } from '../qsp-byte-stream';\n\n// format description https://github.com/QSPFoundation/qsp/blob/master/help/gam_desc.txt\n\nfunction readNewFormat(stream: QspByteStream): QspLocation[] {\n stream.readLine(false); // tool version\n stream.readLine(); // password\n const locCount = parseInt(stream.readLine());\n\n const locations: QspLocation[] = [];\n\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n let description = stream.readLine().split(/\\r?\\n/);\n if (description.length === 1 && description[0] === '') {\n description = [];\n }\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actsCount = parseInt(stream.readLine());\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const image = stream.readLine();\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n actions.push({ image, name: actionName, code: actionCode });\n }\n locations.push({ name, description, code, actions });\n }\n return locations;\n}\n\nfunction readOldFormat(stream: QspByteStream): QspLocation[] {\n stream.seek(0);\n const locCount = parseInt(stream.readLine(false));\n stream.readLine(); // password\n stream.readLine(false); // tool version\n for (let i = 0; i < 27; i++) {\n //empty reserved lines\n stream.readLine();\n }\n const locations: QspLocation[] = [];\n const actsCount = 20;\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n if (actionName) {\n actions.push({ name: actionName, code: actionCode });\n }\n }\n locations.push({ name, description, code, actions });\n }\n\n return locations;\n}\n\nexport function readQsp(buffer: ArrayBuffer): QspLocation[] {\n const stream = new QspByteStream(buffer);\n const header = stream.readLine(false);\n if (header === QSP_GAMEID) {\n return readNewFormat(stream);\n }\n\n return readOldFormat(stream);\n}\n","import { QspLocation } from '../contracts';\n\nconst QSP_STARTLOC = '#';\nconst QSP_ENDLOC = '-';\nconst QSP_QUOTES = [\"'\", '\"'];\nconst QSP_LCURLY = '{';\nconst QSP_RCURLY = '}';\n\nexport function readQsps(content: string): QspLocation[] {\n const locations: QspLocation[] = [];\n\n let isInLoc = false;\n let curLoc: QspLocation | null = null;\n let locCode: string[] = [];\n const lines = content.split(/\\r?\\n/);\n let quote = '';\n let quotesCount = 0;\n for (const line of lines) {\n if (isInLoc) {\n if (!quote && !quotesCount) {\n if (line.startsWith(QSP_ENDLOC)) {\n isInLoc = false;\n if (curLoc) {\n curLoc.code = locCode;\n locCode = [];\n locations.push(curLoc);\n curLoc = null;\n }\n continue;\n }\n }\n locCode.push(line);\n const chars = line.split('');\n for (let i = 0; i < chars.length; ++i) {\n const char = chars[i];\n if (quote) {\n if (char == quote) {\n if (chars[i + 1] == quote) {\n i++;\n } else {\n quote = '';\n }\n }\n } else {\n if (char == QSP_LCURLY) ++quotesCount;\n else if (char == QSP_RCURLY) {\n if (quotesCount) --quotesCount;\n } else if (QSP_QUOTES.includes(char)) quote = char;\n }\n }\n } else {\n if (line.startsWith(QSP_STARTLOC)) {\n isInLoc = true;\n curLoc = {\n name: line.slice(QSP_STARTLOC.length).trim(),\n description: [],\n code: [],\n actions: [],\n };\n }\n }\n }\n\n if (isInLoc && curLoc) {\n curLoc.code = locCode;\n locations.push(curLoc);\n }\n\n return locations;\n}\n","export const VERSION = '2.0.0';\n","import { QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID, QSP_PASSWD } from '../qsp-byte-stream';\nimport { VERSION } from '../version';\n\nexport function writeQsp(locations: QspLocation[]): ArrayBuffer {\n const stream = new QspByteStream();\n\n stream.writeLine(QSP_GAMEID, false);\n stream.writeLine(`@qsp/converters ${VERSION}`, false);\n stream.writeLine(QSP_PASSWD);\n stream.writeLine(String(locations.length));\n\n for (const location of locations) {\n stream.writeLine(location.name);\n stream.writeLine(location.description.join('\\r\\n'));\n stream.writeLine(location.code.join('\\r\\n'));\n\n stream.writeLine(String(location.actions.length));\n for (const action of location.actions) {\n stream.writeLine(action.image ?? '');\n stream.writeLine(action.name);\n stream.writeLine(action.code.join('\\r\\n'));\n }\n }\n return stream.finalize();\n}\n","import { QspAction, QspLocation } from '../contracts';\n\nfunction escapeQspString(input: string): string {\n return input.replace(/'/g, \"''\");\n}\n\nfunction convertDescription(lines: string[], linebreak: string): string {\n return lines\n .map((line, index) => `${index === lines.length - 1 ? '*p' : '*pl'} '${escapeQspString(line)}'${linebreak}`)\n .join('');\n}\n\nfunction convertAction(action: QspAction, linebreak: string): string {\n const name = escapeQspString(action.name);\n const image = action.image ? `, '${escapeQspString(action.image)}'` : '';\n const code = action.code.map((line) => ` ${line}${linebreak}`).join('');\n return `act '${name}'${image}:${linebreak}${code}end`;\n}\n\nfunction convertActions(actions: QspAction[], linebreak: string): string {\n if (!actions.length) return '';\n return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;\n}\n\nfunction convertLocation(location: QspLocation, linebreak: string): string {\n const description = convertDescription(location.description, linebreak);\n const code = location.code.length ? location.code.join(linebreak) + linebreak : '';\n const actions = convertActions(location.actions, linebreak);\n return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;\n}\n\nexport function writeQsps(locations: QspLocation[], linebreak = '\\n'): string {\n return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);\n}\n"],"mappings":";AACA,MAAM,gBAAgB;AACtB,MAAa,aAAa;AAI1B,MAAM,uBAAiC;CACrC;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;C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B,OAAO,KAAK,KAAK,SAAS,KAAK,OAAO,WAAW,CAAC,CAAC,KAAK,EACtB,EAAE;AACnD;AAEA,SAAS,eAAe,SAAsB,WAA2B;CACvE,IAAI,CAAC,QAAQ,QAAQ,OAAO;CAC5B,OAAO,QAAQ,KAAK,WAAW,cAAc,QAAQ,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI;AACrF;AAEA,SAAS,gBAAgB,UAAuB,WAA2B;CACzE,MAAM,cAAc,mBAAmB,SAAS,aAAa,SAAS;CACtE,MAAM,OAAO,SAAS,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,IAAI,YAAY;CAChF,MAAM,UAAU,eAAe,SAAS,SAAS,SAAS;CAC1D,OAAO,KAAK,SAAS,OAAO,YAAY,cAAc,UAAU,KAAK,MAAM,SAAS,KAAK,oCAAoC;AAC/H;AAEA,SAAgB,UAAU,WAA0B,YAAY,MAAc;CAC5E,OAAO,UAAU,KAAK,aAAa,gBAAgB,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS;AACzF"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/contracts.d.ts
|
|
2
|
+
export interface QspLocation {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string[];
|
|
5
|
+
code: string[];
|
|
6
|
+
actions: QspAction[];
|
|
7
|
+
}
|
|
8
|
+
export interface QspAction {
|
|
9
|
+
name: string;
|
|
10
|
+
image?: string;
|
|
11
|
+
code: string[];
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/readers/qsp.d.ts
|
|
15
|
+
export declare function readQsp(buffer: ArrayBuffer): QspLocation[];
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/readers/qsps.d.ts
|
|
18
|
+
export declare function readQsps(content: string): QspLocation[];
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/writers/qsp.d.ts
|
|
21
|
+
export declare function writeQsp(locations: QspLocation[]): ArrayBuffer;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/writers/qsps.d.ts
|
|
24
|
+
export declare function writeQsps(locations: QspLocation[], linebreak?: string): string;
|
|
25
|
+
//#endregion
|
|
26
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region src/contracts.d.ts
|
|
2
|
+
export interface QspLocation {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string[];
|
|
5
|
+
code: string[];
|
|
6
|
+
actions: QspAction[];
|
|
7
|
+
}
|
|
8
|
+
export interface QspAction {
|
|
9
|
+
name: string;
|
|
10
|
+
image?: string;
|
|
11
|
+
code: string[];
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/readers/qsp.d.ts
|
|
15
|
+
export declare function readQsp(buffer: ArrayBuffer): QspLocation[];
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/readers/qsps.d.ts
|
|
18
|
+
export declare function readQsps(content: string): QspLocation[];
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/writers/qsp.d.ts
|
|
21
|
+
export declare function writeQsp(locations: QspLocation[]): ArrayBuffer;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/writers/qsps.d.ts
|
|
24
|
+
export declare function writeQsps(locations: QspLocation[], linebreak?: string): string;
|
|
25
|
+
//#endregion
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
const QSP_STRSDELIM = "\r\n";
|
|
2
|
+
const QSP_GAMEID = "QSPGAME";
|
|
3
|
+
const CP1251ToUnicodeTable = [
|
|
4
|
+
1026,
|
|
5
|
+
1027,
|
|
6
|
+
8218,
|
|
7
|
+
1107,
|
|
8
|
+
8222,
|
|
9
|
+
8230,
|
|
10
|
+
8224,
|
|
11
|
+
8225,
|
|
12
|
+
8364,
|
|
13
|
+
8240,
|
|
14
|
+
1033,
|
|
15
|
+
8249,
|
|
16
|
+
1034,
|
|
17
|
+
1036,
|
|
18
|
+
1035,
|
|
19
|
+
1039,
|
|
20
|
+
1106,
|
|
21
|
+
8216,
|
|
22
|
+
8217,
|
|
23
|
+
8220,
|
|
24
|
+
8221,
|
|
25
|
+
8226,
|
|
26
|
+
8211,
|
|
27
|
+
8212,
|
|
28
|
+
32,
|
|
29
|
+
8482,
|
|
30
|
+
1113,
|
|
31
|
+
8250,
|
|
32
|
+
1114,
|
|
33
|
+
1116,
|
|
34
|
+
1115,
|
|
35
|
+
1119,
|
|
36
|
+
160,
|
|
37
|
+
1038,
|
|
38
|
+
1118,
|
|
39
|
+
1032,
|
|
40
|
+
164,
|
|
41
|
+
1168,
|
|
42
|
+
166,
|
|
43
|
+
167,
|
|
44
|
+
1025,
|
|
45
|
+
169,
|
|
46
|
+
1028,
|
|
47
|
+
171,
|
|
48
|
+
172,
|
|
49
|
+
173,
|
|
50
|
+
174,
|
|
51
|
+
1031,
|
|
52
|
+
176,
|
|
53
|
+
177,
|
|
54
|
+
1030,
|
|
55
|
+
1110,
|
|
56
|
+
1169,
|
|
57
|
+
181,
|
|
58
|
+
182,
|
|
59
|
+
183,
|
|
60
|
+
1105,
|
|
61
|
+
8470,
|
|
62
|
+
1108,
|
|
63
|
+
187,
|
|
64
|
+
1112,
|
|
65
|
+
1029,
|
|
66
|
+
1109,
|
|
67
|
+
1111,
|
|
68
|
+
1040,
|
|
69
|
+
1041,
|
|
70
|
+
1042,
|
|
71
|
+
1043,
|
|
72
|
+
1044,
|
|
73
|
+
1045,
|
|
74
|
+
1046,
|
|
75
|
+
1047,
|
|
76
|
+
1048,
|
|
77
|
+
1049,
|
|
78
|
+
1050,
|
|
79
|
+
1051,
|
|
80
|
+
1052,
|
|
81
|
+
1053,
|
|
82
|
+
1054,
|
|
83
|
+
1055,
|
|
84
|
+
1056,
|
|
85
|
+
1057,
|
|
86
|
+
1058,
|
|
87
|
+
1059,
|
|
88
|
+
1060,
|
|
89
|
+
1061,
|
|
90
|
+
1062,
|
|
91
|
+
1063,
|
|
92
|
+
1064,
|
|
93
|
+
1065,
|
|
94
|
+
1066,
|
|
95
|
+
1067,
|
|
96
|
+
1068,
|
|
97
|
+
1069,
|
|
98
|
+
1070,
|
|
99
|
+
1071,
|
|
100
|
+
1072,
|
|
101
|
+
1073,
|
|
102
|
+
1074,
|
|
103
|
+
1075,
|
|
104
|
+
1076,
|
|
105
|
+
1077,
|
|
106
|
+
1078,
|
|
107
|
+
1079,
|
|
108
|
+
1080,
|
|
109
|
+
1081,
|
|
110
|
+
1082,
|
|
111
|
+
1083,
|
|
112
|
+
1084,
|
|
113
|
+
1085,
|
|
114
|
+
1086,
|
|
115
|
+
1087,
|
|
116
|
+
1088,
|
|
117
|
+
1089,
|
|
118
|
+
1090,
|
|
119
|
+
1091,
|
|
120
|
+
1092,
|
|
121
|
+
1093,
|
|
122
|
+
1094,
|
|
123
|
+
1095,
|
|
124
|
+
1096,
|
|
125
|
+
1097,
|
|
126
|
+
1098,
|
|
127
|
+
1099,
|
|
128
|
+
1100,
|
|
129
|
+
1101,
|
|
130
|
+
1102,
|
|
131
|
+
1103
|
|
132
|
+
];
|
|
133
|
+
function convertCP1251(char) {
|
|
134
|
+
return String.fromCharCode(char >= 128 ? CP1251ToUnicodeTable[char - 128] : char);
|
|
135
|
+
}
|
|
136
|
+
var QspByteStream = class {
|
|
137
|
+
cursor = 0;
|
|
138
|
+
content;
|
|
139
|
+
view;
|
|
140
|
+
isUnicode;
|
|
141
|
+
constructor(fromBuffer) {
|
|
142
|
+
this.content = fromBuffer ?? /* @__PURE__ */ new ArrayBuffer(256);
|
|
143
|
+
this.view = new DataView(this.content);
|
|
144
|
+
this.isUnicode = this.view.getUint8(1) === 0;
|
|
145
|
+
}
|
|
146
|
+
ensureSize(size) {
|
|
147
|
+
if (this.content.byteLength >= size) return;
|
|
148
|
+
const newLength = this.content.byteLength * 2;
|
|
149
|
+
const buffer = new ArrayBuffer(newLength);
|
|
150
|
+
new Uint8Array(buffer).set(new Uint8Array(this.content));
|
|
151
|
+
this.content = buffer;
|
|
152
|
+
this.view = new DataView(this.content);
|
|
153
|
+
}
|
|
154
|
+
finalize() {
|
|
155
|
+
this.content = this.content.slice(0, this.cursor);
|
|
156
|
+
return this.content;
|
|
157
|
+
}
|
|
158
|
+
get eof() {
|
|
159
|
+
return this.cursor >= this.content.byteLength;
|
|
160
|
+
}
|
|
161
|
+
read() {
|
|
162
|
+
const position = this.cursor;
|
|
163
|
+
this.cursor += this.isUnicode ? Uint16Array.BYTES_PER_ELEMENT : Uint8Array.BYTES_PER_ELEMENT;
|
|
164
|
+
return this.isUnicode ? this.view.getUint16(position, true) : this.view.getUint8(position);
|
|
165
|
+
}
|
|
166
|
+
readLine(shouldDecode = true) {
|
|
167
|
+
const chars = [];
|
|
168
|
+
while (!this.eof) {
|
|
169
|
+
const char = this.read();
|
|
170
|
+
if (char === 13) {
|
|
171
|
+
this.read();
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (shouldDecode) chars.push(char === -5 ? 5 : char + 5);
|
|
175
|
+
else chars.push(char);
|
|
176
|
+
}
|
|
177
|
+
return this.isUnicode ? chars.map((char) => String.fromCharCode(char)).join("") : chars.map(convertCP1251).join("");
|
|
178
|
+
}
|
|
179
|
+
write(value) {
|
|
180
|
+
this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);
|
|
181
|
+
const position = this.cursor;
|
|
182
|
+
this.cursor += Int16Array.BYTES_PER_ELEMENT;
|
|
183
|
+
this.view.setUint16(position, value, true);
|
|
184
|
+
}
|
|
185
|
+
writeString(input, shouldEncode = true) {
|
|
186
|
+
const charCodes = input.split("").map((char) => char.charCodeAt(0));
|
|
187
|
+
for (const point of charCodes.values()) if (shouldEncode) this.write(point === 5 ? -5 : point - 5);
|
|
188
|
+
else this.write(point);
|
|
189
|
+
}
|
|
190
|
+
writeLine(input, shouldEncode = true) {
|
|
191
|
+
if (input) this.writeString(input, shouldEncode);
|
|
192
|
+
this.writeString(QSP_STRSDELIM, false);
|
|
193
|
+
}
|
|
194
|
+
seek(offset) {
|
|
195
|
+
this.cursor = offset;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/readers/qsp.ts
|
|
200
|
+
function readNewFormat(stream) {
|
|
201
|
+
stream.readLine(false);
|
|
202
|
+
stream.readLine();
|
|
203
|
+
const locCount = parseInt(stream.readLine());
|
|
204
|
+
const locations = [];
|
|
205
|
+
for (let i = 0; i < locCount; i++) {
|
|
206
|
+
const name = stream.readLine();
|
|
207
|
+
let description = stream.readLine().split(/\r?\n/);
|
|
208
|
+
if (description.length === 1 && description[0] === "") description = [];
|
|
209
|
+
const code = stream.readLine().split(/\r?\n/);
|
|
210
|
+
const actsCount = parseInt(stream.readLine());
|
|
211
|
+
const actions = [];
|
|
212
|
+
for (let j = 0; j < actsCount; ++j) {
|
|
213
|
+
const image = stream.readLine();
|
|
214
|
+
const actionName = stream.readLine();
|
|
215
|
+
const actionCode = stream.readLine().split(/\r?\n/);
|
|
216
|
+
actions.push({
|
|
217
|
+
image,
|
|
218
|
+
name: actionName,
|
|
219
|
+
code: actionCode
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
locations.push({
|
|
223
|
+
name,
|
|
224
|
+
description,
|
|
225
|
+
code,
|
|
226
|
+
actions
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return locations;
|
|
230
|
+
}
|
|
231
|
+
function readOldFormat(stream) {
|
|
232
|
+
stream.seek(0);
|
|
233
|
+
const locCount = parseInt(stream.readLine(false));
|
|
234
|
+
stream.readLine();
|
|
235
|
+
stream.readLine(false);
|
|
236
|
+
for (let i = 0; i < 27; i++) stream.readLine();
|
|
237
|
+
const locations = [];
|
|
238
|
+
const actsCount = 20;
|
|
239
|
+
for (let i = 0; i < locCount; i++) {
|
|
240
|
+
const name = stream.readLine();
|
|
241
|
+
const description = stream.readLine().split(/\r?\n/);
|
|
242
|
+
const code = stream.readLine().split(/\r?\n/);
|
|
243
|
+
const actions = [];
|
|
244
|
+
for (let j = 0; j < actsCount; ++j) {
|
|
245
|
+
const actionName = stream.readLine();
|
|
246
|
+
const actionCode = stream.readLine().split(/\r?\n/);
|
|
247
|
+
if (actionName) actions.push({
|
|
248
|
+
name: actionName,
|
|
249
|
+
code: actionCode
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
locations.push({
|
|
253
|
+
name,
|
|
254
|
+
description,
|
|
255
|
+
code,
|
|
256
|
+
actions
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return locations;
|
|
260
|
+
}
|
|
261
|
+
function readQsp(buffer) {
|
|
262
|
+
const stream = new QspByteStream(buffer);
|
|
263
|
+
if (stream.readLine(false) === "QSPGAME") return readNewFormat(stream);
|
|
264
|
+
return readOldFormat(stream);
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/readers/qsps.ts
|
|
268
|
+
const QSP_STARTLOC = "#";
|
|
269
|
+
const QSP_ENDLOC = "-";
|
|
270
|
+
const QSP_QUOTES = ["'", "\""];
|
|
271
|
+
const QSP_LCURLY = "{";
|
|
272
|
+
const QSP_RCURLY = "}";
|
|
273
|
+
function readQsps(content) {
|
|
274
|
+
const locations = [];
|
|
275
|
+
let isInLoc = false;
|
|
276
|
+
let curLoc = null;
|
|
277
|
+
let locCode = [];
|
|
278
|
+
const lines = content.split(/\r?\n/);
|
|
279
|
+
let quote = "";
|
|
280
|
+
let quotesCount = 0;
|
|
281
|
+
for (const line of lines) if (isInLoc) {
|
|
282
|
+
if (!quote && !quotesCount) {
|
|
283
|
+
if (line.startsWith(QSP_ENDLOC)) {
|
|
284
|
+
isInLoc = false;
|
|
285
|
+
if (curLoc) {
|
|
286
|
+
curLoc.code = locCode;
|
|
287
|
+
locCode = [];
|
|
288
|
+
locations.push(curLoc);
|
|
289
|
+
curLoc = null;
|
|
290
|
+
}
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
locCode.push(line);
|
|
295
|
+
const chars = line.split("");
|
|
296
|
+
for (let i = 0; i < chars.length; ++i) {
|
|
297
|
+
const char = chars[i];
|
|
298
|
+
if (quote) {
|
|
299
|
+
if (char == quote) {
|
|
300
|
+
if (chars[i + 1] == quote) i++;
|
|
301
|
+
else quote = "";
|
|
302
|
+
}
|
|
303
|
+
} else if (char == QSP_LCURLY) ++quotesCount;
|
|
304
|
+
else if (char == QSP_RCURLY) {
|
|
305
|
+
if (quotesCount) --quotesCount;
|
|
306
|
+
} else if (QSP_QUOTES.includes(char)) quote = char;
|
|
307
|
+
}
|
|
308
|
+
} else if (line.startsWith(QSP_STARTLOC)) {
|
|
309
|
+
isInLoc = true;
|
|
310
|
+
curLoc = {
|
|
311
|
+
name: line.slice(1).trim(),
|
|
312
|
+
description: [],
|
|
313
|
+
code: [],
|
|
314
|
+
actions: []
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (isInLoc && curLoc) {
|
|
318
|
+
curLoc.code = locCode;
|
|
319
|
+
locations.push(curLoc);
|
|
320
|
+
}
|
|
321
|
+
return locations;
|
|
322
|
+
}
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/version.ts
|
|
325
|
+
const VERSION = "2.0.0";
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/writers/qsp.ts
|
|
328
|
+
function writeQsp(locations) {
|
|
329
|
+
const stream = new QspByteStream();
|
|
330
|
+
stream.writeLine(QSP_GAMEID, false);
|
|
331
|
+
stream.writeLine(`@qsp/converters ${VERSION}`, false);
|
|
332
|
+
stream.writeLine("No");
|
|
333
|
+
stream.writeLine(String(locations.length));
|
|
334
|
+
for (const location of locations) {
|
|
335
|
+
stream.writeLine(location.name);
|
|
336
|
+
stream.writeLine(location.description.join("\r\n"));
|
|
337
|
+
stream.writeLine(location.code.join("\r\n"));
|
|
338
|
+
stream.writeLine(String(location.actions.length));
|
|
339
|
+
for (const action of location.actions) {
|
|
340
|
+
stream.writeLine(action.image ?? "");
|
|
341
|
+
stream.writeLine(action.name);
|
|
342
|
+
stream.writeLine(action.code.join("\r\n"));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return stream.finalize();
|
|
346
|
+
}
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/writers/qsps.ts
|
|
349
|
+
function escapeQspString(input) {
|
|
350
|
+
return input.replace(/'/g, "''");
|
|
351
|
+
}
|
|
352
|
+
function convertDescription(lines, linebreak) {
|
|
353
|
+
return lines.map((line, index) => `${index === lines.length - 1 ? "*p" : "*pl"} '${escapeQspString(line)}'${linebreak}`).join("");
|
|
354
|
+
}
|
|
355
|
+
function convertAction(action, linebreak) {
|
|
356
|
+
return `act '${escapeQspString(action.name)}'${action.image ? `, '${escapeQspString(action.image)}'` : ""}:${linebreak}${action.code.map((line) => ` ${line}${linebreak}`).join("")}end`;
|
|
357
|
+
}
|
|
358
|
+
function convertActions(actions, linebreak) {
|
|
359
|
+
if (!actions.length) return "";
|
|
360
|
+
return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;
|
|
361
|
+
}
|
|
362
|
+
function convertLocation(location, linebreak) {
|
|
363
|
+
const description = convertDescription(location.description, linebreak);
|
|
364
|
+
const code = location.code.length ? location.code.join(linebreak) + linebreak : "";
|
|
365
|
+
const actions = convertActions(location.actions, linebreak);
|
|
366
|
+
return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;
|
|
367
|
+
}
|
|
368
|
+
function writeQsps(locations, linebreak = "\n") {
|
|
369
|
+
return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);
|
|
370
|
+
}
|
|
371
|
+
//#endregion
|
|
372
|
+
export { readQsp, readQsps, writeQsp, writeQsps };
|
|
373
|
+
|
|
374
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/qsp-byte-stream.ts","../src/readers/qsp.ts","../src/readers/qsps.ts","../src/version.ts","../src/writers/qsp.ts","../src/writers/qsps.ts"],"sourcesContent":["export const QSP_CODREMOV = 5;\nconst QSP_STRSDELIM = '\\r\\n';\nexport const QSP_GAMEID = 'QSPGAME';\nexport const QSP_PASSWD = 'No';\n\n// prettier-ignore\nconst CP1251ToUnicodeTable: number[] = [\n 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac,\n 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, 0x0452, 0x2018,\n 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0020, 0x2122, 0x0459,\n 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, 0x00a0, 0x040e, 0x045e, 0x0408,\n 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac,\n 0x00ad, 0x00ae, 0x0407, 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5,\n 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455,\n 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,\n 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420,\n 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429,\n 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,\n 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b,\n 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444,\n 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d,\n 0x044e, 0x044f,\n];\n\nfunction convertCP1251(char: number): string {\n return String.fromCharCode(char >= 0x80 ? CP1251ToUnicodeTable[char - 0x80] : char);\n}\n\nexport class QspByteStream {\n private cursor = 0;\n private content: ArrayBuffer;\n private view: DataView;\n private isUnicode: boolean;\n\n public constructor(fromBuffer?: ArrayBuffer) {\n this.content = fromBuffer ?? new ArrayBuffer(256);\n this.view = new DataView(this.content);\n this.isUnicode = this.view.getUint8(1) === 0;\n }\n\n private ensureSize(size: number): void {\n if (this.content.byteLength >= size) return;\n const newLength = this.content.byteLength * 2;\n const buffer = new ArrayBuffer(newLength);\n new Uint8Array(buffer).set(new Uint8Array(this.content));\n this.content = buffer;\n this.view = new DataView(this.content);\n }\n\n public finalize(): ArrayBuffer {\n this.content = this.content.slice(0, this.cursor);\n return this.content;\n }\n\n public get eof(): boolean {\n return this.cursor >= this.content.byteLength;\n }\n\n public read(): number {\n const position = this.cursor;\n this.cursor += this.isUnicode ? Uint16Array.BYTES_PER_ELEMENT : Uint8Array.BYTES_PER_ELEMENT;\n return this.isUnicode ? this.view.getUint16(position, true) : this.view.getUint8(position);\n }\n\n public readLine(shouldDecode = true): string {\n const chars: number[] = [];\n while (!this.eof) {\n const char = this.read();\n if (char === 0x0d) {\n this.read();\n break;\n }\n if (shouldDecode) {\n chars.push(char === -QSP_CODREMOV ? QSP_CODREMOV : char + QSP_CODREMOV);\n } else {\n chars.push(char);\n }\n }\n return this.isUnicode ? chars.map((char) => String.fromCharCode(char)).join('') : chars.map(convertCP1251).join('');\n }\n\n public write(value: number): void {\n this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);\n const position = this.cursor;\n this.cursor += Int16Array.BYTES_PER_ELEMENT;\n this.view.setUint16(position, value, true);\n }\n\n public writeString(input: string, shouldEncode = true): void {\n const charCodes = input.split('').map((char): number => char.charCodeAt(0));\n for (const point of charCodes.values()) {\n if (shouldEncode) {\n this.write(point === QSP_CODREMOV ? -QSP_CODREMOV : point - QSP_CODREMOV);\n } else {\n this.write(point);\n }\n }\n }\n\n public writeLine(input: string, shouldEncode = true): void {\n if (input) this.writeString(input, shouldEncode);\n this.writeString(QSP_STRSDELIM, false);\n }\n\n public seek(offset: number): void {\n this.cursor = offset;\n }\n}\n","import { QspAction, QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID } from '../qsp-byte-stream';\n\n// format description https://github.com/QSPFoundation/qsp/blob/master/help/gam_desc.txt\n\nfunction readNewFormat(stream: QspByteStream): QspLocation[] {\n stream.readLine(false); // tool version\n stream.readLine(); // password\n const locCount = parseInt(stream.readLine());\n\n const locations: QspLocation[] = [];\n\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n let description = stream.readLine().split(/\\r?\\n/);\n if (description.length === 1 && description[0] === '') {\n description = [];\n }\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actsCount = parseInt(stream.readLine());\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const image = stream.readLine();\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n actions.push({ image, name: actionName, code: actionCode });\n }\n locations.push({ name, description, code, actions });\n }\n return locations;\n}\n\nfunction readOldFormat(stream: QspByteStream): QspLocation[] {\n stream.seek(0);\n const locCount = parseInt(stream.readLine(false));\n stream.readLine(); // password\n stream.readLine(false); // tool version\n for (let i = 0; i < 27; i++) {\n //empty reserved lines\n stream.readLine();\n }\n const locations: QspLocation[] = [];\n const actsCount = 20;\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n if (actionName) {\n actions.push({ name: actionName, code: actionCode });\n }\n }\n locations.push({ name, description, code, actions });\n }\n\n return locations;\n}\n\nexport function readQsp(buffer: ArrayBuffer): QspLocation[] {\n const stream = new QspByteStream(buffer);\n const header = stream.readLine(false);\n if (header === QSP_GAMEID) {\n return readNewFormat(stream);\n }\n\n return readOldFormat(stream);\n}\n","import { QspLocation } from '../contracts';\n\nconst QSP_STARTLOC = '#';\nconst QSP_ENDLOC = '-';\nconst QSP_QUOTES = [\"'\", '\"'];\nconst QSP_LCURLY = '{';\nconst QSP_RCURLY = '}';\n\nexport function readQsps(content: string): QspLocation[] {\n const locations: QspLocation[] = [];\n\n let isInLoc = false;\n let curLoc: QspLocation | null = null;\n let locCode: string[] = [];\n const lines = content.split(/\\r?\\n/);\n let quote = '';\n let quotesCount = 0;\n for (const line of lines) {\n if (isInLoc) {\n if (!quote && !quotesCount) {\n if (line.startsWith(QSP_ENDLOC)) {\n isInLoc = false;\n if (curLoc) {\n curLoc.code = locCode;\n locCode = [];\n locations.push(curLoc);\n curLoc = null;\n }\n continue;\n }\n }\n locCode.push(line);\n const chars = line.split('');\n for (let i = 0; i < chars.length; ++i) {\n const char = chars[i];\n if (quote) {\n if (char == quote) {\n if (chars[i + 1] == quote) {\n i++;\n } else {\n quote = '';\n }\n }\n } else {\n if (char == QSP_LCURLY) ++quotesCount;\n else if (char == QSP_RCURLY) {\n if (quotesCount) --quotesCount;\n } else if (QSP_QUOTES.includes(char)) quote = char;\n }\n }\n } else {\n if (line.startsWith(QSP_STARTLOC)) {\n isInLoc = true;\n curLoc = {\n name: line.slice(QSP_STARTLOC.length).trim(),\n description: [],\n code: [],\n actions: [],\n };\n }\n }\n }\n\n if (isInLoc && curLoc) {\n curLoc.code = locCode;\n locations.push(curLoc);\n }\n\n return locations;\n}\n","export const VERSION = '2.0.0';\n","import { QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID, QSP_PASSWD } from '../qsp-byte-stream';\nimport { VERSION } from '../version';\n\nexport function writeQsp(locations: QspLocation[]): ArrayBuffer {\n const stream = new QspByteStream();\n\n stream.writeLine(QSP_GAMEID, false);\n stream.writeLine(`@qsp/converters ${VERSION}`, false);\n stream.writeLine(QSP_PASSWD);\n stream.writeLine(String(locations.length));\n\n for (const location of locations) {\n stream.writeLine(location.name);\n stream.writeLine(location.description.join('\\r\\n'));\n stream.writeLine(location.code.join('\\r\\n'));\n\n stream.writeLine(String(location.actions.length));\n for (const action of location.actions) {\n stream.writeLine(action.image ?? '');\n stream.writeLine(action.name);\n stream.writeLine(action.code.join('\\r\\n'));\n }\n }\n return stream.finalize();\n}\n","import { QspAction, QspLocation } from '../contracts';\n\nfunction escapeQspString(input: string): string {\n return input.replace(/'/g, \"''\");\n}\n\nfunction convertDescription(lines: string[], linebreak: string): string {\n return lines\n .map((line, index) => `${index === lines.length - 1 ? '*p' : '*pl'} '${escapeQspString(line)}'${linebreak}`)\n .join('');\n}\n\nfunction convertAction(action: QspAction, linebreak: string): string {\n const name = escapeQspString(action.name);\n const image = action.image ? `, '${escapeQspString(action.image)}'` : '';\n const code = action.code.map((line) => ` ${line}${linebreak}`).join('');\n return `act '${name}'${image}:${linebreak}${code}end`;\n}\n\nfunction convertActions(actions: QspAction[], linebreak: string): string {\n if (!actions.length) return '';\n return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;\n}\n\nfunction convertLocation(location: QspLocation, linebreak: string): string {\n const description = convertDescription(location.description, linebreak);\n const code = location.code.length ? location.code.join(linebreak) + linebreak : '';\n const actions = convertActions(location.actions, linebreak);\n return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;\n}\n\nexport function writeQsps(locations: QspLocation[], linebreak = '\\n'): string {\n return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);\n}\n"],"mappings":"AACA,MAAM,gBAAgB;AACtB,MAAa,aAAa;AAI1B,MAAM,uBAAiC;CACrC;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAAQ;CAChE;CAAQ;CAAQ;CAAQ;C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QAAQ,MAAM,IAAI;AACjC;AAEA,SAAS,mBAAmB,OAAiB,WAA2B;CACtE,OAAO,MACJ,KAAK,MAAM,UAAU,GAAG,UAAU,MAAM,SAAS,IAAI,OAAO,MAAM,IAAI,gBAAgB,IAAI,EAAE,GAAG,WAAW,CAAC,CAC3G,KAAK,EAAE;AACZ;AAEA,SAAS,cAAc,QAAmB,WAA2B;CAInE,OAAO,QAHM,gBAAgB,OAAO,IAGlB,EAAE,GAFN,OAAO,QAAQ,MAAM,gBAAgB,OAAO,KAAK,EAAE,KAAK,GAEzC,GAAG,YADnB,OAAO,KAAK,KAAK,SAAS,KAAK,OAAO,WAAW,CAAC,CAAC,KAAK,EACtB,EAAE;AACnD;AAEA,SAAS,eAAe,SAAsB,WAA2B;CACvE,IAAI,CAAC,QAAQ,QAAQ,OAAO;CAC5B,OAAO,QAAQ,KAAK,WAAW,cAAc,QAAQ,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI;AACrF;AAEA,SAAS,gBAAgB,UAAuB,WAA2B;CACzE,MAAM,cAAc,mBAAmB,SAAS,aAAa,SAAS;CACtE,MAAM,OAAO,SAAS,KAAK,SAAS,SAAS,KAAK,KAAK,SAAS,IAAI,YAAY;CAChF,MAAM,UAAU,eAAe,SAAS,SAAS,SAAS;CAC1D,OAAO,KAAK,SAAS,OAAO,YAAY,cAAc,UAAU,KAAK,MAAM,SAAS,KAAK,oCAAoC;AAC/H;AAEA,SAAgB,UAAU,WAA0B,YAAY,MAAc;CAC5E,OAAO,UAAU,KAAK,aAAa,gBAAgB,UAAU,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS;AACzF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qsp/converters",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "Converters of different file formats for QSP platform",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"qsp",
|
|
@@ -17,30 +17,29 @@
|
|
|
17
17
|
"author": "Sergii Kostyrko <srg.kostyrko@gmail.com>",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "https://github.com/QSPFoundation/converters.git"
|
|
20
|
+
"url": "git+https://github.com/QSPFoundation/converters.git"
|
|
21
21
|
},
|
|
22
|
-
"source": "src/index.ts",
|
|
23
22
|
"exports": {
|
|
24
|
-
"
|
|
25
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
26
28
|
},
|
|
27
|
-
"main": "./dist/index.cjs",
|
|
28
|
-
"module": "./dist/index.module.js",
|
|
29
|
-
"unpkg": "./dist/index.umd.js",
|
|
30
|
-
"typings": "dist/index.d.ts",
|
|
31
29
|
"engines": {
|
|
32
30
|
"node": ">=14"
|
|
33
31
|
},
|
|
34
32
|
"files": [
|
|
35
33
|
"dist"
|
|
36
34
|
],
|
|
35
|
+
"sideEffects": false,
|
|
37
36
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
-
"dev": "
|
|
37
|
+
"build": "tsdown",
|
|
38
|
+
"dev": "tsdown --watch",
|
|
40
39
|
"test": "jest",
|
|
41
40
|
"lint": "eslint .",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
41
|
+
"version": "node scripts/sync-version.js && git add src/version.ts",
|
|
42
|
+
"prepublishOnly": "npm run build"
|
|
44
43
|
},
|
|
45
44
|
"husky": {
|
|
46
45
|
"hooks": {
|
|
@@ -48,24 +47,25 @@
|
|
|
48
47
|
}
|
|
49
48
|
},
|
|
50
49
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"eslint": "^
|
|
55
|
-
"eslint-config-prettier": "^
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"tslib": "^2.4.0",
|
|
66
|
-
"typescript": "^4.7.4"
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"@types/jest": "^30.0.0",
|
|
52
|
+
"@types/node": "^22.20.5",
|
|
53
|
+
"eslint": "^10.13.0",
|
|
54
|
+
"eslint-config-prettier": "^10.1.8",
|
|
55
|
+
"husky": "^9.1.7",
|
|
56
|
+
"jest": "^30.5.2",
|
|
57
|
+
"lint-staged": "^17.6.0",
|
|
58
|
+
"prettier": "^3.9.10",
|
|
59
|
+
"ts-jest": "^29.4.15",
|
|
60
|
+
"ts-node": "^10.9.2",
|
|
61
|
+
"tsdown": "~0.23.1",
|
|
62
|
+
"typescript": "^6.0.3",
|
|
63
|
+
"typescript-eslint": "^8.72.0"
|
|
67
64
|
},
|
|
68
65
|
"publishConfig": {
|
|
69
66
|
"access": "public"
|
|
70
|
-
}
|
|
67
|
+
},
|
|
68
|
+
"main": "./dist/index.cjs",
|
|
69
|
+
"module": "./dist/index.js",
|
|
70
|
+
"types": "./dist/index.d.cts"
|
|
71
71
|
}
|
package/dist/contracts.d.ts
DELETED
package/dist/index.modern.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const n=[1026,1027,8218,1107,8222,8230,8224,8225,8364,8240,1033,8249,1034,1036,1035,1039,1106,8216,8217,8220,8221,8226,8211,8212,32,8482,1113,8250,1114,1116,1115,1119,160,1038,1118,1032,164,1168,166,167,1025,169,1028,171,172,173,174,1031,176,177,1030,1110,1169,181,182,183,1105,8470,1108,187,1112,1029,1109,1111,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103];function t(t){return String.fromCharCode(t>=128?n[t-128]:t)}class e{constructor(n){this.cursor=0,this.content=void 0,this.view=void 0,this.isUnicode=void 0,this.content=null!=n?n:new ArrayBuffer(256),this.view=new DataView(this.content),this.isUnicode=0===this.view.getUint8(1)}ensureSize(n){if(this.content.byteLength>=n)return;const t=new ArrayBuffer(2*this.content.byteLength);new Uint8Array(t).set(new Uint8Array(this.content)),this.content=t,this.view=new DataView(this.content)}finalize(){return this.content=this.content.slice(0,this.cursor),this.content}get eof(){return this.cursor>=this.content.byteLength}read(){const n=this.cursor;return this.cursor+=this.isUnicode?Uint16Array.BYTES_PER_ELEMENT:Uint8Array.BYTES_PER_ELEMENT,this.isUnicode?this.view.getUint16(n,!0):this.view.getUint8(n)}readLine(n=!0){const e=[];for(;!this.eof;){const t=this.read();if(13===t){this.read();break}e.push(n?-5===t?5:t+5:t)}return this.isUnicode?e.map(n=>String.fromCharCode(n)).join(""):e.map(t).join("")}write(n){this.ensureSize(this.cursor+Int16Array.BYTES_PER_ELEMENT);const t=this.cursor;this.cursor+=Int16Array.BYTES_PER_ELEMENT,this.view.setUint16(t,n,!0)}writeString(n,t=!0){const e=n.split("").map(n=>n.charCodeAt(0));for(const n of e.values())this.write(t?5===n?-5:n-5:n)}writeLine(n,t=!0){n&&this.writeString(n,t),this.writeString("\r\n",!1)}seek(n){this.cursor=n}}function i(n){const t=new e(n);return"QSPGAME"===t.readLine(!1)?function(n){n.readLine(!1),n.readLine();const t=parseInt(n.readLine()),e=[];for(let i=0;i<t;i++){const t=n.readLine(),i=n.readLine().split(/\r?\n/),r=n.readLine().split(/\r?\n/),s=parseInt(n.readLine()),o=[];for(let t=0;t<s;++t){const t=n.readLine(),e=n.readLine(),i=n.readLine().split(/\r?\n/);o.push({image:t,name:e,code:i})}e.push({name:t,description:i,code:r,actions:o})}return e}(t):function(n){n.seek(0);const t=parseInt(n.readLine(!1));n.readLine(),n.readLine(!1);for(let t=0;t<27;t++)n.readLine();const e=[];for(let i=0;i<t;i++){const t=n.readLine(),i=n.readLine().split(/\r?\n/),r=n.readLine().split(/\r?\n/),s=[];for(let t=0;t<20;++t){const t=n.readLine(),e=n.readLine().split(/\r?\n/);t&&s.push({name:t,code:e})}e.push({name:t,description:i,code:r,actions:s})}return e}(t)}const r=["'",'"'];function s(n){const t=[];let e=!1,i=null,s=[];const o=n.split(/\r?\n/);let c="",a=0;for(const n of o)if(e){if(!c&&!a&&n.startsWith("-")){e=!1,i&&(i.code=s,s=[],t.push(i),i=null);continue}s.push(n);const o=n.split("");for(let n=0;n<o.length;++n){const t=o[n];c?t==c&&(o[n+1]==c?n++:c=""):"{"==t?++a:"}"==t?a&&--a:r.includes(t)&&(c=t)}}else n.startsWith("#")&&(e=!0,i={name:n.slice("#".length).trim(),description:[],code:[],actions:[]});return e&&i&&(i.code=s,t.push(i)),t}function o(n){const t=new e;t.writeLine("QSPGAME",!1),t.writeLine("@qsp/converters 1.0",!1),t.writeLine("No"),t.writeLine(String(n.length));for(const e of n){t.writeLine(e.name),t.writeLine(e.description.join("\r\n")),t.writeLine(e.code.join("\r\n")),t.writeLine(String(e.actions.length));for(const n of e.actions){var i;t.writeLine(null!=(i=n.image)?i:""),t.writeLine(n.name),t.writeLine(n.code.join("\r\n"))}}return t.finalize()}function c(n){return n.replace(/'/g,"''")}function a(n,t="\n"){return n.map(n=>function(n,t){const e=function(n,t){return n.map((e,i)=>`${i===n.length-1?"*p":"*pl"} '${c(e)}'${t}`).join("")}(n.description,t),i=n.code.length?n.code.join(t)+t:"",r=function(n,t){return n.length?n.map(n=>function(n,t){const e=c(n.name),i=n.image?`, '${c(n.image)}'`:"",r=n.code.map(n=>` ${n}${t}`).join("");return`act '${e}'${i}:${t}${r}end`}(n,t)).join(t)+t:""}(n.actions,t);return`# ${n.name}${t}${e}${r}${i}--- ${n.name} ---------------------------------${t}`}(n,t)).join(t)}export{i as readQsp,s as readQsps,o as writeQsp,a as writeQsps};
|
|
2
|
-
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.modern.js","sources":["../src/qsp-byte-stream.ts","../src/readers/qsp.ts","../src/readers/qsps.ts","../src/writers/qsp.ts","../src/writers/qsps.ts"],"sourcesContent":["export const QSP_CODREMOV = 5;\nconst QSP_STRSDELIM = '\\r\\n';\nexport const QSP_GAMEID = 'QSPGAME';\nexport const QSP_PASSWD = 'No';\n\n// prettier-ignore\nconst CP1251ToUnicodeTable: number[] = [\n 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac,\n 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, 0x0452, 0x2018,\n 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0020, 0x2122, 0x0459,\n 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, 0x00a0, 0x040e, 0x045e, 0x0408,\n 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac,\n 0x00ad, 0x00ae, 0x0407, 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5,\n 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455,\n 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,\n 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420,\n 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429,\n 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,\n 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b,\n 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444,\n 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d,\n 0x044e, 0x044f,\n];\n\nfunction convertCP1251(char: number): string {\n return String.fromCharCode(\n char >= 0x80 ? CP1251ToUnicodeTable[char - 0x80] : char\n );\n}\n\nexport class QspByteStream {\n private cursor = 0;\n private content: ArrayBuffer;\n private view: DataView;\n private isUnicode: boolean;\n\n public constructor(fromBuffer?: ArrayBuffer) {\n this.content = fromBuffer ?? new ArrayBuffer(256);\n this.view = new DataView(this.content);\n this.isUnicode = this.view.getUint8(1) === 0;\n }\n\n private ensureSize(size: number): void {\n if (this.content.byteLength >= size) return;\n const newLength = this.content.byteLength * 2;\n const buffer = new ArrayBuffer(newLength);\n new Uint8Array(buffer).set(new Uint8Array(this.content));\n this.content = buffer;\n this.view = new DataView(this.content);\n }\n\n public finalize(): ArrayBuffer {\n this.content = this.content.slice(0, this.cursor);\n return this.content;\n }\n\n public get eof(): boolean {\n return this.cursor >= this.content.byteLength;\n }\n\n public read(): number {\n const position = this.cursor;\n this.cursor += this.isUnicode\n ? Uint16Array.BYTES_PER_ELEMENT\n : Uint8Array.BYTES_PER_ELEMENT;\n return this.isUnicode\n ? this.view.getUint16(position, true)\n : this.view.getUint8(position);\n }\n\n public readLine(shouldDecode = true): string {\n const chars: number[] = [];\n while (!this.eof) {\n const char = this.read();\n if (char === 0x0d) {\n this.read();\n break;\n }\n if (shouldDecode) {\n chars.push(char === -QSP_CODREMOV ? QSP_CODREMOV : char + QSP_CODREMOV);\n } else {\n chars.push(char);\n }\n }\n return this.isUnicode\n ? // eslint-disable-next-line prefer-spread\n chars.map(char => String.fromCharCode(char)).join('')\n : chars.map(convertCP1251).join('');\n }\n\n public write(value: number): void {\n this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);\n const position = this.cursor;\n this.cursor += Int16Array.BYTES_PER_ELEMENT;\n this.view.setUint16(position, value, true);\n }\n\n public writeString(input: string, shouldEncode = true): void {\n const charCodes = input.split('').map((char): number => char.charCodeAt(0));\n for (const point of charCodes.values()) {\n if (shouldEncode) {\n this.write(\n point === QSP_CODREMOV ? -QSP_CODREMOV : point - QSP_CODREMOV\n );\n } else {\n this.write(point);\n }\n }\n }\n\n public writeLine(input: string, shouldEncode = true): void {\n input && this.writeString(input, shouldEncode);\n this.writeString(QSP_STRSDELIM, false);\n }\n\n public seek(offset: number): void {\n this.cursor = offset;\n }\n}\n","import { QspAction, QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID } from '../qsp-byte-stream';\n\n// format description https://github.com/QSPFoundation/qsp/blob/master/help/gam_desc.txt\n\nfunction readNewFormat(stream: QspByteStream): QspLocation[] {\n stream.readLine(false); // tool version\n stream.readLine(); // password\n const locCount = parseInt(stream.readLine());\n\n const locations: QspLocation[] = [];\n\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actsCount = parseInt(stream.readLine());\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const image = stream.readLine();\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n actions.push({ image, name: actionName, code: actionCode });\n }\n locations.push({ name, description, code, actions });\n }\n return locations;\n}\n\nfunction readOldFormat(stream: QspByteStream): QspLocation[] {\n stream.seek(0);\n const locCount = parseInt(stream.readLine(false));\n stream.readLine(); // password\n stream.readLine(false); // tool version\n for (let i = 0; i < 27; i++) {\n //empty reserved lines\n stream.readLine();\n }\n const locations: QspLocation[] = [];\n const actsCount = 20;\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n if (actionName) {\n actions.push({ name: actionName, code: actionCode });\n }\n }\n locations.push({ name, description, code, actions });\n }\n\n return locations;\n}\n\nexport function readQsp(buffer: ArrayBuffer): QspLocation[] {\n const stream = new QspByteStream(buffer);\n const header = stream.readLine(false);\n if (header === QSP_GAMEID) {\n return readNewFormat(stream);\n }\n\n return readOldFormat(stream);\n}\n","import { QspLocation } from '../contracts';\n\nconst QSP_STARTLOC = '#';\nconst QSP_ENDLOC = '-';\nconst QSP_QUOTES = [\"'\", '\"'];\nconst QSP_LCURLY = '{';\nconst QSP_RCURLY = '}';\n\nexport function readQsps(content: string): QspLocation[] {\n const locations: QspLocation[] = [];\n\n let isInLoc = false;\n let curLoc: QspLocation | null = null;\n let locCode: string[] = [];\n const lines = content.split(/\\r?\\n/);\n let quote = '';\n let quotesCount = 0;\n for (const line of lines) {\n if (isInLoc) {\n if (!quote && !quotesCount) {\n if (line.startsWith(QSP_ENDLOC)) {\n isInLoc = false;\n if (curLoc) {\n curLoc.code = locCode;\n locCode = [];\n locations.push(curLoc);\n curLoc = null;\n }\n continue;\n }\n }\n locCode.push(line);\n const chars = line.split('');\n for (let i = 0; i < chars.length; ++i) {\n const char = chars[i];\n if (quote) {\n if (char == quote) {\n if (chars[i + 1] == quote) {\n i++;\n } else {\n quote = '';\n }\n }\n } else {\n if (char == QSP_LCURLY) ++quotesCount;\n else if (char == QSP_RCURLY) {\n if (quotesCount) --quotesCount;\n } else if (QSP_QUOTES.includes(char)) quote = char;\n }\n }\n } else {\n if (line.startsWith(QSP_STARTLOC)) {\n isInLoc = true;\n curLoc = {\n name: line.slice(QSP_STARTLOC.length).trim(),\n description: [],\n code: [],\n actions: [],\n };\n }\n }\n }\n\n if (isInLoc && curLoc) {\n curLoc.code = locCode;\n locations.push(curLoc);\n }\n\n return locations;\n}\n","import { QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID, QSP_PASSWD } from '../qsp-byte-stream';\n\nexport function writeQsp(locations: QspLocation[]): ArrayBuffer {\n const stream = new QspByteStream();\n\n stream.writeLine(QSP_GAMEID, false);\n stream.writeLine('@qsp/converters 1.0', false);\n stream.writeLine(QSP_PASSWD);\n stream.writeLine(String(locations.length));\n\n for (const location of locations) {\n stream.writeLine(location.name);\n stream.writeLine(location.description.join('\\r\\n'));\n stream.writeLine(location.code.join('\\r\\n'));\n\n stream.writeLine(String(location.actions.length));\n for (const action of location.actions) {\n stream.writeLine(action.image ?? '');\n stream.writeLine(action.name);\n stream.writeLine(action.code.join('\\r\\n'));\n }\n }\n return stream.finalize();\n}\n","import { QspAction, QspLocation } from '../contracts';\n\nfunction escapeQspString(input: string): string {\n return input.replace(/'/g, \"''\");\n}\n\nfunction convertDescription(lines: string[], linebreak: string): string {\n return lines\n .map((line, index) => `${index === lines.length - 1 ? '*p' : '*pl'} '${escapeQspString(line)}'${linebreak}`)\n .join('');\n}\n\nfunction convertAction(action: QspAction, linebreak: string): string {\n const name = escapeQspString(action.name);\n const image = action.image ? `, '${escapeQspString(action.image)}'` : '';\n const code = action.code.map((line) => ` ${line}${linebreak}`).join('');\n return `act '${name}'${image}:${linebreak}${code}end`;\n}\n\nfunction convertActions(actions: QspAction[], linebreak: string): string {\n if (!actions.length) return '';\n return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;\n}\n\nfunction convertLocation(location: QspLocation, linebreak: string): string {\n const description = convertDescription(location.description, linebreak);\n const code = location.code.length ? location.code.join(linebreak) + linebreak : '';\n const actions = convertActions(location.actions, linebreak);\n return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;\n}\n\nexport function writeQsps(locations: QspLocation[], linebreak = '\\n'): string {\n return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);\n}\n"],"names":["char","fromCharCode","CP1251ToUnicodeTable","QspByteStream","constructor","fromBuffer","this","cursor","content","view","isUnicode","ArrayBuffer","DataView","getUint8","ensureSize","size","byteLength","buffer","set","Uint8Array","finalize","slice","read","position","Uint16Array","BYTES_PER_ELEMENT","getUint16","readLine","shouldDecode","eof","chars","push","map","String","join","convertCP1251","write","value","Int16Array","setUint16","writeString","input","shouldEncode","split","charCodeAt","point","charCodes","values","writeLine","seek","offset","readQsp","stream","parseInt","locations","i","locCount","name","code","actsCount","actions","j","actionName","image","actionCode","description","readNewFormat","readOldFormat","QSP_QUOTES","readQsps","isInLoc","curLoc","locCode","lines","quote","quotesCount","line","startsWith","length","includes","trim","writeQsp","location","action","_action$image","escapeQspString","replace","linebreak","index","convertDescription","convertAction","convertActions","convertLocation"],"mappings":"QAMuC,CACrC,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,GAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,IAAQ,KAAQ,KAAQ,KAChE,IAAQ,KAAQ,IAAQ,IAAQ,KAAQ,IAAQ,KAAQ,IAAQ,IAChE,IAAQ,IAAQ,KAAQ,IAAQ,IAAQ,KAAQ,KAAQ,KAAQ,IAChE,IAAQ,IAAQ,KAAQ,KAAQ,KAAQ,IAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,MA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AQkB,OACNlB,EAAQ5B,IAAKmD,GATtB,SAAuBA,EAAmBI,GACxC,MAAM9B,EAAO4B,EAAgBF,EAAO1B,MAC9BM,EAAQoB,EAAOpB,MAAc,MAAAsB,EAAgBF,EAAOpB,UAAY,KACzDoB,EAAOzB,KAAK1B,IAAK4C,GAAc,KAAAA,IAAOW,KAAarD,KAAK,IACrE,MAAO,QAAQuB,KAAQM,KAASwB,IAAY7B,OAKbgC,CAAcP,EAAQI,IAAYrD,KAAKqD,GAAaA,EADvD,GAOZI,CAAeT,EAAStB,QAAS2B,GACjD,WAAYL,EAASzB,OAAO8B,IAAYtB,IAAcL,IAAUF,QAAWwB,EAASzB,yCAAyC8B,IAI1FK,CAAgBV,EAAUK,IAAYrD,KAAKqD"}
|
package/dist/index.module.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function n(n,r){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,r){if(n){if("string"==typeof n)return e(n,r);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?e(n,r):void 0}}(n))||r&&n&&"number"==typeof n.length){t&&(n=t);var i=0;return function(){return i>=n.length?{done:!0}:{done:!1,value:n[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r=[1026,1027,8218,1107,8222,8230,8224,8225,8364,8240,1033,8249,1034,1036,1035,1039,1106,8216,8217,8220,8221,8226,8211,8212,32,8482,1113,8250,1114,1116,1115,1119,160,1038,1118,1032,164,1168,166,167,1025,169,1028,171,172,173,174,1031,176,177,1030,1110,1169,181,182,183,1105,8470,1108,187,1112,1029,1109,1111,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103];function t(e){return String.fromCharCode(e>=128?r[e-128]:e)}var i=/*#__PURE__*/function(){function e(e){this.cursor=0,this.content=void 0,this.view=void 0,this.isUnicode=void 0,this.content=null!=e?e:new ArrayBuffer(256),this.view=new DataView(this.content),this.isUnicode=0===this.view.getUint8(1)}var r,i,o=e.prototype;return o.ensureSize=function(e){if(!(this.content.byteLength>=e)){var n=new ArrayBuffer(2*this.content.byteLength);new Uint8Array(n).set(new Uint8Array(this.content)),this.content=n,this.view=new DataView(this.content)}},o.finalize=function(){return this.content=this.content.slice(0,this.cursor),this.content},o.read=function(){var e=this.cursor;return this.cursor+=this.isUnicode?Uint16Array.BYTES_PER_ELEMENT:Uint8Array.BYTES_PER_ELEMENT,this.isUnicode?this.view.getUint16(e,!0):this.view.getUint8(e)},o.readLine=function(e){void 0===e&&(e=!0);for(var n=[];!this.eof;){var r=this.read();if(13===r){this.read();break}n.push(e?-5===r?5:r+5:r)}return this.isUnicode?n.map(function(e){return String.fromCharCode(e)}).join(""):n.map(t).join("")},o.write=function(e){this.ensureSize(this.cursor+Int16Array.BYTES_PER_ELEMENT);var n=this.cursor;this.cursor+=Int16Array.BYTES_PER_ELEMENT,this.view.setUint16(n,e,!0)},o.writeString=function(e,r){void 0===r&&(r=!0);for(var t,i=n(e.split("").map(function(e){return e.charCodeAt(0)}).values());!(t=i()).done;){var o=t.value;this.write(r?5===o?-5:o-5:o)}},o.writeLine=function(e,n){void 0===n&&(n=!0),e&&this.writeString(e,n),this.writeString("\r\n",!1)},o.seek=function(e){this.cursor=e},r=e,(i=[{key:"eof",get:function(){return this.cursor>=this.content.byteLength}}])&&function(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}(r.prototype,i),Object.defineProperty(r,"prototype",{writable:!1}),e}();function o(e){var n=new i(e);return"QSPGAME"===n.readLine(!1)?function(e){e.readLine(!1),e.readLine();for(var n=parseInt(e.readLine()),r=[],t=0;t<n;t++){for(var i=e.readLine(),o=e.readLine().split(/\r?\n/),a=e.readLine().split(/\r?\n/),s=parseInt(e.readLine()),u=[],c=0;c<s;++c){var d=e.readLine(),f=e.readLine(),h=e.readLine().split(/\r?\n/);u.push({image:d,name:f,code:h})}r.push({name:i,description:o,code:a,actions:u})}return r}(n):function(e){e.seek(0);var n=parseInt(e.readLine(!1));e.readLine(),e.readLine(!1);for(var r=0;r<27;r++)e.readLine();for(var t=[],i=0;i<n;i++){for(var o=e.readLine(),a=e.readLine().split(/\r?\n/),s=e.readLine().split(/\r?\n/),u=[],c=0;c<20;++c){var d=e.readLine(),f=e.readLine().split(/\r?\n/);d&&u.push({name:d,code:f})}t.push({name:o,description:a,code:s,actions:u})}return t}(n)}var a=["'",'"'];function s(e){for(var r,t=[],i=!1,o=null,s=[],u="",c=0,d=n(e.split(/\r?\n/));!(r=d()).done;){var f=r.value;if(i){if(!u&&!c&&f.startsWith("-")){i=!1,o&&(o.code=s,s=[],t.push(o),o=null);continue}s.push(f);for(var h=f.split(""),l=0;l<h.length;++l){var v=h[l];u?v==u&&(h[l+1]==u?l++:u=""):"{"==v?++c:"}"==v?c&&--c:a.includes(v)&&(u=v)}}else f.startsWith("#")&&(i=!0,o={name:f.slice("#".length).trim(),description:[],code:[],actions:[]})}return i&&o&&(o.code=s,t.push(o)),t}function u(e){var r=new i;r.writeLine("QSPGAME",!1),r.writeLine("@qsp/converters 1.0",!1),r.writeLine("No"),r.writeLine(String(e.length));for(var t,o=n(e);!(t=o()).done;){var a=t.value;r.writeLine(a.name),r.writeLine(a.description.join("\r\n")),r.writeLine(a.code.join("\r\n")),r.writeLine(String(a.actions.length));for(var s,u=n(a.actions);!(s=u()).done;){var c,d=s.value;r.writeLine(null!=(c=d.image)?c:""),r.writeLine(d.name),r.writeLine(d.code.join("\r\n"))}}return r.finalize()}function c(e){return e.replace(/'/g,"''")}function d(e,n){return void 0===n&&(n="\n"),e.map(function(e){return function(e,n){var r=function(e,n){return e.map(function(r,t){return(t===e.length-1?"*p":"*pl")+" '"+c(r)+"'"+n}).join("")}(e.description,n),t=e.code.length?e.code.join(n)+n:"",i=function(e,n){return e.length?e.map(function(e){return function(e,n){var r=c(e.name),t=e.image?", '"+c(e.image)+"'":"",i=e.code.map(function(e){return" "+e+n}).join("");return"act '"+r+"'"+t+":"+n+i+"end"}(e,n)}).join(n)+n:""}(e.actions,n);return"# "+e.name+n+r+i+t+"--- "+e.name+" ---------------------------------"+n}(e,n)}).join(n)}export{o as readQsp,s as readQsps,u as writeQsp,d as writeQsps};
|
|
2
|
-
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/qsp-byte-stream.ts","../src/readers/qsp.ts","../src/readers/qsps.ts","../src/writers/qsp.ts","../src/writers/qsps.ts"],"sourcesContent":["export const QSP_CODREMOV = 5;\nconst QSP_STRSDELIM = '\\r\\n';\nexport const QSP_GAMEID = 'QSPGAME';\nexport const QSP_PASSWD = 'No';\n\n// prettier-ignore\nconst CP1251ToUnicodeTable: number[] = [\n 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac,\n 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, 0x0452, 0x2018,\n 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0020, 0x2122, 0x0459,\n 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, 0x00a0, 0x040e, 0x045e, 0x0408,\n 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac,\n 0x00ad, 0x00ae, 0x0407, 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5,\n 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455,\n 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,\n 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420,\n 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429,\n 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,\n 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b,\n 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444,\n 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d,\n 0x044e, 0x044f,\n];\n\nfunction convertCP1251(char: number): string {\n return String.fromCharCode(\n char >= 0x80 ? CP1251ToUnicodeTable[char - 0x80] : char\n );\n}\n\nexport class QspByteStream {\n private cursor = 0;\n private content: ArrayBuffer;\n private view: DataView;\n private isUnicode: boolean;\n\n public constructor(fromBuffer?: ArrayBuffer) {\n this.content = fromBuffer ?? new ArrayBuffer(256);\n this.view = new DataView(this.content);\n this.isUnicode = this.view.getUint8(1) === 0;\n }\n\n private ensureSize(size: number): void {\n if (this.content.byteLength >= size) return;\n const newLength = this.content.byteLength * 2;\n const buffer = new ArrayBuffer(newLength);\n new Uint8Array(buffer).set(new Uint8Array(this.content));\n this.content = buffer;\n this.view = new DataView(this.content);\n }\n\n public finalize(): ArrayBuffer {\n this.content = this.content.slice(0, this.cursor);\n return this.content;\n }\n\n public get eof(): boolean {\n return this.cursor >= this.content.byteLength;\n }\n\n public read(): number {\n const position = this.cursor;\n this.cursor += this.isUnicode\n ? Uint16Array.BYTES_PER_ELEMENT\n : Uint8Array.BYTES_PER_ELEMENT;\n return this.isUnicode\n ? this.view.getUint16(position, true)\n : this.view.getUint8(position);\n }\n\n public readLine(shouldDecode = true): string {\n const chars: number[] = [];\n while (!this.eof) {\n const char = this.read();\n if (char === 0x0d) {\n this.read();\n break;\n }\n if (shouldDecode) {\n chars.push(char === -QSP_CODREMOV ? QSP_CODREMOV : char + QSP_CODREMOV);\n } else {\n chars.push(char);\n }\n }\n return this.isUnicode\n ? // eslint-disable-next-line prefer-spread\n chars.map(char => String.fromCharCode(char)).join('')\n : chars.map(convertCP1251).join('');\n }\n\n public write(value: number): void {\n this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);\n const position = this.cursor;\n this.cursor += Int16Array.BYTES_PER_ELEMENT;\n this.view.setUint16(position, value, true);\n }\n\n public writeString(input: string, shouldEncode = true): void {\n const charCodes = input.split('').map((char): number => char.charCodeAt(0));\n for (const point of charCodes.values()) {\n if (shouldEncode) {\n this.write(\n point === QSP_CODREMOV ? -QSP_CODREMOV : point - QSP_CODREMOV\n );\n } else {\n this.write(point);\n }\n }\n }\n\n public writeLine(input: string, shouldEncode = true): void {\n input && this.writeString(input, shouldEncode);\n this.writeString(QSP_STRSDELIM, false);\n }\n\n public seek(offset: number): void {\n this.cursor = offset;\n }\n}\n","import { QspAction, QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID } from '../qsp-byte-stream';\n\n// format description https://github.com/QSPFoundation/qsp/blob/master/help/gam_desc.txt\n\nfunction readNewFormat(stream: QspByteStream): QspLocation[] {\n stream.readLine(false); // tool version\n stream.readLine(); // password\n const locCount = parseInt(stream.readLine());\n\n const locations: QspLocation[] = [];\n\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actsCount = parseInt(stream.readLine());\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const image = stream.readLine();\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n actions.push({ image, name: actionName, code: actionCode });\n }\n locations.push({ name, description, code, actions });\n }\n return locations;\n}\n\nfunction readOldFormat(stream: QspByteStream): QspLocation[] {\n stream.seek(0);\n const locCount = parseInt(stream.readLine(false));\n stream.readLine(); // password\n stream.readLine(false); // tool version\n for (let i = 0; i < 27; i++) {\n //empty reserved lines\n stream.readLine();\n }\n const locations: QspLocation[] = [];\n const actsCount = 20;\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n if (actionName) {\n actions.push({ name: actionName, code: actionCode });\n }\n }\n locations.push({ name, description, code, actions });\n }\n\n return locations;\n}\n\nexport function readQsp(buffer: ArrayBuffer): QspLocation[] {\n const stream = new QspByteStream(buffer);\n const header = stream.readLine(false);\n if (header === QSP_GAMEID) {\n return readNewFormat(stream);\n }\n\n return readOldFormat(stream);\n}\n","import { QspLocation } from '../contracts';\n\nconst QSP_STARTLOC = '#';\nconst QSP_ENDLOC = '-';\nconst QSP_QUOTES = [\"'\", '\"'];\nconst QSP_LCURLY = '{';\nconst QSP_RCURLY = '}';\n\nexport function readQsps(content: string): QspLocation[] {\n const locations: QspLocation[] = [];\n\n let isInLoc = false;\n let curLoc: QspLocation | null = null;\n let locCode: string[] = [];\n const lines = content.split(/\\r?\\n/);\n let quote = '';\n let quotesCount = 0;\n for (const line of lines) {\n if (isInLoc) {\n if (!quote && !quotesCount) {\n if (line.startsWith(QSP_ENDLOC)) {\n isInLoc = false;\n if (curLoc) {\n curLoc.code = locCode;\n locCode = [];\n locations.push(curLoc);\n curLoc = null;\n }\n continue;\n }\n }\n locCode.push(line);\n const chars = line.split('');\n for (let i = 0; i < chars.length; ++i) {\n const char = chars[i];\n if (quote) {\n if (char == quote) {\n if (chars[i + 1] == quote) {\n i++;\n } else {\n quote = '';\n }\n }\n } else {\n if (char == QSP_LCURLY) ++quotesCount;\n else if (char == QSP_RCURLY) {\n if (quotesCount) --quotesCount;\n } else if (QSP_QUOTES.includes(char)) quote = char;\n }\n }\n } else {\n if (line.startsWith(QSP_STARTLOC)) {\n isInLoc = true;\n curLoc = {\n name: line.slice(QSP_STARTLOC.length).trim(),\n description: [],\n code: [],\n actions: [],\n };\n }\n }\n }\n\n if (isInLoc && curLoc) {\n curLoc.code = locCode;\n locations.push(curLoc);\n }\n\n return locations;\n}\n","import { QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID, QSP_PASSWD } from '../qsp-byte-stream';\n\nexport function writeQsp(locations: QspLocation[]): ArrayBuffer {\n const stream = new QspByteStream();\n\n stream.writeLine(QSP_GAMEID, false);\n stream.writeLine('@qsp/converters 1.0', false);\n stream.writeLine(QSP_PASSWD);\n stream.writeLine(String(locations.length));\n\n for (const location of locations) {\n stream.writeLine(location.name);\n stream.writeLine(location.description.join('\\r\\n'));\n stream.writeLine(location.code.join('\\r\\n'));\n\n stream.writeLine(String(location.actions.length));\n for (const action of location.actions) {\n stream.writeLine(action.image ?? '');\n stream.writeLine(action.name);\n stream.writeLine(action.code.join('\\r\\n'));\n }\n }\n return stream.finalize();\n}\n","import { QspAction, QspLocation } from '../contracts';\n\nfunction escapeQspString(input: string): string {\n return input.replace(/'/g, \"''\");\n}\n\nfunction convertDescription(lines: string[], linebreak: string): string {\n return lines\n .map((line, index) => `${index === lines.length - 1 ? '*p' : '*pl'} '${escapeQspString(line)}'${linebreak}`)\n .join('');\n}\n\nfunction convertAction(action: QspAction, linebreak: string): string {\n const name = escapeQspString(action.name);\n const image = action.image ? `, '${escapeQspString(action.image)}'` : '';\n const code = action.code.map((line) => ` ${line}${linebreak}`).join('');\n return `act '${name}'${image}:${linebreak}${code}end`;\n}\n\nfunction convertActions(actions: QspAction[], linebreak: string): string {\n if (!actions.length) return '';\n return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;\n}\n\nfunction convertLocation(location: QspLocation, linebreak: string): string {\n const description = convertDescription(location.description, linebreak);\n const code = location.code.length ? location.code.join(linebreak) + linebreak : '';\n const actions = convertActions(location.actions, linebreak);\n return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;\n}\n\nexport function writeQsps(locations: QspLocation[], linebreak = '\\n'): string {\n return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);\n}\n"],"names":["CP1251ToUnicodeTable","convertCP1251","char","String","fromCharCode","QspByteStream","fromBuffer","cursor","this","content","view","isUnicode","ArrayBuffer","DataView","getUint8","ensureSize","size","byteLength","buffer","set","Uint8Array","finalize","slice","read","Uint16Array","BYTES_PER_ELEMENT","getUint16","position","readLine","shouldDecode","eof","chars","push","map","join","write","value","Int16Array","setUint16","writeString","input","shouldEncode","_step","_iterator","_createForOfIteratorHelperLoose","split","charCodeAt","values","done","point","writeLine","seek","offset","readQsp","stream","locCount","parseInt","locations","i","name","description","code","actsCount","actions","j","image","actionName","actionCode","readNewFormat","readOldFormat","QSP_QUOTES","readQsps","isInLoc","curLoc","locCode","quote","quotesCount","line","startsWith","length","_char","includes","trim","writeQsp","location","_step2","_iterator2","action","_action$image","escapeQspString","replace","writeQsps","linebreak","convertLocation","lines","index","convertDescription","convertAction","convertActions"],"mappings":"szBAAO,IAMmBA,EAAa,CACrC,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,GAAQ,KAAQ,KAChE,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,IAAQ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AAC9B,IAAI,SAACsD,UATtB,SAAuBA,EAAmBK,GACxC,IAAMjC,EAAO8B,EAAgBF,EAAO5B,MAC9BM,EAAQsB,EAAOtB,MAAP,MAAqBwB,EAAgBF,EAAOtB,OAAY,IAAA,GAC5DJ,EAAG0B,EAAO1B,KAAK5B,IAAI,SAAC4C,GAAD,MAAA,KAAeA,EAAOe,IAAa1D,KAAK,IACrE,cAAeyB,EAAf,IAAuBM,EAAvB,IAAgC2B,EAAY/B,EAA5C,MAK4CoC,CAACV,EAAQK,KAAY1D,KAAK0D,GAAaA,EADvD,GAOZM,CAAed,EAASrB,QAAS6B,GACjD,WAAYR,EAASzB,KAAOiC,EAAYhC,EAAcG,EAAUF,EAAhE,OAA2EuB,EAASzB,KAApF,qCAA6HiC,EAI1FC,CAAgBT,EAAUQ,KAAY1D,KAAK0D"}
|
package/dist/index.umd.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).converters={})}(this,function(e){function n(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function t(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r="QSPGAME",i=[1026,1027,8218,1107,8222,8230,8224,8225,8364,8240,1033,8249,1034,1036,1035,1039,1106,8216,8217,8220,8221,8226,8211,8212,32,8482,1113,8250,1114,1116,1115,1119,160,1038,1118,1032,164,1168,166,167,1025,169,1028,171,172,173,174,1031,176,177,1030,1110,1169,181,182,183,1105,8470,1108,187,1112,1029,1109,1111,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103];function o(e){return String.fromCharCode(e>=128?i[e-128]:e)}var a=/*#__PURE__*/function(){function e(e){this.cursor=0,this.content=void 0,this.view=void 0,this.isUnicode=void 0,this.content=null!=e?e:new ArrayBuffer(256),this.view=new DataView(this.content),this.isUnicode=0===this.view.getUint8(1)}var n,r,i=e.prototype;return i.ensureSize=function(e){if(!(this.content.byteLength>=e)){var n=new ArrayBuffer(2*this.content.byteLength);new Uint8Array(n).set(new Uint8Array(this.content)),this.content=n,this.view=new DataView(this.content)}},i.finalize=function(){return this.content=this.content.slice(0,this.cursor),this.content},i.read=function(){var e=this.cursor;return this.cursor+=this.isUnicode?Uint16Array.BYTES_PER_ELEMENT:Uint8Array.BYTES_PER_ELEMENT,this.isUnicode?this.view.getUint16(e,!0):this.view.getUint8(e)},i.readLine=function(e){void 0===e&&(e=!0);for(var n=[];!this.eof;){var t=this.read();if(13===t){this.read();break}n.push(e?-5===t?5:t+5:t)}return this.isUnicode?n.map(function(e){return String.fromCharCode(e)}).join(""):n.map(o).join("")},i.write=function(e){this.ensureSize(this.cursor+Int16Array.BYTES_PER_ELEMENT);var n=this.cursor;this.cursor+=Int16Array.BYTES_PER_ELEMENT,this.view.setUint16(n,e,!0)},i.writeString=function(e,n){void 0===n&&(n=!0);for(var r,i=t(e.split("").map(function(e){return e.charCodeAt(0)}).values());!(r=i()).done;){var o=r.value;this.write(n?5===o?-5:o-5:o)}},i.writeLine=function(e,n){void 0===n&&(n=!0),e&&this.writeString(e,n),this.writeString("\r\n",!1)},i.seek=function(e){this.cursor=e},n=e,(r=[{key:"eof",get:function(){return this.cursor>=this.content.byteLength}}])&&function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),e}(),s=["'",'"'];function u(e){return e.replace(/'/g,"''")}e.readQsp=function(e){var n=new a(e);return n.readLine(!1)===r?function(e){e.readLine(!1),e.readLine();for(var n=parseInt(e.readLine()),t=[],r=0;r<n;r++){for(var i=e.readLine(),o=e.readLine().split(/\r?\n/),a=e.readLine().split(/\r?\n/),s=parseInt(e.readLine()),u=[],c=0;c<s;++c){var f=e.readLine(),d=e.readLine(),h=e.readLine().split(/\r?\n/);u.push({image:f,name:d,code:h})}t.push({name:i,description:o,code:a,actions:u})}return t}(n):function(e){e.seek(0);var n=parseInt(e.readLine(!1));e.readLine(),e.readLine(!1);for(var t=0;t<27;t++)e.readLine();for(var r=[],i=0;i<n;i++){for(var o=e.readLine(),a=e.readLine().split(/\r?\n/),s=e.readLine().split(/\r?\n/),u=[],c=0;c<20;++c){var f=e.readLine(),d=e.readLine().split(/\r?\n/);f&&u.push({name:f,code:d})}r.push({name:o,description:a,code:s,actions:u})}return r}(n)},e.readQsps=function(e){for(var n,r=[],i=!1,o=null,a=[],u="",c=0,f=t(e.split(/\r?\n/));!(n=f()).done;){var d=n.value;if(i){if(!u&&!c&&d.startsWith("-")){i=!1,o&&(o.code=a,a=[],r.push(o),o=null);continue}a.push(d);for(var h=d.split(""),l=0;l<h.length;++l){var p=h[l];u?p==u&&(h[l+1]==u?l++:u=""):"{"==p?++c:"}"==p?c&&--c:s.includes(p)&&(u=p)}}else d.startsWith("#")&&(i=!0,o={name:d.slice("#".length).trim(),description:[],code:[],actions:[]})}return i&&o&&(o.code=a,r.push(o)),r},e.writeQsp=function(e){var n=new a;n.writeLine(r,!1),n.writeLine("@qsp/converters 1.0",!1),n.writeLine("No"),n.writeLine(String(e.length));for(var i,o=t(e);!(i=o()).done;){var s=i.value;n.writeLine(s.name),n.writeLine(s.description.join("\r\n")),n.writeLine(s.code.join("\r\n")),n.writeLine(String(s.actions.length));for(var u,c=t(s.actions);!(u=c()).done;){var f,d=u.value;n.writeLine(null!=(f=d.image)?f:""),n.writeLine(d.name),n.writeLine(d.code.join("\r\n"))}}return n.finalize()},e.writeQsps=function(e,n){return void 0===n&&(n="\n"),e.map(function(e){return function(e,n){var t=function(e,n){return e.map(function(t,r){return(r===e.length-1?"*p":"*pl")+" '"+u(t)+"'"+n}).join("")}(e.description,n),r=e.code.length?e.code.join(n)+n:"",i=function(e,n){return e.length?e.map(function(e){return function(e,n){var t=u(e.name),r=e.image?", '"+u(e.image)+"'":"",i=e.code.map(function(e){return" "+e+n}).join("");return"act '"+t+"'"+r+":"+n+i+"end"}(e,n)}).join(n)+n:""}(e.actions,n);return"# "+e.name+n+t+i+r+"--- "+e.name+" ---------------------------------"+n}(e,n)}).join(n)}});
|
|
2
|
-
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/qsp-byte-stream.ts","../src/readers/qsps.ts","../src/writers/qsps.ts","../src/readers/qsp.ts","../src/writers/qsp.ts"],"sourcesContent":["export const QSP_CODREMOV = 5;\nconst QSP_STRSDELIM = '\\r\\n';\nexport const QSP_GAMEID = 'QSPGAME';\nexport const QSP_PASSWD = 'No';\n\n// prettier-ignore\nconst CP1251ToUnicodeTable: number[] = [\n 0x0402, 0x0403, 0x201a, 0x0453, 0x201e, 0x2026, 0x2020, 0x2021, 0x20ac,\n 0x2030, 0x0409, 0x2039, 0x040a, 0x040c, 0x040b, 0x040f, 0x0452, 0x2018,\n 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x0020, 0x2122, 0x0459,\n 0x203a, 0x045a, 0x045c, 0x045b, 0x045f, 0x00a0, 0x040e, 0x045e, 0x0408,\n 0x00a4, 0x0490, 0x00a6, 0x00a7, 0x0401, 0x00a9, 0x0404, 0x00ab, 0x00ac,\n 0x00ad, 0x00ae, 0x0407, 0x00b0, 0x00b1, 0x0406, 0x0456, 0x0491, 0x00b5,\n 0x00b6, 0x00b7, 0x0451, 0x2116, 0x0454, 0x00bb, 0x0458, 0x0405, 0x0455,\n 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,\n 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420,\n 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429,\n 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,\n 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b,\n 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444,\n 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d,\n 0x044e, 0x044f,\n];\n\nfunction convertCP1251(char: number): string {\n return String.fromCharCode(\n char >= 0x80 ? CP1251ToUnicodeTable[char - 0x80] : char\n );\n}\n\nexport class QspByteStream {\n private cursor = 0;\n private content: ArrayBuffer;\n private view: DataView;\n private isUnicode: boolean;\n\n public constructor(fromBuffer?: ArrayBuffer) {\n this.content = fromBuffer ?? new ArrayBuffer(256);\n this.view = new DataView(this.content);\n this.isUnicode = this.view.getUint8(1) === 0;\n }\n\n private ensureSize(size: number): void {\n if (this.content.byteLength >= size) return;\n const newLength = this.content.byteLength * 2;\n const buffer = new ArrayBuffer(newLength);\n new Uint8Array(buffer).set(new Uint8Array(this.content));\n this.content = buffer;\n this.view = new DataView(this.content);\n }\n\n public finalize(): ArrayBuffer {\n this.content = this.content.slice(0, this.cursor);\n return this.content;\n }\n\n public get eof(): boolean {\n return this.cursor >= this.content.byteLength;\n }\n\n public read(): number {\n const position = this.cursor;\n this.cursor += this.isUnicode\n ? Uint16Array.BYTES_PER_ELEMENT\n : Uint8Array.BYTES_PER_ELEMENT;\n return this.isUnicode\n ? this.view.getUint16(position, true)\n : this.view.getUint8(position);\n }\n\n public readLine(shouldDecode = true): string {\n const chars: number[] = [];\n while (!this.eof) {\n const char = this.read();\n if (char === 0x0d) {\n this.read();\n break;\n }\n if (shouldDecode) {\n chars.push(char === -QSP_CODREMOV ? QSP_CODREMOV : char + QSP_CODREMOV);\n } else {\n chars.push(char);\n }\n }\n return this.isUnicode\n ? // eslint-disable-next-line prefer-spread\n chars.map(char => String.fromCharCode(char)).join('')\n : chars.map(convertCP1251).join('');\n }\n\n public write(value: number): void {\n this.ensureSize(this.cursor + Int16Array.BYTES_PER_ELEMENT);\n const position = this.cursor;\n this.cursor += Int16Array.BYTES_PER_ELEMENT;\n this.view.setUint16(position, value, true);\n }\n\n public writeString(input: string, shouldEncode = true): void {\n const charCodes = input.split('').map((char): number => char.charCodeAt(0));\n for (const point of charCodes.values()) {\n if (shouldEncode) {\n this.write(\n point === QSP_CODREMOV ? -QSP_CODREMOV : point - QSP_CODREMOV\n );\n } else {\n this.write(point);\n }\n }\n }\n\n public writeLine(input: string, shouldEncode = true): void {\n input && this.writeString(input, shouldEncode);\n this.writeString(QSP_STRSDELIM, false);\n }\n\n public seek(offset: number): void {\n this.cursor = offset;\n }\n}\n","import { QspLocation } from '../contracts';\n\nconst QSP_STARTLOC = '#';\nconst QSP_ENDLOC = '-';\nconst QSP_QUOTES = [\"'\", '\"'];\nconst QSP_LCURLY = '{';\nconst QSP_RCURLY = '}';\n\nexport function readQsps(content: string): QspLocation[] {\n const locations: QspLocation[] = [];\n\n let isInLoc = false;\n let curLoc: QspLocation | null = null;\n let locCode: string[] = [];\n const lines = content.split(/\\r?\\n/);\n let quote = '';\n let quotesCount = 0;\n for (const line of lines) {\n if (isInLoc) {\n if (!quote && !quotesCount) {\n if (line.startsWith(QSP_ENDLOC)) {\n isInLoc = false;\n if (curLoc) {\n curLoc.code = locCode;\n locCode = [];\n locations.push(curLoc);\n curLoc = null;\n }\n continue;\n }\n }\n locCode.push(line);\n const chars = line.split('');\n for (let i = 0; i < chars.length; ++i) {\n const char = chars[i];\n if (quote) {\n if (char == quote) {\n if (chars[i + 1] == quote) {\n i++;\n } else {\n quote = '';\n }\n }\n } else {\n if (char == QSP_LCURLY) ++quotesCount;\n else if (char == QSP_RCURLY) {\n if (quotesCount) --quotesCount;\n } else if (QSP_QUOTES.includes(char)) quote = char;\n }\n }\n } else {\n if (line.startsWith(QSP_STARTLOC)) {\n isInLoc = true;\n curLoc = {\n name: line.slice(QSP_STARTLOC.length).trim(),\n description: [],\n code: [],\n actions: [],\n };\n }\n }\n }\n\n if (isInLoc && curLoc) {\n curLoc.code = locCode;\n locations.push(curLoc);\n }\n\n return locations;\n}\n","import { QspAction, QspLocation } from '../contracts';\n\nfunction escapeQspString(input: string): string {\n return input.replace(/'/g, \"''\");\n}\n\nfunction convertDescription(lines: string[], linebreak: string): string {\n return lines\n .map((line, index) => `${index === lines.length - 1 ? '*p' : '*pl'} '${escapeQspString(line)}'${linebreak}`)\n .join('');\n}\n\nfunction convertAction(action: QspAction, linebreak: string): string {\n const name = escapeQspString(action.name);\n const image = action.image ? `, '${escapeQspString(action.image)}'` : '';\n const code = action.code.map((line) => ` ${line}${linebreak}`).join('');\n return `act '${name}'${image}:${linebreak}${code}end`;\n}\n\nfunction convertActions(actions: QspAction[], linebreak: string): string {\n if (!actions.length) return '';\n return actions.map((action) => convertAction(action, linebreak)).join(linebreak) + linebreak;\n}\n\nfunction convertLocation(location: QspLocation, linebreak: string): string {\n const description = convertDescription(location.description, linebreak);\n const code = location.code.length ? location.code.join(linebreak) + linebreak : '';\n const actions = convertActions(location.actions, linebreak);\n return `# ${location.name}${linebreak}${description}${actions}${code}--- ${location.name} ---------------------------------${linebreak}`;\n}\n\nexport function writeQsps(locations: QspLocation[], linebreak = '\\n'): string {\n return locations.map((location) => convertLocation(location, linebreak)).join(linebreak);\n}\n","import { QspAction, QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID } from '../qsp-byte-stream';\n\n// format description https://github.com/QSPFoundation/qsp/blob/master/help/gam_desc.txt\n\nfunction readNewFormat(stream: QspByteStream): QspLocation[] {\n stream.readLine(false); // tool version\n stream.readLine(); // password\n const locCount = parseInt(stream.readLine());\n\n const locations: QspLocation[] = [];\n\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actsCount = parseInt(stream.readLine());\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const image = stream.readLine();\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n actions.push({ image, name: actionName, code: actionCode });\n }\n locations.push({ name, description, code, actions });\n }\n return locations;\n}\n\nfunction readOldFormat(stream: QspByteStream): QspLocation[] {\n stream.seek(0);\n const locCount = parseInt(stream.readLine(false));\n stream.readLine(); // password\n stream.readLine(false); // tool version\n for (let i = 0; i < 27; i++) {\n //empty reserved lines\n stream.readLine();\n }\n const locations: QspLocation[] = [];\n const actsCount = 20;\n for (let i = 0; i < locCount; i++) {\n const name = stream.readLine();\n const description = stream.readLine().split(/\\r?\\n/);\n const code = stream.readLine().split(/\\r?\\n/);\n\n const actions: QspAction[] = [];\n for (let j = 0; j < actsCount; ++j) {\n const actionName = stream.readLine();\n const actionCode = stream.readLine().split(/\\r?\\n/);\n if (actionName) {\n actions.push({ name: actionName, code: actionCode });\n }\n }\n locations.push({ name, description, code, actions });\n }\n\n return locations;\n}\n\nexport function readQsp(buffer: ArrayBuffer): QspLocation[] {\n const stream = new QspByteStream(buffer);\n const header = stream.readLine(false);\n if (header === QSP_GAMEID) {\n return readNewFormat(stream);\n }\n\n return readOldFormat(stream);\n}\n","import { QspLocation } from '../contracts';\nimport { QspByteStream, QSP_GAMEID, QSP_PASSWD } from '../qsp-byte-stream';\n\nexport function writeQsp(locations: QspLocation[]): ArrayBuffer {\n const stream = new QspByteStream();\n\n stream.writeLine(QSP_GAMEID, false);\n stream.writeLine('@qsp/converters 1.0', false);\n stream.writeLine(QSP_PASSWD);\n stream.writeLine(String(locations.length));\n\n for (const location of locations) {\n stream.writeLine(location.name);\n stream.writeLine(location.description.join('\\r\\n'));\n stream.writeLine(location.code.join('\\r\\n'));\n\n stream.writeLine(String(location.actions.length));\n for (const action of location.actions) {\n stream.writeLine(action.image ?? '');\n stream.writeLine(action.name);\n stream.writeLine(action.code.join('\\r\\n'));\n }\n }\n return stream.finalize();\n}\n"],"names":["QSP_GAMEID","CP1251ToUnicodeTable","convertCP1251","char","String","fromCharCode","QspByteStream","fromBuffer","cursor","this","content","view","isUnicode","ArrayBuffer","DataView","getUint8","ensureSize","size","byteLength","buffer","set","Uint8Array","finalize","slice","read","Uint16Array","BYTES_PER_ELEMENT","getUint16","position","readLine","shouldDecode","eof","chars","push","map","join","write","value","Int16Array","setUint16","writeString","input","shouldEncode","_step","_iterator","_createForOfIteratorHelperLoose","split","charCodeAt","values","done","point","writeLine","seek","offset","QSP_QUOTES","escapeQspString","replace","readQsp","stream","locCount","parseInt","locations","i","name","description","code","actsCount","actions","j","image","actionName","actionCode","readNewFormat","readOldFormat","isInLoc","curLoc","locCode","quote","quotesCount","line","startsWith","length","_char","includes","trim","location","_step2","_iterator2","action","_action$image","writeQsps","linebreak","convertLocation","lines","index","convertDescription","convertAction","convertActions"],"mappings":"0hCAAO,IAEMA,EAAa,UAIAC,EAAa,CACrC,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAAQ,KAChE,KAAQ,KAAQ,KA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,KAAK9B,KAAKwD,GAAaA,EAAY,GAC1ExB,EARR,SAAwBA,EAAsBwB,GAC5C,OAAKxB,EAAQc,OACCd,EAACjC,IAAI,SAACsD,UATtB,SAAuBA,EAAmBG,GACxC,IAAM5B,EAAOR,EAAgBiC,EAAOzB,MAC9BM,EAAQmB,EAAOnB,MAAP,MAAqBd,EAAgBiC,EAAOnB,OAAY,IAAA,GAC5DJ,EAAGuB,EAAOvB,KAAK/B,IAAI,SAAC6C,GAAD,MAAA,KAAeA,EAAOY,IAAaxD,KAAK,IACrE,cAAe4B,EAAf,IAAuBM,EAAvB,IAAgCsB,EAAY1B,EAA5C,MAK4C+B,CAACR,EAAQG,KAAYxD,KAAKwD,GAAaA,EADvD,GAOZM,CAAeZ,EAASlB,QAASwB,GACjD,WAAYN,EAAStB,KAAO4B,EAAY3B,EAAcG,EAAUF,EAAhE,OAA2EoB,EAAStB,KAApF,qCAA6H4B,EAI1FC,CAAgBP,EAAUM,KAAYxD,KAAKwD"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare const QSP_CODREMOV = 5;
|
|
2
|
-
export declare const QSP_GAMEID = "QSPGAME";
|
|
3
|
-
export declare const QSP_PASSWD = "No";
|
|
4
|
-
export declare class QspByteStream {
|
|
5
|
-
private cursor;
|
|
6
|
-
private content;
|
|
7
|
-
private view;
|
|
8
|
-
private isUnicode;
|
|
9
|
-
constructor(fromBuffer?: ArrayBuffer);
|
|
10
|
-
private ensureSize;
|
|
11
|
-
finalize(): ArrayBuffer;
|
|
12
|
-
get eof(): boolean;
|
|
13
|
-
read(): number;
|
|
14
|
-
readLine(shouldDecode?: boolean): string;
|
|
15
|
-
write(value: number): void;
|
|
16
|
-
writeString(input: string, shouldEncode?: boolean): void;
|
|
17
|
-
writeLine(input: string, shouldEncode?: boolean): void;
|
|
18
|
-
seek(offset: number): void;
|
|
19
|
-
}
|
package/dist/readers/qsp.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/readers/qsps.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/writers/qsp.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/writers/qsps.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|