dcl-npc-toolkit 0.0.0 → 1.0.6-20230511223948.commit-74300a8

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 ADDED
@@ -0,0 +1,622 @@
1
+
2
+ # NPC-library
3
+
4
+ A collection of tools for creating Non-Player-Characters (NPCs). These are capable of having conversations with the player, and play different animations.
5
+
6
+ Capabilities of the NPCs in this library:
7
+
8
+ - Start a conversation when clicked or when walking near
9
+ - Trigger any action when clicked or when walking near
10
+ - Trigger any action when the player walks away
11
+ - Turn around slowly to always face the player
12
+ - Play an animation in the NPC 3d model, optionally returning to loop the idle animation afterwards
13
+
14
+ The dialog messages can also require that the player chooses options, and any action can be triggered when the player picks an option or advances past a message.
15
+ ## Using the UI utils library
16
+
17
+ To use any of the helpers provided by the utils library you must install it in your Decentrland project.
18
+
19
+ ### Via the Decentraland Editor
20
+
21
+ Make sure you've [installed the Decentraland editor](https://docs.decentraland.org/creator/development-guide/sdk7/installation-guide/#the-decentraland-editor).
22
+
23
+ 1) Open your scene's folder using Visual Studio Code.
24
+
25
+ > **📔 Note**: The Visual Studio window must be at the root folder of the scene project.
26
+ 2) Open the Decentraland Editor tab on Visual Studio. Note that the bottom section lists all of your project's currently installed dependencies.
27
+
28
+ 3) Click the `+` icon on the header of the **Dependencies** view.
29
+
30
+ 4) Visual Studio opens an input box at the top of the screen. Write `@dcl-sdk/npc-utils` and hit enter. The dependency is then installed to your scene.
31
+
32
+
33
+ 5. Import the library into the scene's script. Add this line at the start of your `index.ts` file, or any other TypeScript files that require it:
34
+
35
+ ```ts
36
+ import * as npc from '@dcl-sdk/npc-utils'
37
+ ```
38
+
39
+ 6. In your TypeScript file, call the `create` function passing it a `TransformType` and a `NPCData` object. The `NPCData` object requires a minimum of a `NPCType` and a function to trigger when the NPC is activated:
40
+
41
+ ```ts
42
+ export let myNPC = npc.create({position: Vector3.create(8,0,8),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
43
+ //NPC Data Object
44
+ {
45
+ type: npc.NPCType.CUSTOM,
46
+ model: 'models/npc.glb',
47
+ onActivate:()=>{console.log('npc activated');}
48
+ }
49
+ )
50
+ ```
51
+
52
+ 7. Write a dialog script for your character, preferably on a separate file, making it of type `Dialog[]`.
53
+
54
+ ```ts
55
+ import { Dialog } from '@dcl-sdk/npc-utils'
56
+
57
+ export let ILoveCats: Dialog[] = [
58
+ {
59
+ text: `I really lo-ove cats`,
60
+ isEndOfDialog: true
61
+ }
62
+ ]
63
+ ```
64
+
65
+
66
+ ### Via the CLI
67
+
68
+ 1. Install the library as an npm bundle. Run this command in your scene's project folder:
69
+
70
+ ```
71
+ npm i @dcl-sdk/npc-utils
72
+ ```
73
+
74
+ 2. Run `npm run start` or `npm run build` so the dependencies are correctly installed.
75
+
76
+ 3. Import the library into the scene's script. Add this line at the start of your `index.ts` file, or any other TypeScript files that require it:
77
+
78
+ ```ts
79
+ import * as npc from '@dcl-sdk/npc-utils'
80
+ ```
81
+
82
+ 4. In your TypeScript file, call the `create` function passing it a `TransformType` and a `NPCData` object. The `NPCData` object requires a minimum of a `NPCType` and a function to trigger when the NPC is activated:
83
+
84
+ ```ts
85
+ export let myNPC = npc.create({position: Vector3.create(8,0,8),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
86
+ //NPC Data Object
87
+ {
88
+ type: npc.NPCType.CUSTOM,
89
+ model: 'models/npc.glb',
90
+ onActivate:()=>{console.log('npc activated');}
91
+ }
92
+ )
93
+ ```
94
+
95
+ 5. Write a dialog script for your character, preferably on a separate file, making it of type `Dialog[]`.
96
+
97
+ ```ts
98
+ import { Dialog } from '@dcl-sdk/npc-utils'
99
+
100
+ export let ILoveCats: Dialog[] = [
101
+ {
102
+ text: `I really lo-ove cats`,
103
+ isEndOfDialog: true
104
+ }
105
+ ]
106
+ ```
107
+
108
+ ## NPC Default Behavior
109
+
110
+ NPCs at the very least must have:
111
+
112
+ - `position`: (_TransformType_) Must include position, rotation and scale.
113
+ - `NPCData`: (_Data Object_) with a minimum of two variables
114
+ - `type`: (_NPCType_) you have the choice to use a custom GLB object or an `AvatarShape` for your npc
115
+ - `NPCType.CUSTOM`
116
+ - `NPCType.AVATAR`
117
+ - `onActivate()`: (_()=> void_) A function to call when the NPC is activated.
118
+
119
+ *if you decide to use a `NPCType.CUSTOM` GLB model for your avatar, you must pass in a model object inside the `NPCData`*
120
+ - `model`: (_string_) The path to a 3D model
121
+
122
+ ```ts
123
+ export let myNPC = npc.create({position: Vector3.create(8,0,8),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
124
+ //NPC Data Object
125
+ {
126
+ type: npc.NPCType.CUSTOM,
127
+ model: 'models/npc.glb',
128
+ onActivate:()=>{console.log('npc activated');}
129
+ }
130
+ )
131
+ ```
132
+
133
+ With this default configuration, the NPC behaves in the following way:
134
+
135
+ - The `onActivate()` function is called when pressing E on the NPC, and when the player walks near at a distance of 6 meters.
136
+ - Once activated, there's a cooldown period of 5 seconds, that prevents the NPC to be activated again.
137
+ - After walking away from the NPC, if its dialog window was open it will be closed, and if the NPC was rotating to follow the player it will stop.
138
+ - If the NPC already has an open dialog window, clicking on the NPC won't do anything, to prevent accidentally clicking on it while flipping through the conversation.
139
+ - If the NPC has an animation named 'Idle', it will play it in a loop. If other non-looping animations are played, it will return to looping the 'Idle' animation after the indicated duration.
140
+
141
+ Many of these behaviors can be overridden or tweaked with the exposed properties.
142
+
143
+ ## NPC Additional Properties
144
+
145
+ To configure other properties of an NPC, add a fourth argument as an `NPCData` object. This object can have the following optional properties:
146
+
147
+ - `idleAnim`: _(string)_ Name of the idle animation in the model. This animation is always looped. After playing a non-looping animation it returns to looping this one.
148
+ - `faceUser`: _(boolean)_ Set if the NPC rotates to face the user while active.
149
+ - `dialogSound`: _(string)_ Path to sound file to play once for every entry shown on the UI. If the dialog entry being shown has an `audio` field, the NPC will play the file referenced by the `audio` field instead.
150
+ - `coolDownDuration`: _(number)_ Change the cooldown period for activating the NPC again. The number is in seconds.
151
+ - `hoverText`: _(string)_ Set the UI hover feedback when pointing the cursor at the NPC. _TALK_ by default.
152
+ - `onlyClickTrigger`: _(boolean)_ If true, the NPC can't be activated by walking near. Just by clicking on it or calling its `activate()` function.
153
+ - `onlyETrigger`: _(boolean)_ If true, the NPC can't be activated by walking near. Just by pressing the E key on it or calling its `activate()` function.
154
+ - `onlyExternalTrigger`: _(boolean)_ If true, the NPC can't be activated by clicking, pressing E, or walking near. Just by calling its `activate()` function.
155
+ - `reactDistance`: _(number)_ Radius in meters for the player to activate the NPC or trigger the `onWalkAway()` function when leaving the radius.
156
+ - `continueOnWalkAway`: _(boolean)_ If true,when the player walks out of the `reactDistance` radius, the dialog window stays open and the NPC keeps turning to face the player (if applicable). It doesn't affect the triggering of the `onWalkAway()` function.
157
+ - `onWalkAway`: (_()=> void_) Function to call every time the player walks out of the `reactDistance` radius.
158
+ - `walkingAnim`: _(string)_ Name of the walking animation on the model. This animation is looped when calling the `followPath()` function.
159
+ - `walkingSpeed`: _(number)_ Speed of the NPC when walking. By default _2_.
160
+ - `path`: _(Vector3)_ Default path to walk. If a value is provided for this field on NPC initialization, the NPC will walk over this path in loop from the start.
161
+ - `noUI`: _(boolean)_ If true, no UI object is built for UI dialogs for this NPC. This may help optimize the scene if this feature is not used.
162
+
163
+ ```ts
164
+ export let myNPC = npc.create({position: Vector3.create(8,0,8),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
165
+ //NPC Data Object
166
+ {
167
+ type: npc.NPCType.CUSTOM,
168
+ model: 'models/npc.glb',
169
+ onActivate: ()=>{console.log('npc activated');},
170
+ onWalkAway: ()=>{console.log('test on walk away function')},
171
+ faceUser: true,
172
+ reactDistance: 3,
173
+ idleAnim: 'idle1',
174
+ walkingAnim: 'walk1',
175
+ hoverText: 'Activate',
176
+ continueOnWalkAway: true,
177
+ onlyClickTrigger: false,
178
+ onlyExternalTrigger: false
179
+ }
180
+ )
181
+ ```
182
+
183
+ ## Get NPC Data
184
+
185
+ ```ts
186
+ npc.getData(myNPC)
187
+ ```
188
+
189
+ There are several properties you can check on an NPC to know what its current state is:
190
+
191
+ - `.state`: An enum value of type `NPCState`. Supported values are `NPCState.STANDING` (default), `NPCState.TALKING`, and `NPCState.FOLLOWPATH`. `TALKING` is applied when the dialog window is opened, and set back to `STANDING` when the window is closed. `FOLLOWPATH` is applied when the NPC starts walking, and set back to `STANDING` when the NPC finishes its path or is stopped.
192
+ - `.introduced`: Boolean, false by default. Set to true if the NPC has spoken to the player at least once in this session.
193
+ - `.visible`: Returns a Boolean, false by default. True if the dialog window for this NPC is currently open.
194
+ - `.inCooldown`: Boolean, false by default. True if the NPC was recently activated and it's now in cooldown. The NPC won't respond to being activated till `inCooldown` is false.
195
+
196
+ > TIP: If you want to force an activation of the NPC in spite of the `inCooldown` value, you can force this value to true before activating.
197
+
198
+ ## NPC Callable Actions
199
+
200
+ An NPC object has several callable functions that come with the class:
201
+
202
+ ### Talk
203
+
204
+ To start a conversation with the NPC using the dialog UI, call the `talk()` function. The function takes the following **required** parameter:
205
+
206
+ - `script`: _(Dialog[])_ This array contains the information to manage the conversation, including events that may be triggered, options to choose, etc.
207
+
208
+ It can also take the following optional parameters:
209
+
210
+ - `startIndex`: _(number | string)_ The _Dialog_ object from the `script` array to open first. By default this is _0_, the first element of the array. Pass a number to open the entry on a given array position, or pass a string to open the entry with a `name` property matching that string.
211
+ - `duration`: _(number)_ Number of seconds to wait before closing the dialog window. If no value is set, the window is kept open till the player reaches the end of the conversation or something else closes it.
212
+
213
+ ```ts
214
+ npc.talk(myNPC,myScript, 0)
215
+ ```
216
+
217
+ Learn how to build a script object for NPCs in a section below.
218
+
219
+ ### Play Animations
220
+
221
+ By default, the NPC will loop an animation named 'Idle', or with a name passed in the `idleAnim` parameter.
222
+
223
+ Make the NPC play another animation by calling the `playAnimation()` function. The function takes the following **required** parameter:
224
+
225
+ - `animationName`: _(string)_ The name of the animation to play.
226
+
227
+ It can also take the following optional parameters:
228
+
229
+ - `noLoop`: _(boolean)_ If true, plays the animation just once. Otherwise, the animation is looped.
230
+ - `duration`: _(number)_ Specifies the duration in seconds of the animation. When finished, it returns to playing the idle animation.
231
+
232
+ > Note: If `noLoop` is true but no `duration` is set, the model will stay still after playing the animation instead of returning to the idle animation.
233
+
234
+ ```ts
235
+ npc.playAnimation(myNPC, `Head_Yes`, true, 2.63)
236
+ ```
237
+
238
+ ### Change idle animation
239
+
240
+ The NPC's idle animation is looped by default whenever the NPC is not playing any other animations. In some cases you may want to have different idle animations depending on the circumstances, like while in a conversation, or if the NPC changes its general attitude after some event.
241
+
242
+ You set the NPC's idle animation when creating the NPC, using the `idleAnim` field. To change this animation at some later time, use `changeIdleAnim()`.
243
+
244
+ The `changeIdleAnim()` function takes two arguments:
245
+
246
+ - `animation`: The name of the new animation to set as the idle animation
247
+ - `play`: Optionally pass this value as _true_ if you want this new animation to start playing right away.
248
+
249
+ ```ts
250
+ npc.changeIdleAnim(myNPC,`AngryIdle`, true)
251
+ ```
252
+
253
+ ### Activate
254
+
255
+ The `activate()` function can be used to trigger the `onActivate()` function, as an alternative to pressing E or walking near.
256
+
257
+ ```ts
258
+ npc.activate(myNPC)
259
+ ```
260
+
261
+ The `activate()` function is callable even when in cool down period, and it doesn't start a new cool down period.
262
+
263
+ ### Stop Walking
264
+
265
+ If the NPC is currently walking, call `stopWalking()` to stop it moving and return to playing its idle animation.
266
+
267
+ ```ts
268
+ npc.stopWalking(myNPC)
269
+ ```
270
+
271
+ `stopWalking()` can be called with no parameters, or it can also be called with:
272
+
273
+ - `duration`: Seconds to wait before starting to walk again. If not provided, the NPC will stop walking indefinitely.
274
+
275
+ > Note: If the NPC is has its dialog window open when the timer for the `duration` ends, the NPC will not return to walking.
276
+
277
+ To make the NPC play a different animation from idle when paused, call `playAnimation()` after `stopWalking()`.
278
+
279
+ ### Follow Path
280
+
281
+ Make an NPC walk following a path of `Vector3` points by calling `followPath()`. While walking, the NPC will play the `walkingAnim` if one was set when defining the NPC. The path can be taken once or on a loop.
282
+
283
+ `followPath()` can be called with no parameters if a `path` was already provided in the NPC's initialization or in a previous calling of `followPath()`. If the NPC was previously in the middle of walking a path and was interrupted, calling `followPath()` again with no arguments will return the NPC to that path.
284
+
285
+ ```ts
286
+ npc.followPath(myNPC)
287
+ ```
288
+
289
+ > Note: If the NPC is initialized with a `path` value, it will start out walking that path in a loop, no need to run `followPath()`.
290
+
291
+ `followPath()` has a single optional parameter of type `FollowPathData`. This object may have the following optional fields:
292
+
293
+ - path: Array of `Vector3` positions to walk over.
294
+ - speed: Speed to move at while walking this path. If no `speed` or `totalDuration` is provided, it uses the NPC's `walkingSpeed`, which is _2_ by default.
295
+ - totalDuration: The duration in _seconds_ that the whole path should take. The NPC will move at the constant speed required to finish in that time. This value overrides that of the _speed_.
296
+ - loop: _boolean_ If true, the NPC walks in circles over the provided set of points in the path. _false_ by default, unless the NPC is initiated with a `path`, in which case it starts as _true_.
297
+ - curve: _boolean_ If true, the path is traced a single smooth curve that passes over each of the indicated points. The curve is made out of straight-line segments, the path is stored with 4 times as many points as originally defined. _false_ by default.
298
+ - startingPoint: Index position for what point to start from on the path. _0_ by default.
299
+ - onFinishCallback: Function to call when the NPC finished walking over all the points on the path. This is only called when `loop` is _false_.
300
+ - onReachedPointCallback: Function to call once every time the NPC reaches a point in the path.
301
+
302
+ ```ts
303
+ export let myNPC = npc.create({position: Vector3.create(8,0,8),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
304
+ //NPC Data Object
305
+ {
306
+ type: npc.NPCType.CUSTOM,
307
+ model: 'models/npc.glb',
308
+ onActivate: ()=>{console.log('npc activated');},
309
+ onWalkAway: ()=>{console.log('test on walk away function')},
310
+ faceUser: true,
311
+ reactDistance: 3,
312
+ idleAnim: 'idle1',
313
+ walkingAnim: 'walk1',
314
+ hoverText: "Activate"
315
+ }
316
+ )
317
+
318
+ npc.followPath(myNPC,
319
+ {
320
+ path:path,
321
+ loop:true,
322
+ pathType: npc.NPCPathType.RIGID_PATH,
323
+ onFinishCallback:()=>{console.log('path is done')},
324
+ onReachedPointCallback:()=>{console.log('ending oint')},
325
+ totalDuration: 20
326
+ }
327
+ )
328
+
329
+ ```
330
+
331
+ #### NPC Walking Speed
332
+
333
+ The following list of factors are used to determine speed in hierarchical order:
334
+
335
+ - `totalDuration` parameter set when calling `followPath()` is used over the total distance travelled over the path.
336
+ - `speed` parameter set when calling `followPath()`
337
+ - `walkingSpeed` parameter set when initializing NPC
338
+ - Default value _2_.
339
+
340
+ #### Joining the path
341
+
342
+ If the NPC's current position when calling `followPath()` doesn't match the first position in the `path` array (or the one that matches the `startingPoint` value), the current position is added to the `path` array. The NPC will start by walking from its current position to the first point provided in the path.
343
+
344
+ The `path` can be a single point, and the NPC will then walk a from its current position to that point.
345
+
346
+ > Note: If the speed of the NPC is determined by a `totalDuration` value, the segment that the NPC walks to join into the path is counted as part of the full path. If this segment is long, it will increase the NPC walking speed so that the full path lasts as what's indicated by the `totalDuration`.
347
+
348
+ In this example the NPC is far away from the start of the path. It will first walk from _10, 0, 10_ to _2, 0, 2_ and then continue the path.
349
+
350
+ ```ts
351
+ export let myNPC = npc.create({position: Vector3.create(10,0,10),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
352
+ //NPC Data Object
353
+ {
354
+ type: npc.NPCType.CUSTOM,
355
+ model: 'models/npc.glb',
356
+ onActivate: ()=>{console.log('npc activated');},
357
+ }
358
+ )
359
+ npc.followPath(myNPC,
360
+ {
361
+ path: [new Vector3(2, 0, 2), new Vector3(4, 0, 4), new Vector3(6, 0, 6)]
362
+ })
363
+ ```
364
+
365
+ #### Example Interrupting the NPC
366
+
367
+ In the following example, an NPC starts roaming walking over a path, pausing on every point to call out for its lost kitten. If the player activates the NPC (by pressing E on it or walking near it) the NPC stops, and turns to face the player and talk. When the conversation is over, the NPC returns to walking its path from where it left off.
368
+
369
+ ```ts
370
+ export let myNPC = npc.create({position: Vector3.create(10,0,10),rotation:Quaternion.Zero(), scale: Vector3.create(1,1,1)},
371
+ //NPC Data Object
372
+ {
373
+ type: npc.NPCType.CUSTOM,
374
+ model: 'models/npc.glb',
375
+ onActivate: ()=>{
376
+ npc.stopWalking(myNPC);
377
+ npc.talk(myNPC, lostCat, 0)
378
+ console.log('npc activated');
379
+ },
380
+ walkingAnim: 'walk1',
381
+ faceUser:true
382
+ }
383
+ )
384
+
385
+ npc.followPath(myNPC,
386
+ {
387
+ path: [new Vector3(4, 0, 30), new Vector3(6, 0, 29), new Vector3(15, 0, 25)],
388
+ loop: true,
389
+ onReachedPointCallback: () => {
390
+ npc.stopWalking(myNPC, 3)
391
+ npc.playAnimation(myNPC, `Cocky`, true, 2.93)
392
+ }
393
+ })
394
+
395
+ export let lostCat: Dialog[] = [
396
+ {
397
+ text: `I lost my cat, I'm going crazy here`
398
+ },
399
+ {
400
+ text: `Have you seen it anywhere?`
401
+ },
402
+ {
403
+ text: `Ok, I'm gonna go back to looking for it`,
404
+ triggeredByNext: () => {
405
+ npc.followPath(myNPC)
406
+ },
407
+ isEndOfDialog: true
408
+ }
409
+ ]
410
+ ```
411
+
412
+ ### End interaction
413
+
414
+ The `endInteraction()` function can be used to abruptly end interactions with the NPC.
415
+
416
+ If applicable, it closes the dialog UI, hides speech bubbles, and makes the NPC stop rotating to face the player.
417
+
418
+ ```ts
419
+ npc.endInteraction(myNPC)
420
+ ```
421
+
422
+ As an alternative, you can call the `handleWalkAway()` function, which has the same effects (as long as `continueOnWalkAway` isn't set to true), but also triggers the `onWalkAway()` function.
423
+
424
+ ## NPC Dialog Window
425
+
426
+ You can display an interactive dialog window to simulate a conversation with a non-player character (NPC).
427
+
428
+ The conversation is based on a script in JSON format. The script can include questions that can take you forward or backward, or end the conversation.
429
+
430
+ <img src="screenshots/NPC1.png" width="500">
431
+
432
+ ### The NPC script
433
+
434
+ Each entry on the script must include at least a `text` field, but can include several more fields to further customize it.
435
+
436
+ Below is a minimal dialog.
437
+
438
+ ```ts
439
+ export let NPCTalk: Dialog[] = [
440
+ {
441
+ text: 'Hi there'
442
+ },
443
+ {
444
+ text: 'It sure is nice talking to you'
445
+ },
446
+ {
447
+ text: 'I must go, my planet needs me',
448
+ isEndOfDialog: true
449
+ }
450
+ ]
451
+ ```
452
+
453
+ The player advances through each entry by clicking the mouse button. Once the last is reached, clicking again closes the window, as it's marked as `isEndOfDialog`.
454
+
455
+ The script must adhere to the following schema:
456
+
457
+ ```ts
458
+ class Dialog {
459
+ text: string
460
+ fontSize?: number
461
+ typeSpeed?: number
462
+ isEndOfDialog?: boolean
463
+ isQuestion?:boolean
464
+ buttons?: ButtonData[]
465
+ audio?: string
466
+ triggeredByNext?: () => void
467
+ }
468
+ ```
469
+
470
+ > Note: A `Dialog` object can be used as an input both for the `talk()` function (that is displayed in the UI), and the `talkBubble()` function (that is displayed in a floating bubble over the NPC). Properties marked with `*` are only applicable to UI dialogs.
471
+
472
+
473
+ You can set the following fields to change the appearance of a dialog:
474
+
475
+ - `text`: The dialog text
476
+ - `fontSize`: Size of the text
477
+
478
+ Other fields:
479
+ - `buttons *`: An array of buttons to use in a question entry, covered in the next section.
480
+ - `audio`: String with the path to an audio file to play once when this dialog is shown on the UI.
481
+ - `typeSpeed`: The text appears one character at a time, simulating typing. Players can click to skip the animation. Tune the speed of this typing (30 by default) to go slower or faster. Set to _-1_ to skip the animation.
482
+
483
+ #### Questions and conversation trees
484
+
485
+ The script can include questions that prompt the player to pick between two or up to four options. These questions can branch the conversation out and trigger other actions in the scene.
486
+
487
+ <img src="screenshots/NPC2.png" width="500">
488
+
489
+ > Note: Questions are only used by UI dialogs. If used in a speech bubble, questions will be displayed as regular entries with no buttons or options.
490
+
491
+ To make an entry a question, set the `isQuestion` field to _true_. This displays a set of buttons rather than the click icon. It also disables the click to advance to the next entry.
492
+
493
+ The `buttons` property of an entry contains an array of `ButtonData` objects, each one of these defines one button.
494
+
495
+ When on a question entry, you must provide at least the following for each button:
496
+
497
+ - `label`: _(string)_ The label to show on the button.
498
+ - `goToDialog`: _(number | string)_ The index or name of the next dialog entry to display when activated.
499
+
500
+ > TIP: It's always better to refer to an entry by name, since the array index might shift if you add more entries and it can get hard to keep track of these references.
501
+
502
+ You can also set the following:
503
+
504
+ - `triggeredActions`: _( () => void )_ An additional function to run whenever the button is activated
505
+ - `fontSize`: _(number)_ Font size of the text
506
+ - `offsetX`: _(number)_ Offset of the label on the X axis, relative to its normal position.
507
+ - `offsetY`: _(number)_ Offset of the label on the Y axis, relative to its normal position.
508
+
509
+ All buttons can be clicked to activate them. Additionally, the first button in the array can be activated by pressing the _E_ key. The second button in the array can be activated by pressing the _F_ key,
510
+
511
+ <img src="screenshots/NPC3.png" width="500">
512
+
513
+ ```ts
514
+ export let GemsMission: Dialog[] = [
515
+ {
516
+ text: `Hello stranger`
517
+ },
518
+ {
519
+ text: `Can you help me finding my missing gems?`,
520
+ isQuestion: true,
521
+ buttons: [
522
+ { label: `Yes!`, goToDialog: 2 },
523
+ { label: `I'm busy`, goToDialog: 4 }
524
+ ]
525
+ },
526
+ {
527
+ text: `Ok, awesome, thanks!`
528
+ },
529
+ {
530
+ text: `I need you to find 10 gems scattered around this scene, go find them!`,
531
+ isEndOfDialog: true
532
+ },
533
+ {
534
+ text: `Ok, come back soon`,
535
+ isEndOfDialog: true
536
+ }
537
+ ]
538
+ ```
539
+
540
+ #### Triggering functions from the dialog
541
+
542
+ You can run functions that may affect any other part of your scene. These functions get triggered when the player interacts with the dialog window, or when the NPC displays speech bubbles.
543
+
544
+ - `triggeredByNext`: Is executed when the player advances to the next dialog on a non-question dialog. The function also gets called if the dialog is the end of the conversation. It also gets called when a speech bubble advances to the next entry.
545
+
546
+ - `triggeredActions`: This property is associated to a button and is executed on a question dialog if the player activates the corresponding button. You can have up to 4 different buttons per entry, each with its own actions.
547
+
548
+ ```ts
549
+ export let GemsMission: Dialog[] = [
550
+ {
551
+ text: `Hello stranger`,
552
+ triggeredByNext: () => {
553
+ // NPC plays animation to show a gem
554
+ }
555
+ },
556
+ {
557
+ text: `Can you help me finding my missing gems?`,
558
+ isQuestion: true,
559
+ buttons: [
560
+ {
561
+ label: `Yes!`,
562
+ goToDialog: 2,
563
+ triggeredActions: () => {
564
+ // NPC plays an animation to celebrate
565
+ }
566
+ },
567
+ {
568
+ label: `I'm busy`,
569
+ goToDialog: 4
570
+ triggeredActions: () => {
571
+ // NPC waves goodbye
572
+ }
573
+ },
574
+ ]
575
+ },
576
+ {
577
+ text: `Ok, awesome, thanks!`,
578
+ },
579
+ {
580
+ text: `I need you to find 10 gems scattered around this scene, go find them!`,
581
+ isEndOfDialog: true
582
+ triggeredByNext: () => {
583
+ // Gems are rendered all around the scene
584
+ }
585
+ },
586
+ {
587
+ text: `Ok, come back soon`,
588
+ isEndOfDialog: true
589
+ }
590
+ ]
591
+ ```
592
+
593
+
594
+ ## Contribute
595
+
596
+ In order to test changes made to this repository in active scenes, do the following:
597
+
598
+ 1. Run `npm run build` for the internal files of the library to be generated
599
+ 2. Run `npm run link` on this repository
600
+ 3. On a new Decentraland scene, import this library as you normally would and include the tests you need
601
+ 4. On the scene directory, run `npm link @dcl-sdk/npc-utils`
602
+
603
+ > Note: When done testing, run `npm unlink` on both folders, so that the scene stops using the local version of the library.
604
+
605
+
606
+ ## CI/CD
607
+
608
+ This repository uses `semantic-release` to automatically release new versions of the package to NPM.
609
+
610
+ Use the following convention for commit names:
611
+
612
+ `feat: something`: Minor release, every time you add a feature or enhancement that doesn’t break the api.
613
+
614
+ `fix: something`: Bug fixing / patch
615
+
616
+ `chore: something`: Anything that doesn't require a release to npm, like changing the readme. Updating a dependency is **not** a chore if it fixes a bug or a vulnerability, that's a `fix`.
617
+
618
+ If you break the API of the library, you need to do a major release, and that's done a different way. You need to add a second comment that starts with `BREAKING CHANGE`, like:
619
+
620
+ ```
621
+ commit -m "feat: changed the signature of a method" -m "BREAKING CHANGE: this commit breaks the API, changing foo(arg1) to foo(arg1, arg2)"
622
+ ```
@@ -0,0 +1,2 @@
1
+ export declare const IsFollowingPath: import("@dcl/sdk/ecs").MapComponentDefinition<import("@dcl/sdk/ecs").MapResult<{}>>;
2
+ export declare const IsTypingDialog: import("@dcl/sdk/ecs").MapComponentDefinition<import("@dcl/sdk/ecs").MapResult<{}>>;
@@ -0,0 +1,4 @@
1
+ import { engine } from "@dcl/sdk/ecs";
2
+ export const IsFollowingPath = engine.defineComponent("isFollowingPath", {});
3
+ export const IsTypingDialog = engine.defineComponent("isTypingDialog", {});
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tcG9uZW50cy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9jb21wb25lbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFFdEMsTUFBTSxDQUFDLE1BQU0sZUFBZSxHQUFHLE1BQU0sQ0FBQyxlQUFlLENBQUMsaUJBQWlCLEVBQUUsRUFBRSxDQUFDLENBQUE7QUFDNUUsTUFBTSxDQUFDLE1BQU0sY0FBYyxHQUFHLE1BQU0sQ0FBQyxlQUFlLENBQUMsZ0JBQWdCLEVBQUUsRUFBRSxDQUFDLENBQUEiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBlbmdpbmUgfSBmcm9tIFwiQGRjbC9zZGsvZWNzXCI7XG5cbmV4cG9ydCBjb25zdCBJc0ZvbGxvd2luZ1BhdGggPSBlbmdpbmUuZGVmaW5lQ29tcG9uZW50KFwiaXNGb2xsb3dpbmdQYXRoXCIsIHt9KVxuZXhwb3J0IGNvbnN0IElzVHlwaW5nRGlhbG9nID0gZW5naW5lLmRlZmluZUNvbXBvbmVudChcImlzVHlwaW5nRGlhbG9nXCIsIHt9KVxuXG4iXX0=
@@ -0,0 +1,11 @@
1
+ export declare let extraFemaleShoes: any[];
2
+ export declare let extraFemalePants: any[];
3
+ export declare let extraFemaleTop: any[];
4
+ export declare let extraMaleShoes: any[];
5
+ export declare let extraMalePants: any[];
6
+ export declare let extraMaleTop: any[];
7
+ export declare let extraskin: any[];
8
+ export declare let extrahair: any[];
9
+ export declare let extraFemaleHairstyle: any[];
10
+ export declare let extraMaleHairstyle: any[];
11
+ export declare let extraeyes: any[];