|
@@ -1,4 +1,6 @@
|
|
import qsrc2tw from "./src/qsrc2tw.js";
|
|
import qsrc2tw from "./src/qsrc2tw.js";
|
|
|
|
+import npcInit from "./src/npcInit.js";
|
|
|
|
+import skillDefinitions from "./src/skillDefinitions.js";
|
|
|
|
|
|
import {glob} from 'glob';
|
|
import {glob} from 'glob';
|
|
import fs from 'node:fs';
|
|
import fs from 'node:fs';
|
|
@@ -104,44 +106,74 @@ async function convertFile(filePath){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
const startTime = (new Date()).getTime();
|
|
const startTime = (new Date()).getTime();
|
|
- const codeHash = md5(data);
|
|
|
|
|
|
+
|
|
const baseFileNameStr = baseFileName(filePath);
|
|
const baseFileNameStr = baseFileName(filePath);
|
|
const outFilePath = path.join(outPath,generatedFilesPrefix,baseFileNameStr.split('.')[0]+'.tw');
|
|
const outFilePath = path.join(outPath,generatedFilesPrefix,baseFileNameStr.split('.')[0]+'.tw');
|
|
-
|
|
|
|
- if((data.split('\n')?.[1]).startsWith("!! SKIP_QSRC2TW")){
|
|
|
|
|
|
+ const outFilePathTS = path.join(outPath,generatedFilesPrefix,baseFileNameStr.split('.')[0]+'.ts');
|
|
|
|
+
|
|
|
|
+ const qsp2twOptions = data.split('\n')?.[1];
|
|
|
|
+ if(qsp2twOptions.startsWith("!! SKIP_QSRC2TW")){
|
|
|
|
+ if(fs.existsSync(outFilePath))
|
|
|
|
+ fs.unlink(outFilePath,(err) => {if (err) throw err;});
|
|
|
|
+ if(fs.existsSync(outFilePathTS))
|
|
|
|
+ fs.unlink(outFilePathTS,(err) => {if (err) throw err;});
|
|
resolve("SKIP");
|
|
resolve("SKIP");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- if (fs.existsSync(outFilePath)) {
|
|
|
|
|
|
|
|
- try{
|
|
|
|
- const secondLineData = fs.readFileSync(outFilePath, "utf-8").split('\n')[1];
|
|
|
|
- const qsrc2twResultMatch = secondLineData.match(/<!--\s*qsrc2twResult=({.*})\s*-->/);
|
|
|
|
- if(qsrc2twResultMatch){
|
|
|
|
- const qsrc2twResult = JSON.parse(qsrc2twResultMatch[1]);
|
|
|
|
-
|
|
|
|
- if((qsrc2twResult.code && codeHash == qsrc2twResult.code) &&
|
|
|
|
- (qsrc2twResult.version && VERSION == qsrc2twResult.version)){
|
|
|
|
- resolve("EXISTS");
|
|
|
|
- return;
|
|
|
|
|
|
+
|
|
|
|
+ //#region Skip File Output if outfile exists, is based on the same codebase (determined by hash) and has used the same compier-version
|
|
|
|
+ const codeHash = md5(data);
|
|
|
|
+ if (fs.existsSync(outFilePath)) {
|
|
|
|
+
|
|
|
|
+ try{
|
|
|
|
+ const secondLineData = fs.readFileSync(outFilePath, "utf-8").split('\n')[1];
|
|
|
|
+ const qsrc2twResultMatch = secondLineData.match(/<!--\s*qsrc2twResult=({.*})\s*-->/);
|
|
|
|
+ if(qsrc2twResultMatch){
|
|
|
|
+ const qsrc2twResult = JSON.parse(qsrc2twResultMatch[1]);
|
|
|
|
+
|
|
|
|
+ if((qsrc2twResult.code && codeHash == qsrc2twResult.code) &&
|
|
|
|
+ (qsrc2twResult.version && VERSION == qsrc2twResult.version)){
|
|
|
|
+ resolve("EXISTS");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ catch(e){
|
|
|
|
+ //Something unexpected happens. No need to handle this, because we'll just run the default file-processing.
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- catch(e){
|
|
|
|
|
|
+ //#endregion
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ var convertMode = "default";
|
|
|
|
+
|
|
|
|
+ if(qsp2twOptions.startsWith("!! QSRC2TW_module")){
|
|
|
|
+ convertMode = qsp2twOptions.trim().split(" ").toReversed()[0];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Return value is Array [TwineCode, TSCode]. TwineCode must not be null.
|
|
|
|
+ */
|
|
|
|
+ var convertFunction = (code)=>[null,null];
|
|
|
|
+ switch (convertMode) {
|
|
|
|
+ case "default": convertFunction = (code) => [qsrc2tw(code, true),null]; break;
|
|
|
|
+ case "npcInit": convertFunction = (code) => npcInit(code); break;
|
|
|
|
+ case "stat_sklattrib_lvlset": convertFunction = (code) => skillDefinitions(code); break;
|
|
|
|
+ default:
|
|
|
|
+ console.warn("Unreckognized Convert Mode");
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
try{
|
|
try{
|
|
let twineCode = "";
|
|
let twineCode = "";
|
|
consoleActive = options.verboseErrors;
|
|
consoleActive = options.verboseErrors;
|
|
|
|
+ let twineCodeRaw = undefined;
|
|
|
|
+ let tsCodeRaw = undefined;
|
|
try{
|
|
try{
|
|
- twineCode = qsrc2tw(data, true)
|
|
|
|
- .split('\n')
|
|
|
|
- .toSpliced(1,0,`<!--qsrc2twResult={"version":${VERSION},"code":"${codeHash}","time":"${(new Date().toISOString())}"}-->`)
|
|
|
|
- .join('\n');
|
|
|
|
|
|
+ [twineCodeRaw,tsCodeRaw] = convertFunction(data);
|
|
}
|
|
}
|
|
catch(e){
|
|
catch(e){
|
|
throw e;
|
|
throw e;
|
|
@@ -149,13 +181,34 @@ async function convertFile(filePath){
|
|
finally{
|
|
finally{
|
|
consoleActive = true;
|
|
consoleActive = true;
|
|
}
|
|
}
|
|
|
|
+ if(!twineCodeRaw){
|
|
|
|
+ console.error("Twine Code must be generated by every converMode");
|
|
|
|
+ reject("Invalid convertFunction");
|
|
|
|
+ return;
|
|
|
|
+ }else{
|
|
|
|
+ twineCode = twineCodeRaw.split('\n')
|
|
|
|
+ .toSpliced(1,0,`<!--qsrc2twResult={"version":${VERSION},"code":"${codeHash}","time":"${(new Date().toISOString())}"}-->`)
|
|
|
|
+ .join('\n');
|
|
|
|
+ fs.writeFile(outFilePath, twineCode, err => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.error(err);
|
|
|
|
+ } else {
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
- fs.writeFile(outFilePath, twineCode, err => {
|
|
|
|
- if (err) {
|
|
|
|
- console.error(err);
|
|
|
|
- } else {
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+
|
|
|
|
+ if(!tsCodeRaw){
|
|
|
|
+ if(fs.existsSync(outFilePathTS))
|
|
|
|
+ fs.unlink(outFilePathTS,(err) => {if (err) throw err;});
|
|
|
|
+ }else{
|
|
|
|
+ fs.writeFile(outFilePathTS, tsCodeRaw, err => {
|
|
|
|
+ if (err) {
|
|
|
|
+ console.error(err);
|
|
|
|
+ } else {
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
const executionTime = (new Date()).getTime() - startTime;
|
|
const executionTime = (new Date()).getTime() - startTime;
|
|
|
|
|