@novely/dynamic-character 0.4.0 → 0.7.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.jsx DELETED
@@ -1,449 +0,0 @@
1
- // src/utils.ts
2
- var once = (fn) => {
3
- let called = false;
4
- return () => {
5
- if (!called) {
6
- called = true;
7
- fn();
8
- }
9
- };
10
- };
11
- var getEntries = (object) => {
12
- return Object.entries(object);
13
- };
14
- var getKeys = (object) => {
15
- return Object.keys(object);
16
- };
17
- var toArray = (target) => {
18
- return Array.isArray(target) ? target : [target];
19
- };
20
- var permutation = (items, size = items.length) => {
21
- if (!size) {
22
- return [[]];
23
- }
24
- size = Math.min(items.length, size);
25
- return items.flatMap((item) => {
26
- return permutation(
27
- items.filter((it) => it !== item),
28
- size - 1
29
- ).map((permutation2) => [item, ...permutation2]);
30
- });
31
- };
32
- var getEmotionString = ({ base, attributes }) => {
33
- return `${base}@${getEntries(attributes).map(([name, value]) => `${name}_${value}`).join("__")}`;
34
- };
35
- var getSavedEmotion = (state, character, clothingData, fallback) => {
36
- const id = `$$emotion_${character}`;
37
- const saved = state()[id];
38
- if (!saved) {
39
- return fallback;
40
- }
41
- const filteredAttributes = Object.keys(saved.attributes).filter((key) => key in fallback.attributes).reduce(
42
- (acc, key) => {
43
- acc[key] = saved.attributes[key];
44
- return acc;
45
- },
46
- {}
47
- );
48
- const base = clothingData.base.includes(saved.base) ? saved.base : fallback.base;
49
- return {
50
- base,
51
- attributes: {
52
- ...fallback.attributes,
53
- ...filteredAttributes
54
- }
55
- };
56
- };
57
- var saveEmotion = (state, character, emotion) => {
58
- state({ [`$$emotion_${character}`]: emotion });
59
- };
60
-
61
- // src/picker.ts
62
- import { createComponent } from "solid-js";
63
- import { render } from "solid-js/web";
64
-
65
- // src/components/Picker.tsx
66
- import { template as _$template2 } from "solid-js/web";
67
- import { delegateEvents as _$delegateEvents2 } from "solid-js/web";
68
- import { memo as _$memo } from "solid-js/web";
69
- import { effect as _$effect2 } from "solid-js/web";
70
- import { createComponent as _$createComponent2 } from "solid-js/web";
71
- import { insert as _$insert2 } from "solid-js/web";
72
- import { createSignal as createSignal2, Show } from "solid-js";
73
-
74
- // src/components/Slider.tsx
75
- import { template as _$template } from "solid-js/web";
76
- import { delegateEvents as _$delegateEvents } from "solid-js/web";
77
- import { setAttribute as _$setAttribute } from "solid-js/web";
78
- import { effect as _$effect } from "solid-js/web";
79
- import { insert as _$insert } from "solid-js/web";
80
- import { createComponent as _$createComponent } from "solid-js/web";
81
- import { createSignal, createEffect, untrack, createSelector, For } from "solid-js";
82
- var _tmpl$ = /* @__PURE__ */ _$template(`<div role="region" class="ndc-slider"><div role="group" class="ndc-controls"><button type="button" class="ndc-button-nav ndc-button-nav-prev"><svg data-icon fill="currentColor" viewBox="0 0 256 256"><path d="M165.66 202.34a8 8 0 0 1-11.32 11.32l-80-80a8 8 0 0 1 0-11.32l80-80a8 8 0 0 1 11.32 11.32L91.31 128Z"></path></svg></button><button type="button" class="ndc-button-nav ndc-button-nav-next"><svg data-icon fill="currentColor" viewBox="0 0 256 256"><path d="m181.66 133.66-80 80a8 8 0 0 1-11.32-11.32L164.69 128 90.34 53.66a8 8 0 0 1 11.32-11.32l80 80a8 8 0 0 1 0 11.32Z"></path></svg></button></div><div class="ndc-slides" aria-live="polite">`);
83
- var _tmpl$2 = /* @__PURE__ */ _$template(`<div role="group" class="ndc-slide">`);
84
- var Slider = (props) => {
85
- const [currentSlide, setCurrentSlide] = createSignal(props.initialSlideIndex);
86
- const isSelected = createSelector(currentSlide);
87
- createEffect(() => {
88
- const currentIndex = currentSlide();
89
- untrack(() => props.onIndexChange(currentIndex));
90
- });
91
- return (() => {
92
- const _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild, _el$4 = _el$3.nextSibling, _el$5 = _el$2.nextSibling;
93
- _el$.$$keydown = (event) => {
94
- if (event.key === "ArrowLeft") {
95
- setCurrentSlide((value) => value > 0 ? value - 1 : props.slides.length - 1);
96
- } else if (event.key === "ArrowRight") {
97
- setCurrentSlide((value) => value < props.slides.length - 1 ? value + 1 : 0);
98
- }
99
- };
100
- _el$3.$$click = () => {
101
- setCurrentSlide((slide) => {
102
- if (slide > 0) {
103
- return slide - 1;
104
- }
105
- return props.slides.length - 1;
106
- });
107
- };
108
- _el$4.$$click = () => {
109
- setCurrentSlide((slide) => {
110
- if (slide < props.slides.length - 1) {
111
- return slide + 1;
112
- }
113
- return 0;
114
- });
115
- };
116
- _$insert(_el$5, _$createComponent(For, {
117
- get each() {
118
- return props.slides;
119
- },
120
- children: (variant, i) => {
121
- return (() => {
122
- const _el$6 = _tmpl$2();
123
- _$insert(_el$6, () => props.children(variant, i));
124
- _$effect(() => _el$6.classList.toggle("ndc-slide-active", !!isSelected(i())));
125
- return _el$6;
126
- })();
127
- }
128
- }));
129
- _$effect((_p$) => {
130
- const _v$ = props.translation.ui.variants, _v$2 = !props.expanded, _v$3 = props.translation.ui.slidesControl, _v$4 = props.translation.ui.prevSlide, _v$5 = props.translation.ui.nextSlide;
131
- _v$ !== _p$._v$ && _$setAttribute(_el$, "aria-label", _p$._v$ = _v$);
132
- _v$2 !== _p$._v$2 && _el$.classList.toggle("ndc-slider-picker-collapsed", _p$._v$2 = _v$2);
133
- _v$3 !== _p$._v$3 && _$setAttribute(_el$2, "aria-label", _p$._v$3 = _v$3);
134
- _v$4 !== _p$._v$4 && _$setAttribute(_el$3, "aria-label", _p$._v$4 = _v$4);
135
- _v$5 !== _p$._v$5 && _$setAttribute(_el$4, "aria-label", _p$._v$5 = _v$5);
136
- return _p$;
137
- }, {
138
- _v$: void 0,
139
- _v$2: void 0,
140
- _v$3: void 0,
141
- _v$4: void 0,
142
- _v$5: void 0
143
- });
144
- return _el$;
145
- })();
146
- };
147
- _$delegateEvents(["keydown", "click"]);
148
-
149
- // src/components/Picker.tsx
150
- import pLimit from "p-limit";
151
- var _tmpl$3 = /* @__PURE__ */ _$template2(`<div class="ndc-picker-root"><button type="button" class="ndc-collapse-button"><svg data-icon fill="#fefefe" width="3rem" height="3rem" viewBox="0 0 256 256"><path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z"></path></svg></button><div class="ndc-heading">`);
152
- var _tmpl$22 = /* @__PURE__ */ _$template2(`<p class="ndc-variant-name">`);
153
- var _tmpl$32 = /* @__PURE__ */ _$template2(`<div class="ndc-control-buttons"><button type="button" class="button">`);
154
- var limitClick = pLimit(1);
155
- var Picker = (props) => {
156
- const [expanded, setExpanded] = createSignal2(props.initialExpanded);
157
- const [appearance, setAppearance] = createSignal2(props.initialEmotion);
158
- const initialSlideIndex = props.getInitialSlideIndex(appearance());
159
- return (() => {
160
- const _el$ = _tmpl$3(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild, _el$4 = _el$2.nextSibling;
161
- _el$2.$$click = () => {
162
- setExpanded((value) => !value);
163
- };
164
- _$insert2(_el$4, () => props.title);
165
- _$insert2(_el$, _$createComponent2(Slider, {
166
- get expanded() {
167
- return expanded();
168
- },
169
- initialSlideIndex,
170
- get slides() {
171
- return props.slides;
172
- },
173
- get translation() {
174
- return props.translation;
175
- },
176
- onIndexChange: (index) => props.onIndexChange(appearance(), setAppearance, index),
177
- children: (variant, i) => {
178
- const price = props.pricing[i()];
179
- const apply = once(() => {
180
- props.sumbit();
181
- props.saveEmotion(appearance());
182
- });
183
- const onClick = () => {
184
- limitClick(async () => {
185
- if (!price || props.isBought(variant)) {
186
- return apply();
187
- }
188
- if (await props.buy(variant)) {
189
- apply();
190
- }
191
- });
192
- };
193
- return [(() => {
194
- const _el$5 = _tmpl$22();
195
- _$insert2(_el$5, () => props.translationGroup[variant]);
196
- return _el$5;
197
- })(), (() => {
198
- const _el$6 = _tmpl$32(), _el$7 = _el$6.firstChild;
199
- _el$7.$$click = onClick;
200
- _$insert2(_el$7, _$createComponent2(Show, {
201
- get when() {
202
- return price && !props.isBought(variant);
203
- },
204
- get children() {
205
- return [_$memo(() => props.translation.ui.buy), " ", price];
206
- },
207
- get fallback() {
208
- return props.translation.ui.sumbit;
209
- }
210
- }));
211
- return _el$6;
212
- })()];
213
- }
214
- }), null);
215
- _$effect2((_p$) => {
216
- const _v$ = !expanded(), _v$2 = !expanded(), _v$3 = !expanded();
217
- _v$ !== _p$._v$ && _el$.classList.toggle("ndc-picker-root-collapsed", _p$._v$ = _v$);
218
- _v$2 !== _p$._v$2 && _el$3.classList.toggle("ndc-collapse-button-icon-collapsed", _p$._v$2 = _v$2);
219
- _v$3 !== _p$._v$3 && _el$4.classList.toggle("ndc-heading-picker-collapsed", _p$._v$3 = _v$3);
220
- return _p$;
221
- }, {
222
- _v$: void 0,
223
- _v$2: void 0,
224
- _v$3: void 0
225
- });
226
- return _el$;
227
- })();
228
- };
229
- _$delegateEvents2(["click"]);
230
-
231
- // src/picker.ts
232
- var CHARACTER_STYLE_PICKER = Symbol();
233
- var PRELOADED_EMOTIONS = /* @__PURE__ */ new Set();
234
- var showPicker = function(options) {
235
- const {
236
- clothingData,
237
- options: { character: characterId, defaultAttributes, defaultBase, translation: translations }
238
- } = this;
239
- const { base, attributes } = clothingData;
240
- const handler = ({ clear, flags, getDomNodes, rendererContext, lang, state }) => {
241
- const translation = translations[lang];
242
- const initialEmotion = getSavedEmotion(state, characterId, clothingData, {
243
- base: defaultBase,
244
- attributes: defaultAttributes
245
- });
246
- const { promise, resolve } = Promise.withResolvers();
247
- const { element } = getDomNodes(true);
248
- const character = rendererContext.character(characterId);
249
- character.emotion(getEmotionString(initialEmotion), true);
250
- character.append();
251
- const { title, slides, translationGroup, pricing, getInitialSlideIndex } = (() => {
252
- const { pricing: pricing2 } = clothingData;
253
- if (options.type === "attribute") {
254
- const slides2 = attributes[options.name];
255
- return {
256
- title: translation.title.attributes[options.name],
257
- slides: attributes[options.name],
258
- translationGroup: translation.attributes[options.name],
259
- pricing: pricing2 ? slides2.map((s) => pricing2.attributes[options.name][s]) : Array(slides2.length).fill(0),
260
- getInitialSlideIndex: (appearance) => {
261
- return slides2.indexOf(appearance.attributes[options.name]);
262
- }
263
- };
264
- }
265
- return {
266
- title: translation.title.base,
267
- slides: base,
268
- translationGroup: translation.base,
269
- pricing: pricing2 ? base.map((s) => pricing2.base[s]) : Array(base.length).fill(0),
270
- getInitialSlideIndex: (appearance) => {
271
- return base.indexOf(appearance.base);
272
- }
273
- };
274
- })();
275
- const onIndexChange = (appearance, setAppearance, slide) => {
276
- const updated = slides[slide];
277
- let emotion = "";
278
- if (options.type === "base") {
279
- emotion = getEmotionString(
280
- setAppearance({
281
- base: updated,
282
- attributes: appearance.attributes
283
- })
284
- );
285
- } else {
286
- emotion = getEmotionString(
287
- setAppearance({
288
- base: appearance.base,
289
- attributes: {
290
- ...appearance.attributes,
291
- [options.name]: updated
292
- }
293
- })
294
- );
295
- }
296
- character.emotion(emotion, true);
297
- PRELOADED_EMOTIONS.add(emotion);
298
- const nextIndex = slide < slides.length - 1 ? slide + 1 : 0;
299
- const prevIndex = slide > 0 ? slide - 1 : slides.length - 1;
300
- for (const index of [nextIndex, prevIndex]) {
301
- let emotion2 = "";
302
- if (options.type === "base") {
303
- emotion2 = getEmotionString({ base: slides[index], attributes: appearance.attributes });
304
- } else {
305
- emotion2 = getEmotionString({
306
- base: appearance.base,
307
- attributes: { ...appearance.attributes, [options.name]: slides[index] }
308
- });
309
- }
310
- if (PRELOADED_EMOTIONS.has(emotion2)) {
311
- continue;
312
- } else {
313
- PRELOADED_EMOTIONS.add(emotion2);
314
- }
315
- character.emotion(emotion2, false);
316
- }
317
- };
318
- const saveEmotionWrapper = (appearance) => {
319
- saveEmotion(state, characterId, appearance);
320
- };
321
- const cleanup = render(
322
- () => createComponent(Picker, {
323
- title,
324
- initialExpanded: !flags.preview,
325
- initialEmotion,
326
- slides,
327
- pricing,
328
- translation,
329
- translationGroup,
330
- getInitialSlideIndex,
331
- onIndexChange,
332
- saveEmotion: saveEmotionWrapper,
333
- sumbit: resolve,
334
- buy: options.buy,
335
- isBought: options.isBought
336
- }),
337
- element
338
- );
339
- const cleanupOnce = once(cleanup);
340
- clear(cleanupOnce);
341
- promise.then(cleanupOnce);
342
- return promise;
343
- };
344
- handler.id = CHARACTER_STYLE_PICKER;
345
- handler.key = `show-picker--${characterId}`;
346
- handler.callOnlyLatest = true;
347
- handler.requireUserAction = true;
348
- return handler;
349
- };
350
-
351
- // src/show.ts
352
- var SHOW_CHARACTER = Symbol();
353
- var showCharacter = function() {
354
- const handler = ({ rendererContext, state }) => {
355
- const emotion = getSavedEmotion(state, this.options.character, this.clothingData, {
356
- base: this.options.defaultBase,
357
- attributes: this.options.defaultAttributes
358
- });
359
- const emotionString = getEmotionString(emotion);
360
- const character = rendererContext.character(this.options.character);
361
- character.emotion(emotionString, true);
362
- character.append();
363
- };
364
- handler.id = SHOW_CHARACTER;
365
- handler.key = `dynamic-show-character--${this.options.character}`;
366
- handler.callOnlyLatest = true;
367
- return handler;
368
- };
369
-
370
- // src/actions.ts
371
- var DEFAULT_SHOW_BASE_OPTIONS = {
372
- type: "base",
373
- buy: async () => true,
374
- isBought: () => true
375
- };
376
- var DEFAULT_SHOW_ATTRIBUTE_OPTIONS = {
377
- type: "attribute",
378
- buy: async () => true,
379
- isBought: () => true
380
- };
381
- var createActions = function(engine, options) {
382
- const that = {
383
- clothingData: this,
384
- options
385
- };
386
- return {
387
- showBasePicker: (options2 = {}) => {
388
- const handler = showPicker.call(that, {
389
- ...DEFAULT_SHOW_BASE_OPTIONS,
390
- ...options2
391
- });
392
- return engine.action.custom(handler);
393
- },
394
- showAttributePicker: (options2) => {
395
- const handler = showPicker.call(that, {
396
- ...DEFAULT_SHOW_ATTRIBUTE_OPTIONS,
397
- ...options2
398
- });
399
- return engine.action.custom(handler);
400
- },
401
- showCharacter: () => {
402
- return engine.action.custom(showCharacter.call(that));
403
- }
404
- };
405
- };
406
-
407
- // src/emotions.ts
408
- var generateEmotions = ({
409
- base,
410
- attributes,
411
- pricing
412
- }) => {
413
- const emotions = {};
414
- const combineBaseWithAttributes = (baseEmotion, baseAssets, currentAttributes, attributesLeft) => {
415
- if (attributesLeft.length === 0) {
416
- const key = `${baseEmotion}@${currentAttributes.join("__")}`;
417
- emotions[key] = baseAssets;
418
- return;
419
- }
420
- const [attribute, variants] = attributesLeft[0];
421
- const remainingAttributes = attributesLeft.slice(1);
422
- for (const [variant, emotions2] of Object.entries(variants)) {
423
- const attributeAssets = emotions2[baseEmotion];
424
- combineBaseWithAttributes(
425
- baseEmotion,
426
- [...baseAssets, ...toArray(attributeAssets)],
427
- [...currentAttributes, `${attribute}_${variant}`],
428
- remainingAttributes
429
- );
430
- }
431
- };
432
- for (const [baseEmotion, baseAssets] of getEntries(base)) {
433
- for (const _permutation of permutation(getEntries(attributes))) {
434
- combineBaseWithAttributes(baseEmotion, toArray(baseAssets), [], _permutation);
435
- }
436
- }
437
- const clothingData = {
438
- base: getKeys(base),
439
- attributes: Object.fromEntries(getEntries(attributes).map(([name, value]) => [name, getKeys(value)])),
440
- pricing
441
- };
442
- return {
443
- emotions,
444
- createActions: createActions.bind(clothingData)
445
- };
446
- };
447
- export {
448
- generateEmotions
449
- };
package/dist/picker.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { CustomHandler } from '@novely/core';
2
- import type { AllThis, InternalShowPickerOptions } from './types';
3
- declare const showPicker: (this: AllThis, options: InternalShowPickerOptions) => CustomHandler;
4
- export { showPicker };
package/dist/show.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { CustomHandler } from '@novely/core';
2
- import type { AllThis } from './types';
3
- declare const showCharacter: (this: AllThis) => CustomHandler;
4
- export { showCharacter };
package/dist/types.d.ts DELETED
@@ -1,164 +0,0 @@
1
- import type { Character, Data, Lang, NovelyAsset, State, TypeEssentials, ValidAction } from '@novely/core';
2
- type Attributes<BaseKeys extends string = string> = Record<string, Record<string, Record<BaseKeys, NovelyAsset | NovelyAsset[]>>>;
3
- type EmotionsDefinition<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
4
- base: Record<BaseKeys, NovelyAsset | NovelyAsset[]>;
5
- attributes: Attribs;
6
- pricing?: {
7
- base: Record<BaseKeys, number>;
8
- attributes: {
9
- [Attribute in keyof Attribs]: Record<keyof Attribs[Attribute], number>;
10
- };
11
- };
12
- };
13
- /**
14
- * Utilities
15
- *
16
- * https://stackoverflow.com/a/55128956
17
- * https://blog.beraliv.dev/2021-05-30-permutations-in-typescript
18
- * https://twitter.com/mattpocockuk/status/1622730173446557697
19
- */
20
- type Permutation<T, K = T> = [T] extends [never] ? [] : K extends unknown ? [K, ...Permutation<Exclude<T, K>>] : never;
21
- type Prettify<T> = {
22
- [K in keyof T]: T[K];
23
- } & {};
24
- /** Types */
25
- type GetAttributeVariants<Attribs extends Attributes, Attribute extends string> = {
26
- [Variant in keyof Attribs[Attribute] & string]: `${Attribute & string}_${Variant}`;
27
- }[keyof Attribs[Attribute] & string];
28
- type GetAttributesTuple<Attribs extends Attributes> = Permutation<keyof Attribs>;
29
- type GetAttributesVariants<Attribs extends Attributes, T extends unknown[]> = T extends [
30
- infer First,
31
- ...infer Rest
32
- ] ? First extends string ? [Permutation<GetAttributeVariants<Attribs, First>>, ...GetAttributesVariants<Attribs, Rest>] : never : [];
33
- type CombineAttributes<T extends any[], Prefix extends string = ''> = T extends [infer First, ...infer Rest] ? First extends string[] ? Rest extends any[] ? CombineAttributes<Rest, `${Prefix}${First[number]}__`> : never : never : Prefix extends `${infer Result}__` ? Result : never;
34
- type AddBase<BaseKeys extends string, Attributes extends string> = `${BaseKeys}@${Attributes}`;
35
- type GenerateEmotions<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = AddBase<BaseKeys, CombineAttributes<GetAttributesVariants<Attribs, GetAttributesTuple<Attribs>>>>;
36
- type GeneratedEmotions<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = Prettify<Record<GenerateEmotions<BaseKeys, Attribs>, NovelyAsset[]>>;
37
- type ClothingData<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
38
- base: BaseKeys[];
39
- attributes: {
40
- [Attribute in keyof Attribs]: (keyof Attribs[Attribute] & string)[];
41
- };
42
- pricing?: {
43
- base: Record<BaseKeys, number>;
44
- attributes: {
45
- [Attribute in keyof Attribs]: Record<keyof Attribs[Attribute], number>;
46
- };
47
- };
48
- };
49
- type CreateActionsFN<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
50
- <Engine extends EngineInstance>(engine: Engine, options: AllOptions<NoInfer<Engine['typeEssentials']>, NoInfer<BaseKeys>, NoInfer<Attribs>>): {
51
- showBasePicker: (options?: ShowPickerOptionsBase) => ValidAction;
52
- showAttributePicker: (options: ShowPickerOptionsAttribute<Attribs>) => ValidAction;
53
- showCharacter: () => ValidAction;
54
- };
55
- };
56
- type EmotionsResult<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
57
- emotions: GeneratedEmotions<BaseKeys, Attribs>;
58
- createActions: CreateActionsFN<BaseKeys, Attribs>;
59
- };
60
- type Entries<T> = T extends Record<infer T, infer K> ? [T, K][] : never;
61
- type DefaultTypeEssentials = TypeEssentials<Lang, State, Data, Record<string, Character>>;
62
- type AllOptions<TE extends DefaultTypeEssentials, BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
63
- /**
64
- * Character ID
65
- */
66
- character: string;
67
- /**
68
- * Default style base
69
- */
70
- defaultBase: BaseKeys;
71
- /**
72
- * Default style attributes
73
- */
74
- defaultAttributes: {
75
- [Attribute in keyof Attribs]: keyof Attribs[Attribute] & string;
76
- };
77
- /**
78
- * Translation
79
- */
80
- translation: {
81
- [Language in NonNullable<TE['l']>]: {
82
- /**
83
- * Attribute items translations
84
- */
85
- attributes: {
86
- [Attribute in keyof Attribs]: {
87
- [Variant in keyof Attribs[Attribute]]: string;
88
- };
89
- };
90
- /**
91
- * Base translations
92
- */
93
- base: {
94
- [Base in BaseKeys]: string;
95
- };
96
- /**
97
- * Title translations
98
- */
99
- title: {
100
- base: string;
101
- attributes: {
102
- [Attribute in keyof Attribs]: string;
103
- };
104
- };
105
- /**
106
- * Translation of UI components
107
- */
108
- ui: {
109
- variants: string;
110
- slidesControl: string;
111
- prevSlide: string;
112
- nextSlide: string;
113
- sumbit: string;
114
- buy: string;
115
- };
116
- };
117
- };
118
- };
119
- type AllThis = {
120
- clothingData: ClothingData<string, Attributes>;
121
- options: AllOptions<DefaultTypeEssentials, string, Attributes>;
122
- };
123
- type EmotionObject = {
124
- base: string;
125
- attributes: Record<string, string>;
126
- };
127
- type InternalShowPickerBase = {
128
- type: 'base';
129
- };
130
- type InternalShowPickerAttribute = {
131
- type: 'attribute';
132
- name: string;
133
- };
134
- type InternalShowPickerBuyOptions = {
135
- buy: (variant: string) => Promise<boolean>;
136
- isBought: (variant: string) => boolean;
137
- };
138
- type InternalShowPickerOptions = (InternalShowPickerBase | InternalShowPickerAttribute) & InternalShowPickerBuyOptions;
139
- type ShowPickerBuyFunctions = {
140
- /**
141
- * Function to buy attribute variant
142
- * @param variant Attribute variant
143
- * @returns Boolean indicating is item bought or not
144
- */
145
- buy?: (variant: string) => Promise<boolean>;
146
- /**
147
- * Function to check is attribute variant is bought
148
- * @param variant Attribute variant
149
- * @returns Boolean indicating is item bought or not
150
- */
151
- isBought?: (variant: string) => boolean;
152
- };
153
- type ShowPickerOptionsAttribute<Attribs extends Attributes> = ShowPickerBuyFunctions & {
154
- /**
155
- * Name of the attribute
156
- */
157
- name: keyof Attribs & string;
158
- };
159
- type ShowPickerOptionsBase = ShowPickerBuyFunctions;
160
- type EngineInstance = {
161
- action: Record<string, (...args: any[]) => ValidAction>;
162
- typeEssentials: DefaultTypeEssentials;
163
- };
164
- export type { Entries, EmotionsDefinition, EmotionsResult, Attributes, ClothingData, EmotionObject, AllOptions, AllThis, DefaultTypeEssentials, InternalShowPickerOptions, ShowPickerOptionsAttribute, ShowPickerOptionsBase, EngineInstance, };
package/dist/utils.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import type { StateFunction, State } from '@novely/core';
2
- import type { EmotionObject, ClothingData, Attributes } from './types';
3
- declare const once: (fn: () => void) => () => void;
4
- declare const getEntries: <T extends PropertyKey, K>(object: Record<T, K>) => [T, K][];
5
- declare const getKeys: <T extends PropertyKey>(object: Record<T, unknown>) => T[];
6
- declare const toArray: <T>(target: T | T[]) => T[];
7
- declare const permutation: <T>(items: T[], size?: number) => T[][];
8
- declare const getEmotionString: ({ base, attributes }: EmotionObject) => string;
9
- /**
10
- * Return fallback value joined with saved emotion, when there is no saved, returns only fallback
11
- * @param character Character Id
12
- * @param fallback Default emotions
13
- */
14
- declare const getSavedEmotion: (state: StateFunction<State>, character: string, clothingData: ClothingData<string, Attributes>, fallback: EmotionObject) => EmotionObject;
15
- declare const saveEmotion: (state: StateFunction<State>, character: string, emotion: EmotionObject) => void;
16
- export { once, getEntries, getKeys, toArray, permutation, getEmotionString, saveEmotion, getSavedEmotion };