@novely/core 0.40.0-next → 0.40.0
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/dist/index.d.ts +2 -1
- package/dist/index.global.js +105 -28
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +105 -28
- package/dist/index.js.map +1 -1
- package/package.json +63 -63
package/dist/index.js
CHANGED
|
@@ -585,26 +585,31 @@ var fetchContentType = async (url, request) => {
|
|
|
585
585
|
return "";
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
|
-
var getResourseType = memoize2(
|
|
589
|
-
|
|
588
|
+
var getResourseType = memoize2(
|
|
589
|
+
async ({ url, request }) => {
|
|
590
|
+
if (!isCSSImage(url)) {
|
|
591
|
+
return "other";
|
|
592
|
+
}
|
|
593
|
+
const extension = getUrlFileExtension(url);
|
|
594
|
+
if (HOWLER_SUPPORTED_FILE_FORMATS.has(extension)) {
|
|
595
|
+
return "audio";
|
|
596
|
+
}
|
|
597
|
+
if (SUPPORTED_IMAGE_FILE_FORMATS.has(extension)) {
|
|
598
|
+
return "image";
|
|
599
|
+
}
|
|
600
|
+
const contentType = await fetchContentType(url, request);
|
|
601
|
+
if (contentType.includes("audio")) {
|
|
602
|
+
return "audio";
|
|
603
|
+
}
|
|
604
|
+
if (contentType.includes("image")) {
|
|
605
|
+
return "image";
|
|
606
|
+
}
|
|
590
607
|
return "other";
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
getCacheKey: ({ url }) => url
|
|
591
611
|
}
|
|
592
|
-
|
|
593
|
-
if (HOWLER_SUPPORTED_FILE_FORMATS.has(extension)) {
|
|
594
|
-
return "audio";
|
|
595
|
-
}
|
|
596
|
-
if (SUPPORTED_IMAGE_FILE_FORMATS.has(extension)) {
|
|
597
|
-
return "image";
|
|
598
|
-
}
|
|
599
|
-
const contentType = await fetchContentType(url, request);
|
|
600
|
-
if (contentType.includes("audio")) {
|
|
601
|
-
return "audio";
|
|
602
|
-
}
|
|
603
|
-
if (contentType.includes("image")) {
|
|
604
|
-
return "image";
|
|
605
|
-
}
|
|
606
|
-
return "other";
|
|
607
|
-
});
|
|
612
|
+
);
|
|
608
613
|
var capitalize = (str2) => {
|
|
609
614
|
return str2[0].toUpperCase() + str2.slice(1);
|
|
610
615
|
};
|
|
@@ -784,6 +789,17 @@ var getCharactersData = (characters) => {
|
|
|
784
789
|
var toArray = (target) => {
|
|
785
790
|
return Array.isArray(target) ? target : [target];
|
|
786
791
|
};
|
|
792
|
+
var getLanguageFromStore = (store2) => {
|
|
793
|
+
return store2.get().meta[0];
|
|
794
|
+
};
|
|
795
|
+
var getVolumeFromStore = (store2) => {
|
|
796
|
+
const { meta } = store2.get();
|
|
797
|
+
return {
|
|
798
|
+
music: meta[2],
|
|
799
|
+
sound: meta[3],
|
|
800
|
+
voice: meta[4]
|
|
801
|
+
};
|
|
802
|
+
};
|
|
787
803
|
|
|
788
804
|
// src/novely.ts
|
|
789
805
|
import { throttle } from "es-toolkit/function";
|
|
@@ -966,6 +982,11 @@ import pLimit from "p-limit";
|
|
|
966
982
|
import { DEV as DEV3 } from "esm-env";
|
|
967
983
|
|
|
968
984
|
// src/preloading.ts
|
|
985
|
+
var ACTION_NAME_TO_VOLUME_MAP = {
|
|
986
|
+
"playMusic": "music",
|
|
987
|
+
"playSound": "sound",
|
|
988
|
+
"voice": "voice"
|
|
989
|
+
};
|
|
969
990
|
var enqueueAssetForPreloading = (asset2) => {
|
|
970
991
|
if (!PRELOADED_ASSETS.has(asset2)) {
|
|
971
992
|
ASSETS_TO_PRELOAD.add(asset2);
|
|
@@ -974,7 +995,10 @@ var enqueueAssetForPreloading = (asset2) => {
|
|
|
974
995
|
var handleAssetsPreloading = async ({ request, limiter, preloadAudioBlocking, preloadImageBlocking }) => {
|
|
975
996
|
const list = mapSet(ASSETS_TO_PRELOAD, (asset2) => {
|
|
976
997
|
return limiter(async () => {
|
|
977
|
-
const type = await getResourseType(
|
|
998
|
+
const type = await getResourseType({
|
|
999
|
+
url: asset2,
|
|
1000
|
+
request
|
|
1001
|
+
});
|
|
978
1002
|
switch (type) {
|
|
979
1003
|
case "audio": {
|
|
980
1004
|
await preloadAudioBlocking(asset2);
|
|
@@ -992,7 +1016,7 @@ var handleAssetsPreloading = async ({ request, limiter, preloadAudioBlocking, pr
|
|
|
992
1016
|
await Promise.allSettled(list);
|
|
993
1017
|
ASSETS_TO_PRELOAD.clear();
|
|
994
1018
|
};
|
|
995
|
-
var huntAssets = ({ characters, action, props, handle }) => {
|
|
1019
|
+
var huntAssets = ({ volume, lang, mode, characters, action, props, handle }) => {
|
|
996
1020
|
if (action === "showBackground") {
|
|
997
1021
|
if (isString(props[0])) {
|
|
998
1022
|
handle(handleAudioAsset(props[0]));
|
|
@@ -1001,13 +1025,39 @@ var huntAssets = ({ characters, action, props, handle }) => {
|
|
|
1001
1025
|
for (const value of Object.values(props[0])) {
|
|
1002
1026
|
if (isImageAsset(value)) {
|
|
1003
1027
|
handle(value);
|
|
1028
|
+
} else if (isAsset(value)) {
|
|
1029
|
+
const unwrapped = handleImageAsset(value);
|
|
1030
|
+
if (isImageAsset(unwrapped)) {
|
|
1031
|
+
handle(unwrapped);
|
|
1032
|
+
}
|
|
1004
1033
|
}
|
|
1005
1034
|
}
|
|
1006
1035
|
}
|
|
1007
1036
|
return;
|
|
1008
1037
|
}
|
|
1038
|
+
const getVolumeFor = (action2) => {
|
|
1039
|
+
if (action2 in ACTION_NAME_TO_VOLUME_MAP) {
|
|
1040
|
+
return volume[ACTION_NAME_TO_VOLUME_MAP[action2]];
|
|
1041
|
+
}
|
|
1042
|
+
return 0;
|
|
1043
|
+
};
|
|
1009
1044
|
if (isAudioAction(action) && isString(props[0])) {
|
|
1010
|
-
|
|
1045
|
+
if (getVolumeFor(action) > 0) {
|
|
1046
|
+
handle(handleAudioAsset(props[0]));
|
|
1047
|
+
}
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
if (action === "voice" && typeof props[0] === "object") {
|
|
1051
|
+
if (getVolumeFor("voice") == 0) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
for (const [language, value] of Object.entries(props[0])) {
|
|
1055
|
+
if (mode === "blocking") {
|
|
1056
|
+
value && handle(handleAudioAsset(value));
|
|
1057
|
+
} else if (language === lang) {
|
|
1058
|
+
value && handle(handleAudioAsset(value));
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1011
1061
|
return;
|
|
1012
1062
|
}
|
|
1013
1063
|
if (action === "showCharacter" && isString(props[0]) && isString(props[1])) {
|
|
@@ -1099,7 +1149,15 @@ var novely = ({
|
|
|
1099
1149
|
}
|
|
1100
1150
|
return (...props) => {
|
|
1101
1151
|
if (preloadAssets === "blocking") {
|
|
1102
|
-
huntAssets({
|
|
1152
|
+
huntAssets({
|
|
1153
|
+
action: action2,
|
|
1154
|
+
props,
|
|
1155
|
+
mode: preloadAssets,
|
|
1156
|
+
characters,
|
|
1157
|
+
lang: getLanguageFromStore(storageData),
|
|
1158
|
+
volume: getVolumeFromStore(storageData),
|
|
1159
|
+
handle: enqueueAssetForPreloading
|
|
1160
|
+
});
|
|
1103
1161
|
}
|
|
1104
1162
|
return [action2, ...props];
|
|
1105
1163
|
};
|
|
@@ -1362,7 +1420,15 @@ var novely = ({
|
|
|
1362
1420
|
if (isAudioAction(action2)) return;
|
|
1363
1421
|
if (action2 === "vibrate") return;
|
|
1364
1422
|
if (action2 === "end") return;
|
|
1365
|
-
huntAssets({
|
|
1423
|
+
huntAssets({
|
|
1424
|
+
action: action2,
|
|
1425
|
+
props,
|
|
1426
|
+
mode: preloadAssets,
|
|
1427
|
+
characters,
|
|
1428
|
+
lang: getLanguageFromStore(storageData),
|
|
1429
|
+
volume: getVolumeFromStore(storageData),
|
|
1430
|
+
handle: assets.push.bind(assets)
|
|
1431
|
+
});
|
|
1366
1432
|
return match(action2, props, {
|
|
1367
1433
|
ctx,
|
|
1368
1434
|
data: data2
|
|
@@ -1403,7 +1469,10 @@ var novely = ({
|
|
|
1403
1469
|
getCustomActionHolder(ctx, fn).cleanup();
|
|
1404
1470
|
};
|
|
1405
1471
|
const getResourseTypeForRenderer = (url) => {
|
|
1406
|
-
return getResourseType(
|
|
1472
|
+
return getResourseType({
|
|
1473
|
+
url,
|
|
1474
|
+
request
|
|
1475
|
+
});
|
|
1407
1476
|
};
|
|
1408
1477
|
const getCharacterColor = (c) => {
|
|
1409
1478
|
return c in characters ? characters[c].color : "#000000";
|
|
@@ -1472,7 +1541,15 @@ var novely = ({
|
|
|
1472
1541
|
refer
|
|
1473
1542
|
});
|
|
1474
1543
|
for (const [action3, ...props2] of collection) {
|
|
1475
|
-
huntAssets({
|
|
1544
|
+
huntAssets({
|
|
1545
|
+
action: action3,
|
|
1546
|
+
props: props2,
|
|
1547
|
+
mode: preloadAssets,
|
|
1548
|
+
characters,
|
|
1549
|
+
lang: getLanguageFromStore(storageData),
|
|
1550
|
+
volume: getVolumeFromStore(storageData),
|
|
1551
|
+
handle: enqueueAssetForPreloading
|
|
1552
|
+
});
|
|
1476
1553
|
}
|
|
1477
1554
|
handleAssetsPreloading({
|
|
1478
1555
|
...renderer.misc,
|
|
@@ -1591,7 +1668,7 @@ var novely = ({
|
|
|
1591
1668
|
function({ ctx, push }, [fn]) {
|
|
1592
1669
|
const { restoring, goingBack, preview: preview2 } = ctx.meta;
|
|
1593
1670
|
const result = fn({
|
|
1594
|
-
lang: storageData
|
|
1671
|
+
lang: getLanguageFromStore(storageData),
|
|
1595
1672
|
goingBack,
|
|
1596
1673
|
restoring,
|
|
1597
1674
|
preview: preview2,
|
|
@@ -1610,7 +1687,7 @@ var novely = ({
|
|
|
1610
1687
|
}
|
|
1611
1688
|
const transformedChoices = choices.map(([content, action2, visible]) => {
|
|
1612
1689
|
const shown = !visible || visible({
|
|
1613
|
-
lang: storageData
|
|
1690
|
+
lang: getLanguageFromStore(storageData),
|
|
1614
1691
|
state: getStateAtCtx(ctx)
|
|
1615
1692
|
});
|
|
1616
1693
|
if (DEV3 && action2.length === 0 && !shown) {
|
|
@@ -1697,7 +1774,7 @@ var novely = ({
|
|
|
1697
1774
|
ctx.clearBlockingActions(void 0);
|
|
1698
1775
|
}
|
|
1699
1776
|
const state = getStateFunction(ctx);
|
|
1700
|
-
const lang = storageData
|
|
1777
|
+
const lang = getLanguageFromStore(storageData);
|
|
1701
1778
|
const result = handleCustomAction(ctx, fn, {
|
|
1702
1779
|
...ctx.custom(fn),
|
|
1703
1780
|
state,
|