From 745b543617bbc298e0613d8a306a92ead693f2ad Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:44:47 +0100 Subject: [PATCH] refactor HashtagScriptManager and adding-elements to improve operation handling; update tests for pause operations --- src/managers/HashtagScriptManager.ts | 16 ++++++++++++++-- src/parser/adding-elements.ts | 25 ++----------------------- tests/pixivn-features.test.ts | 25 +++++++++++++++++++++---- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/managers/HashtagScriptManager.ts b/src/managers/HashtagScriptManager.ts index d0a57e8..b4d7e19 100644 --- a/src/managers/HashtagScriptManager.ts +++ b/src/managers/HashtagScriptManager.ts @@ -82,8 +82,8 @@ export default class HashtagScriptManager { return undefined; } - let operationType = HashtagScriptManager.removeExtraDoubleQuotes(list[1]); - let type = HashtagScriptManager.removeExtraDoubleQuotes(list[0]); + let operationType = list.length > 1 ? HashtagScriptManager.removeExtraDoubleQuotes(list[1]) : ""; + let type = list.length > 0 ? HashtagScriptManager.removeExtraDoubleQuotes(list[0]) : ""; switch (operationType) { case "image": return HashtagScriptManager.getImageOperationFromComment(list, "image"); @@ -151,6 +151,18 @@ export default class HashtagScriptManager { return effect } } + else { + switch (type) { + case "pause": + if ("dialogue" in step) { + delete step.dialogue + } + if ("goNextStep" in step) { + delete step.goNextStep + } + break + } + } } } catch (e) { diff --git a/src/parser/adding-elements.ts b/src/parser/adding-elements.ts index 8f4803d..e0a56e5 100644 --- a/src/parser/adding-elements.ts +++ b/src/parser/adding-elements.ts @@ -1,6 +1,5 @@ import { getCharacterById } from "@drincs/pixi-vn"; import { PixiVNJsonConditionalStatements, PixiVNJsonLabelStep, PixiVNJsonStepSwitchElementType, PixiVNJsonValueGet } from "@drincs/pixi-vn-json"; -import { PAUSE_HASHTAG_SCRIPT } from "../constant"; import { StandardDivert } from "../types/parserItems/Divert"; import { MyVariableAssignment } from "../types/parserItems/VariableAssignment"; import { getLabelByStandardDivert } from "../utility/divert-utility"; @@ -44,31 +43,11 @@ function addConditionalElementStep( } if (isHashtagScript) { if (Array.isArray(item)) { - let tempList: any[] = [] - item.forEach((i) => { - if (typeof i === "string" && i === PAUSE_HASHTAG_SCRIPT) { - let value: PixiVNJsonLabelStep = { - dialogue: undefined, - } - if (tempList.length > 0) { - value.operations = [{ - type: "operationtoconvert", - values: tempList, - }] - tempList = [] - } - list.push(value) - } - else { - tempList.push(i) - } - }) - if (tempList.length > 0) { - // TODO: call or jump + if (item.length > 0) { list.push({ operations: [{ type: "operationtoconvert", - values: tempList, + values: item, }], goNextStep: true, }) diff --git a/tests/pixivn-features.test.ts b/tests/pixivn-features.test.ts index d50ebc0..e7f3320 100644 --- a/tests/pixivn-features.test.ts +++ b/tests/pixivn-features.test.ts @@ -542,7 +542,15 @@ test('effect image', async () => { goNextStep: true, }, { - dialogue: undefined, + operations: [ + { + type: "operationtoconvert", + values: [ + "pause", + ], + }, + ], + goNextStep: true, }, { end: "label_end", @@ -593,7 +601,7 @@ test('effect image', async () => { goNextStep: true, }, { - dialogue: undefined, + operations: [], }, { end: "label_end", @@ -954,7 +962,15 @@ test('input', async () => { goNextStep: true, }, { - dialogue: undefined, + operations: [ + { + type: "operationtoconvert", + values: [ + "pause", + ], + }, + ], + goNextStep: true, }, { operations: [ @@ -1000,7 +1016,8 @@ test('input', async () => { goNextStep: true, }, { - dialogue: undefined, + operations: [ + ], }, { operations: [