@novely/core 0.37.0-beta.0 → 0.37.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 +8 -2
- package/dist/index.global.js +33 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +33 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49,6 +49,7 @@ var MAIN_CONTEXT_KEY = "$MAIN";
|
|
|
49
49
|
var STACK_MAP = /* @__PURE__ */ new Map();
|
|
50
50
|
var CUSTOM_ACTION_MAP = /* @__PURE__ */ new Map();
|
|
51
51
|
var PRELOADED_ASSETS = /* @__PURE__ */ new Set();
|
|
52
|
+
var RESOURCE_TYPE_CACHE = /* @__PURE__ */ new Map();
|
|
52
53
|
|
|
53
54
|
// src/utils.ts
|
|
54
55
|
import { DEV } from "esm-env";
|
|
@@ -500,24 +501,31 @@ var fetchContentType = async (request, url) => {
|
|
|
500
501
|
}
|
|
501
502
|
};
|
|
502
503
|
var getResourseType = async (request, url) => {
|
|
504
|
+
if (RESOURCE_TYPE_CACHE.has(url)) {
|
|
505
|
+
return RESOURCE_TYPE_CACHE.get(url);
|
|
506
|
+
}
|
|
507
|
+
const encache = (value) => {
|
|
508
|
+
RESOURCE_TYPE_CACHE.set(url, value);
|
|
509
|
+
return value;
|
|
510
|
+
};
|
|
503
511
|
if (!isCSSImage(url)) {
|
|
504
|
-
return "other";
|
|
512
|
+
return encache("other");
|
|
505
513
|
}
|
|
506
514
|
const extension = getUrlFileExtension(url);
|
|
507
515
|
if (HOWLER_SUPPORTED_FILE_FORMATS.has(extension)) {
|
|
508
|
-
return "audio";
|
|
516
|
+
return encache("audio");
|
|
509
517
|
}
|
|
510
518
|
if (SUPPORTED_IMAGE_FILE_FORMATS.has(extension)) {
|
|
511
|
-
return "image";
|
|
519
|
+
return encache("image");
|
|
512
520
|
}
|
|
513
521
|
const contentType = await fetchContentType(request, url);
|
|
514
522
|
if (contentType.includes("audio")) {
|
|
515
|
-
return "audio";
|
|
523
|
+
return encache("audio");
|
|
516
524
|
}
|
|
517
525
|
if (contentType.includes("image")) {
|
|
518
|
-
return "image";
|
|
526
|
+
return encache("image");
|
|
519
527
|
}
|
|
520
|
-
return "other";
|
|
528
|
+
return encache("other");
|
|
521
529
|
};
|
|
522
530
|
var capitalize = (str2) => {
|
|
523
531
|
return str2[0].toUpperCase() + str2.slice(1);
|
|
@@ -1024,38 +1032,38 @@ var novely = ({
|
|
|
1024
1032
|
const script = (part) => {
|
|
1025
1033
|
return limitScript(() => scriptBase(part));
|
|
1026
1034
|
};
|
|
1027
|
-
const
|
|
1035
|
+
const assetPreloadingCheck = (action2, props, doAction = assetsToPreloadAdd) => {
|
|
1028
1036
|
if (action2 === "showBackground") {
|
|
1029
1037
|
if (isImageAsset(props[0])) {
|
|
1030
|
-
|
|
1038
|
+
doAction(props[0]);
|
|
1031
1039
|
}
|
|
1032
1040
|
if (props[0] && typeof props[0] === "object") {
|
|
1033
1041
|
for (const value of Object.values(props[0])) {
|
|
1034
1042
|
if (!isImageAsset(value))
|
|
1035
1043
|
continue;
|
|
1036
|
-
|
|
1044
|
+
doAction(value);
|
|
1037
1045
|
}
|
|
1038
1046
|
}
|
|
1039
1047
|
return;
|
|
1040
1048
|
}
|
|
1041
1049
|
if (isAudioAction(action2) && isString(props[0])) {
|
|
1042
|
-
|
|
1050
|
+
doAction(props[0]);
|
|
1043
1051
|
return;
|
|
1044
1052
|
}
|
|
1045
1053
|
if (action2 === "showCharacter" && isString(props[0]) && isString(props[1])) {
|
|
1046
1054
|
const images = characters[props[0]].emotions[props[1]];
|
|
1047
1055
|
if (Array.isArray(images)) {
|
|
1048
1056
|
for (const asset of images) {
|
|
1049
|
-
|
|
1057
|
+
doAction(asset);
|
|
1050
1058
|
}
|
|
1051
1059
|
} else {
|
|
1052
|
-
|
|
1060
|
+
doAction(images);
|
|
1053
1061
|
}
|
|
1054
1062
|
return;
|
|
1055
1063
|
}
|
|
1056
1064
|
if (action2 === "custom" && props[0].assets && props[0].assets.length > 0) {
|
|
1057
1065
|
for (const asset of props[0].assets) {
|
|
1058
|
-
|
|
1066
|
+
doAction(asset);
|
|
1059
1067
|
}
|
|
1060
1068
|
}
|
|
1061
1069
|
};
|
|
@@ -1066,7 +1074,7 @@ var novely = ({
|
|
|
1066
1074
|
}
|
|
1067
1075
|
return (...props) => {
|
|
1068
1076
|
if (preloadAssets === "blocking") {
|
|
1069
|
-
|
|
1077
|
+
assetPreloadingCheck(action2, props);
|
|
1070
1078
|
}
|
|
1071
1079
|
return [action2, ...props];
|
|
1072
1080
|
};
|
|
@@ -1317,8 +1325,11 @@ var novely = ({
|
|
|
1317
1325
|
return translation[lang].internal[key];
|
|
1318
1326
|
};
|
|
1319
1327
|
const preview = async (save2, name) => {
|
|
1320
|
-
if (isEmpty(story))
|
|
1321
|
-
return
|
|
1328
|
+
if (isEmpty(story)) {
|
|
1329
|
+
return Promise.resolve({
|
|
1330
|
+
assets: []
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1322
1333
|
const [path, data2] = save2;
|
|
1323
1334
|
const { queue } = getActionsFromPath(story, path, true);
|
|
1324
1335
|
const ctx = renderer.getContext(name);
|
|
@@ -1328,6 +1339,7 @@ var novely = ({
|
|
|
1328
1339
|
skip: EMPTY_SET
|
|
1329
1340
|
});
|
|
1330
1341
|
useStack(ctx).push(klona(save2));
|
|
1342
|
+
const assets = [];
|
|
1331
1343
|
await processor.run(([action2, ...props]) => {
|
|
1332
1344
|
if (isAudioAction(action2))
|
|
1333
1345
|
return;
|
|
@@ -1335,11 +1347,15 @@ var novely = ({
|
|
|
1335
1347
|
return;
|
|
1336
1348
|
if (action2 === "end")
|
|
1337
1349
|
return;
|
|
1350
|
+
assetPreloadingCheck(action2, props, assets.push.bind(assets));
|
|
1338
1351
|
return match(action2, props, {
|
|
1339
1352
|
ctx,
|
|
1340
1353
|
data: data2
|
|
1341
1354
|
});
|
|
1342
1355
|
});
|
|
1356
|
+
return {
|
|
1357
|
+
assets
|
|
1358
|
+
};
|
|
1343
1359
|
};
|
|
1344
1360
|
const removeContext = (name) => {
|
|
1345
1361
|
STACK_MAP.delete(name);
|
|
@@ -1436,7 +1452,7 @@ var novely = ({
|
|
|
1436
1452
|
refer
|
|
1437
1453
|
});
|
|
1438
1454
|
for (const [action3, ...props2] of collection) {
|
|
1439
|
-
|
|
1455
|
+
assetPreloadingCheck(action3, props2);
|
|
1440
1456
|
}
|
|
1441
1457
|
const { preloadAudioBlocking, preloadImageBlocking } = renderer.misc;
|
|
1442
1458
|
ASSETS_TO_PRELOAD.forEach(async (asset) => {
|