Skip to content

Commit

Permalink
refactor HashtagScriptManager and adding-elements to improve operatio…
Browse files Browse the repository at this point in the history
…n handling; update tests for pause operations
  • Loading branch information
BlackRam-oss committed Nov 22, 2024
1 parent 032689a commit 745b543
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
16 changes: 14 additions & 2 deletions src/managers/HashtagScriptManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 2 additions & 23 deletions src/parser/adding-elements.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
})
Expand Down
25 changes: 21 additions & 4 deletions tests/pixivn-features.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,15 @@ test('effect image', async () => {
goNextStep: true,
},
{
dialogue: undefined,
operations: [
{
type: "operationtoconvert",
values: [
"pause",
],
},
],
goNextStep: true,
},
{
end: "label_end",
Expand Down Expand Up @@ -593,7 +601,7 @@ test('effect image', async () => {
goNextStep: true,
},
{
dialogue: undefined,
operations: [],
},
{
end: "label_end",
Expand Down Expand Up @@ -954,7 +962,15 @@ test('input', async () => {
goNextStep: true,
},
{
dialogue: undefined,
operations: [
{
type: "operationtoconvert",
values: [
"pause",
],
},
],
goNextStep: true,
},
{
operations: [
Expand Down Expand Up @@ -1000,7 +1016,8 @@ test('input', async () => {
goNextStep: true,
},
{
dialogue: undefined,
operations: [
],
},
{
operations: [
Expand Down

0 comments on commit 745b543

Please sign in to comment.