@novely/core 0.36.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 +42 -4
- package/dist/index.global.js +35 -17
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +35 -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);
|
|
@@ -937,6 +945,7 @@ import pLimit from "p-limit";
|
|
|
937
945
|
import { DEV as DEV2 } from "esm-env";
|
|
938
946
|
var novely = ({
|
|
939
947
|
characters,
|
|
948
|
+
characterAssetSizes = {},
|
|
940
949
|
defaultEmotions = {},
|
|
941
950
|
storage = localStorageStorage({ key: "novely-game-storage" }),
|
|
942
951
|
storageDelay = Promise.resolve(),
|
|
@@ -1023,38 +1032,38 @@ var novely = ({
|
|
|
1023
1032
|
const script = (part) => {
|
|
1024
1033
|
return limitScript(() => scriptBase(part));
|
|
1025
1034
|
};
|
|
1026
|
-
const
|
|
1035
|
+
const assetPreloadingCheck = (action2, props, doAction = assetsToPreloadAdd) => {
|
|
1027
1036
|
if (action2 === "showBackground") {
|
|
1028
1037
|
if (isImageAsset(props[0])) {
|
|
1029
|
-
|
|
1038
|
+
doAction(props[0]);
|
|
1030
1039
|
}
|
|
1031
1040
|
if (props[0] && typeof props[0] === "object") {
|
|
1032
1041
|
for (const value of Object.values(props[0])) {
|
|
1033
1042
|
if (!isImageAsset(value))
|
|
1034
1043
|
continue;
|
|
1035
|
-
|
|
1044
|
+
doAction(value);
|
|
1036
1045
|
}
|
|
1037
1046
|
}
|
|
1038
1047
|
return;
|
|
1039
1048
|
}
|
|
1040
1049
|
if (isAudioAction(action2) && isString(props[0])) {
|
|
1041
|
-
|
|
1050
|
+
doAction(props[0]);
|
|
1042
1051
|
return;
|
|
1043
1052
|
}
|
|
1044
1053
|
if (action2 === "showCharacter" && isString(props[0]) && isString(props[1])) {
|
|
1045
1054
|
const images = characters[props[0]].emotions[props[1]];
|
|
1046
1055
|
if (Array.isArray(images)) {
|
|
1047
1056
|
for (const asset of images) {
|
|
1048
|
-
|
|
1057
|
+
doAction(asset);
|
|
1049
1058
|
}
|
|
1050
1059
|
} else {
|
|
1051
|
-
|
|
1060
|
+
doAction(images);
|
|
1052
1061
|
}
|
|
1053
1062
|
return;
|
|
1054
1063
|
}
|
|
1055
1064
|
if (action2 === "custom" && props[0].assets && props[0].assets.length > 0) {
|
|
1056
1065
|
for (const asset of props[0].assets) {
|
|
1057
|
-
|
|
1066
|
+
doAction(asset);
|
|
1058
1067
|
}
|
|
1059
1068
|
}
|
|
1060
1069
|
};
|
|
@@ -1065,7 +1074,7 @@ var novely = ({
|
|
|
1065
1074
|
}
|
|
1066
1075
|
return (...props) => {
|
|
1067
1076
|
if (preloadAssets === "blocking") {
|
|
1068
|
-
|
|
1077
|
+
assetPreloadingCheck(action2, props);
|
|
1069
1078
|
}
|
|
1070
1079
|
return [action2, ...props];
|
|
1071
1080
|
};
|
|
@@ -1316,8 +1325,11 @@ var novely = ({
|
|
|
1316
1325
|
return translation[lang].internal[key];
|
|
1317
1326
|
};
|
|
1318
1327
|
const preview = async (save2, name) => {
|
|
1319
|
-
if (isEmpty(story))
|
|
1320
|
-
return
|
|
1328
|
+
if (isEmpty(story)) {
|
|
1329
|
+
return Promise.resolve({
|
|
1330
|
+
assets: []
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1321
1333
|
const [path, data2] = save2;
|
|
1322
1334
|
const { queue } = getActionsFromPath(story, path, true);
|
|
1323
1335
|
const ctx = renderer.getContext(name);
|
|
@@ -1327,6 +1339,7 @@ var novely = ({
|
|
|
1327
1339
|
skip: EMPTY_SET
|
|
1328
1340
|
});
|
|
1329
1341
|
useStack(ctx).push(klona(save2));
|
|
1342
|
+
const assets = [];
|
|
1330
1343
|
await processor.run(([action2, ...props]) => {
|
|
1331
1344
|
if (isAudioAction(action2))
|
|
1332
1345
|
return;
|
|
@@ -1334,11 +1347,15 @@ var novely = ({
|
|
|
1334
1347
|
return;
|
|
1335
1348
|
if (action2 === "end")
|
|
1336
1349
|
return;
|
|
1350
|
+
assetPreloadingCheck(action2, props, assets.push.bind(assets));
|
|
1337
1351
|
return match(action2, props, {
|
|
1338
1352
|
ctx,
|
|
1339
1353
|
data: data2
|
|
1340
1354
|
});
|
|
1341
1355
|
});
|
|
1356
|
+
return {
|
|
1357
|
+
assets
|
|
1358
|
+
};
|
|
1342
1359
|
};
|
|
1343
1360
|
const removeContext = (name) => {
|
|
1344
1361
|
STACK_MAP.delete(name);
|
|
@@ -1373,6 +1390,7 @@ var novely = ({
|
|
|
1373
1390
|
const renderer = createRenderer({
|
|
1374
1391
|
mainContextKey: MAIN_CONTEXT_KEY,
|
|
1375
1392
|
characters,
|
|
1393
|
+
characterAssetSizes,
|
|
1376
1394
|
set,
|
|
1377
1395
|
restore,
|
|
1378
1396
|
save,
|
|
@@ -1434,7 +1452,7 @@ var novely = ({
|
|
|
1434
1452
|
refer
|
|
1435
1453
|
});
|
|
1436
1454
|
for (const [action3, ...props2] of collection) {
|
|
1437
|
-
|
|
1455
|
+
assetPreloadingCheck(action3, props2);
|
|
1438
1456
|
}
|
|
1439
1457
|
const { preloadAudioBlocking, preloadImageBlocking } = renderer.misc;
|
|
1440
1458
|
ASSETS_TO_PRELOAD.forEach(async (asset) => {
|