@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/README.md +137 -137
- package/dist/index.d.ts +133 -2
- package/dist/index.js +434 -0
- package/dist/index.js.map +1 -0
- package/dist/{index.css → style.css} +58 -27
- package/license +15 -15
- package/package.json +33 -30
- package/dist/actions.d.ts +0 -7
- package/dist/components/Picker.d.ts +0 -19
- package/dist/components/Slider.d.ts +0 -12
- package/dist/emotions.d.ts +0 -3
- package/dist/index.jsx +0 -449
- package/dist/picker.d.ts +0 -4
- package/dist/show.d.ts +0 -4
- package/dist/types.d.ts +0 -164
- package/dist/utils.d.ts +0 -16
package/README.md
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
|
-
# @novely/dynamic-character
|
|
2
|
-
|
|
3
|
-
Will give a way to dynamically dress characters.
|
|
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
|
-
|
|
11
|
-
```ts
|
|
12
|
-
import { generateEmotions } from '@novely/dynamic-character';
|
|
13
|
-
import '@novely/dynamic-character/dist/
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
```ts
|
|
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';
|
|
24
|
-
|
|
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';
|
|
30
|
-
|
|
31
|
-
const { emotions: emotionsYou, createActions: createActionsYou } = generateEmotions({
|
|
32
|
-
base: {
|
|
33
|
-
male: asset(You_male),
|
|
34
|
-
female: asset(You_female)
|
|
35
|
-
},
|
|
36
|
-
attributes: {
|
|
37
|
-
bottoms: {
|
|
38
|
-
shorts: {
|
|
39
|
-
female: asset(You_female_bottoms__shorts),
|
|
40
|
-
male: asset(You_male_bottoms__shorts)
|
|
41
|
-
},
|
|
42
|
-
jeans: {
|
|
43
|
-
female: asset(You_female_bottoms__jeans),
|
|
44
|
-
male: asset(You_male_bottoms__jeans)
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
tops: {
|
|
48
|
-
pink: {
|
|
49
|
-
male: asset(You_male_tops__pink_tshirt),
|
|
50
|
-
female: asset(You_female_tops__pink_tshirt)
|
|
51
|
-
},
|
|
52
|
-
white: {
|
|
53
|
-
male: asset(You_male_tops__white_tshirt),
|
|
54
|
-
female: asset(You_female_tops__white_tshirt)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const engine = novely({
|
|
61
|
-
...,
|
|
62
|
-
translation: {
|
|
63
|
-
en: {
|
|
64
|
-
internal: EN
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
characters: {
|
|
68
|
-
You: {
|
|
69
|
-
name: {
|
|
70
|
-
en: 'You',
|
|
71
|
-
},
|
|
72
|
-
color: '#000000',
|
|
73
|
-
emotions: emotionsYou
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const dynamicYou = createActionsYou(engine, {
|
|
79
|
-
character: 'You',
|
|
80
|
-
defaultBase: 'male',
|
|
81
|
-
defaultAttributes: {
|
|
82
|
-
bottoms: 'jeans',
|
|
83
|
-
tops: 'white'
|
|
84
|
-
},
|
|
85
|
-
translation: {
|
|
86
|
-
en: {
|
|
87
|
-
title: {
|
|
88
|
-
base: 'Body',
|
|
89
|
-
attributes: {
|
|
90
|
-
bottoms: 'Bottoms',
|
|
91
|
-
tops: 'Tops'
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
base: {
|
|
95
|
-
male: 'Male',
|
|
96
|
-
female: 'Female'
|
|
97
|
-
},
|
|
98
|
-
attributes: {
|
|
99
|
-
bottoms: {
|
|
100
|
-
jeans: 'Jeans',
|
|
101
|
-
shorts: 'Shorts'
|
|
102
|
-
},
|
|
103
|
-
tops: {
|
|
104
|
-
pink: 'Pink t-shirt',
|
|
105
|
-
white: 'White t-shirt'
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
ui: {
|
|
109
|
-
variants: 'Options',
|
|
110
|
-
slidesControl: 'Slides Control',
|
|
111
|
-
prevSlide: 'Previous',
|
|
112
|
-
nextSlide: 'Next',
|
|
113
|
-
sumbit: 'Submit',
|
|
114
|
-
sumbit: 'Submit',
|
|
115
|
-
buy: 'Buy'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
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
|
-
})
|
|
136
|
-
|
|
137
|
-
```
|
|
1
|
+
# @novely/dynamic-character
|
|
2
|
+
|
|
3
|
+
Will give a way to dynamically dress characters.
|
|
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
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { generateEmotions } from '@novely/dynamic-character';
|
|
13
|
+
import '@novely/dynamic-character/dist/style.css';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```ts
|
|
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';
|
|
24
|
+
|
|
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';
|
|
30
|
+
|
|
31
|
+
const { emotions: emotionsYou, createActions: createActionsYou } = generateEmotions({
|
|
32
|
+
base: {
|
|
33
|
+
male: asset(You_male),
|
|
34
|
+
female: asset(You_female)
|
|
35
|
+
},
|
|
36
|
+
attributes: {
|
|
37
|
+
bottoms: {
|
|
38
|
+
shorts: {
|
|
39
|
+
female: asset(You_female_bottoms__shorts),
|
|
40
|
+
male: asset(You_male_bottoms__shorts)
|
|
41
|
+
},
|
|
42
|
+
jeans: {
|
|
43
|
+
female: asset(You_female_bottoms__jeans),
|
|
44
|
+
male: asset(You_male_bottoms__jeans)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
tops: {
|
|
48
|
+
pink: {
|
|
49
|
+
male: asset(You_male_tops__pink_tshirt),
|
|
50
|
+
female: asset(You_female_tops__pink_tshirt)
|
|
51
|
+
},
|
|
52
|
+
white: {
|
|
53
|
+
male: asset(You_male_tops__white_tshirt),
|
|
54
|
+
female: asset(You_female_tops__white_tshirt)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const engine = novely({
|
|
61
|
+
...,
|
|
62
|
+
translation: {
|
|
63
|
+
en: {
|
|
64
|
+
internal: EN
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
characters: {
|
|
68
|
+
You: {
|
|
69
|
+
name: {
|
|
70
|
+
en: 'You',
|
|
71
|
+
},
|
|
72
|
+
color: '#000000',
|
|
73
|
+
emotions: emotionsYou
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const dynamicYou = createActionsYou(engine, {
|
|
79
|
+
character: 'You',
|
|
80
|
+
defaultBase: 'male',
|
|
81
|
+
defaultAttributes: {
|
|
82
|
+
bottoms: 'jeans',
|
|
83
|
+
tops: 'white'
|
|
84
|
+
},
|
|
85
|
+
translation: {
|
|
86
|
+
en: {
|
|
87
|
+
title: {
|
|
88
|
+
base: 'Body',
|
|
89
|
+
attributes: {
|
|
90
|
+
bottoms: 'Bottoms',
|
|
91
|
+
tops: 'Tops'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
base: {
|
|
95
|
+
male: 'Male',
|
|
96
|
+
female: 'Female'
|
|
97
|
+
},
|
|
98
|
+
attributes: {
|
|
99
|
+
bottoms: {
|
|
100
|
+
jeans: 'Jeans',
|
|
101
|
+
shorts: 'Shorts'
|
|
102
|
+
},
|
|
103
|
+
tops: {
|
|
104
|
+
pink: 'Pink t-shirt',
|
|
105
|
+
white: 'White t-shirt'
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
ui: {
|
|
109
|
+
variants: 'Options',
|
|
110
|
+
slidesControl: 'Slides Control',
|
|
111
|
+
prevSlide: 'Previous',
|
|
112
|
+
nextSlide: 'Next',
|
|
113
|
+
sumbit: 'Submit',
|
|
114
|
+
sumbit: 'Submit',
|
|
115
|
+
buy: 'Buy'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
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
|
+
})
|
|
136
|
+
|
|
137
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Character, Data, EngineTypes, Lang, NovelyAsset, State, ValidAction } from "@novely/core";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type Attributes<BaseKeys extends string = string> = Record<string, Record<string, Record<BaseKeys, NovelyAsset | NovelyAsset[]>>>;
|
|
5
|
+
type EmotionsDefinition<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
6
|
+
base: Record<BaseKeys, NovelyAsset | NovelyAsset[]>;
|
|
7
|
+
attributes: Attribs;
|
|
8
|
+
pricing?: {
|
|
9
|
+
base: Record<BaseKeys, number>;
|
|
10
|
+
attributes: { [Attribute in keyof Attribs]: Record<keyof Attribs[Attribute], number> };
|
|
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> = { [K in keyof T]: T[K] } & {};
|
|
22
|
+
/** Types */
|
|
23
|
+
type GetAttributeVariants<Attribs extends Attributes, Attribute extends string> = { [Variant in keyof Attribs[Attribute] & string]: `${Attribute & string}_${Variant}` }[keyof Attribs[Attribute] & string];
|
|
24
|
+
type GetAttributesTuple<Attribs extends Attributes> = Permutation<keyof Attribs>;
|
|
25
|
+
type GetAttributesVariants<Attribs extends Attributes, T extends unknown[]> = T extends [infer First, ...infer Rest] ? First extends string ? [Permutation<GetAttributeVariants<Attribs, First>>, ...GetAttributesVariants<Attribs, Rest>] : never : [];
|
|
26
|
+
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;
|
|
27
|
+
type AddBase<BaseKeys extends string, Attributes extends string> = `${BaseKeys}@${Attributes}`;
|
|
28
|
+
type GenerateEmotions<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = AddBase<BaseKeys, CombineAttributes<GetAttributesVariants<Attribs, GetAttributesTuple<Attribs>>>>;
|
|
29
|
+
type GeneratedEmotions<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = Prettify<Record<GenerateEmotions<BaseKeys, Attribs>, NovelyAsset[]>>;
|
|
30
|
+
type ClothingData<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
31
|
+
base: BaseKeys[];
|
|
32
|
+
attributes: { [Attribute in keyof Attribs]: (keyof Attribs[Attribute] & string)[] };
|
|
33
|
+
pricing?: {
|
|
34
|
+
base: Record<BaseKeys, number>;
|
|
35
|
+
attributes: { [Attribute in keyof Attribs]: Record<keyof Attribs[Attribute], number> };
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
type CreateActionsFN<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
39
|
+
<Engine extends EngineInstance>(engine: Engine, options: AllOptions<NoInfer<Engine['types']>, NoInfer<BaseKeys>, NoInfer<Attribs>>): {
|
|
40
|
+
showBasePicker: (options?: ShowPickerOptionsBase) => ValidAction;
|
|
41
|
+
showAttributePicker: (options: ShowPickerOptionsAttribute<Attribs>) => ValidAction;
|
|
42
|
+
showCharacter: () => ValidAction;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
type EmotionsResult<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
46
|
+
emotions: GeneratedEmotions<BaseKeys, Attribs>;
|
|
47
|
+
createActions: CreateActionsFN<BaseKeys, Attribs>;
|
|
48
|
+
};
|
|
49
|
+
type DefaultEngineTypes = EngineTypes<Lang, State, Data, Record<string, Character>>;
|
|
50
|
+
type AllOptions<TE extends DefaultEngineTypes, BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
|
|
51
|
+
/**
|
|
52
|
+
* Character ID
|
|
53
|
+
*/
|
|
54
|
+
character: string;
|
|
55
|
+
/**
|
|
56
|
+
* Default style base
|
|
57
|
+
*/
|
|
58
|
+
defaultBase: BaseKeys;
|
|
59
|
+
/**
|
|
60
|
+
* Default style attributes
|
|
61
|
+
*/
|
|
62
|
+
defaultAttributes: { [Attribute in keyof Attribs]: keyof Attribs[Attribute] & string };
|
|
63
|
+
/**
|
|
64
|
+
* Translation
|
|
65
|
+
*/
|
|
66
|
+
translation: { [Language in NonNullable<TE['l']>]: {
|
|
67
|
+
/**
|
|
68
|
+
* Attribute items translations
|
|
69
|
+
*/
|
|
70
|
+
attributes: { [Attribute in keyof Attribs]: { [Variant in keyof Attribs[Attribute]]: string } };
|
|
71
|
+
/**
|
|
72
|
+
* Base translations
|
|
73
|
+
*/
|
|
74
|
+
base: { [Base in BaseKeys]: string };
|
|
75
|
+
/**
|
|
76
|
+
* Title translations
|
|
77
|
+
*/
|
|
78
|
+
title: {
|
|
79
|
+
base: string;
|
|
80
|
+
attributes: { [Attribute in keyof Attribs]: string };
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Translation of UI components
|
|
84
|
+
*/
|
|
85
|
+
ui: {
|
|
86
|
+
variants: string;
|
|
87
|
+
slidesControl: string;
|
|
88
|
+
prevSlide: string;
|
|
89
|
+
nextSlide: string;
|
|
90
|
+
sumbit: string;
|
|
91
|
+
buy: string;
|
|
92
|
+
};
|
|
93
|
+
} };
|
|
94
|
+
};
|
|
95
|
+
type EmotionObject = {
|
|
96
|
+
base: string;
|
|
97
|
+
attributes: Record<string, string>;
|
|
98
|
+
};
|
|
99
|
+
type ShowPickerBuyFunctions = {
|
|
100
|
+
/**
|
|
101
|
+
* Function to buy attribute variant
|
|
102
|
+
* @param variant Attribute variant
|
|
103
|
+
* @returns Boolean indicating is item bought or not
|
|
104
|
+
*/
|
|
105
|
+
buy?: (variant: string) => Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Function to check is attribute variant is bought
|
|
108
|
+
* @param variant Attribute variant
|
|
109
|
+
* @returns Boolean indicating is item bought or not
|
|
110
|
+
*/
|
|
111
|
+
isBought?: (variant: string) => boolean;
|
|
112
|
+
};
|
|
113
|
+
type ShowPickerOptionsAttribute<Attribs extends Attributes> = ShowPickerBuyFunctions & {
|
|
114
|
+
/**
|
|
115
|
+
* Name of the attribute
|
|
116
|
+
*/
|
|
117
|
+
name: keyof Attribs & string;
|
|
118
|
+
};
|
|
119
|
+
type ShowPickerOptionsBase = ShowPickerBuyFunctions;
|
|
120
|
+
type EngineInstance = {
|
|
121
|
+
action: Record<string, (...args: any[]) => ValidAction>;
|
|
122
|
+
types: DefaultEngineTypes;
|
|
123
|
+
};
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/emotions.d.ts
|
|
126
|
+
declare const generateEmotions: <BaseKeys extends string, Attribs extends Attributes<BaseKeys>>({
|
|
127
|
+
base,
|
|
128
|
+
attributes,
|
|
129
|
+
pricing
|
|
130
|
+
}: EmotionsDefinition<BaseKeys, Attribs>) => EmotionsResult<BaseKeys, Attribs>;
|
|
131
|
+
//#endregion
|
|
132
|
+
export { type AllOptions, type Attributes, type ClothingData, type EmotionObject, type EmotionsResult, type ShowPickerOptionsAttribute, type ShowPickerOptionsBase, generateEmotions };
|
|
133
|
+
//# sourceMappingURL=index.d.ts.map
|