-
Notifications
You must be signed in to change notification settings - Fork 0
/
VerseModuleBase.ts
157 lines (153 loc) · 3.73 KB
/
VerseModuleBase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import type {
EnvAdapter,
OtherPerson,
VerseStartResult,
} from "@verseengine/verse-three";
/** {@link EnvAdapter.addTextDataChangedListener} with typed data */
export type TextDataChangedListener<D extends Record<string, any>> = (
otherPerson: OtherPerson,
data: D,
) => unknown;
/**
* the module
*/
export type GenerateInitializable<
D extends Record<string, any>,
RequireData extends Record<string, any>,
O,
> = (base: VerseModuleBase<D, RequireData>) => Initializable<O>;
/**
* module should return this
*/
export type Initializable<O> = {
initialize(options: O): unknown;
};
export type VerseModuleBase<
Data extends Record<string, any> = {},
RequireData extends Record<string, any> = {},
> = VerseStartResult & {
envAdapter: EnvAdapter;
/**
* DOM element to attach some controls
*
* @category Module creation
*
* @example
* ```ts
* domRoot.appendChild(myDiv);
* ```
*/
domRoot: HTMLElement;
/** parsed player.getTextData() */
getData(): Data & RequireData;
/**
* merging player.setTextData() like `player.setTextData({...previousData, ...appendData})`
*
* @category Module creation
*
* @example
* ```ts
* putData({ foo: 1 }); // { foo: 1 }
* putData({ bar: 2 }); // { foo: 1, bar: 2 }
* getData(); // { foo: 1, bar: 2 }
* ```
*/
putData(appendData: Partial<Data>): Data;
/**
* @see {@link addTextDataChangedListener}
*
* @category Module creation
*/
textDataChangedListeners: TextDataChangedListener<any>[];
/**
* {@link EnvAdapter.addTextDataChangedListener}
*
* @category Module creation
*
* @example
* ```ts
* avatarChangedListeners.push((avatar) => {
* const meta = player.avatar.vrm?.meta
* console.log(`changed to ${meta?.metaVersion === "0" ? meta.title : meta?.name}`);
* });
* ```
*/
avatarChangedListeners: Parameters<
EnvAdapter["addAvatarChangedListener"]
>[0][];
/**
* {@link EnvAdapter.addOtherPersonAvatarChangedListener}
*
* @category Module creation
*
* @example
* ```ts
* otherPersonAvatarChangedListeners.push((otherPerson) => {
* const meta = otherPerson.avatar?.vrm?.meta
* console.log(`changed to ${meta?.metaVersion === "0" ? meta.title : meta?.name}`);
* });
* ```
*/
otherPersonAvatarChangedListeners: Parameters<
EnvAdapter["addOtherPersonAvatarChangedListener"]
>[0][];
/**
* {@link EnvAdapter.addTextDataChangedListener}
*
* @category Module creation
*
* @example
* ```ts
* addTextDataChangedListener((otherPerson, data) => {
* console.log(data);
* });
* ```
*/
addTextDataChangedListener(
listener: TextDataChangedListener<Data & RequireData>,
): void;
/**
* initialize a module
*
* @category General use
*
* @example
* ```ts
* verseModule.with(micStatus, ({ initialize }) =>
* initialize({ textureUrl: "./asset/ui/mute.png" }),
* )
* ```
*/
with<D extends Record<string, any>, O>(
gen: GenerateInitializable<D, Data, O>,
cb?: (initializable: Initializable<O>) => unknown,
): VerseModuleBase<Data & D, Data & D>;
/**
* initialize a module
*
* @category General use
*
* @example
* ```ts
* verseModule.initialize(adjustNameplatePosition)
* ```
*/
initialize<D extends Record<string, any>>(
gen: GenerateInitializable<D, Data, void>,
options?: void,
): VerseModuleBase<Data & D, Data & D>;
/**
* initialize a module
*
* @category General use
*
* @example
* ```ts
* verseModule.initialize(micStatus, { textureUrl: "./asset/ui/mute.png" })
* ```
*/
initialize<D extends Record<string, any>, O>(
gen: GenerateInitializable<D, Data, O>,
options: O,
): VerseModuleBase<Data & D, Data & D>;
};