3 커밋 ccb6b76eef ... 75890a4689

작성자 SHA1 메시지 날짜
  Stephan Fuchs 75890a4689 remove `images/`-prefix from detected images 2 달 전
  Stephan Fuchs e940d53adc wardrobeItemsTypes 2 달 전
  Stephan Fuchs 2ddce8399d task_processor uses its own hash for version control of output files 2 달 전
3개의 변경된 파일40개의 추가작업 그리고 5개의 파일을 삭제
  1. 4 1
      src/defaultProcess.js
  2. 30 0
      src/wardrobeItemsTypes.js
  3. 6 4
      task_processor.js

+ 4 - 1
src/defaultProcess.js

@@ -11,7 +11,10 @@ export default function defaultProcess(code){
     const imageRegex = /<<='(?:<center>)?<img (?:'\+\(QSP\.\$set_imgh\[0\]\)\+' )?src="([\w\s/]+\.jpg)">(?:<\/center>)?'>>/gi;
     twineCodeTemp = twineCode;
     while(regexResult = imageRegex.exec(twineCode)) {
-        twineCodeTemp = twineCodeTemp.replace(regexResult[0],`<<image '${regexResult[1]}'>>`);
+        let imagePath = regexResult[1];
+        if(imagePath.startsWith('images/') && imagePath.length > 7)
+            imagePath = imagePath.substring(7);
+        twineCodeTemp = twineCodeTemp.replace(regexResult[0],`<<image '${imagePath}'>>`);
     }
     twineCode = twineCodeTemp;
 

+ 30 - 0
src/wardrobeItemsTypes.js

@@ -0,0 +1,30 @@
+import defaultProcess from "./defaultProcess.js";
+
+export default function wardrobeItemsTypes(code,options){
+    const twineCode = defaultProcess(code);
+
+    let tsCode = 'setup.wardrobeItemVars ??= {};\n';
+
+    const regexes = {
+        'bras': /if (\w+)S\[i\] = metka_bras and \1\[i\] = 1:/gm,
+        'clothes': /if (\w+)\[i\] = 1 and \(\$clothingworntype ! '\1' or clothingwornnumber ! i\):/gm,
+        'coats': /if (\w+)_s\[i\] = coat_loc and \1\[i\] = 1:/gm,
+        'panties': /if (\w+)S\[i\] = metka_panties and \1\[i\] = 1:/gm,
+        'shoes': /if (\w+)_s\[i\] = sloc and \1\[i\] = 1:/gm,
+    };
+
+    let result;
+
+    for(const[type, regex] of Object.entries(regexes)){
+        let i = 0;
+
+        while(result = regex.exec(code)) {
+            if(i++ == 0)
+                tsCode += `setup.wardrobeItemVars['${type}'] ??= [];\n`;
+            tsCode += `setup.wardrobeItemVars['${type}'].push('${result[1]}');\n`;
+        }
+
+    }
+
+    return [twineCode,tsCode];
+}

+ 6 - 4
task_processor.js

@@ -8,8 +8,9 @@ import defaultProcess from "./src/defaultProcess.js";
 import npcInit from "./src/npcInit.js";
 import skillDefinitions from "./src/skillDefinitions.js";
 import wardrobeItems from "./src/wardrobeItems.js";
+import wardrobeItemsTypes from "./src/wardrobeItemsTypes.js";
 
-
+const thisFilesHash = md5(fs.readFileSync(__filename,{encoding: 'utf8'}));
 
 //https://stackoverflow.com/a/25221100/7200161
 function baseFileName(fullpath){
@@ -53,7 +54,7 @@ function convertFile(task){
 						const qsrc2twResult = JSON.parse(qsrc2twResultMatch[1]);
 
 						if((qsrc2twResult.code && codeHash == qsrc2twResult.code) &&
-							(qsrc2twResult.version && VERSION == qsrc2twResult.version)){
+							(qsrc2twResult.version && thisFilesHash == qsrc2twResult.version)){
 								return [0,"EXISTS"];
 						}
 					}
@@ -91,6 +92,7 @@ function convertFile(task){
 			case "npcInit": convertFunction = (code,options) => npcInit(code); break;
 			case "stat_sklattrib_lvlset": convertFunction = (code,options) => skillDefinitions(code); break;
 			case "wardrobeItems": convertFunction = (code,options) => wardrobeItems(code,options); break;
+			case "wardrobeItemsTypes": convertFunction = (code,options) => wardrobeItemsTypes(code,options); break;
 			default:
 				console.warn("Unreckognized Convert Mode");
 				break;
@@ -119,7 +121,7 @@ function convertFile(task){
 				return [2,"Invalid convertFunction"];
 			}else{
 				twineCode = twineCodeRaw.split('\n')
-								.toSpliced(1,0,`<!--qsrc2twResult={"version":${VERSION},"code":"${codeHash}","time":"${(new Date().toISOString())}"}-->`)
+								.toSpliced(1,0,`<!--qsrc2twResult={"version":"${thisFilesHash}","code":"${codeHash}","time":"${(new Date().toISOString())}"}-->`)
 								.join('\n');
 				fs.writeFile(outFilePath, twineCode, err => {
 					if (err) {
@@ -160,4 +162,4 @@ function convertFile(task){
 
 parentPort.on('message', (task) => {
     parentPort.postMessage(convertFile(task));
-});
+});