@rpgjs/action-battle 5.0.0-beta.1 → 5.0.0-beta.3

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.
@@ -1,55 +1,41 @@
1
- const DEFAULT_ACTION_BATTLE_OPTIONS = {
2
- ui: {
3
- actionBar: {
4
- enabled: false,
5
- autoOpen: false,
6
- mode: "both"
7
- },
8
- targeting: {
9
- enabled: true,
10
- showGrid: true,
11
- colors: {
12
- area: 3120887,
13
- edge: 1796760,
14
- cursor: 16765286
15
- }
16
- }
17
- },
18
- skills: {
19
- defaultAoeMask: ["#"]
20
- },
21
- targeting: {
22
- affects: "events",
23
- allowEmptyTarget: true
24
- }
1
+ var DEFAULT_ANIMATION_BY_KEY = {
2
+ attack: "attack",
3
+ hurt: "hurt",
4
+ die: "die",
5
+ castSkill: "skill"
25
6
  };
26
- function normalizeActionBattleOptions(options = {}) {
27
- return {
28
- ui: {
29
- actionBar: {
30
- ...DEFAULT_ACTION_BATTLE_OPTIONS.ui?.actionBar,
31
- ...options.ui?.actionBar
32
- },
33
- targeting: {
34
- ...DEFAULT_ACTION_BATTLE_OPTIONS.ui?.targeting,
35
- ...options.ui?.targeting,
36
- colors: {
37
- ...DEFAULT_ACTION_BATTLE_OPTIONS.ui?.targeting?.colors,
38
- ...options.ui?.targeting?.colors
39
- }
40
- }
41
- },
42
- skills: {
43
- ...DEFAULT_ACTION_BATTLE_OPTIONS.skills,
44
- ...options.skills
45
- },
46
- targeting: {
47
- ...DEFAULT_ACTION_BATTLE_OPTIONS.targeting,
48
- ...options.targeting
49
- }
50
- };
7
+ function resolveActionBattleAnimation(key, entity, animations, context, defaults = {}) {
8
+ const defaultAnimationName = defaults.animationName ?? DEFAULT_ANIMATION_BY_KEY[key];
9
+ const defaultRepeat = defaults.repeat ?? 1;
10
+ const hasConfiguredAnimation = animations ? Object.prototype.hasOwnProperty.call(animations, key) : false;
11
+ if (!hasConfiguredAnimation && key !== "attack") return null;
12
+ const configured = hasConfiguredAnimation ? animations?.[key] : defaultAnimationName;
13
+ const result = typeof configured === "function" ? configured(entity, context) : configured;
14
+ if (result == null) return null;
15
+ if (typeof result === "string") return {
16
+ animationName: result,
17
+ repeat: defaultRepeat,
18
+ waitEnd: false
19
+ };
20
+ return {
21
+ animationName: result.animationName ?? defaultAnimationName,
22
+ graphic: result.graphic,
23
+ repeat: result.repeat ?? defaultRepeat,
24
+ waitEnd: result.waitEnd ?? false,
25
+ delayMs: result.delayMs
26
+ };
51
27
  }
52
- export {
53
- DEFAULT_ACTION_BATTLE_OPTIONS,
54
- normalizeActionBattleOptions
55
- };
28
+ function playActionBattleAnimation(key, entity, animations, context, defaults = {}) {
29
+ const animation = resolveActionBattleAnimation(key, entity, animations, context, defaults);
30
+ if (!animation) return null;
31
+ if (animation.graphic !== void 0) entity.setGraphicAnimation(animation.animationName, animation.graphic, animation.repeat);
32
+ else entity.setGraphicAnimation(animation.animationName, animation.repeat);
33
+ return animation;
34
+ }
35
+ function getActionBattleAnimationRemovalDelay(animation) {
36
+ if (!animation) return 0;
37
+ if (animation.delayMs !== void 0) return animation.delayMs;
38
+ return animation.waitEnd ? 500 : 0;
39
+ }
40
+ //#endregion
41
+ export { getActionBattleAnimationRemovalDelay, playActionBattleAnimation };