@qsp/converters 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Sergii Kostyrko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # QSP file format converters
2
+
3
+ Converters of different file formats for QSP platform [http://qsp.org/](http://qsp.org/)
4
+ ## Installation
5
+
6
+ ```bash
7
+ npm install --save @qsp/converters
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ This library has separate functions for reading and writing file formats. QSP primary format is binary, but there exists also commonly agreed text format. Library references these 2 formats as `qsp` for binary and `qsps` for text format. File reading/writing was deliberately not made a part of library so it can easily be used in any environment (browser or Node.js) that supports ArrayBuffer and typed arrays.
13
+ Text format is expecting `utf8` encoded string so if you have string in different encoding you need to convert it before using library.
14
+
15
+ ### Reading
16
+
17
+ ```typescript
18
+ function readQsp(buffer: ArrayBuffer): QspLocation[];
19
+ function readQsps(content: string): QspLocation[];
20
+ ```
21
+
22
+ ### Writing
23
+
24
+ ```typescript
25
+ function function writeQsp(locations: QspLocation[]): ArrayBuffer;
26
+ function function writeQsps(locations: QspLocation[], linebreak?: string): string;
27
+ ```
28
+
29
+ `writeQsps` uses `\n` as line-break by default but this can be configured using second argument.
30
+
31
+ ## Licensing
32
+
33
+ The code in this project is licensed under MIT license.
@@ -0,0 +1,11 @@
1
+ export interface QspLocation {
2
+ name: string;
3
+ description: string[];
4
+ code: string[];
5
+ actions: QspAction[];
6
+ }
7
+ export interface QspAction {
8
+ name: string;
9
+ image?: string;
10
+ code: string[];
11
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
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}(),o=["'",'"'];function a(e){return e.replace(/'/g,"''")}exports.readQsp=function(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)},exports.readQsps=function(e){for(var r,t=[],i=!1,a=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,a&&(a.code=s,s=[],t.push(a),a=null);continue}s.push(f);for(var h=f.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:o.includes(p)&&(u=p)}}else f.startsWith("#")&&(i=!0,a={name:f.slice("#".length).trim(),description:[],code:[],actions:[]})}return i&&a&&(a.code=s,t.push(a)),t},exports.writeQsp=function(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()},exports.writeQsps=function(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")+" '"+a(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=a(e.name),t=e.image?", '"+a(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)};
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,I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AAOnB,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"}
@@ -0,0 +1,5 @@
1
+ export * from './contracts';
2
+ export * from './readers/qsp';
3
+ export * from './readers/qsps';
4
+ export * from './writers/qsp';
5
+ export * from './writers/qsps';
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
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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GACjD,WAAYL,EAASzB,OAAO8B,IAAYtB,IAAcL,IAAUF,QAAWwB,EAASzB,yCAAyC8B,IAI1FK,CAAgBV,EAAUK,IAAYrD,KAAKqD"}
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
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,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,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cG,EAAUF,EAAhE,OAA2EuB,EAASzB,KAApF,qCAA6HiC,EAI1FC,CAAgBT,EAAUQ,KAAY1D,KAAK0D"}
@@ -0,0 +1,2 @@
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
@@ -0,0 +1 @@
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,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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B,EAAY3B,EAAcG,EAAUF,EAAhE,OAA2EoB,EAAStB,KAApF,qCAA6H4B,EAI1FC,CAAgBP,EAAUM,KAAYxD,KAAKwD"}
@@ -0,0 +1,19 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ import { QspLocation } from '../contracts';
2
+ export declare function readQsp(buffer: ArrayBuffer): QspLocation[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { QspLocation } from '../contracts';
2
+ export declare function readQsps(content: string): QspLocation[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { QspLocation } from '../contracts';
2
+ export declare function writeQsp(locations: QspLocation[]): ArrayBuffer;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { QspLocation } from '../contracts';
2
+ export declare function writeQsps(locations: QspLocation[], linebreak?: string): string;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@qsp/converters",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "Converters of different file formats for QSP platform",
6
+ "keywords": [
7
+ "qsp",
8
+ "qsps",
9
+ "file",
10
+ "converter"
11
+ ],
12
+ "homepage": "https://github.com/QSPFoundation/converters#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/QSPFoundation/converters/issues"
15
+ },
16
+ "license": "MIT",
17
+ "author": "Sergii Kostyrko <srg.kostyrko@gmail.com>",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/QSPFoundation/converters.git"
21
+ },
22
+ "source": "src/index.ts",
23
+ "exports": {
24
+ "require": "./dist/index.cjs",
25
+ "default": "./dist/index.modern.js"
26
+ },
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.module.js",
29
+ "unpkg": "./dist/index.umd.js",
30
+ "typings": "dist/index.d.ts",
31
+ "engines": {
32
+ "node": ">=14"
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "build": "microbundle",
39
+ "dev": "microbundle watch",
40
+ "test": "jest",
41
+ "lint": "eslint .",
42
+ "prerelease": "npm run build",
43
+ "release": "np"
44
+ },
45
+ "husky": {
46
+ "hooks": {
47
+ "pre-commit": "lint-staged"
48
+ }
49
+ },
50
+ "devDependencies": {
51
+ "@types/jest": "^28.1.2",
52
+ "@typescript-eslint/eslint-plugin": "^5.28.0",
53
+ "@typescript-eslint/parser": "^5.28.0",
54
+ "eslint": "^8.18.0",
55
+ "eslint-config-prettier": "^8.5.0",
56
+ "eslint-plugin-import": "^2.26.0",
57
+ "husky": "^8.0.1",
58
+ "jest": "^28.1.1",
59
+ "lint-staged": "^13.0.2",
60
+ "microbundle": "^0.15.0",
61
+ "np": "^7.6.2",
62
+ "prettier": "2.7.1",
63
+ "ts-jest": "^28.0.5",
64
+ "ts-node": "^10.8.1",
65
+ "tslib": "^2.4.0",
66
+ "typescript": "^4.7.4"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public"
70
+ }
71
+ }