@novely/core 0.15.2 → 0.16.0-alpha.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 -2
- package/dist/index.global.js +157 -13
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/package.json +62 -61
package/dist/index.d.ts
CHANGED
|
@@ -381,9 +381,9 @@ interface NovelyInit<Languages extends string, Characters extends Record<string,
|
|
|
381
381
|
}
|
|
382
382
|
declare const novely: <Languages extends string, Characters extends Record<string, Character<Languages>>, StateScheme extends State, DataScheme extends Data>({ characters, storage, storageDelay, renderer: createRenderer, initialScreen, translation, languages, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, }: NovelyInit<Languages, Characters, StateScheme, DataScheme>) => {
|
|
383
383
|
/**
|
|
384
|
-
* Function to set
|
|
384
|
+
* Function to set game script
|
|
385
385
|
*/
|
|
386
|
-
|
|
386
|
+
script: (part: Story) => Promise<void>;
|
|
387
387
|
/**
|
|
388
388
|
* Function to get actions
|
|
389
389
|
*/
|
package/dist/index.global.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var Novely = (() => {
|
|
3
|
+
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
7
12
|
var __export = (target, all) => {
|
|
8
13
|
for (var name in all)
|
|
9
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,8 +21,134 @@ var Novely = (() => {
|
|
|
16
21
|
}
|
|
17
22
|
return to;
|
|
18
23
|
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
19
32
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
33
|
|
|
34
|
+
// ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
|
|
35
|
+
var require_yocto_queue = __commonJS({
|
|
36
|
+
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
|
|
37
|
+
"use strict";
|
|
38
|
+
var Node = class {
|
|
39
|
+
/// value;
|
|
40
|
+
/// next;
|
|
41
|
+
constructor(value) {
|
|
42
|
+
this.value = value;
|
|
43
|
+
this.next = void 0;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var Queue = class {
|
|
47
|
+
// TODO: Use private class fields when targeting Node.js 12.
|
|
48
|
+
// #_head;
|
|
49
|
+
// #_tail;
|
|
50
|
+
// #_size;
|
|
51
|
+
constructor() {
|
|
52
|
+
this.clear();
|
|
53
|
+
}
|
|
54
|
+
enqueue(value) {
|
|
55
|
+
const node = new Node(value);
|
|
56
|
+
if (this._head) {
|
|
57
|
+
this._tail.next = node;
|
|
58
|
+
this._tail = node;
|
|
59
|
+
} else {
|
|
60
|
+
this._head = node;
|
|
61
|
+
this._tail = node;
|
|
62
|
+
}
|
|
63
|
+
this._size++;
|
|
64
|
+
}
|
|
65
|
+
dequeue() {
|
|
66
|
+
const current = this._head;
|
|
67
|
+
if (!current) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this._head = this._head.next;
|
|
71
|
+
this._size--;
|
|
72
|
+
return current.value;
|
|
73
|
+
}
|
|
74
|
+
clear() {
|
|
75
|
+
this._head = void 0;
|
|
76
|
+
this._tail = void 0;
|
|
77
|
+
this._size = 0;
|
|
78
|
+
}
|
|
79
|
+
get size() {
|
|
80
|
+
return this._size;
|
|
81
|
+
}
|
|
82
|
+
*[Symbol.iterator]() {
|
|
83
|
+
let current = this._head;
|
|
84
|
+
while (current) {
|
|
85
|
+
yield current.value;
|
|
86
|
+
current = current.next;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
module.exports = Queue;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
|
|
95
|
+
var require_p_limit = __commonJS({
|
|
96
|
+
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
|
|
97
|
+
"use strict";
|
|
98
|
+
var Queue = require_yocto_queue();
|
|
99
|
+
var pLimit2 = (concurrency) => {
|
|
100
|
+
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
101
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
102
|
+
}
|
|
103
|
+
const queue = new Queue();
|
|
104
|
+
let activeCount = 0;
|
|
105
|
+
const next = () => {
|
|
106
|
+
activeCount--;
|
|
107
|
+
if (queue.size > 0) {
|
|
108
|
+
queue.dequeue()();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const run = async (fn, resolve, ...args) => {
|
|
112
|
+
activeCount++;
|
|
113
|
+
const result = (async () => fn(...args))();
|
|
114
|
+
resolve(result);
|
|
115
|
+
try {
|
|
116
|
+
await result;
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
next();
|
|
120
|
+
};
|
|
121
|
+
const enqueue = (fn, resolve, ...args) => {
|
|
122
|
+
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
123
|
+
(async () => {
|
|
124
|
+
await Promise.resolve();
|
|
125
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
126
|
+
queue.dequeue()();
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
};
|
|
130
|
+
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
131
|
+
enqueue(fn, resolve, ...args);
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperties(generator, {
|
|
134
|
+
activeCount: {
|
|
135
|
+
get: () => activeCount
|
|
136
|
+
},
|
|
137
|
+
pendingCount: {
|
|
138
|
+
get: () => queue.size
|
|
139
|
+
},
|
|
140
|
+
clearQueue: {
|
|
141
|
+
value: () => {
|
|
142
|
+
queue.clear();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return generator;
|
|
147
|
+
};
|
|
148
|
+
module.exports = pLimit2;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
21
152
|
// src/index.ts
|
|
22
153
|
var src_exports = {};
|
|
23
154
|
__export(src_exports, {
|
|
@@ -353,6 +484,9 @@ var Novely = (() => {
|
|
|
353
484
|
};
|
|
354
485
|
};
|
|
355
486
|
|
|
487
|
+
// src/novely.ts
|
|
488
|
+
var import_p_limit = __toESM(require_p_limit(), 1);
|
|
489
|
+
|
|
356
490
|
// ../../node_modules/.pnpm/esm-env@1.0.0/node_modules/esm-env/prod-ssr.js
|
|
357
491
|
var DEV = false;
|
|
358
492
|
|
|
@@ -375,28 +509,41 @@ var Novely = (() => {
|
|
|
375
509
|
askBeforeExit = true,
|
|
376
510
|
preloadAssets = "lazy"
|
|
377
511
|
}) => {
|
|
512
|
+
const limitScript = (0, import_p_limit.default)(1);
|
|
378
513
|
const story = {};
|
|
379
514
|
const times = /* @__PURE__ */ new Set();
|
|
380
515
|
const ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
|
|
381
516
|
const assetsLoaded = createControlledPromise();
|
|
517
|
+
const dataLoaded = createControlledPromise();
|
|
518
|
+
let scriptCalled = false;
|
|
382
519
|
defaultData ||= {};
|
|
383
520
|
defaultState ||= {};
|
|
384
521
|
const intime = (value) => {
|
|
385
522
|
return times.add(value), value;
|
|
386
523
|
};
|
|
387
|
-
const
|
|
524
|
+
const scriptBase = async (part) => {
|
|
388
525
|
Object.assign(story, flattenStory(part));
|
|
389
|
-
};
|
|
390
|
-
const withStory = async (story2) => {
|
|
391
|
-
script(story2);
|
|
392
526
|
if (preloadAssets === "blocking" && ASSETS_TO_PRELOAD.size > 0) {
|
|
393
527
|
renderer.ui.showScreen("loading");
|
|
394
528
|
await renderer.misc.preloadImagesBlocking(ASSETS_TO_PRELOAD);
|
|
395
529
|
}
|
|
530
|
+
const screen = renderer.ui.getScreen();
|
|
531
|
+
const nextScreen = scriptCalled ? screen : initialScreen;
|
|
396
532
|
ASSETS_TO_PRELOAD.clear();
|
|
397
533
|
assetsLoaded.resolve();
|
|
398
|
-
if (
|
|
399
|
-
|
|
534
|
+
if (nextScreen === "game") {
|
|
535
|
+
await assetsLoaded.promise;
|
|
536
|
+
await dataLoaded.promise;
|
|
537
|
+
if (!scriptCalled) {
|
|
538
|
+
restore();
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
renderer.ui.showScreen(nextScreen);
|
|
542
|
+
}
|
|
543
|
+
scriptCalled = true;
|
|
544
|
+
};
|
|
545
|
+
const script = (part) => {
|
|
546
|
+
return limitScript(() => scriptBase(part));
|
|
400
547
|
};
|
|
401
548
|
const action = new Proxy({}, {
|
|
402
549
|
get(_, prop) {
|
|
@@ -494,11 +641,8 @@ var Novely = (() => {
|
|
|
494
641
|
stored.data = defaultData;
|
|
495
642
|
}
|
|
496
643
|
$$.update((prev) => (prev.dataLoaded = true, prev));
|
|
644
|
+
dataLoaded.resolve();
|
|
497
645
|
$.update(() => stored);
|
|
498
|
-
if (initialScreen === "game") {
|
|
499
|
-
await assetsLoaded.promise;
|
|
500
|
-
restore();
|
|
501
|
-
}
|
|
502
646
|
};
|
|
503
647
|
storageDelay.then(getStoredData);
|
|
504
648
|
const initial = getDefaultSave(klona(defaultState));
|
|
@@ -884,7 +1028,7 @@ var Novely = (() => {
|
|
|
884
1028
|
throw new Error("Attempt to use AnimateCharacter without classes. Classes should be provided [https://novely.pages.dev/guide/actions/animateCharacter.html]");
|
|
885
1029
|
}
|
|
886
1030
|
if (DEV && (timeout <= 0 || !Number.isFinite(timeout) || Number.isNaN(timeout))) {
|
|
887
|
-
throw new Error("Attempt to use AnimateCharacter with unacceptable timeout. It should be finite
|
|
1031
|
+
throw new Error("Attempt to use AnimateCharacter with unacceptable timeout. It should be finite and greater than zero");
|
|
888
1032
|
}
|
|
889
1033
|
const handler = (get) => {
|
|
890
1034
|
const { clear } = get("@@internal-animate-character", false);
|
|
@@ -1035,9 +1179,9 @@ var Novely = (() => {
|
|
|
1035
1179
|
}
|
|
1036
1180
|
return {
|
|
1037
1181
|
/**
|
|
1038
|
-
* Function to set
|
|
1182
|
+
* Function to set game script
|
|
1039
1183
|
*/
|
|
1040
|
-
|
|
1184
|
+
script,
|
|
1041
1185
|
/**
|
|
1042
1186
|
* Function to get actions
|
|
1043
1187
|
*/
|