@rpgjs/action-battle 5.0.0-beta.2 → 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,69 +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
- },
25
- animations: {}
1
+ var DEFAULT_ANIMATION_BY_KEY = {
2
+ attack: "attack",
3
+ hurt: "hurt",
4
+ die: "die",
5
+ castSkill: "skill"
26
6
  };
27
- let currentActionBattleOptions = DEFAULT_ACTION_BATTLE_OPTIONS;
28
- function normalizeActionBattleOptions(options = {}) {
29
- return {
30
- ui: {
31
- actionBar: {
32
- ...DEFAULT_ACTION_BATTLE_OPTIONS.ui?.actionBar,
33
- ...options.ui?.actionBar
34
- },
35
- targeting: {
36
- ...DEFAULT_ACTION_BATTLE_OPTIONS.ui?.targeting,
37
- ...options.ui?.targeting,
38
- colors: {
39
- ...DEFAULT_ACTION_BATTLE_OPTIONS.ui?.targeting?.colors,
40
- ...options.ui?.targeting?.colors
41
- }
42
- }
43
- },
44
- skills: {
45
- ...DEFAULT_ACTION_BATTLE_OPTIONS.skills,
46
- ...options.skills
47
- },
48
- targeting: {
49
- ...DEFAULT_ACTION_BATTLE_OPTIONS.targeting,
50
- ...options.targeting
51
- },
52
- animations: {
53
- ...DEFAULT_ACTION_BATTLE_OPTIONS.animations,
54
- ...options.animations
55
- }
56
- };
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
+ };
57
27
  }
58
- function setActionBattleOptions(options) {
59
- currentActionBattleOptions = options;
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;
60
34
  }
61
- function getActionBattleOptions() {
62
- return currentActionBattleOptions;
35
+ function getActionBattleAnimationRemovalDelay(animation) {
36
+ if (!animation) return 0;
37
+ if (animation.delayMs !== void 0) return animation.delayMs;
38
+ return animation.waitEnd ? 500 : 0;
63
39
  }
64
- export {
65
- DEFAULT_ACTION_BATTLE_OPTIONS,
66
- getActionBattleOptions,
67
- normalizeActionBattleOptions,
68
- setActionBattleOptions
69
- };
40
+ //#endregion
41
+ export { getActionBattleAnimationRemovalDelay, playActionBattleAnimation };