@novely/dynamic-character 0.3.1 → 0.5.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/README.md +58 -37
- package/dist/actions.d.ts +7 -0
- package/dist/components/Picker.d.ts +19 -0
- package/dist/components/Slider.d.ts +12 -0
- package/dist/emotions.d.ts +1 -1
- package/dist/index.css +10 -26
- package/dist/index.d.ts +1 -6
- package/dist/index.jsx +338 -323
- package/dist/picker.d.ts +2 -2
- package/dist/show.d.ts +2 -2
- package/dist/types.d.ts +66 -21
- package/dist/utils.d.ts +2 -1
- package/package.json +6 -6
- package/dist/slider.d.ts +0 -3
package/README.md
CHANGED
|
@@ -2,81 +2,89 @@
|
|
|
2
2
|
|
|
3
3
|
Will give a way to dynamically dress characters.
|
|
4
4
|
|
|
5
|
+
<div style="width: 100%; display: flex; justify-content: flex-start;">
|
|
6
|
+
<img alt="" src="https://raw.githubusercontent.com/yhdgms1/novely/main/packages/dynamic-character/preview.jpg" style="max-height: 20vh; max-width: 100vw;" />
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
5
11
|
```ts
|
|
6
12
|
import { generateEmotions } from '@novely/dynamic-character';
|
|
7
13
|
import '@novely/dynamic-character/dist/index.css';
|
|
8
14
|
```
|
|
9
15
|
|
|
10
16
|
```ts
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
17
|
+
import { novely, asset, EN } from '@novely/core';
|
|
18
|
+
|
|
19
|
+
import You_female from './assets/You-female-body.png';
|
|
20
|
+
import You_female_bottoms__shorts from './assets/You-female-bottoms--shorts.png'
|
|
21
|
+
import You_female_bottoms__jeans from './assets/You-female-bottoms--jeans.png'
|
|
22
|
+
import You_female_tops__pink_tshirt from './assets/You-female-tops--pink-t-shirt.png';
|
|
23
|
+
import You_female_tops__white_tshirt from './assets/You-female-tops--white-t-shirt.png';
|
|
16
24
|
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
25
|
+
import You_male from './assets/You-male-body.png';
|
|
26
|
+
import You_male_bottoms__shorts from './assets/You-male-bottoms--shorts.png'
|
|
27
|
+
import You_male_bottoms__jeans from './assets/You-male-bottoms--jeans.png'
|
|
28
|
+
import You_male_tops__pink_tshirt from './assets/You-male-tops--pink-t-shirt.png';
|
|
29
|
+
import You_male_tops__white_tshirt from './assets/You-male-tops--white-t-shirt.png';
|
|
22
30
|
|
|
23
|
-
const { emotions:
|
|
31
|
+
const { emotions: emotionsYou, createActions: createActionsYou } = generateEmotions({
|
|
24
32
|
base: {
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
male: asset(You_male),
|
|
34
|
+
female: asset(You_female)
|
|
27
35
|
},
|
|
28
36
|
attributes: {
|
|
29
37
|
bottoms: {
|
|
30
38
|
shorts: {
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
female: asset(You_female_bottoms__shorts),
|
|
40
|
+
male: asset(You_male_bottoms__shorts)
|
|
33
41
|
},
|
|
34
42
|
jeans: {
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
female: asset(You_female_bottoms__jeans),
|
|
44
|
+
male: asset(You_male_bottoms__jeans)
|
|
37
45
|
}
|
|
38
46
|
},
|
|
39
47
|
tops: {
|
|
40
48
|
pink: {
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
male: asset(You_male_tops__pink_tshirt),
|
|
50
|
+
female: asset(You_female_tops__pink_tshirt)
|
|
43
51
|
},
|
|
44
52
|
white: {
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
male: asset(You_male_tops__white_tshirt),
|
|
54
|
+
female: asset(You_female_tops__white_tshirt)
|
|
47
55
|
}
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
});
|
|
51
59
|
|
|
52
60
|
const engine = novely({
|
|
53
|
-
|
|
61
|
+
...,
|
|
54
62
|
translation: {
|
|
55
63
|
en: {
|
|
56
64
|
internal: EN
|
|
57
65
|
}
|
|
58
66
|
},
|
|
59
67
|
characters: {
|
|
60
|
-
|
|
68
|
+
You: {
|
|
61
69
|
name: {
|
|
62
|
-
en: '
|
|
70
|
+
en: 'You',
|
|
63
71
|
},
|
|
64
72
|
color: '#000000',
|
|
65
|
-
emotions:
|
|
73
|
+
emotions: emotionsYou
|
|
66
74
|
},
|
|
67
75
|
},
|
|
68
76
|
});
|
|
69
77
|
|
|
70
|
-
const
|
|
71
|
-
character: '
|
|
72
|
-
defaultBase: '
|
|
78
|
+
const dynamicYou = createActionsYou(engine, {
|
|
79
|
+
character: 'You',
|
|
80
|
+
defaultBase: 'male',
|
|
73
81
|
defaultAttributes: {
|
|
74
82
|
bottoms: 'jeans',
|
|
75
83
|
tops: 'white'
|
|
76
84
|
},
|
|
77
85
|
translation: {
|
|
78
86
|
en: {
|
|
79
|
-
|
|
87
|
+
title: {
|
|
80
88
|
base: 'Body',
|
|
81
89
|
attributes: {
|
|
82
90
|
bottoms: 'Bottoms',
|
|
@@ -84,8 +92,8 @@ const { showPicker: showPickerYou, showCharacter: showYou } = createPickerAction
|
|
|
84
92
|
}
|
|
85
93
|
},
|
|
86
94
|
base: {
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
male: 'Male',
|
|
96
|
+
female: 'Female'
|
|
89
97
|
},
|
|
90
98
|
attributes: {
|
|
91
99
|
bottoms: {
|
|
@@ -98,19 +106,32 @@ const { showPicker: showPickerYou, showCharacter: showYou } = createPickerAction
|
|
|
98
106
|
}
|
|
99
107
|
},
|
|
100
108
|
ui: {
|
|
101
|
-
tablist: 'Clothing Options',
|
|
102
109
|
variants: 'Options',
|
|
103
110
|
slidesControl: 'Slides Control',
|
|
104
111
|
prevSlide: 'Previous',
|
|
105
112
|
nextSlide: 'Next',
|
|
106
|
-
sumbit: 'Submit'
|
|
113
|
+
sumbit: 'Submit',
|
|
114
|
+
sumbit: 'Submit',
|
|
115
|
+
buy: 'Buy'
|
|
107
116
|
}
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
});
|
|
111
120
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
engine.script({
|
|
122
|
+
start: [
|
|
123
|
+
// Male or Female
|
|
124
|
+
dynamicYou.showBasePicker(),
|
|
125
|
+
// Jeans or Shorts
|
|
126
|
+
dynamicYou.showAttributePicker({ name: 'bottoms' }),
|
|
127
|
+
// Pink or White t-shirt
|
|
128
|
+
dynamicYou.showAttributePicker({ name: 'tops' }),
|
|
129
|
+
// Show the character
|
|
130
|
+
dynamicYou.showCharacter(),
|
|
131
|
+
// Admire the appearance :)
|
|
132
|
+
engine.action.say("You", "Mirror, Mirror on the Wall, Who’s the Fairest of Them All?"),
|
|
133
|
+
engine.action.end()
|
|
134
|
+
]
|
|
135
|
+
})
|
|
115
136
|
|
|
116
|
-
|
|
137
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EngineInstance, Attributes, ClothingData, AllOptions, ShowPickerOptionsAttribute, ShowPickerOptionsBase, DefaultEngineTypes } from './types';
|
|
2
|
+
declare const createActions: (this: ClothingData<string, Attributes>, engine: EngineInstance, options: AllOptions<DefaultEngineTypes, string, Attributes>) => {
|
|
3
|
+
showBasePicker: (options?: ShowPickerOptionsBase) => import("@novely/core").ValidAction;
|
|
4
|
+
showAttributePicker: (options: ShowPickerOptionsAttribute<Attributes>) => import("@novely/core").ValidAction;
|
|
5
|
+
showCharacter: () => import("@novely/core").ValidAction;
|
|
6
|
+
};
|
|
7
|
+
export { createActions };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Component, Setter } from 'solid-js';
|
|
2
|
+
import type { AllThis, EmotionObject } from '../types';
|
|
3
|
+
type PickerProps = {
|
|
4
|
+
title: string;
|
|
5
|
+
initialExpanded: boolean;
|
|
6
|
+
initialEmotion: EmotionObject;
|
|
7
|
+
slides: string[];
|
|
8
|
+
pricing: number[];
|
|
9
|
+
translationGroup: Record<string, string>;
|
|
10
|
+
translation: AllThis['options']['translation'][string];
|
|
11
|
+
getInitialSlideIndex: (appearance: EmotionObject) => number;
|
|
12
|
+
onIndexChange: (appearance: EmotionObject, setAppearance: Setter<EmotionObject>, slide: number) => void;
|
|
13
|
+
saveEmotion: (appearance: EmotionObject) => void;
|
|
14
|
+
sumbit: () => void;
|
|
15
|
+
buy: (variant: string) => Promise<boolean>;
|
|
16
|
+
isBought: (variant: string) => boolean;
|
|
17
|
+
};
|
|
18
|
+
declare const Picker: Component<PickerProps>;
|
|
19
|
+
export { Picker };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Accessor, Component, JSX } from 'solid-js';
|
|
2
|
+
import type { AllThis } from '../types';
|
|
3
|
+
type SliderProps = {
|
|
4
|
+
initialSlideIndex: number;
|
|
5
|
+
slides: string[];
|
|
6
|
+
expanded: boolean;
|
|
7
|
+
translation: AllThis['options']['translation'][string];
|
|
8
|
+
children: (slide: string, i: Accessor<number>) => JSX.Element;
|
|
9
|
+
onIndexChange: (currentIndex: number) => void;
|
|
10
|
+
};
|
|
11
|
+
declare const Slider: Component<SliderProps>;
|
|
12
|
+
export { Slider };
|
package/dist/emotions.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Attributes, EmotionsDefinition, EmotionsResult } from './types';
|
|
2
|
-
declare const generateEmotions: <BaseKeys extends string, Attribs extends Attributes<BaseKeys>>({ base, attributes, }: EmotionsDefinition<BaseKeys, Attribs>) => EmotionsResult<BaseKeys, Attribs>;
|
|
2
|
+
declare const generateEmotions: <BaseKeys extends string, Attribs extends Attributes<BaseKeys>>({ base, attributes, pricing, }: EmotionsDefinition<BaseKeys, Attribs>) => EmotionsResult<BaseKeys, Attribs>;
|
|
3
3
|
export { generateEmotions };
|
package/dist/index.css
CHANGED
|
@@ -41,39 +41,23 @@
|
|
|
41
41
|
.ndc-tabpanel-hidden {
|
|
42
42
|
display: none;
|
|
43
43
|
}
|
|
44
|
-
.ndc-
|
|
45
|
-
|
|
44
|
+
.ndc-heading {
|
|
45
|
+
margin-top: -2rem;
|
|
46
|
+
width: 40%;
|
|
46
47
|
box-shadow: 0 0 0 .15rem var(--appearance-picker-tablist-border-color, #ffa6cd), var(--novely-px) var(--novely-px) .25rem var(--appearance-picker-box-shadow-color, #00000072);
|
|
48
|
+
text-align: center;
|
|
47
49
|
background-color: #ffc7df;
|
|
48
50
|
border-radius: .875rem;
|
|
49
|
-
flex-flow: row;
|
|
50
51
|
gap: .5rem;
|
|
51
|
-
margin-
|
|
52
|
-
|
|
52
|
+
margin-left: auto;
|
|
53
|
+
margin-right: auto;
|
|
54
|
+
padding: .75rem;
|
|
53
55
|
transition: opacity .15s ease-in-out;
|
|
54
|
-
display: flex;
|
|
55
56
|
}
|
|
56
|
-
.ndc-
|
|
57
|
+
.ndc-heading-picker-collapsed {
|
|
57
58
|
opacity: 0;
|
|
58
59
|
pointer-events: none;
|
|
59
60
|
}
|
|
60
|
-
.ndc-tab-button {
|
|
61
|
-
cursor: pointer;
|
|
62
|
-
white-space: nowrap;
|
|
63
|
-
background-color: #ffe9f3;
|
|
64
|
-
border: none;
|
|
65
|
-
border-radius: .5rem;
|
|
66
|
-
flex-shrink: 0;
|
|
67
|
-
place-content: center;
|
|
68
|
-
align-items: center;
|
|
69
|
-
padding: .55rem .85rem;
|
|
70
|
-
display: flex;
|
|
71
|
-
box-shadow: 0 0 0 .1rem #ffa6cd;
|
|
72
|
-
}
|
|
73
|
-
.ndc-tab-button:hover {
|
|
74
|
-
color: var(--novely-button-hover-color, #ffb7a2);
|
|
75
|
-
background-color: #fff;
|
|
76
|
-
}
|
|
77
61
|
.ndc-slider {
|
|
78
62
|
flex-direction: column;
|
|
79
63
|
align-items: center;
|
|
@@ -157,7 +141,7 @@
|
|
|
157
141
|
.ndc-picker-root-collapsed {
|
|
158
142
|
transform: translateY(calc(100% - 1.2rem));
|
|
159
143
|
}
|
|
160
|
-
.ndc-
|
|
144
|
+
.ndc-heading {
|
|
161
145
|
box-shadow: 0 0 0 .1rem var(--appearance-picker-tablist-border-color, #ffa6cd);
|
|
162
146
|
}
|
|
163
147
|
.ndc-slider,
|
|
@@ -196,7 +180,7 @@
|
|
|
196
180
|
border-bottom-right-radius: 0;
|
|
197
181
|
border-bottom-left-radius: 0;
|
|
198
182
|
}
|
|
199
|
-
.ndc-
|
|
183
|
+
.ndc-heading-picker-collapsed,
|
|
200
184
|
.ndc-slider-picker-collapsed {
|
|
201
185
|
opacity: 0;
|
|
202
186
|
pointer-events: none;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export type { Attributes, ClothingData, AllOptions, EmotionObject, EmotionsResult, ShowPickerOptionsAttribute, ShowPickerOptionsBase, } from './types';
|
|
2
2
|
export { generateEmotions } from './emotions';
|
|
3
|
-
declare const createDynamicCharacter: <TE extends DefaultTypeEssentials, BaseKeys extends string, Attribs extends Attributes<BaseKeys>>(_: TE, clothingData: ClothingData<BaseKeys, Attribs>, options: DynCharacterOptions<NoInfer<TE>, NoInfer<BaseKeys>, NoInfer<Attribs>>) => {
|
|
4
|
-
showPicker: () => import("@novely/core").CustomHandler;
|
|
5
|
-
showCharacter: () => import("@novely/core").CustomHandler;
|
|
6
|
-
};
|
|
7
|
-
export { createDynamicCharacter };
|
package/dist/index.jsx
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
var getEntries = (object) => {
|
|
3
12
|
return Object.entries(object);
|
|
4
13
|
};
|
|
@@ -49,345 +58,287 @@ var saveEmotion = (state, character, emotion) => {
|
|
|
49
58
|
state({ [`$$emotion_${character}`]: emotion });
|
|
50
59
|
};
|
|
51
60
|
|
|
52
|
-
// src/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const [attribute, variants] = attributesLeft[0];
|
|
65
|
-
const remainingAttributes = attributesLeft.slice(1);
|
|
66
|
-
for (const [variant, emotions2] of Object.entries(variants)) {
|
|
67
|
-
const attributeAssets = emotions2[baseEmotion];
|
|
68
|
-
combineBaseWithAttributes(
|
|
69
|
-
baseEmotion,
|
|
70
|
-
[...baseAssets, ...toArray(attributeAssets)],
|
|
71
|
-
[...currentAttributes, `${attribute}_${variant}`],
|
|
72
|
-
remainingAttributes
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
for (const [baseEmotion, baseAssets] of getEntries(base)) {
|
|
77
|
-
for (const _permutation of permutation(getEntries(attributes))) {
|
|
78
|
-
combineBaseWithAttributes(baseEmotion, toArray(baseAssets), [], _permutation);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const clothingData = {
|
|
82
|
-
base: getKeys(base),
|
|
83
|
-
attributes: Object.fromEntries(getEntries(attributes).map(([name, value]) => [name, getKeys(value)]))
|
|
84
|
-
};
|
|
85
|
-
return {
|
|
86
|
-
emotions,
|
|
87
|
-
clothingData
|
|
88
|
-
};
|
|
89
|
-
};
|
|
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";
|
|
90
73
|
|
|
91
|
-
// src/
|
|
74
|
+
// src/components/Slider.tsx
|
|
92
75
|
import { template as _$template } from "solid-js/web";
|
|
93
76
|
import { delegateEvents as _$delegateEvents } from "solid-js/web";
|
|
94
|
-
import { memo as _$memo } from "solid-js/web";
|
|
95
77
|
import { setAttribute as _$setAttribute } from "solid-js/web";
|
|
96
78
|
import { effect as _$effect } from "solid-js/web";
|
|
97
79
|
import { insert as _$insert } from "solid-js/web";
|
|
98
80
|
import { createComponent as _$createComponent } from "solid-js/web";
|
|
99
|
-
import {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
+
var _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
|
+
var _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
|
+
var _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$.e && _$setAttribute(_el$, "aria-label", _p$.e = _v$);
|
|
132
|
+
_v$2 !== _p$.t && _el$.classList.toggle("ndc-slider-picker-collapsed", _p$.t = _v$2);
|
|
133
|
+
_v$3 !== _p$.a && _$setAttribute(_el$2, "aria-label", _p$.a = _v$3);
|
|
134
|
+
_v$4 !== _p$.o && _$setAttribute(_el$3, "aria-label", _p$.o = _v$4);
|
|
135
|
+
_v$5 !== _p$.i && _$setAttribute(_el$4, "aria-label", _p$.i = _v$5);
|
|
136
|
+
return _p$;
|
|
137
|
+
}, {
|
|
138
|
+
e: void 0,
|
|
139
|
+
t: void 0,
|
|
140
|
+
a: void 0,
|
|
141
|
+
o: void 0,
|
|
142
|
+
i: void 0
|
|
121
143
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
var _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);
|
|
130
163
|
};
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
+
var _el$5 = _tmpl$22();
|
|
195
|
+
_$insert2(_el$5, () => props.translationGroup[variant]);
|
|
196
|
+
return _el$5;
|
|
197
|
+
})(), (() => {
|
|
198
|
+
var _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
|
+
var _v$ = !expanded(), _v$2 = !expanded(), _v$3 = !expanded();
|
|
217
|
+
_v$ !== _p$.e && _el$.classList.toggle("ndc-picker-root-collapsed", _p$.e = _v$);
|
|
218
|
+
_v$2 !== _p$.t && _el$3.classList.toggle("ndc-collapse-button-icon-collapsed", _p$.t = _v$2);
|
|
219
|
+
_v$3 !== _p$.a && _el$4.classList.toggle("ndc-heading-picker-collapsed", _p$.a = _v$3);
|
|
220
|
+
return _p$;
|
|
221
|
+
}, {
|
|
222
|
+
e: void 0,
|
|
223
|
+
t: void 0,
|
|
224
|
+
a: void 0
|
|
225
|
+
});
|
|
226
|
+
return _el$;
|
|
227
|
+
})();
|
|
134
228
|
};
|
|
135
|
-
|
|
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) {
|
|
136
235
|
const {
|
|
137
236
|
clothingData,
|
|
138
|
-
options: {
|
|
139
|
-
character: characterId,
|
|
140
|
-
defaultAttributes,
|
|
141
|
-
defaultBase,
|
|
142
|
-
excludeAttributes,
|
|
143
|
-
translation: translations
|
|
144
|
-
}
|
|
237
|
+
options: { character: characterId, defaultAttributes, defaultBase, translation: translations }
|
|
145
238
|
} = this;
|
|
146
|
-
const {
|
|
147
|
-
|
|
148
|
-
attributes
|
|
149
|
-
} = clothingData;
|
|
150
|
-
const handler = ({
|
|
151
|
-
clear,
|
|
152
|
-
flags,
|
|
153
|
-
getDomNodes,
|
|
154
|
-
rendererContext,
|
|
155
|
-
lang,
|
|
156
|
-
state
|
|
157
|
-
}) => {
|
|
239
|
+
const { base, attributes } = clothingData;
|
|
240
|
+
const handler = ({ clear, flags, getDomNodes, rendererContext, lang, state }) => {
|
|
158
241
|
const translation = translations[lang];
|
|
159
242
|
const initialEmotion = getSavedEmotion(state, characterId, clothingData, {
|
|
160
243
|
base: defaultBase,
|
|
161
244
|
attributes: defaultAttributes
|
|
162
245
|
});
|
|
163
|
-
const {
|
|
164
|
-
|
|
165
|
-
resolve
|
|
166
|
-
} = Promise.withResolvers();
|
|
167
|
-
const {
|
|
168
|
-
element
|
|
169
|
-
} = getDomNodes(true);
|
|
246
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
247
|
+
const { element } = getDomNodes(true);
|
|
170
248
|
const character = rendererContext.character(characterId);
|
|
171
249
|
character.emotion(getEmotionString(initialEmotion), true);
|
|
172
250
|
character.append();
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
character.emotion(getEmotionString(appearance()), true);
|
|
185
|
-
saveEmotion(state, characterId, appearance());
|
|
186
|
-
});
|
|
187
|
-
return (() => {
|
|
188
|
-
const _el$ = _tmpl$(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild, _el$4 = _el$2.nextSibling;
|
|
189
|
-
_el$2.$$click = () => {
|
|
190
|
-
setExpanded((value) => !value);
|
|
191
|
-
};
|
|
192
|
-
_$use((element2) => onCleanup(slidy(element2, {
|
|
193
|
-
axis: "x"
|
|
194
|
-
}).destroy), _el$4);
|
|
195
|
-
_$insert(_el$4, _$createComponent(For, {
|
|
196
|
-
each: tabs,
|
|
197
|
-
children: (tab, i) => (() => {
|
|
198
|
-
const _el$5 = _tmpl$2();
|
|
199
|
-
_$use((element2) => {
|
|
200
|
-
setTabElements((elements) => {
|
|
201
|
-
elements[i()] = element2;
|
|
202
|
-
return elements;
|
|
203
|
-
});
|
|
204
|
-
}, _el$5);
|
|
205
|
-
_el$5.$$keydown = (event) => {
|
|
206
|
-
const change = event.key === "ArrowLeft" ? -1 : event.key === "ArrowRight" ? 1 : 0;
|
|
207
|
-
if (change === 0) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
event.stopPropagation();
|
|
211
|
-
event.preventDefault();
|
|
212
|
-
const nextTab = activeTab() + change;
|
|
213
|
-
if (nextTab < 0) {
|
|
214
|
-
setActiveTab(tabs.length - 1);
|
|
215
|
-
} else if (nextTab > tabs.length - 1) {
|
|
216
|
-
setActiveTab(0);
|
|
217
|
-
} else {
|
|
218
|
-
setActiveTab(nextTab);
|
|
219
|
-
}
|
|
220
|
-
const activeTabElement = tabElements()[activeTab()];
|
|
221
|
-
if (activeTabElement) {
|
|
222
|
-
activeTabElement.focus();
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
_el$5.$$click = () => {
|
|
226
|
-
setActiveTab(i());
|
|
227
|
-
};
|
|
228
|
-
_$insert(_el$5, () => tab.type === "attribute" ? translation.tabs.attributes[tab.value] : translation.tabs.base);
|
|
229
|
-
_$effect((_p$) => {
|
|
230
|
-
const _v$5 = tab.tab, _v$6 = tab.panel, _v$7 = i() === activeTab(), _v$8 = i() === activeTab() ? void 0 : -1;
|
|
231
|
-
_v$5 !== _p$._v$5 && _$setAttribute(_el$5, "id", _p$._v$5 = _v$5);
|
|
232
|
-
_v$6 !== _p$._v$6 && _$setAttribute(_el$5, "aria-controls", _p$._v$6 = _v$6);
|
|
233
|
-
_v$7 !== _p$._v$7 && _$setAttribute(_el$5, "aria-selected", _p$._v$7 = _v$7);
|
|
234
|
-
_v$8 !== _p$._v$8 && _$setAttribute(_el$5, "tabindex", _p$._v$8 = _v$8);
|
|
235
|
-
return _p$;
|
|
236
|
-
}, {
|
|
237
|
-
_v$5: void 0,
|
|
238
|
-
_v$6: void 0,
|
|
239
|
-
_v$7: void 0,
|
|
240
|
-
_v$8: void 0
|
|
241
|
-
});
|
|
242
|
-
return _el$5;
|
|
243
|
-
})()
|
|
244
|
-
}));
|
|
245
|
-
_$insert(_el$, _$createComponent(For, {
|
|
246
|
-
each: tabs,
|
|
247
|
-
children: (tab, i) => {
|
|
248
|
-
const variants = tab.type === "attribute" ? attributes[tab.value] : base;
|
|
249
|
-
const translationGroup = tab.type === "attribute" ? translation.attributes[tab.value] : translation.base;
|
|
250
|
-
const initialSlideIndex = (() => {
|
|
251
|
-
const currentAppearance = untrack(appearance);
|
|
252
|
-
if (tab.type === "base") {
|
|
253
|
-
return base.indexOf(currentAppearance.base);
|
|
254
|
-
}
|
|
255
|
-
return variants.indexOf(currentAppearance.attributes[tab.value]);
|
|
256
|
-
})();
|
|
257
|
-
const [currentSlide, setCurrentSlide] = createSignal(initialSlideIndex);
|
|
258
|
-
createEffect(() => {
|
|
259
|
-
if (activeTab() !== i()) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const currentAppearance = untrack(appearance);
|
|
263
|
-
const slide = currentSlide();
|
|
264
|
-
const currentVariant = variants[slide];
|
|
265
|
-
if (tab.type === "base") {
|
|
266
|
-
const emotion = getEmotionString(setAppearance({
|
|
267
|
-
base: currentVariant,
|
|
268
|
-
attributes: currentAppearance.attributes
|
|
269
|
-
}));
|
|
270
|
-
character.emotion(emotion, true);
|
|
271
|
-
PRELOADED_EMOTIONS.add(emotion);
|
|
272
|
-
} else {
|
|
273
|
-
const emotion = getEmotionString(setAppearance({
|
|
274
|
-
base: currentAppearance.base,
|
|
275
|
-
attributes: {
|
|
276
|
-
...currentAppearance.attributes,
|
|
277
|
-
[tab.value]: currentVariant
|
|
278
|
-
}
|
|
279
|
-
}));
|
|
280
|
-
character.emotion(emotion, true);
|
|
281
|
-
PRELOADED_EMOTIONS.add(emotion);
|
|
282
|
-
}
|
|
283
|
-
const nextIndex = slide < variants.length ? slide : 0;
|
|
284
|
-
const prevIndex = slide > 0 ? slide - 1 : variants.length - 1;
|
|
285
|
-
for (const index of [nextIndex, prevIndex]) {
|
|
286
|
-
const emotion = tab.type === "base" ? getEmotionString({
|
|
287
|
-
base: variants[index],
|
|
288
|
-
attributes: currentAppearance.attributes
|
|
289
|
-
}) : getEmotionString({
|
|
290
|
-
base: currentAppearance.base,
|
|
291
|
-
attributes: {
|
|
292
|
-
...currentAppearance.attributes,
|
|
293
|
-
[tab.value]: variants[index]
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
if (PRELOADED_EMOTIONS.has(emotion)) {
|
|
297
|
-
continue;
|
|
298
|
-
} else {
|
|
299
|
-
PRELOADED_EMOTIONS.add(emotion);
|
|
300
|
-
}
|
|
301
|
-
character.emotion(emotion, false);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
return (() => {
|
|
305
|
-
const _el$6 = _tmpl$3(), _el$7 = _el$6.firstChild, _el$8 = _el$7.firstChild, _el$9 = _el$8.firstChild, _el$10 = _el$9.nextSibling, _el$11 = _el$8.nextSibling;
|
|
306
|
-
_el$7.$$keydown = (event) => {
|
|
307
|
-
if (event.key === "ArrowLeft") {
|
|
308
|
-
setCurrentSlide((value) => value > 0 ? value - 1 : variants.length - 1);
|
|
309
|
-
} else if (event.key === "ArrowRight") {
|
|
310
|
-
setCurrentSlide((value) => value < variants.length - 1 ? value + 1 : 0);
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
_el$9.$$click = () => {
|
|
314
|
-
setCurrentSlide((slide) => {
|
|
315
|
-
if (slide > 0) {
|
|
316
|
-
return slide - 1;
|
|
317
|
-
}
|
|
318
|
-
return variants.length - 1;
|
|
319
|
-
});
|
|
320
|
-
};
|
|
321
|
-
_el$10.$$click = () => {
|
|
322
|
-
setCurrentSlide((slide) => {
|
|
323
|
-
if (slide < variants.length - 1) {
|
|
324
|
-
return slide + 1;
|
|
325
|
-
}
|
|
326
|
-
return 0;
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
_$insert(_el$11, _$createComponent(For, {
|
|
330
|
-
each: variants,
|
|
331
|
-
children: (variant, i2) => {
|
|
332
|
-
const titleId = createUniqueId();
|
|
333
|
-
return (() => {
|
|
334
|
-
const _el$12 = _tmpl$4(), _el$13 = _el$12.firstChild, _el$14 = _el$13.nextSibling, _el$15 = _el$14.firstChild;
|
|
335
|
-
_$setAttribute(_el$12, "aria-labelledby", titleId);
|
|
336
|
-
_$setAttribute(_el$13, "id", titleId);
|
|
337
|
-
_$insert(_el$13, () => translationGroup[variant]);
|
|
338
|
-
_el$15.$$click = () => {
|
|
339
|
-
resolve();
|
|
340
|
-
};
|
|
341
|
-
_$insert(_el$15, () => translation.ui.sumbit);
|
|
342
|
-
_$effect(() => _el$12.classList.toggle("ndc-slide-active", !!(i2() == currentSlide())));
|
|
343
|
-
return _el$12;
|
|
344
|
-
})();
|
|
345
|
-
}
|
|
346
|
-
}));
|
|
347
|
-
_$effect((_p$) => {
|
|
348
|
-
const _v$9 = tab.tab, _v$10 = tab.panel, _v$11 = !!(activeTab() !== i()), _v$12 = translation.ui.variants, _v$13 = !expanded(), _v$14 = translation.ui.slidesControl, _v$15 = translation.ui.prevSlide, _v$16 = translation.ui.nextSlide;
|
|
349
|
-
_v$9 !== _p$._v$9 && _$setAttribute(_el$6, "aria-labelledby", _p$._v$9 = _v$9);
|
|
350
|
-
_v$10 !== _p$._v$10 && _$setAttribute(_el$6, "id", _p$._v$10 = _v$10);
|
|
351
|
-
_v$11 !== _p$._v$11 && _el$6.classList.toggle("ndc-tabpanel-hidden", _p$._v$11 = _v$11);
|
|
352
|
-
_v$12 !== _p$._v$12 && _$setAttribute(_el$7, "aria-label", _p$._v$12 = _v$12);
|
|
353
|
-
_v$13 !== _p$._v$13 && _el$7.classList.toggle("ndc-slider-picker-collapsed", _p$._v$13 = _v$13);
|
|
354
|
-
_v$14 !== _p$._v$14 && _$setAttribute(_el$8, "aria-label", _p$._v$14 = _v$14);
|
|
355
|
-
_v$15 !== _p$._v$15 && _$setAttribute(_el$9, "aria-label", _p$._v$15 = _v$15);
|
|
356
|
-
_v$16 !== _p$._v$16 && _$setAttribute(_el$10, "aria-label", _p$._v$16 = _v$16);
|
|
357
|
-
return _p$;
|
|
358
|
-
}, {
|
|
359
|
-
_v$9: void 0,
|
|
360
|
-
_v$10: void 0,
|
|
361
|
-
_v$11: void 0,
|
|
362
|
-
_v$12: void 0,
|
|
363
|
-
_v$13: void 0,
|
|
364
|
-
_v$14: void 0,
|
|
365
|
-
_v$15: void 0,
|
|
366
|
-
_v$16: void 0
|
|
367
|
-
});
|
|
368
|
-
return _el$6;
|
|
369
|
-
})();
|
|
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]);
|
|
370
262
|
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
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);
|
|
387
320
|
};
|
|
388
|
-
const cleanup = render(
|
|
389
|
-
|
|
390
|
-
|
|
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);
|
|
391
342
|
return promise;
|
|
392
343
|
};
|
|
393
344
|
handler.id = CHARACTER_STYLE_PICKER;
|
|
@@ -396,7 +347,6 @@ var showPicker = function() {
|
|
|
396
347
|
handler.requireUserAction = true;
|
|
397
348
|
return handler;
|
|
398
349
|
};
|
|
399
|
-
_$delegateEvents(["click", "keydown"]);
|
|
400
350
|
|
|
401
351
|
// src/show.ts
|
|
402
352
|
var SHOW_CHARACTER = Symbol();
|
|
@@ -417,18 +367,83 @@ var showCharacter = function() {
|
|
|
417
367
|
return handler;
|
|
418
368
|
};
|
|
419
369
|
|
|
420
|
-
// src/
|
|
421
|
-
var
|
|
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) {
|
|
422
382
|
const that = {
|
|
423
|
-
clothingData,
|
|
383
|
+
clothingData: this,
|
|
424
384
|
options
|
|
425
385
|
};
|
|
426
386
|
return {
|
|
427
|
-
|
|
428
|
-
|
|
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)
|
|
429
445
|
};
|
|
430
446
|
};
|
|
431
447
|
export {
|
|
432
|
-
createDynamicCharacter,
|
|
433
448
|
generateEmotions
|
|
434
449
|
};
|
package/dist/picker.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CustomHandler } from '@novely/core';
|
|
2
|
-
import type {
|
|
3
|
-
declare const showPicker: (this:
|
|
2
|
+
import type { AllThis, InternalShowPickerOptions } from './types';
|
|
3
|
+
declare const showPicker: (this: AllThis, options: InternalShowPickerOptions) => CustomHandler;
|
|
4
4
|
export { showPicker };
|
package/dist/show.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CustomHandler } from '@novely/core';
|
|
2
|
-
import type {
|
|
3
|
-
declare const showCharacter: (this:
|
|
2
|
+
import type { AllThis } from './types';
|
|
3
|
+
declare const showCharacter: (this: AllThis) => CustomHandler;
|
|
4
4
|
export { showCharacter };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type { Character, Data, Lang, NovelyAsset, State,
|
|
1
|
+
import type { Character, Data, Lang, NovelyAsset, State, EngineTypes, ValidAction } from '@novely/core';
|
|
2
2
|
type Attributes<BaseKeys extends string = string> = Record<string, Record<string, Record<BaseKeys, NovelyAsset | NovelyAsset[]>>>;
|
|
3
3
|
type EmotionsDefinition<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
4
4
|
base: Record<BaseKeys, NovelyAsset | NovelyAsset[]>;
|
|
5
5
|
attributes: Attribs;
|
|
6
|
+
pricing?: {
|
|
7
|
+
base: Record<BaseKeys, number>;
|
|
8
|
+
attributes: {
|
|
9
|
+
[Attribute in keyof Attribs]: Record<keyof Attribs[Attribute], number>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
6
12
|
};
|
|
7
13
|
/**
|
|
8
14
|
* Utilities
|
|
@@ -33,15 +39,27 @@ type ClothingData<BaseKeys extends string, Attribs extends Attributes<BaseKeys>>
|
|
|
33
39
|
attributes: {
|
|
34
40
|
[Attribute in keyof Attribs]: (keyof Attribs[Attribute] & string)[];
|
|
35
41
|
};
|
|
36
|
-
|
|
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['types']>, NoInfer<BaseKeys>, NoInfer<Attribs>>): {
|
|
51
|
+
showBasePicker: (options?: ShowPickerOptionsBase) => ValidAction;
|
|
52
|
+
showAttributePicker: (options: ShowPickerOptionsAttribute<Attribs>) => ValidAction;
|
|
53
|
+
showCharacter: () => ValidAction;
|
|
54
|
+
};
|
|
37
55
|
};
|
|
38
56
|
type EmotionsResult<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
39
57
|
emotions: GeneratedEmotions<BaseKeys, Attribs>;
|
|
40
|
-
|
|
58
|
+
createActions: CreateActionsFN<BaseKeys, Attribs>;
|
|
41
59
|
};
|
|
42
60
|
type Entries<T> = T extends Record<infer T, infer K> ? [T, K][] : never;
|
|
43
|
-
type
|
|
44
|
-
type
|
|
61
|
+
type DefaultEngineTypes = EngineTypes<Lang, State, Data, Record<string, Character>>;
|
|
62
|
+
type AllOptions<TE extends DefaultEngineTypes, BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
45
63
|
/**
|
|
46
64
|
* Character ID
|
|
47
65
|
*/
|
|
@@ -56,10 +74,6 @@ type DynCharacterOptions<TE extends DefaultTypeEssentials, BaseKeys extends stri
|
|
|
56
74
|
defaultAttributes: {
|
|
57
75
|
[Attribute in keyof Attribs]: keyof Attribs[Attribute] & string;
|
|
58
76
|
};
|
|
59
|
-
/**
|
|
60
|
-
* Attributes to exclude from picker
|
|
61
|
-
*/
|
|
62
|
-
excludeAttributes?: (keyof Attribs & string)[];
|
|
63
77
|
/**
|
|
64
78
|
* Translation
|
|
65
79
|
*/
|
|
@@ -80,16 +94,10 @@ type DynCharacterOptions<TE extends DefaultTypeEssentials, BaseKeys extends stri
|
|
|
80
94
|
[Base in BaseKeys]: string;
|
|
81
95
|
};
|
|
82
96
|
/**
|
|
83
|
-
*
|
|
97
|
+
* Title translations
|
|
84
98
|
*/
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Base tab translation
|
|
88
|
-
*/
|
|
99
|
+
title: {
|
|
89
100
|
base: string;
|
|
90
|
-
/**
|
|
91
|
-
* Attribute translations
|
|
92
|
-
*/
|
|
93
101
|
attributes: {
|
|
94
102
|
[Attribute in keyof Attribs]: string;
|
|
95
103
|
};
|
|
@@ -98,22 +106,59 @@ type DynCharacterOptions<TE extends DefaultTypeEssentials, BaseKeys extends stri
|
|
|
98
106
|
* Translation of UI components
|
|
99
107
|
*/
|
|
100
108
|
ui: {
|
|
101
|
-
tablist: string;
|
|
102
109
|
variants: string;
|
|
103
110
|
slidesControl: string;
|
|
104
111
|
prevSlide: string;
|
|
105
112
|
nextSlide: string;
|
|
106
113
|
sumbit: string;
|
|
114
|
+
buy: string;
|
|
107
115
|
};
|
|
108
116
|
};
|
|
109
117
|
};
|
|
110
118
|
};
|
|
111
|
-
type
|
|
119
|
+
type AllThis = {
|
|
112
120
|
clothingData: ClothingData<string, Attributes>;
|
|
113
|
-
options:
|
|
121
|
+
options: AllOptions<DefaultEngineTypes, string, Attributes>;
|
|
114
122
|
};
|
|
115
123
|
type EmotionObject = {
|
|
116
124
|
base: string;
|
|
117
125
|
attributes: Record<string, string>;
|
|
118
126
|
};
|
|
119
|
-
|
|
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
|
+
types: DefaultEngineTypes;
|
|
163
|
+
};
|
|
164
|
+
export type { Entries, EmotionsDefinition, EmotionsResult, Attributes, ClothingData, EmotionObject, AllOptions, AllThis, DefaultEngineTypes, InternalShowPickerOptions, ShowPickerOptionsAttribute, ShowPickerOptionsBase, EngineInstance, };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { StateFunction, State } from '@novely/core';
|
|
2
2
|
import type { EmotionObject, ClothingData, Attributes } from './types';
|
|
3
|
+
declare const once: (fn: () => void) => () => void;
|
|
3
4
|
declare const getEntries: <T extends PropertyKey, K>(object: Record<T, K>) => [T, K][];
|
|
4
5
|
declare const getKeys: <T extends PropertyKey>(object: Record<T, unknown>) => T[];
|
|
5
6
|
declare const toArray: <T>(target: T | T[]) => T[];
|
|
@@ -12,4 +13,4 @@ declare const getEmotionString: ({ base, attributes }: EmotionObject) => string;
|
|
|
12
13
|
*/
|
|
13
14
|
declare const getSavedEmotion: (state: StateFunction<State>, character: string, clothingData: ClothingData<string, Attributes>, fallback: EmotionObject) => EmotionObject;
|
|
14
15
|
declare const saveEmotion: (state: StateFunction<State>, character: string, emotion: EmotionObject) => void;
|
|
15
|
-
export { getEntries, getKeys, toArray, permutation, getEmotionString, saveEmotion, getSavedEmotion };
|
|
16
|
+
export { once, getEntries, getKeys, toArray, permutation, getEmotionString, saveEmotion, getSavedEmotion };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novely/dynamic-character",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
"module": "./dist/index.jsx",
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"esbuild": "^0.
|
|
13
|
+
"esbuild": "^0.25.5",
|
|
14
14
|
"esbuild-plugin-solid": "^0.6.0",
|
|
15
|
-
"typescript": "^5.
|
|
15
|
+
"typescript": "^5.8.3"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"
|
|
19
|
-
"solid-js": "~1.9.
|
|
20
|
-
"@novely/core": "0.
|
|
18
|
+
"p-limit": "^6.2.0",
|
|
19
|
+
"solid-js": "~1.9.7",
|
|
20
|
+
"@novely/core": "0.52.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@novely/core": "*",
|
package/dist/slider.d.ts
DELETED