@rpgjs/server 5.0.0-alpha.28 → 5.0.0-alpha.29
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/dist/Player/Player.d.ts +36 -21
- package/dist/index.js +36 -28
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/Player/Player.ts +74 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/server",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.29",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,16 +11,16 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"description": "",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@rpgjs/common": "5.0.0-alpha.
|
|
15
|
-
"@rpgjs/physic": "5.0.0-alpha.
|
|
16
|
-
"@rpgjs/testing": "5.0.0-alpha.
|
|
14
|
+
"@rpgjs/common": "5.0.0-alpha.29",
|
|
15
|
+
"@rpgjs/physic": "5.0.0-alpha.29",
|
|
16
|
+
"@rpgjs/testing": "5.0.0-alpha.29",
|
|
17
17
|
"@rpgjs/database": "^4.3.0",
|
|
18
18
|
"@signe/di": "^2.7.3",
|
|
19
19
|
"@signe/reactive": "^2.7.3",
|
|
20
20
|
"@signe/room": "^2.7.3",
|
|
21
21
|
"@signe/sync": "^2.7.3",
|
|
22
22
|
"rxjs": "^7.8.2",
|
|
23
|
-
"zod": "^4.2.
|
|
23
|
+
"zod": "^4.2.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"vite": "^7.3.0",
|
package/src/Player/Player.ts
CHANGED
|
@@ -416,43 +416,94 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
416
416
|
return dataLoaded
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
|
|
419
420
|
/**
|
|
421
|
+
* @deprecated Use setGraphicAnimation instead.
|
|
422
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
423
|
+
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
424
|
+
*/
|
|
425
|
+
setAnimation(animationName: string, nbTimes: number = Infinity) {
|
|
426
|
+
console.warn('setAnimation is deprecated. Use setGraphicAnimation instead.');
|
|
427
|
+
this.setGraphicAnimation(animationName, nbTimes);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @deprecated Use setGraphicAnimation instead.
|
|
432
|
+
* @param graphic - The graphic to use for the animation (e.g., 'attack', 'skill', 'walk')
|
|
433
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
434
|
+
* @param replaceGraphic - Whether to replace the player's graphic (default: false)
|
|
435
|
+
*/
|
|
436
|
+
showAnimation(graphic: string, animationName: string, replaceGraphic: boolean = false) {
|
|
437
|
+
if (replaceGraphic) {
|
|
438
|
+
console.warn('showAnimation is deprecated. Use player.setGraphicAnimation instead.');
|
|
439
|
+
this.setGraphicAnimation(animationName, graphic);
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
console.warn('showAnimation is deprecated. Use map.showAnimation instead.');
|
|
443
|
+
const map = this.getCurrentMap();
|
|
444
|
+
map?.showAnimation({ x: this.x(), y: this.y() }, graphic, animationName);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
420
449
|
* Set the current animation of the player's sprite
|
|
421
|
-
*
|
|
450
|
+
*
|
|
422
451
|
* This method changes the animation state of the player's current sprite.
|
|
423
452
|
* It's used to trigger character animations like attack, skill, or custom movements.
|
|
424
453
|
* When `nbTimes` is set to a finite number, the animation will play that many times
|
|
425
454
|
* before returning to the previous animation state.
|
|
426
|
-
*
|
|
455
|
+
*
|
|
427
456
|
* If `animationFixed` is true, this method will not change the animation.
|
|
428
|
-
*
|
|
457
|
+
*
|
|
429
458
|
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
430
459
|
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* ```ts
|
|
434
|
-
* // Set continuous walk animation
|
|
435
|
-
* player.setAnimation('walk');
|
|
436
|
-
*
|
|
437
|
-
* // Play attack animation 3 times then return to previous state
|
|
438
|
-
* player.setAnimation('attack', 3);
|
|
439
|
-
*
|
|
440
|
-
* // Lock animation to prevent automatic changes
|
|
441
|
-
* player.animationFixed = true;
|
|
442
|
-
* player.setAnimation('skill'); // This will be ignored
|
|
443
|
-
*
|
|
444
|
-
* // Set idle/stand animation
|
|
445
|
-
* player.setAnimation('stand');
|
|
446
|
-
* ```
|
|
447
460
|
*/
|
|
448
|
-
|
|
461
|
+
setGraphicAnimation(animationName: string, nbTimes: number): void;
|
|
462
|
+
/**
|
|
463
|
+
* Set the current animation of the player's sprite with a temporary graphic change
|
|
464
|
+
*
|
|
465
|
+
* This method changes the animation state of the player's current sprite and temporarily
|
|
466
|
+
* changes the player's graphic (sprite sheet) during the animation. The graphic is
|
|
467
|
+
* automatically reset when the animation finishes.
|
|
468
|
+
*
|
|
469
|
+
* When `nbTimes` is set to a finite number, the animation will play that many times
|
|
470
|
+
* before returning to the previous animation state and graphic.
|
|
471
|
+
*
|
|
472
|
+
* If `animationFixed` is true, this method will not change the animation.
|
|
473
|
+
*
|
|
474
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
475
|
+
* @param graphic - The graphic(s) to temporarily use during the animation
|
|
476
|
+
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
477
|
+
*/
|
|
478
|
+
setGraphicAnimation(animationName: string, graphic: string | string[], nbTimes: number): void;
|
|
479
|
+
setGraphicAnimation(animationName: string, graphic: string | string[]): void;
|
|
480
|
+
setGraphicAnimation(animationName: string, graphicOrNbTimes?: string | string[] | number, nbTimes: number = 1): void {
|
|
449
481
|
// Don't change animation if it's locked
|
|
450
482
|
if (this.animationFixed) {
|
|
451
483
|
return;
|
|
452
484
|
}
|
|
485
|
+
|
|
486
|
+
let graphic: string | string[] | undefined;
|
|
487
|
+
let finalNbTimes: number = Infinity;
|
|
488
|
+
|
|
489
|
+
// Handle overloads
|
|
490
|
+
if (typeof graphicOrNbTimes === 'number') {
|
|
491
|
+
// setGraphicAnimation(animationName, nbTimes)
|
|
492
|
+
finalNbTimes = graphicOrNbTimes;
|
|
493
|
+
} else if (graphicOrNbTimes !== undefined) {
|
|
494
|
+
// setGraphicAnimation(animationName, graphic, nbTimes)
|
|
495
|
+
graphic = graphicOrNbTimes;
|
|
496
|
+
finalNbTimes = nbTimes ?? Infinity;
|
|
497
|
+
} else {
|
|
498
|
+
// setGraphicAnimation(animationName) - nbTimes remains Infinity
|
|
499
|
+
finalNbTimes = Infinity;
|
|
500
|
+
}
|
|
501
|
+
|
|
453
502
|
const map = this.getCurrentMap();
|
|
454
503
|
if (!map) return;
|
|
455
|
-
|
|
504
|
+
|
|
505
|
+
if (finalNbTimes === Infinity) {
|
|
506
|
+
if (graphic) this.setGraphic(graphic);
|
|
456
507
|
this.animationName.set(animationName);
|
|
457
508
|
}
|
|
458
509
|
else {
|
|
@@ -460,7 +511,8 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
460
511
|
type: "setAnimation",
|
|
461
512
|
value: {
|
|
462
513
|
animationName,
|
|
463
|
-
|
|
514
|
+
graphic,
|
|
515
|
+
nbTimes: finalNbTimes,
|
|
464
516
|
object: this.id,
|
|
465
517
|
},
|
|
466
518
|
});
|