@novely/dynamic-character 0.1.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.
@@ -0,0 +1,4 @@
1
+ import type { CustomHandler } from '@novely/core';
2
+ import type { DynCharacterThis } from './types';
3
+ declare const showPicker: (this: DynCharacterThis) => CustomHandler;
4
+ export { showPicker };
package/dist/show.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { CustomHandler } from '@novely/core';
2
+ import type { DynCharacterThis } from './types';
3
+ declare const showCharacter: (this: DynCharacterThis) => CustomHandler;
4
+ export { showCharacter };
@@ -0,0 +1,120 @@
1
+ import type { Character, Data, Lang, NovelyAsset, State, TypeEssentials } 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
+ };
7
+ /**
8
+ * Utilities
9
+ *
10
+ * https://stackoverflow.com/a/55128956
11
+ * https://blog.beraliv.dev/2021-05-30-permutations-in-typescript
12
+ * https://twitter.com/mattpocockuk/status/1622730173446557697
13
+ */
14
+ type Permutation<T, K = T> = [T] extends [never] ? [] : K extends unknown ? [K, ...Permutation<Exclude<T, K>>] : never;
15
+ type Prettify<T> = {
16
+ [K in keyof T]: T[K];
17
+ } & {};
18
+ /** Types */
19
+ type GetAttributeVariants<Attribs extends Attributes, Attribute extends string> = {
20
+ [Variant in keyof Attribs[Attribute] & string]: `${Attribute & string}_${Variant}`;
21
+ }[keyof Attribs[Attribute] & string];
22
+ type GetAttributesTuple<Attribs extends Attributes> = Permutation<keyof Attribs>;
23
+ type GetAttributesVariants<Attribs extends Attributes, T extends unknown[]> = T extends [
24
+ infer First,
25
+ ...infer Rest
26
+ ] ? First extends string ? [Permutation<GetAttributeVariants<Attribs, First>>, ...GetAttributesVariants<Attribs, Rest>] : never : [];
27
+ 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;
28
+ type AddBase<BaseKeys extends string, Attributes extends string> = `${BaseKeys}@${Attributes}`;
29
+ type GenerateEmotions<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = AddBase<BaseKeys, CombineAttributes<GetAttributesVariants<Attribs, GetAttributesTuple<Attribs>>>>;
30
+ type GeneratedEmotions<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = Prettify<Record<GenerateEmotions<BaseKeys, Attribs>, NovelyAsset[]>>;
31
+ type ClothingData<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
32
+ base: BaseKeys[];
33
+ attributes: {
34
+ [Attribute in keyof Attribs]: (keyof Attribs[Attribute] & string)[];
35
+ };
36
+ __attributes?: Attribs;
37
+ };
38
+ type EmotionsResult<BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
39
+ emotions: GeneratedEmotions<BaseKeys, Attribs>;
40
+ clothingData: Prettify<ClothingData<BaseKeys, Attribs>>;
41
+ };
42
+ type Entries<T> = T extends Record<infer T, infer K> ? [T, K][] : never;
43
+ type DefaultTypeEssentials = TypeEssentials<Lang, State, Data, Record<string, Character>>;
44
+ type DynCharacterOptions<TE extends DefaultTypeEssentials, BaseKeys extends string, Attribs extends Attributes<BaseKeys>> = {
45
+ /**
46
+ * Character ID
47
+ */
48
+ character: string;
49
+ /**
50
+ * Default style base
51
+ */
52
+ defaultBase: BaseKeys;
53
+ /**
54
+ * Default style attributes
55
+ */
56
+ defaultAttributes: {
57
+ [Attribute in keyof Attribs]: keyof Attribs[Attribute] & string;
58
+ };
59
+ /**
60
+ * Attributes to exclude from picker
61
+ */
62
+ excludeAttributes?: (keyof Attribs & string)[];
63
+ /**
64
+ * Translation
65
+ */
66
+ translation: {
67
+ [Language in NonNullable<TE['l']>]: {
68
+ /**
69
+ * Attribute items translations
70
+ */
71
+ attributes: {
72
+ [Attribute in keyof Attribs]: {
73
+ [Variant in keyof Attribs[Attribute]]: string;
74
+ };
75
+ };
76
+ /**
77
+ * Base translations
78
+ */
79
+ base: {
80
+ [Base in BaseKeys]: string;
81
+ };
82
+ /**
83
+ * Tabs translations
84
+ */
85
+ tabs: {
86
+ /**
87
+ * Base tab translation
88
+ */
89
+ base: string;
90
+ /**
91
+ * Attribute translations
92
+ */
93
+ attributes: {
94
+ [Attribute in keyof Attribs]: string;
95
+ };
96
+ };
97
+ /**
98
+ * Translation of UI components
99
+ */
100
+ ui: {
101
+ tablist: string;
102
+ variants: string;
103
+ slidesControl: string;
104
+ prevSlide: string;
105
+ nextSlide: string;
106
+ apply: string;
107
+ sumbit: string;
108
+ };
109
+ };
110
+ };
111
+ };
112
+ type DynCharacterThis = {
113
+ clothingData: ClothingData<string, Attributes>;
114
+ options: DynCharacterOptions<DefaultTypeEssentials, string, Attributes>;
115
+ };
116
+ type EmotionObject = {
117
+ base: string;
118
+ attributes: Record<string, string>;
119
+ };
120
+ export type { Entries, EmotionsDefinition, EmotionsResult, Attributes, ClothingData, EmotionObject, DynCharacterOptions, DynCharacterThis, DefaultTypeEssentials, };
@@ -0,0 +1,15 @@
1
+ import type { StateFunction, State } from '@novely/core';
2
+ import type { EmotionObject, ClothingData, Attributes } from './types';
3
+ declare const getEntries: <T extends PropertyKey, K>(object: Record<T, K>) => [T, K][];
4
+ declare const getKeys: <T extends PropertyKey>(object: Record<T, unknown>) => T[];
5
+ declare const toArray: <T>(target: T | T[]) => T[];
6
+ declare const permutation: <T>(items: T[], size?: number) => T[][];
7
+ declare const getEmotionString: ({ base, attributes }: EmotionObject) => string;
8
+ /**
9
+ * Return fallback value joined with saved emotion, when there is no saved, returns only fallback
10
+ * @param character Character Id
11
+ * @param fallback Default emotions
12
+ */
13
+ declare const getSavedEmotion: (state: StateFunction<State>, character: string, clothingData: ClothingData<string, Attributes>, fallback: EmotionObject) => EmotionObject;
14
+ declare const saveEmotion: (state: StateFunction<State>, character: string, emotion: EmotionObject) => void;
15
+ export { getEntries, getKeys, toArray, permutation, getEmotionString, saveEmotion, getSavedEmotion };
package/license ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2024, Artem Schukin
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@novely/dynamic-character",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "types": "./dist/index.d.ts",
9
+ "main": "./dist/index.jsx",
10
+ "module": "./dist/index.jsx",
11
+ "sideEffects": false,
12
+ "devDependencies": {
13
+ "esbuild": "^0.24.0",
14
+ "esbuild-plugin-solid": "^0.6.0",
15
+ "typescript": "^5.6.2"
16
+ },
17
+ "dependencies": {
18
+ "solid-js": "~1.9.3",
19
+ "@novely/core": "0.46.2"
20
+ },
21
+ "peerDependencies": {
22
+ "@novely/core": "*",
23
+ "solid-js": "*"
24
+ },
25
+ "license": "ISC",
26
+ "bugs": {
27
+ "url": "https://github.com/yhdgms1/novely/issues"
28
+ },
29
+ "homepage": "https://github.com/yhdgms1/novely/tree/main/packages/dynamic-character",
30
+ "keywords": [
31
+ "novely"
32
+ ],
33
+ "author": {
34
+ "name": "Artemiy Schukin",
35
+ "url": "https://github.com/yhdgms1"
36
+ },
37
+ "contributors": [],
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/yhdgms1/novely.git"
41
+ },
42
+ "files": [
43
+ "dist/*"
44
+ ],
45
+ "scripts": {
46
+ "dev": "node ./build.js --w",
47
+ "build": "node ./build.js && tsc"
48
+ }
49
+ }