@drincs/pixi-vn-ink 0.1.1 → 0.1.3
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/README.md +78 -8
- package/dist/constant.d.mts +3 -0
- package/dist/constant.d.ts +3 -0
- package/dist/constant.js +8 -0
- package/dist/constant.js.map +1 -0
- package/dist/constant.mjs +6 -0
- package/dist/constant.mjs.map +1 -0
- package/dist/functions/ChoiceInfoConverter.d.mts +1 -1
- package/dist/functions/ChoiceInfoConverter.d.ts +1 -1
- package/dist/functions/ChoiceInfoConverter.js +20 -7
- package/dist/functions/ChoiceInfoConverter.js.map +1 -1
- package/dist/functions/ChoiceInfoConverter.mjs +20 -7
- package/dist/functions/ChoiceInfoConverter.mjs.map +1 -1
- package/dist/functions/Importer.d.mts +15 -0
- package/dist/functions/Importer.d.ts +15 -0
- package/dist/functions/Importer.js +85 -21
- package/dist/functions/Importer.js.map +1 -1
- package/dist/functions/Importer.mjs +85 -21
- package/dist/functions/Importer.mjs.map +1 -1
- package/dist/functions/InkToPixivn.d.mts +7 -2
- package/dist/functions/InkToPixivn.d.ts +7 -2
- package/dist/functions/InkToPixivn.js +85 -21
- package/dist/functions/InkToPixivn.js.map +1 -1
- package/dist/functions/InkToPixivn.mjs +85 -21
- package/dist/functions/InkToPixivn.mjs.map +1 -1
- package/dist/functions/StoryInfoConverter.js +80 -17
- package/dist/functions/StoryInfoConverter.js.map +1 -1
- package/dist/functions/StoryInfoConverter.mjs +80 -17
- package/dist/functions/StoryInfoConverter.mjs.map +1 -1
- package/dist/functions/index.js +85 -21
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/index.mjs +85 -21
- package/dist/functions/index.mjs.map +1 -1
- package/dist/functions/utility.d.mts +3 -0
- package/dist/functions/utility.d.ts +3 -0
- package/dist/functions/utility.js +12 -0
- package/dist/functions/utility.js.map +1 -0
- package/dist/functions/utility.mjs +10 -0
- package/dist/functions/utility.mjs.map +1 -0
- package/dist/index.js +85 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -21
- package/dist/index.mjs.map +1 -1
- package/dist/types/LabelChoiceRes.d.mts +1 -1
- package/dist/types/LabelChoiceRes.d.ts +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,15 +1,85 @@
|
|
|
1
|
-
# Pixi
|
|
1
|
+
# Pixi’VN + Ink Language
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pixi’VN gives you the ability to write your own narrative using Ink.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## What is ink?
|
|
6
|
+
|
|
7
|
+
Ink is a scripting language for writing interactive narrative. It is used in games like 80 Days, Heaven's Vault, and Sorcery! to create branching stories.
|
|
8
|
+
|
|
9
|
+
This language is very simple to learn, you can learn the basics in a few minutes. Go on [ink website](https://www.inklestudios.com/ink/) to learn more about it.
|
|
10
|
+
|
|
11
|
+
## Start using Ink in Pixi’VN
|
|
12
|
+
|
|
13
|
+
If you have not created a project yet then it is recommended to use the [template](/start/getting-started.md#project-initialization) and select a template that is based on ink.
|
|
14
|
+
|
|
15
|
+
Otherwise to add ink to your Pixi’VN project you need to install the `@drincs/pixi-vn-ink` package.
|
|
6
16
|
|
|
7
17
|
```bash
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
# npm
|
|
19
|
+
npm install @drincs/pixi-vn-ink
|
|
20
|
+
|
|
21
|
+
# yarn
|
|
22
|
+
yarn add @drincs/pixi-vn-ink
|
|
23
|
+
|
|
24
|
+
# pnpm
|
|
25
|
+
pnpm add @drincs/pixi-vn-ink
|
|
26
|
+
|
|
27
|
+
# bun
|
|
28
|
+
bun add @drincs/pixi-vn-ink
|
|
11
29
|
```
|
|
12
30
|
|
|
13
|
-
|
|
31
|
+
After installing the package you need to import the `importInkText()` function from the package and use it to import the ink script into your project.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// main.ts
|
|
35
|
+
import { importInkText } from '@drincs/pixi-vn-ink'
|
|
14
36
|
|
|
15
|
-
|
|
37
|
+
const inkText = `
|
|
38
|
+
=== start ===
|
|
39
|
+
Hello
|
|
40
|
+
-> END
|
|
41
|
+
`
|
|
42
|
+
|
|
43
|
+
importInkText([inkText, ...])
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Now you can run the `start` knot (or label) with [Pixi’VN functions](/start/labels.md#run-a-label).
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
GameStepManager.callLabel(`start`, {})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Import text contained in .ink files
|
|
53
|
+
|
|
54
|
+
( This method has been tested only on projects generated with vitejs )
|
|
55
|
+
|
|
56
|
+
To import text contained in .ink files you need create the file `ink.d.ts`:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// src/ink.d.ts
|
|
60
|
+
declare module '*.ink' {
|
|
61
|
+
const value: string
|
|
62
|
+
export default value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
After that you need to add the `.ink` extension to the `assetsInclude` option in the `vite.config.ts` file:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// vite.config.ts
|
|
71
|
+
export default defineConfig({
|
|
72
|
+
// ...
|
|
73
|
+
assetsInclude: ['**/*.ink'],
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
After that you can import the ink file and add `?raw` at the end of the import to get the text content.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// main.ts
|
|
81
|
+
import { importInkText } from '@drincs/pixi-vn-ink'
|
|
82
|
+
import startLabel from './ink_labels/start.ink?raw'
|
|
83
|
+
|
|
84
|
+
importInkText([startLabel, ...])
|
|
85
|
+
```
|
package/dist/constant.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constant.ts"],"names":[],"mappings":";;;AAAO,IAAM,0BAA6B,GAAA","file":"constant.js","sourcesContent":["export const CHOISE_LABEL_KEY_SEPARATOR = \"_|_\"\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constant.ts"],"names":[],"mappings":";AAAO,IAAM,0BAA6B,GAAA","file":"constant.mjs","sourcesContent":["export const CHOISE_LABEL_KEY_SEPARATOR = \"_|_\"\n"]}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/functions/utility.ts
|
|
4
|
+
function unionStringOrArray(start = "", end = "") {
|
|
5
|
+
const startArray = Array.isArray(start) ? start : [start];
|
|
6
|
+
const endArray = Array.isArray(end) ? end : [end];
|
|
7
|
+
return [.../* @__PURE__ */ new Set([...startArray, ...endArray])];
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
// src/functions/ChoiceInfoConverter.ts
|
|
4
|
-
function getLabelChoice(items, result) {
|
|
11
|
+
function getLabelChoice(items, result, lastLabel) {
|
|
5
12
|
let text = "";
|
|
6
13
|
let label = "";
|
|
7
14
|
let preDialog = "";
|
|
8
|
-
items.
|
|
15
|
+
for (let index = 0; index < items.length; index++) {
|
|
16
|
+
let v = items[index];
|
|
9
17
|
if (typeof v === "string") {
|
|
10
18
|
if (v.startsWith("^")) {
|
|
11
19
|
text = v.substring(1);
|
|
@@ -17,14 +25,19 @@ function getLabelChoice(items, result) {
|
|
|
17
25
|
} else if ("s" in v && v["s"] instanceof Array) {
|
|
18
26
|
let t = findChoiceText(v["s"]);
|
|
19
27
|
if (t) {
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
if (lastLabel && result[lastLabel]) {
|
|
29
|
+
result[lastLabel].preDialog = { text: t };
|
|
30
|
+
result[lastLabel].text = unionStringOrArray(t, result[lastLabel].text);
|
|
31
|
+
} else {
|
|
32
|
+
text = t;
|
|
33
|
+
preDialog = t;
|
|
34
|
+
}
|
|
22
35
|
}
|
|
23
36
|
}
|
|
24
37
|
}
|
|
25
38
|
if (text && label) {
|
|
26
39
|
if (result[label]) {
|
|
27
|
-
result[label].text = text
|
|
40
|
+
result[label].text = unionStringOrArray(text, result[label].text);
|
|
28
41
|
} else {
|
|
29
42
|
result[label] = { text };
|
|
30
43
|
}
|
|
@@ -32,10 +45,10 @@ function getLabelChoice(items, result) {
|
|
|
32
45
|
result[label].preDialog = { text: preDialog };
|
|
33
46
|
}
|
|
34
47
|
let newListItem = items.slice(index + 1);
|
|
35
|
-
getLabelChoice(newListItem, result);
|
|
48
|
+
getLabelChoice(newListItem, result, label);
|
|
36
49
|
return;
|
|
37
50
|
}
|
|
38
|
-
}
|
|
51
|
+
}
|
|
39
52
|
}
|
|
40
53
|
function findChoiceText(items) {
|
|
41
54
|
for (const item of items) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/functions/ChoiceInfoConverter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../../src/functions/utility.ts","../../src/functions/ChoiceInfoConverter.ts"],"names":[],"mappings":";;;AAAO,SAAS,kBAAmB,CAAA,KAAA,GAA2B,EAAI,EAAA,GAAA,GAAyB,EAAc,EAAA;AACrG,EAAA,MAAM,aAAa,KAAM,CAAA,OAAA,CAAQ,KAAK,CAAI,GAAA,KAAA,GAAQ,CAAC,KAAK,CAAA,CAAA;AACxD,EAAA,MAAM,WAAW,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAI,GAAA,GAAA,GAAM,CAAC,GAAG,CAAA,CAAA;AAChD,EAAO,OAAA,CAAC,mBAAG,IAAI,GAAI,CAAA,CAAC,GAAG,UAAY,EAAA,GAAG,QAAQ,CAAC,CAAC,CAAA,CAAA;AACpD,CAAA;;;ACAO,SAAS,cAAA,CAAe,KAAc,EAAA,MAAA,EAAwB,SAAoB,EAAA;AACrF,EAAA,IAAI,IAAe,GAAA,EAAA,CAAA;AACnB,EAAA,IAAI,KAAgB,GAAA,EAAA,CAAA;AACpB,EAAA,IAAI,SAAoB,GAAA,EAAA,CAAA;AACxB,EAAA,KA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AAA,SACJ;AAAA,OACJ;AAAA,KACJ;AACA,IAAA,IAAI,QAAQ,KAAO,EAAA;AACf,MAAI,IAAA,MAAA,CAAO,KAAK,CAAG,EAAA;AACf,QAAO,MAAA,CAAA,KAAK,EAAE,IAAO,GAAA,kBAAA,CAAmB,MAAM,MAAO,CAAA,KAAK,EAAE,IAAI,CAAA,CAAA;AAAA,OAE/D,MAAA;AACD,QAAO,MAAA,CAAA,KAAK,CAAI,GAAA,EAAE,IAAW,EAAA,CAAA;AAAA,OACjC;AACA,MAAA,IAAI,SAAW,EAAA;AACX,QAAA,MAAA,CAAO,KAAK,CAAA,CAAE,SAAY,GAAA,EAAE,MAAM,SAAU,EAAA,CAAA;AAAA,OAChD;AAEA,MAAA,IAAI,WAAc,GAAA,KAAA,CAAM,KAAM,CAAA,KAAA,GAAQ,CAAC,CAAA,CAAA;AACvC,MAAe,cAAA,CAAA,WAAA,EAAa,QAAQ,KAAK,CAAA,CAAA;AACzC,MAAA,OAAA;AAAA,KACJ;AAAA,GACJ;AACJ,CAAA;AAEA,SAAS,eAAe,KAAiD,EAAA;AACrE,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACtB,IAAI,IAAA,OAAO,SAAS,QAAU,EAAA;AAC1B,MAAI,IAAA,IAAA,CAAK,UAAW,CAAA,GAAG,CAAG,EAAA;AACtB,QAAO,OAAA,IAAA,CAAK,UAAU,CAAC,CAAA,CAAA;AAAA,OAC3B;AAAA,KACJ,MAAA,IACS,gBAAgB,KAAO,EAAA;AAC5B,MAAI,IAAA,GAAA,GAAM,eAAe,IAAI,CAAA,CAAA;AAC7B,MAAA,IAAI,GAAK,EAAA;AACL,QAAO,OAAA,GAAA,CAAA;AAAA,OACX;AAAA,KACJ;AAAA,GACJ;AACJ","file":"ChoiceInfoConverter.js","sourcesContent":["export function unionStringOrArray(start: string | string[] = \"\", end: string | string[] = \"\"): string[] {\n const startArray = Array.isArray(start) ? start : [start];\n const endArray = Array.isArray(end) ? end : [end];\n return [...new Set([...startArray, ...endArray])];\n}","import LabelChoiceRes from '../types/LabelChoiceRes';\nimport RootParserItemType from '../types/parserItems/RootParserItemType';\nimport { unionStringOrArray } from './utility';\n\nexport function getLabelChoice(items: any[], result: LabelChoiceRes, lastLabel?: string) {\n let text: string = \"\"\n let label: string = \"\"\n let preDialog: string = \"\"\n for (let index = 0; index < items.length; index++) {\n let v = items[index]\n if (typeof v === \"string\") {\n // Dialog\n if (v.startsWith(\"^\")) {\n text = v.substring(1)\n }\n }\n else if (v && typeof v === \"object\") {\n // if is a choice\n if (\"*\" in v && typeof v[\"*\"] && typeof v[\"*\"] === \"string\" && v[\"*\"].includes(\"c\")) {\n let l = \"c\" + v[\"*\"].split(\"c\")[1]\n label = l\n }\n // if is choise info\n else if (\"s\" in v && v[\"s\"] instanceof Array) {\n let t = findChoiceText(v[\"s\"])\n if (t) {\n if (lastLabel && result[lastLabel]) {\n result[lastLabel].preDialog = { text: t }\n result[lastLabel].text = unionStringOrArray(t, result[lastLabel].text)\n }\n else {\n text = t\n preDialog = t\n }\n }\n }\n }\n if (text && label) {\n if (result[label]) {\n result[label].text = unionStringOrArray(text, result[label].text)\n }\n else {\n result[label] = { text: text }\n }\n if (preDialog) {\n result[label].preDialog = { text: preDialog }\n }\n // split text and label\n let newListItem = items.slice(index + 1)\n getLabelChoice(newListItem, result, label)\n return\n }\n }\n}\n\nfunction findChoiceText(items: RootParserItemType[]): string | undefined {\n for (const item of items) {\n if (typeof item === \"string\") {\n if (item.startsWith(\"^\")) {\n return item.substring(1)\n }\n }\n else if (item instanceof Array) {\n let res = findChoiceText(item)\n if (res) {\n return res\n }\n }\n }\n}\n"]}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
// src/functions/utility.ts
|
|
2
|
+
function unionStringOrArray(start = "", end = "") {
|
|
3
|
+
const startArray = Array.isArray(start) ? start : [start];
|
|
4
|
+
const endArray = Array.isArray(end) ? end : [end];
|
|
5
|
+
return [.../* @__PURE__ */ new Set([...startArray, ...endArray])];
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
// src/functions/ChoiceInfoConverter.ts
|
|
2
|
-
function getLabelChoice(items, result) {
|
|
9
|
+
function getLabelChoice(items, result, lastLabel) {
|
|
3
10
|
let text = "";
|
|
4
11
|
let label = "";
|
|
5
12
|
let preDialog = "";
|
|
6
|
-
items.
|
|
13
|
+
for (let index = 0; index < items.length; index++) {
|
|
14
|
+
let v = items[index];
|
|
7
15
|
if (typeof v === "string") {
|
|
8
16
|
if (v.startsWith("^")) {
|
|
9
17
|
text = v.substring(1);
|
|
@@ -15,14 +23,19 @@ function getLabelChoice(items, result) {
|
|
|
15
23
|
} else if ("s" in v && v["s"] instanceof Array) {
|
|
16
24
|
let t = findChoiceText(v["s"]);
|
|
17
25
|
if (t) {
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
if (lastLabel && result[lastLabel]) {
|
|
27
|
+
result[lastLabel].preDialog = { text: t };
|
|
28
|
+
result[lastLabel].text = unionStringOrArray(t, result[lastLabel].text);
|
|
29
|
+
} else {
|
|
30
|
+
text = t;
|
|
31
|
+
preDialog = t;
|
|
32
|
+
}
|
|
20
33
|
}
|
|
21
34
|
}
|
|
22
35
|
}
|
|
23
36
|
if (text && label) {
|
|
24
37
|
if (result[label]) {
|
|
25
|
-
result[label].text = text
|
|
38
|
+
result[label].text = unionStringOrArray(text, result[label].text);
|
|
26
39
|
} else {
|
|
27
40
|
result[label] = { text };
|
|
28
41
|
}
|
|
@@ -30,10 +43,10 @@ function getLabelChoice(items, result) {
|
|
|
30
43
|
result[label].preDialog = { text: preDialog };
|
|
31
44
|
}
|
|
32
45
|
let newListItem = items.slice(index + 1);
|
|
33
|
-
getLabelChoice(newListItem, result);
|
|
46
|
+
getLabelChoice(newListItem, result, label);
|
|
34
47
|
return;
|
|
35
48
|
}
|
|
36
|
-
}
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
51
|
function findChoiceText(items) {
|
|
39
52
|
for (const item of items) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/functions/ChoiceInfoConverter.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/functions/utility.ts","../../src/functions/ChoiceInfoConverter.ts"],"names":[],"mappings":";AAAO,SAAS,kBAAmB,CAAA,KAAA,GAA2B,EAAI,EAAA,GAAA,GAAyB,EAAc,EAAA;AACrG,EAAA,MAAM,aAAa,KAAM,CAAA,OAAA,CAAQ,KAAK,CAAI,GAAA,KAAA,GAAQ,CAAC,KAAK,CAAA,CAAA;AACxD,EAAA,MAAM,WAAW,KAAM,CAAA,OAAA,CAAQ,GAAG,CAAI,GAAA,GAAA,GAAM,CAAC,GAAG,CAAA,CAAA;AAChD,EAAO,OAAA,CAAC,mBAAG,IAAI,GAAI,CAAA,CAAC,GAAG,UAAY,EAAA,GAAG,QAAQ,CAAC,CAAC,CAAA,CAAA;AACpD,CAAA;;;ACAO,SAAS,cAAA,CAAe,KAAc,EAAA,MAAA,EAAwB,SAAoB,EAAA;AACrF,EAAA,IAAI,IAAe,GAAA,EAAA,CAAA;AACnB,EAAA,IAAI,KAAgB,GAAA,EAAA,CAAA;AACpB,EAAA,IAAI,SAAoB,GAAA,EAAA,CAAA;AACxB,EAAA,KAAA,IAAS,KAAQ,GAAA,CAAA,EAAG,KAAQ,GAAA,KAAA,CAAM,QAAQ,KAAS,EAAA,EAAA;AAC/C,IAAI,IAAA,CAAA,GAAI,MAAM,KAAK,CAAA,CAAA;AACnB,IAAI,IAAA,OAAO,MAAM,QAAU,EAAA;AAEvB,MAAI,IAAA,CAAA,CAAE,UAAW,CAAA,GAAG,CAAG,EAAA;AACnB,QAAO,IAAA,GAAA,CAAA,CAAE,UAAU,CAAC,CAAA,CAAA;AAAA,OACxB;AAAA,KAEK,MAAA,IAAA,CAAA,IAAK,OAAO,CAAA,KAAM,QAAU,EAAA;AAEjC,MAAA,IAAI,OAAO,CAAK,IAAA,OAAO,CAAE,CAAA,GAAG,KAAK,OAAO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AAA,IAAI,WAAc,GAAA,KAAA,CAAM,KAAM,CAAA,KAAA,GAAQ,CAAC,CAAA,CAAA;AACvC,MAAe,cAAA,CAAA,WAAA,EAAa,QAAQ,KAAK,CAAA,CAAA;AACzC,MAAA,OAAA;AAAA,KACJ;AAAA,GACJ;AACJ,CAAA;AAEA,SAAS,eAAe,KAAiD,EAAA;AACrE,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACtB,IAAI,IAAA,OAAO,SAAS,QAAU,EAAA;AAC1B,MAAI,IAAA,IAAA,CAAK,UAAW,CAAA,GAAG,CAAG,EAAA;AACtB,QAAO,OAAA,IAAA,CAAK,UAAU,CAAC,CAAA,CAAA;AAAA,OAC3B;AAAA,KACJ,MAAA,IACS,gBAAgB,KAAO,EAAA;AAC5B,MAAI,IAAA,GAAA,GAAM,eAAe,IAAI,CAAA,CAAA;AAC7B,MAAA,IAAI,GAAK,EAAA;AACL,QAAO,OAAA,GAAA,CAAA;AAAA,OACX;AAAA,KACJ;AAAA,GACJ;AACJ","file":"ChoiceInfoConverter.mjs","sourcesContent":["export function unionStringOrArray(start: string | string[] = \"\", end: string | string[] = \"\"): string[] {\n const startArray = Array.isArray(start) ? start : [start];\n const endArray = Array.isArray(end) ? end : [end];\n return [...new Set([...startArray, ...endArray])];\n}","import LabelChoiceRes from '../types/LabelChoiceRes';\nimport RootParserItemType from '../types/parserItems/RootParserItemType';\nimport { unionStringOrArray } from './utility';\n\nexport function getLabelChoice(items: any[], result: LabelChoiceRes, lastLabel?: string) {\n let text: string = \"\"\n let label: string = \"\"\n let preDialog: string = \"\"\n for (let index = 0; index < items.length; index++) {\n let v = items[index]\n if (typeof v === \"string\") {\n // Dialog\n if (v.startsWith(\"^\")) {\n text = v.substring(1)\n }\n }\n else if (v && typeof v === \"object\") {\n // if is a choice\n if (\"*\" in v && typeof v[\"*\"] && typeof v[\"*\"] === \"string\" && v[\"*\"].includes(\"c\")) {\n let l = \"c\" + v[\"*\"].split(\"c\")[1]\n label = l\n }\n // if is choise info\n else if (\"s\" in v && v[\"s\"] instanceof Array) {\n let t = findChoiceText(v[\"s\"])\n if (t) {\n if (lastLabel && result[lastLabel]) {\n result[lastLabel].preDialog = { text: t }\n result[lastLabel].text = unionStringOrArray(t, result[lastLabel].text)\n }\n else {\n text = t\n preDialog = t\n }\n }\n }\n }\n if (text && label) {\n if (result[label]) {\n result[label].text = unionStringOrArray(text, result[label].text)\n }\n else {\n result[label] = { text: text }\n }\n if (preDialog) {\n result[label].preDialog = { text: preDialog }\n }\n // split text and label\n let newListItem = items.slice(index + 1)\n getLabelChoice(newListItem, result, label)\n return\n }\n }\n}\n\nfunction findChoiceText(items: RootParserItemType[]): string | undefined {\n for (const item of items) {\n if (typeof item === \"string\") {\n if (item.startsWith(\"^\")) {\n return item.substring(1)\n }\n }\n else if (item instanceof Array) {\n let res = findChoiceText(item)\n if (res) {\n return res\n }\n }\n }\n}\n"]}
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function imports string or array of strings written in ink language into the Pixi’VN engine.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { importInkText } from 'pixi-vn'
|
|
6
|
+
* importInkText(`
|
|
7
|
+
* === back_in_london ===
|
|
8
|
+
* Hello, World!
|
|
9
|
+
* `)
|
|
10
|
+
*
|
|
11
|
+
* GameStepManager.callLabel("back_in_london", {})
|
|
12
|
+
* ```
|
|
13
|
+
* @param text string or array of strings written in ink language
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
1
16
|
declare function importInkText(text: string | string[]): void;
|
|
2
17
|
|
|
3
18
|
export { importInkText };
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function imports string or array of strings written in ink language into the Pixi’VN engine.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { importInkText } from 'pixi-vn'
|
|
6
|
+
* importInkText(`
|
|
7
|
+
* === back_in_london ===
|
|
8
|
+
* Hello, World!
|
|
9
|
+
* `)
|
|
10
|
+
*
|
|
11
|
+
* GameStepManager.callLabel("back_in_london", {})
|
|
12
|
+
* ```
|
|
13
|
+
* @param text string or array of strings written in ink language
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
1
16
|
declare function importInkText(text: string | string[]): void;
|
|
2
17
|
|
|
3
18
|
export { importInkText };
|
|
@@ -5,12 +5,23 @@ var Compiler = require('inkjs/compiler/Compiler');
|
|
|
5
5
|
|
|
6
6
|
// src/functions/Importer.ts
|
|
7
7
|
|
|
8
|
+
// src/constant.ts
|
|
9
|
+
var CHOISE_LABEL_KEY_SEPARATOR = "_|_";
|
|
10
|
+
|
|
11
|
+
// src/functions/utility.ts
|
|
12
|
+
function unionStringOrArray(start = "", end = "") {
|
|
13
|
+
const startArray = Array.isArray(start) ? start : [start];
|
|
14
|
+
const endArray = Array.isArray(end) ? end : [end];
|
|
15
|
+
return [.../* @__PURE__ */ new Set([...startArray, ...endArray])];
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
// src/functions/ChoiceInfoConverter.ts
|
|
9
|
-
function getLabelChoice(items, result) {
|
|
19
|
+
function getLabelChoice(items, result, lastLabel) {
|
|
10
20
|
let text = "";
|
|
11
21
|
let label = "";
|
|
12
22
|
let preDialog = "";
|
|
13
|
-
items.
|
|
23
|
+
for (let index = 0; index < items.length; index++) {
|
|
24
|
+
let v = items[index];
|
|
14
25
|
if (typeof v === "string") {
|
|
15
26
|
if (v.startsWith("^")) {
|
|
16
27
|
text = v.substring(1);
|
|
@@ -22,14 +33,19 @@ function getLabelChoice(items, result) {
|
|
|
22
33
|
} else if ("s" in v && v["s"] instanceof Array) {
|
|
23
34
|
let t = findChoiceText(v["s"]);
|
|
24
35
|
if (t) {
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
if (lastLabel && result[lastLabel]) {
|
|
37
|
+
result[lastLabel].preDialog = { text: t };
|
|
38
|
+
result[lastLabel].text = unionStringOrArray(t, result[lastLabel].text);
|
|
39
|
+
} else {
|
|
40
|
+
text = t;
|
|
41
|
+
preDialog = t;
|
|
42
|
+
}
|
|
27
43
|
}
|
|
28
44
|
}
|
|
29
45
|
}
|
|
30
46
|
if (text && label) {
|
|
31
47
|
if (result[label]) {
|
|
32
|
-
result[label].text = text
|
|
48
|
+
result[label].text = unionStringOrArray(text, result[label].text);
|
|
33
49
|
} else {
|
|
34
50
|
result[label] = { text };
|
|
35
51
|
}
|
|
@@ -37,10 +53,10 @@ function getLabelChoice(items, result) {
|
|
|
37
53
|
result[label].preDialog = { text: preDialog };
|
|
38
54
|
}
|
|
39
55
|
let newListItem = items.slice(index + 1);
|
|
40
|
-
getLabelChoice(newListItem, result);
|
|
56
|
+
getLabelChoice(newListItem, result, label);
|
|
41
57
|
return;
|
|
42
58
|
}
|
|
43
|
-
}
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
function findChoiceText(items) {
|
|
46
62
|
for (const item of items) {
|
|
@@ -64,7 +80,7 @@ function getInkLabel(story) {
|
|
|
64
80
|
findLabel(story, label);
|
|
65
81
|
return label;
|
|
66
82
|
} catch (e) {
|
|
67
|
-
console.error("[Pixi
|
|
83
|
+
console.error("[Pixi\u2019VN Ink] Error parsing ink file", e);
|
|
68
84
|
}
|
|
69
85
|
}
|
|
70
86
|
function findLabel(story, labels) {
|
|
@@ -86,7 +102,7 @@ function addLabels(storyItem, result, dadLabelKey = "", shareData = { preDialog:
|
|
|
86
102
|
if (value instanceof Array) {
|
|
87
103
|
let labels = [];
|
|
88
104
|
let subLabels = {};
|
|
89
|
-
let labelName = (dadLabelKey ? dadLabelKey +
|
|
105
|
+
let labelName = (dadLabelKey ? dadLabelKey + CHOISE_LABEL_KEY_SEPARATOR : "") + key;
|
|
90
106
|
getLabel(value, labelName, labels, subLabels, shareData);
|
|
91
107
|
for (const [subKey, subValue] of Object.entries(subLabels)) {
|
|
92
108
|
result[subKey] = subValue;
|
|
@@ -117,7 +133,19 @@ function getLabel(items, labelKey, labelSteps, subLabels, shareData, isNewLine =
|
|
|
117
133
|
} else if (typeof v === "string") {
|
|
118
134
|
if (v.startsWith("^")) {
|
|
119
135
|
if (!isNewLine && labelSteps.length > 0) {
|
|
120
|
-
|
|
136
|
+
if (labelSteps[labelSteps.length - 1].glueEnabled) {
|
|
137
|
+
labelSteps.push({
|
|
138
|
+
dialog: v.substring(1)
|
|
139
|
+
});
|
|
140
|
+
} else {
|
|
141
|
+
let newDialog = labelSteps[labelSteps.length - 1].dialog;
|
|
142
|
+
if (typeof newDialog === "string" || newDialog instanceof Array || !newDialog) {
|
|
143
|
+
labelSteps[labelSteps.length - 1].dialog = unionStringOrArray(newDialog, v.substring(1));
|
|
144
|
+
} else {
|
|
145
|
+
newDialog.text = unionStringOrArray(newDialog.text, v.substring(1));
|
|
146
|
+
labelSteps[labelSteps.length - 1].dialog = newDialog;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
121
149
|
} else {
|
|
122
150
|
labelSteps.push({
|
|
123
151
|
dialog: v.substring(1)
|
|
@@ -138,16 +166,46 @@ function getLabel(items, labelKey, labelSteps, subLabels, shareData, isNewLine =
|
|
|
138
166
|
end: "game_end"
|
|
139
167
|
});
|
|
140
168
|
isNewLine = false;
|
|
169
|
+
} else if (v == "<>") {
|
|
170
|
+
labelSteps.push({
|
|
171
|
+
glueEnabled: true,
|
|
172
|
+
goNextStep: true
|
|
173
|
+
});
|
|
174
|
+
isNewLine = false;
|
|
141
175
|
}
|
|
142
176
|
} else if (v instanceof Array) {
|
|
143
177
|
getLabel(v, labelKey, labelSteps, subLabels, shareData, isNewLine);
|
|
144
178
|
} else if (v && typeof v === "object") {
|
|
145
|
-
if ("->" in v && typeof v["->"] === "string" && !v["->"]
|
|
179
|
+
if ("->" in v && typeof v["->"] === "string" && !new RegExp(/^\.\^\.\^\.\d\.s$/).test(v["->"])) {
|
|
180
|
+
let labelIdToOpen = v["->"];
|
|
181
|
+
let glueEnabled = isNewLine ? void 0 : true;
|
|
182
|
+
let goNextStep = isNewLine ? void 0 : true;
|
|
183
|
+
if (
|
|
184
|
+
// if there are a sub label "=label"
|
|
185
|
+
new RegExp(/^\.\^\.\^\.\^\.\^\..*$/).test(v["->"]) && labelKey
|
|
186
|
+
) {
|
|
187
|
+
let endOfLabel = v["->"].substring(9);
|
|
188
|
+
labelIdToOpen = labelKey.split(CHOISE_LABEL_KEY_SEPARATOR)[0] + CHOISE_LABEL_KEY_SEPARATOR + endOfLabel;
|
|
189
|
+
} else if (
|
|
190
|
+
// if there are a sub label "=label"
|
|
191
|
+
new RegExp(/^\.\^\.\^\.\^\..*$/).test(v["->"]) && labelKey.includes(CHOISE_LABEL_KEY_SEPARATOR)
|
|
192
|
+
) {
|
|
193
|
+
let endOfLabel = v["->"].substring(7);
|
|
194
|
+
labelIdToOpen = labelKey.split(CHOISE_LABEL_KEY_SEPARATOR)[0] + CHOISE_LABEL_KEY_SEPARATOR + endOfLabel;
|
|
195
|
+
} else if (
|
|
196
|
+
// if there are a sub label "=label"
|
|
197
|
+
new RegExp(/^\.\^\..*$/).test(v["->"]) && labelKey
|
|
198
|
+
) {
|
|
199
|
+
let endOfLabel = v["->"].substring(3);
|
|
200
|
+
labelIdToOpen = labelKey + CHOISE_LABEL_KEY_SEPARATOR + endOfLabel;
|
|
201
|
+
}
|
|
146
202
|
labelSteps.push({
|
|
147
203
|
labelToOpen: {
|
|
148
|
-
labelId:
|
|
204
|
+
labelId: labelIdToOpen,
|
|
149
205
|
type: "call"
|
|
150
|
-
}
|
|
206
|
+
},
|
|
207
|
+
glueEnabled,
|
|
208
|
+
goNextStep
|
|
151
209
|
});
|
|
152
210
|
isNewLine = false;
|
|
153
211
|
} else if ("*" in v && typeof v["*"] === "string" && v["*"].includes("c")) {
|
|
@@ -165,9 +223,9 @@ function getLabel(items, labelKey, labelSteps, subLabels, shareData, isNewLine =
|
|
|
165
223
|
let choices = {};
|
|
166
224
|
getLabelChoice(envList, choices);
|
|
167
225
|
for (const [key, value] of Object.entries(choices)) {
|
|
168
|
-
let newKey = labelKey +
|
|
169
|
-
if (labelSteps.length > 0 && "
|
|
170
|
-
(_a = labelSteps[labelSteps.length - 1].
|
|
226
|
+
let newKey = labelKey + CHOISE_LABEL_KEY_SEPARATOR + key;
|
|
227
|
+
if (labelSteps.length > 0 && "choices" in labelSteps[labelSteps.length - 1]) {
|
|
228
|
+
(_a = labelSteps[labelSteps.length - 1].choices) == null ? void 0 : _a.push({
|
|
171
229
|
text: value.text,
|
|
172
230
|
label: newKey,
|
|
173
231
|
props: {},
|
|
@@ -175,7 +233,7 @@ function getLabel(items, labelKey, labelSteps, subLabels, shareData, isNewLine =
|
|
|
175
233
|
});
|
|
176
234
|
} else {
|
|
177
235
|
labelSteps.push({
|
|
178
|
-
|
|
236
|
+
choices: [{
|
|
179
237
|
text: value.text,
|
|
180
238
|
label: newKey,
|
|
181
239
|
props: {},
|
|
@@ -190,28 +248,34 @@ function getLabel(items, labelKey, labelSteps, subLabels, shareData, isNewLine =
|
|
|
190
248
|
}
|
|
191
249
|
}
|
|
192
250
|
}
|
|
251
|
+
if (labelKey.includes(CHOISE_LABEL_KEY_SEPARATOR) && labelSteps.length == 2 && labelSteps[0].dialog == " " && labelSteps[1].labelToOpen) {
|
|
252
|
+
labelSteps.shift();
|
|
253
|
+
labelSteps[0].glueEnabled = void 0;
|
|
254
|
+
labelSteps[0].goNextStep = void 0;
|
|
255
|
+
}
|
|
193
256
|
}
|
|
194
257
|
|
|
195
258
|
// src/functions/InkToPixivn.ts
|
|
196
259
|
function convertInkText(text) {
|
|
260
|
+
let result = {};
|
|
197
261
|
let json = convertorInkToJson(text);
|
|
198
262
|
let obj;
|
|
199
263
|
try {
|
|
200
264
|
obj = JSON.parse(json);
|
|
201
265
|
} catch (e) {
|
|
202
|
-
console.error("[Pixi
|
|
266
|
+
console.error("[Pixi\u2019VN Ink] Error parsing ink file", e);
|
|
203
267
|
return;
|
|
204
268
|
}
|
|
205
|
-
|
|
269
|
+
result.labels = getInkLabel(obj.root);
|
|
270
|
+
return result;
|
|
206
271
|
}
|
|
207
272
|
function convertorInkToJson(test) {
|
|
208
273
|
try {
|
|
209
274
|
const story = new Compiler.Compiler(test).Compile();
|
|
210
275
|
let json = story.ToJson();
|
|
211
|
-
console.log(json);
|
|
212
276
|
return json || "";
|
|
213
277
|
} catch (e) {
|
|
214
|
-
console.error("[Pixi
|
|
278
|
+
console.error("[Pixi\u2019VN] Error compiling ink file", e);
|
|
215
279
|
return "";
|
|
216
280
|
}
|
|
217
281
|
}
|