@gamepark/react-game 7.3.2 → 7.4.1
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/components/GameProvider/GameProvider.js +2 -3
- package/dist/components/GameProvider/GameProvider.js.map +1 -1
- package/dist/components/Header/HeaderText.d.ts +6 -1
- package/dist/components/Header/HeaderText.js +14 -5
- package/dist/components/Header/HeaderText.js.map +1 -1
- package/dist/components/JournalTabs/JournalTabs.js +1 -1
- package/dist/components/JournalTabs/JournalTabs.js.map +1 -1
- package/dist/components/LoadingScreen/LoadingScreen.js +5 -0
- package/dist/components/LoadingScreen/LoadingScreen.js.map +1 -1
- package/dist/components/material/DraggableMaterial.d.ts +12 -2
- package/dist/components/material/DraggableMaterial.js +47 -57
- package/dist/components/material/DraggableMaterial.js.map +1 -1
- package/dist/components/material/GameTable/DynamicItemsDisplay.js +53 -8
- package/dist/components/material/GameTable/DynamicItemsDisplay.js.map +1 -1
- package/dist/components/material/GameTable/GameMaterialDisplay.js +5 -2
- package/dist/components/material/GameTable/GameMaterialDisplay.js.map +1 -1
- package/dist/components/material/GameTable/GameTable.d.ts +1 -0
- package/dist/components/material/GameTable/GameTable.js +49 -18
- package/dist/components/material/GameTable/GameTable.js.map +1 -1
- package/dist/components/material/GameTable/GameTableNavigation.js +7 -0
- package/dist/components/material/GameTable/GameTableNavigation.js.map +1 -1
- package/dist/components/material/GameTable/ItemDisplay.js +4 -4
- package/dist/components/material/GameTable/ItemDisplay.js.map +1 -1
- package/dist/components/material/GameTable/StaticItemsDisplay.js +21 -6
- package/dist/components/material/GameTable/StaticItemsDisplay.js.map +1 -1
- package/dist/components/material/GameTable/focus/FocusProvider.js +11 -5
- package/dist/components/material/GameTable/focus/FocusProvider.js.map +1 -1
- package/dist/components/material/GameTable/focus/NoZoomFocusProvider.js +2 -2
- package/dist/components/material/GameTable/focus/NoZoomFocusProvider.js.map +1 -1
- package/dist/components/material/GameTable/focus/index.d.ts +1 -0
- package/dist/components/material/GameTable/focus/index.js +1 -0
- package/dist/components/material/GameTable/focus/index.js.map +1 -1
- package/dist/components/material/GameTable/index.d.ts +2 -0
- package/dist/components/material/GameTable/index.js +2 -0
- package/dist/components/material/GameTable/index.js.map +1 -1
- package/dist/components/material/MaterialDescription.d.ts +1 -1
- package/dist/components/material/MaterialDescription.js +10 -13
- package/dist/components/material/MaterialDescription.js.map +1 -1
- package/dist/components/material/animations/AnimationBuilder.d.ts +160 -0
- package/dist/components/material/animations/AnimationBuilder.js +287 -0
- package/dist/components/material/animations/AnimationBuilder.js.map +1 -0
- package/dist/components/material/animations/CreateItemAnimations.d.ts +4 -2
- package/dist/components/material/animations/CreateItemAnimations.js +91 -10
- package/dist/components/material/animations/CreateItemAnimations.js.map +1 -1
- package/dist/components/material/animations/DeleteItemAnimations.d.ts +4 -8
- package/dist/components/material/animations/DeleteItemAnimations.js +24 -14
- package/dist/components/material/animations/DeleteItemAnimations.js.map +1 -1
- package/dist/components/material/animations/DeleteItemAtOnceAnimations.d.ts +3 -1
- package/dist/components/material/animations/DeleteItemAtOnceAnimations.js +16 -4
- package/dist/components/material/animations/DeleteItemAtOnceAnimations.js.map +1 -1
- package/dist/components/material/animations/ItemAnimations.d.ts +46 -1
- package/dist/components/material/animations/ItemAnimations.js +155 -1
- package/dist/components/material/animations/ItemAnimations.js.map +1 -1
- package/dist/components/material/animations/MaterialAnimations.d.ts +2 -1
- package/dist/components/material/animations/MaterialAnimations.js +6 -6
- package/dist/components/material/animations/MaterialAnimations.js.map +1 -1
- package/dist/components/material/animations/MaterialGameAnimations.d.ts +94 -1
- package/dist/components/material/animations/MaterialGameAnimations.js +150 -2
- package/dist/components/material/animations/MaterialGameAnimations.js.map +1 -1
- package/dist/components/material/animations/MoveItemAnimations.d.ts +3 -1
- package/dist/components/material/animations/MoveItemAnimations.js +51 -7
- package/dist/components/material/animations/MoveItemAnimations.js.map +1 -1
- package/dist/components/material/animations/MoveItemAtOnceAnimations.d.ts +5 -2
- package/dist/components/material/animations/MoveItemAtOnceAnimations.js +57 -5
- package/dist/components/material/animations/MoveItemAtOnceAnimations.js.map +1 -1
- package/dist/components/material/animations/Trajectory.d.ts +132 -0
- package/dist/components/material/animations/Trajectory.js +87 -0
- package/dist/components/material/animations/Trajectory.js.map +1 -0
- package/dist/components/material/animations/index.d.ts +3 -0
- package/dist/components/material/animations/index.js +3 -0
- package/dist/components/material/animations/index.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useLegalMoves.js +2 -1
- package/dist/hooks/useLegalMoves.js.map +1 -1
- package/dist/hooks/useMaterialContextRef.d.ts +10 -0
- package/dist/hooks/useMaterialContextRef.js +12 -0
- package/dist/hooks/useMaterialContextRef.js.map +1 -0
- package/dist/hooks/usePlayerName.js +1 -1
- package/dist/hooks/usePlayerName.js.map +1 -1
- package/dist/hooks/useUndo.js +12 -3
- package/dist/hooks/useUndo.js.map +1 -1
- package/dist/locators/DeckLocator.d.ts +3 -1
- package/dist/locators/DeckLocator.js +6 -0
- package/dist/locators/DeckLocator.js.map +1 -1
- package/dist/locators/HandLocator.d.ts +1 -0
- package/dist/locators/HandLocator.js +3 -0
- package/dist/locators/HandLocator.js.map +1 -1
- package/dist/locators/ListLocator.d.ts +1 -0
- package/dist/locators/ListLocator.js +3 -0
- package/dist/locators/ListLocator.js.map +1 -1
- package/dist/locators/Locator.d.ts +39 -0
- package/dist/locators/Locator.js +74 -1
- package/dist/locators/Locator.js.map +1 -1
- package/dist/locators/PileLocator.d.ts +1 -0
- package/dist/locators/PileLocator.js +3 -0
- package/dist/locators/PileLocator.js.map +1 -1
- package/dist/utilities/translation.util.js +1 -1
- package/dist/utilities/translation.util.js.map +1 -1
- package/package.json +79 -78
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Interpolation, Theme } from '@emotion/react';
|
|
2
|
+
import { Animation } from '@gamepark/react-client';
|
|
3
|
+
import { Coordinates, GridBoundaries, ItemMove, MaterialMove } from '@gamepark/rules-api';
|
|
4
|
+
import { ItemContext, Locator } from '../../../locators';
|
|
5
|
+
import { MaterialSoundConfig } from '../sound';
|
|
6
|
+
import { ItemAnimations } from './ItemAnimations';
|
|
7
|
+
import { MaterialAnimationContext, MaterialGameAnimationContext } from './MaterialGameAnimations';
|
|
8
|
+
import { ElevationConfig, Trajectory, Waypoint } from './Trajectory';
|
|
9
|
+
/**
|
|
10
|
+
* Predicate function to determine if an animation configuration applies to a move.
|
|
11
|
+
*/
|
|
12
|
+
export type AnimationPredicate<P extends number = number, M extends number = number, L extends number = number> = (move: MaterialMove<P, M, L>, context: MaterialAnimationContext<P, M, L>) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Fluent builder for configuring animations.
|
|
15
|
+
* Use this to define duration, sound, and trajectory for animations.
|
|
16
|
+
*/
|
|
17
|
+
export declare class AnimationBuilder<P extends number = number, M extends number = number, L extends number = number> extends ItemAnimations<P, M, L> {
|
|
18
|
+
/** @internal Predicates to match moves */
|
|
19
|
+
readonly predicates: AnimationPredicate<P, M, L>[];
|
|
20
|
+
/** @internal Duration in seconds */
|
|
21
|
+
private _duration?;
|
|
22
|
+
/** @internal Sound configuration */
|
|
23
|
+
private _sound?;
|
|
24
|
+
/** @internal Trajectory configuration */
|
|
25
|
+
private _trajectory;
|
|
26
|
+
/** @internal Whether this animation plays after the move is applied */
|
|
27
|
+
private _postMove;
|
|
28
|
+
/** @internal Custom item animation function */
|
|
29
|
+
private _itemAnimation?;
|
|
30
|
+
/**
|
|
31
|
+
* Add a predicate to filter which moves this configuration applies to.
|
|
32
|
+
* All predicates must return true for the configuration to apply.
|
|
33
|
+
*/
|
|
34
|
+
filter(predicate: AnimationPredicate<P, M, L>): this;
|
|
35
|
+
/**
|
|
36
|
+
* Set the animation duration in milliseconds.
|
|
37
|
+
* @param ms Duration in milliseconds
|
|
38
|
+
*/
|
|
39
|
+
duration(ms: number): this;
|
|
40
|
+
/**
|
|
41
|
+
* Get the configured duration in seconds.
|
|
42
|
+
*/
|
|
43
|
+
get durationSeconds(): number | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Set the sound to play during the animation.
|
|
46
|
+
* @param sound Sound file path, configuration object, or false to disable
|
|
47
|
+
*/
|
|
48
|
+
sound(sound: string | MaterialSoundConfig | false): this;
|
|
49
|
+
/**
|
|
50
|
+
* Get the sound configuration.
|
|
51
|
+
*/
|
|
52
|
+
get soundConfig(): string | MaterialSoundConfig | false | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Set a custom item animation function.
|
|
55
|
+
* This overrides the default position-based animation with fully custom keyframes.
|
|
56
|
+
* @param fn Function that returns CSS animation for each item
|
|
57
|
+
*/
|
|
58
|
+
itemAnimation(fn: (context: ItemContext<P, M, L>, animation: Animation<MaterialMove<P, M, L>>, boundaries: GridBoundaries) => Interpolation<Theme>): this;
|
|
59
|
+
/**
|
|
60
|
+
* Skip this animation entirely (duration = 0).
|
|
61
|
+
*/
|
|
62
|
+
skip(): this;
|
|
63
|
+
/**
|
|
64
|
+
* Make this animation play after the move is applied (AFTER_MOVE step).
|
|
65
|
+
* By default, animations play before the move (BEFORE_MOVE step).
|
|
66
|
+
* Useful for animating items that become visible only after the move.
|
|
67
|
+
*/
|
|
68
|
+
postMove(): this;
|
|
69
|
+
/**
|
|
70
|
+
* Configure a complete trajectory with elevation and waypoints.
|
|
71
|
+
* @param config Trajectory configuration
|
|
72
|
+
*/
|
|
73
|
+
trajectory(config: Trajectory<P, M, L> | ((context: ItemContext<P, M, L>) => Trajectory<P, M, L>)): this;
|
|
74
|
+
/**
|
|
75
|
+
* Get the trajectory configuration.
|
|
76
|
+
*/
|
|
77
|
+
get trajectoryConfig(): Trajectory<P, M, L> | ((context: ItemContext<P, M, L>) => Trajectory<P, M, L>);
|
|
78
|
+
/**
|
|
79
|
+
* Configure the elevation arc.
|
|
80
|
+
* @param heightOrConfig Height in em, or full configuration object
|
|
81
|
+
*/
|
|
82
|
+
arc(heightOrConfig?: number | ElevationConfig): this;
|
|
83
|
+
/**
|
|
84
|
+
* Disable elevation (flat movement).
|
|
85
|
+
*/
|
|
86
|
+
flat(): this;
|
|
87
|
+
/**
|
|
88
|
+
* Add a waypoint to pass through during the animation.
|
|
89
|
+
* @param locatorOrCoordinates Locator instance or absolute coordinates
|
|
90
|
+
* @param at Position in animation (0-1), default 0.5
|
|
91
|
+
*/
|
|
92
|
+
via(locatorOrCoordinates: Locator<P, M, L> | Coordinates, at?: number): this;
|
|
93
|
+
via(waypoint: Waypoint<P, M, L>): this;
|
|
94
|
+
/**
|
|
95
|
+
* Add multiple waypoints to pass through.
|
|
96
|
+
* @param waypoints Array of waypoints
|
|
97
|
+
*/
|
|
98
|
+
through(...waypoints: Waypoint<P, M, L>[]): this;
|
|
99
|
+
/**
|
|
100
|
+
* Set the global easing function for the animation.
|
|
101
|
+
* @param easing CSS easing function
|
|
102
|
+
*/
|
|
103
|
+
easing(easing: string): this;
|
|
104
|
+
/**
|
|
105
|
+
* Check if this configuration matches a move.
|
|
106
|
+
* @internal
|
|
107
|
+
*/
|
|
108
|
+
matches(move: MaterialMove<P, M, L>, context: MaterialAnimationContext<P, M, L>): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get the duration for this animation.
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
getDuration(move: MaterialMove<P, M, L>, context: MaterialGameAnimationContext<P, M, L>): number;
|
|
114
|
+
/**
|
|
115
|
+
* Get the item animation CSS.
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
getItemAnimation(context: ItemContext<P, M, L>, animation: Animation<MaterialMove<P, M, L>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a predicate that matches moves by the current player.
|
|
122
|
+
*/
|
|
123
|
+
export declare function isMyMove<P extends number = number, M extends number = number, L extends number = number>(): AnimationPredicate<P, M, L>;
|
|
124
|
+
/**
|
|
125
|
+
* Create a predicate that matches moves during a specific rule.
|
|
126
|
+
* @param ruleId The rule ID to match
|
|
127
|
+
*/
|
|
128
|
+
export declare function isRule<P extends number = number, M extends number = number, L extends number = number>(ruleId: number): AnimationPredicate<P, M, L>;
|
|
129
|
+
/**
|
|
130
|
+
* Create a predicate that matches moves for a specific material type.
|
|
131
|
+
* @param materialType The material type to match
|
|
132
|
+
*/
|
|
133
|
+
export declare function isMaterial<P extends number = number, M extends number = number, L extends number = number>(materialType: M): AnimationPredicate<P, M, L>;
|
|
134
|
+
/**
|
|
135
|
+
* Create a predicate that matches a specific item move type.
|
|
136
|
+
* @param moveType The item move type to match
|
|
137
|
+
*/
|
|
138
|
+
export declare function isMoveType<P extends number = number, M extends number = number, L extends number = number>(moveType: ItemMove<P, M, L>['type']): AnimationPredicate<P, M, L>;
|
|
139
|
+
/**
|
|
140
|
+
* Create a predicate that matches moves from a specific location type.
|
|
141
|
+
* @param locationType The source location type to match
|
|
142
|
+
*/
|
|
143
|
+
export declare function isFromLocation<P extends number = number, M extends number = number, L extends number = number>(locationType: L): AnimationPredicate<P, M, L>;
|
|
144
|
+
/**
|
|
145
|
+
* Create a predicate that matches moves to a specific location type.
|
|
146
|
+
* @param locationType The destination location type to match
|
|
147
|
+
*/
|
|
148
|
+
export declare function isToLocation<P extends number = number, M extends number = number, L extends number = number>(locationType: L): AnimationPredicate<P, M, L>;
|
|
149
|
+
/**
|
|
150
|
+
* Combine predicates with AND logic (all must match).
|
|
151
|
+
*/
|
|
152
|
+
export declare function and<P extends number = number, M extends number = number, L extends number = number>(...predicates: AnimationPredicate<P, M, L>[]): AnimationPredicate<P, M, L>;
|
|
153
|
+
/**
|
|
154
|
+
* Combine predicates with OR logic (any must match).
|
|
155
|
+
*/
|
|
156
|
+
export declare function or<P extends number = number, M extends number = number, L extends number = number>(...predicates: AnimationPredicate<P, M, L>[]): AnimationPredicate<P, M, L>;
|
|
157
|
+
/**
|
|
158
|
+
* Negate a predicate.
|
|
159
|
+
*/
|
|
160
|
+
export declare function not<P extends number = number, M extends number = number, L extends number = number>(predicate: AnimationPredicate<P, M, L>): AnimationPredicate<P, M, L>;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { AnimationStep } from '@gamepark/react-client';
|
|
2
|
+
import { MoveKind } from '@gamepark/rules-api';
|
|
3
|
+
import { ItemAnimations } from './ItemAnimations';
|
|
4
|
+
import { MaterialAnimations } from './MaterialAnimations';
|
|
5
|
+
import { defaultElevation } from './Trajectory';
|
|
6
|
+
/**
|
|
7
|
+
* Fluent builder for configuring animations.
|
|
8
|
+
* Use this to define duration, sound, and trajectory for animations.
|
|
9
|
+
*/
|
|
10
|
+
export class AnimationBuilder extends ItemAnimations {
|
|
11
|
+
/** @internal Predicates to match moves */
|
|
12
|
+
predicates = [];
|
|
13
|
+
/** @internal Duration in seconds */
|
|
14
|
+
_duration;
|
|
15
|
+
/** @internal Sound configuration */
|
|
16
|
+
_sound;
|
|
17
|
+
/** @internal Trajectory configuration */
|
|
18
|
+
_trajectory = {};
|
|
19
|
+
/** @internal Whether this animation plays after the move is applied */
|
|
20
|
+
_postMove = false;
|
|
21
|
+
/** @internal Custom item animation function */
|
|
22
|
+
_itemAnimation;
|
|
23
|
+
/**
|
|
24
|
+
* Add a predicate to filter which moves this configuration applies to.
|
|
25
|
+
* All predicates must return true for the configuration to apply.
|
|
26
|
+
*/
|
|
27
|
+
filter(predicate) {
|
|
28
|
+
this.predicates.push(predicate);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the animation duration in milliseconds.
|
|
33
|
+
* @param ms Duration in milliseconds
|
|
34
|
+
*/
|
|
35
|
+
duration(ms) {
|
|
36
|
+
this._duration = ms / 1000;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the configured duration in seconds.
|
|
41
|
+
*/
|
|
42
|
+
get durationSeconds() {
|
|
43
|
+
return this._duration;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set the sound to play during the animation.
|
|
47
|
+
* @param sound Sound file path, configuration object, or false to disable
|
|
48
|
+
*/
|
|
49
|
+
sound(sound) {
|
|
50
|
+
this._sound = sound;
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the sound configuration.
|
|
55
|
+
*/
|
|
56
|
+
get soundConfig() {
|
|
57
|
+
return this._sound;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set a custom item animation function.
|
|
61
|
+
* This overrides the default position-based animation with fully custom keyframes.
|
|
62
|
+
* @param fn Function that returns CSS animation for each item
|
|
63
|
+
*/
|
|
64
|
+
itemAnimation(fn) {
|
|
65
|
+
this._itemAnimation = fn;
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Skip this animation entirely (duration = 0).
|
|
70
|
+
*/
|
|
71
|
+
skip() {
|
|
72
|
+
this._duration = 0;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Make this animation play after the move is applied (AFTER_MOVE step).
|
|
77
|
+
* By default, animations play before the move (BEFORE_MOVE step).
|
|
78
|
+
* Useful for animating items that become visible only after the move.
|
|
79
|
+
*/
|
|
80
|
+
postMove() {
|
|
81
|
+
this._postMove = true;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Configure a complete trajectory with elevation and waypoints.
|
|
86
|
+
* @param config Trajectory configuration
|
|
87
|
+
*/
|
|
88
|
+
trajectory(config) {
|
|
89
|
+
this._trajectory = config;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the trajectory configuration.
|
|
94
|
+
*/
|
|
95
|
+
get trajectoryConfig() {
|
|
96
|
+
return this._trajectory;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Configure the elevation arc.
|
|
100
|
+
* @param heightOrConfig Height in em, or full configuration object
|
|
101
|
+
*/
|
|
102
|
+
arc(heightOrConfig) {
|
|
103
|
+
if (typeof this._trajectory === 'function')
|
|
104
|
+
this._trajectory = {};
|
|
105
|
+
if (typeof heightOrConfig === 'number') {
|
|
106
|
+
this._trajectory.elevation = { ...defaultElevation, height: heightOrConfig };
|
|
107
|
+
}
|
|
108
|
+
else if (heightOrConfig) {
|
|
109
|
+
this._trajectory.elevation = heightOrConfig;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this._trajectory.elevation = defaultElevation;
|
|
113
|
+
}
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Disable elevation (flat movement).
|
|
118
|
+
*/
|
|
119
|
+
flat() {
|
|
120
|
+
if (typeof this._trajectory === 'function')
|
|
121
|
+
this._trajectory = {};
|
|
122
|
+
this._trajectory.elevation = false;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
via(arg1, at = 0.5) {
|
|
126
|
+
if (typeof this._trajectory === 'function')
|
|
127
|
+
this._trajectory = {};
|
|
128
|
+
if (!this._trajectory.waypoints) {
|
|
129
|
+
this._trajectory.waypoints = [];
|
|
130
|
+
}
|
|
131
|
+
if (typeof arg1 === 'object' && 'at' in arg1) {
|
|
132
|
+
// Full waypoint object
|
|
133
|
+
this._trajectory.waypoints.push(arg1);
|
|
134
|
+
}
|
|
135
|
+
else if (typeof arg1 === 'object' && 'placeItem' in arg1) {
|
|
136
|
+
// Locator instance
|
|
137
|
+
this._trajectory.waypoints.push({ at, locator: arg1 });
|
|
138
|
+
}
|
|
139
|
+
else if (typeof arg1 === 'object') {
|
|
140
|
+
// Coordinates
|
|
141
|
+
this._trajectory.waypoints.push({ at, coordinates: arg1 });
|
|
142
|
+
}
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Add multiple waypoints to pass through.
|
|
147
|
+
* @param waypoints Array of waypoints
|
|
148
|
+
*/
|
|
149
|
+
through(...waypoints) {
|
|
150
|
+
if (typeof this._trajectory === 'function')
|
|
151
|
+
this._trajectory = {};
|
|
152
|
+
if (!this._trajectory.waypoints) {
|
|
153
|
+
this._trajectory.waypoints = [];
|
|
154
|
+
}
|
|
155
|
+
this._trajectory.waypoints.push(...waypoints);
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Set the global easing function for the animation.
|
|
160
|
+
* @param easing CSS easing function
|
|
161
|
+
*/
|
|
162
|
+
easing(easing) {
|
|
163
|
+
if (typeof this._trajectory === 'function')
|
|
164
|
+
this._trajectory = {};
|
|
165
|
+
this._trajectory.easing = easing;
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Check if this configuration matches a move.
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
matches(move, context) {
|
|
173
|
+
return this.predicates.every(predicate => predicate(move, context));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get the duration for this animation.
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
getDuration(move, context) {
|
|
180
|
+
if (this._postMove) {
|
|
181
|
+
// Post-move animation: only return duration during AFTER_MOVE step
|
|
182
|
+
if (context.step !== AnimationStep.AFTER_MOVE)
|
|
183
|
+
return 0;
|
|
184
|
+
return this._duration ?? 1;
|
|
185
|
+
}
|
|
186
|
+
if (move.kind !== MoveKind.ItemMove)
|
|
187
|
+
return this._duration ?? 0;
|
|
188
|
+
const trajectory = typeof this._trajectory === 'function' ? {} : this._trajectory;
|
|
189
|
+
return new MaterialAnimationsWithTrajectory(this._duration, trajectory).getDuration(move, context);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Get the item animation CSS.
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
195
|
+
getItemAnimation(context, animation, boundaries) {
|
|
196
|
+
if (this._itemAnimation) {
|
|
197
|
+
return this._itemAnimation(context, animation, boundaries);
|
|
198
|
+
}
|
|
199
|
+
const trajectory = typeof this._trajectory === 'function' ? this._trajectory(context) : this._trajectory;
|
|
200
|
+
return new MaterialAnimationsWithTrajectory(this._duration, trajectory).getItemAnimation(context, animation, boundaries);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Extended MaterialAnimations that supports trajectory configuration.
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
class MaterialAnimationsWithTrajectory extends MaterialAnimations {
|
|
208
|
+
constructor(duration, trajectory) {
|
|
209
|
+
// Pass trajectory directly to the parent constructor
|
|
210
|
+
super(duration, 0.2, trajectory);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// ==========================================
|
|
214
|
+
// Predicate helpers
|
|
215
|
+
// ==========================================
|
|
216
|
+
/**
|
|
217
|
+
* Create a predicate that matches moves by the current player.
|
|
218
|
+
*/
|
|
219
|
+
export function isMyMove() {
|
|
220
|
+
return (_, context) => context.player === context.action.playerId;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a predicate that matches moves during a specific rule.
|
|
224
|
+
* @param ruleId The rule ID to match
|
|
225
|
+
*/
|
|
226
|
+
export function isRule(ruleId) {
|
|
227
|
+
return (_, context) => context.rules.game.rule?.id === ruleId;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Create a predicate that matches moves for a specific material type.
|
|
231
|
+
* @param materialType The material type to match
|
|
232
|
+
*/
|
|
233
|
+
export function isMaterial(materialType) {
|
|
234
|
+
return (move) => move.kind === MoveKind.ItemMove && move.itemType === materialType;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a predicate that matches a specific item move type.
|
|
238
|
+
* @param moveType The item move type to match
|
|
239
|
+
*/
|
|
240
|
+
export function isMoveType(moveType) {
|
|
241
|
+
return (move) => move.kind === MoveKind.ItemMove && move.type === moveType;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a predicate that matches moves from a specific location type.
|
|
245
|
+
* @param locationType The source location type to match
|
|
246
|
+
*/
|
|
247
|
+
export function isFromLocation(locationType) {
|
|
248
|
+
return (move, context) => {
|
|
249
|
+
if (move.kind !== MoveKind.ItemMove)
|
|
250
|
+
return false;
|
|
251
|
+
const item = context.rules.material(move.itemType).getItem('itemIndex' in move ? move.itemIndex : 0);
|
|
252
|
+
return item?.location?.type === locationType;
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Create a predicate that matches moves to a specific location type.
|
|
257
|
+
* @param locationType The destination location type to match
|
|
258
|
+
*/
|
|
259
|
+
export function isToLocation(locationType) {
|
|
260
|
+
return (move) => {
|
|
261
|
+
if (move.kind !== MoveKind.ItemMove)
|
|
262
|
+
return false;
|
|
263
|
+
return 'location' in move && move.location?.type === locationType;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// ==========================================
|
|
267
|
+
// Predicate combinators
|
|
268
|
+
// ==========================================
|
|
269
|
+
/**
|
|
270
|
+
* Combine predicates with AND logic (all must match).
|
|
271
|
+
*/
|
|
272
|
+
export function and(...predicates) {
|
|
273
|
+
return (move, context) => predicates.every(p => p(move, context));
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Combine predicates with OR logic (any must match).
|
|
277
|
+
*/
|
|
278
|
+
export function or(...predicates) {
|
|
279
|
+
return (move, context) => predicates.some(p => p(move, context));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Negate a predicate.
|
|
283
|
+
*/
|
|
284
|
+
export function not(predicate) {
|
|
285
|
+
return (move, context) => !predicate(move, context);
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=AnimationBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimationBuilder.js","sourceRoot":"","sources":["../../../../src/components/material/animations/AnimationBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,aAAa,EAAE,MAAM,wBAAwB,CAAA;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undaries, ItemMove } from '@gamepark/rules-api';
|
|
|
4
4
|
import { ItemContext } from '../../../locators';
|
|
5
5
|
import { ItemAnimations } from './ItemAnimations';
|
|
6
6
|
import { MaterialGameAnimationContext } from './MaterialGameAnimations';
|
|
7
|
+
import { Trajectory } from './Trajectory';
|
|
7
8
|
export declare class CreateItemAnimations<P extends number = number, M extends number = number, L extends number = number> extends ItemAnimations<P, M, L> {
|
|
8
9
|
protected duration: number;
|
|
9
|
-
|
|
10
|
+
protected trajectory?: Trajectory<P, M, L> | undefined;
|
|
11
|
+
constructor(duration?: number, trajectory?: Trajectory<P, M, L> | undefined);
|
|
10
12
|
getPreDuration(move: CreateItem<P, M, L>, context: MaterialGameAnimationContext<P, M, L>): number;
|
|
11
|
-
getPostDuration(move: CreateItem<P, M, L>,
|
|
13
|
+
getPostDuration(move: CreateItem<P, M, L>, context: MaterialGameAnimationContext<P, M, L>): number;
|
|
12
14
|
getItemAnimation(context: ItemContext<P, M, L>, animation: Animation<CreateItem<P, M, L>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
13
15
|
isItemToAnimate(context: ItemContext<P, M, L>, animation: Animation<CreateItem<P, M, L>>): boolean;
|
|
14
16
|
protected getKeyframesFromOrigin(origin: string, _animation: Animation<ItemMove<P, M, L>>, _context: ItemContext<P, M, L>): {
|
|
@@ -1,25 +1,83 @@
|
|
|
1
1
|
import { keyframes } from '@emotion/react';
|
|
2
|
+
import { AnimationStep } from '@gamepark/react-client';
|
|
2
3
|
import { fadeIn } from '../../../css';
|
|
3
4
|
import { defaultOrigin, getItemFromContext, getOriginDeltaPosition } from '../../../locators';
|
|
4
5
|
import { getFirstStockItem, getFirstStockItemTransforms } from './getFirstStockItemTransforms.util';
|
|
5
6
|
import { ItemAnimations } from './ItemAnimations';
|
|
6
7
|
import { toClosestRotations, toSingleRotation } from './rotations.utils';
|
|
7
8
|
import { transformItem } from './transformItem.util';
|
|
8
|
-
|
|
9
|
+
// Use action.id as key instead of object reference, because Immer proxies in the reducer
|
|
10
|
+
// differ from the finalized objects used during React rendering.
|
|
11
|
+
const createdItemIndexes = new Map();
|
|
12
|
+
const preQuantitySnapshots = new WeakMap();
|
|
13
|
+
function getConsequenceIndex(action) {
|
|
14
|
+
const step = action.animation?.step;
|
|
15
|
+
return (step === AnimationStep.BEFORE_MOVE || step === AnimationStep.AFTER_UNDO)
|
|
16
|
+
? action.played - 1
|
|
17
|
+
: action.played - 2;
|
|
18
|
+
}
|
|
19
|
+
function getInnerMap(map, key) {
|
|
20
|
+
let inner = map.get(key);
|
|
21
|
+
if (!inner) {
|
|
22
|
+
inner = new Map();
|
|
23
|
+
map.set(key, inner);
|
|
24
|
+
}
|
|
25
|
+
return inner;
|
|
26
|
+
}
|
|
27
|
+
function getWeakInnerMap(weakMap, action) {
|
|
28
|
+
let map = weakMap.get(action);
|
|
29
|
+
if (!map) {
|
|
30
|
+
map = new Map();
|
|
31
|
+
weakMap.set(action, map);
|
|
32
|
+
}
|
|
33
|
+
return map;
|
|
34
|
+
}
|
|
9
35
|
export class CreateItemAnimations extends ItemAnimations {
|
|
10
36
|
duration;
|
|
11
|
-
|
|
37
|
+
trajectory;
|
|
38
|
+
constructor(duration = 1, trajectory) {
|
|
12
39
|
super();
|
|
13
40
|
this.duration = duration;
|
|
41
|
+
this.trajectory = trajectory;
|
|
14
42
|
}
|
|
15
43
|
getPreDuration(move, context) {
|
|
16
44
|
const rules = new context.Rules(context.game, { player: context.playerId });
|
|
17
|
-
|
|
45
|
+
const items = rules.game.items?.[move.itemType] ?? [];
|
|
46
|
+
const key = getConsequenceIndex(context.action);
|
|
47
|
+
getWeakInnerMap(preQuantitySnapshots, context.action).set(key, items.map((item) => item.quantity));
|
|
18
48
|
return 0;
|
|
19
49
|
}
|
|
20
|
-
getPostDuration(move,
|
|
21
|
-
const
|
|
22
|
-
|
|
50
|
+
getPostDuration(move, context) {
|
|
51
|
+
const rules = new context.Rules(context.game, { player: context.playerId });
|
|
52
|
+
const items = rules.game.items?.[move.itemType] ?? [];
|
|
53
|
+
const key = getConsequenceIndex(context.action);
|
|
54
|
+
const actionId = context.action.id;
|
|
55
|
+
const snapshots = preQuantitySnapshots.get(context.action);
|
|
56
|
+
const snapshot = snapshots?.get(key);
|
|
57
|
+
if (snapshot) {
|
|
58
|
+
for (let i = 0; i < items.length; i++) {
|
|
59
|
+
const oldQuantity = i < snapshot.length ? (snapshot[i] ?? 1) : 0;
|
|
60
|
+
const newQuantity = items[i]?.quantity ?? 1;
|
|
61
|
+
if (newQuantity > oldQuantity) {
|
|
62
|
+
getInnerMap(createdItemIndexes, actionId).set(key, i);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
snapshots?.delete(key);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// Fallback: use prediction (may be wrong in simultaneous phases)
|
|
70
|
+
getInnerMap(createdItemIndexes, actionId).set(key, rules.mutator(move.itemType).getItemCreationIndex(move.item));
|
|
71
|
+
}
|
|
72
|
+
// Clean up to prevent memory leaks (Map doesn't auto-collect like WeakMap)
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
const map = createdItemIndexes.get(actionId);
|
|
75
|
+
if (map) {
|
|
76
|
+
map.delete(key);
|
|
77
|
+
if (map.size === 0)
|
|
78
|
+
createdItemIndexes.delete(actionId);
|
|
79
|
+
}
|
|
80
|
+
}, this.duration * 2000);
|
|
23
81
|
return this.duration;
|
|
24
82
|
}
|
|
25
83
|
getItemAnimation(context, animation, boundaries) {
|
|
@@ -40,9 +98,19 @@ export class CreateItemAnimations extends ItemAnimations {
|
|
|
40
98
|
if (currentOrigin.y !== futureOrigin.y) {
|
|
41
99
|
originTransforms.unshift(`translateY(${-getOriginDeltaPosition(boundaries.yMin, boundaries.yMax, futureOrigin.y, currentOrigin.y)}em)`);
|
|
42
100
|
}
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
101
|
+
// Check if trajectory is configured
|
|
102
|
+
const contextWithTrajectory = context;
|
|
103
|
+
const trajectory = this.trajectory ?? contextWithTrajectory.trajectory;
|
|
104
|
+
if (trajectory) {
|
|
105
|
+
const trajectoryContext = { ...context, trajectory };
|
|
106
|
+
const animationKeyframes = this.getTrajectoryKeyframes(originTransforms, targetTransforms, animation, trajectoryContext);
|
|
107
|
+
return this.getAnimationCssWithTrajectory(animationKeyframes, animation.duration, trajectory.easing, trajectory.elevation);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const animationKeyframes = this.getTransformKeyframes(originTransforms.join(' '), targetTransforms.join(' '), animation, context);
|
|
111
|
+
const description = context.material[context.type];
|
|
112
|
+
return description?.getAnimationCss(animationKeyframes, animation.duration);
|
|
113
|
+
}
|
|
46
114
|
}
|
|
47
115
|
else {
|
|
48
116
|
return fadeIn(animation.duration);
|
|
@@ -50,7 +118,20 @@ export class CreateItemAnimations extends ItemAnimations {
|
|
|
50
118
|
}
|
|
51
119
|
isItemToAnimate(context, animation) {
|
|
52
120
|
const { type, index, displayIndex } = context;
|
|
53
|
-
|
|
121
|
+
const key = getConsequenceIndex(animation.action);
|
|
122
|
+
let createdIndex = createdItemIndexes.get(animation.action.id)?.get(key);
|
|
123
|
+
// Fallback: action.id may have changed during notification reconciliation
|
|
124
|
+
// (local id "local-xxx" replaced by server-assigned id), so search all entries
|
|
125
|
+
if (createdIndex === undefined) {
|
|
126
|
+
for (const [, innerMap] of createdItemIndexes) {
|
|
127
|
+
const candidate = innerMap.get(key);
|
|
128
|
+
if (candidate !== undefined) {
|
|
129
|
+
createdIndex = candidate;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (animation.move.itemType !== type || createdIndex !== index)
|
|
54
135
|
return false;
|
|
55
136
|
const quantity = getItemFromContext(context).quantity ?? 1;
|
|
56
137
|
const createdQuantity = animation.move.item.quantity ?? 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateItemAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/CreateItemAnimations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAS,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"CreateItemAnimations.js","sourceRoot":"","sources":["../../../../src/components/material/animations/CreateItemAnimations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAS,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAa,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAe,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAA;AACnG,OAAO,EAAE,cAAc,EAA6B,MAAM,kBAAkB,CAAA;AAE5E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,yFAAyF;AACzF,iEAAiE;AACjE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA2C,CAAA;AAC7E,MAAM,oBAAoB,GAAG,IAAI,OAAO,EAA+C,CAAA;AAEvF,SAAS,mBAAmB,CAAC,MAAyD;IACpF,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,EAAE,IAAI,CAAA;IACnC,OAAO,CAAC,IAAI,KAAK,aAAa,CAAC,WAAW,IAAI,IAAI,KAAK,aAAa,CAAC,UAAU,CAAC;QAC9E,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;QACnB,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;AACvB,CAAC;AAED,SAAS,WAAW,CAAO,GAA0F,EAAE,GAAM;IAC3H,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACxB,IAAI,CAAC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,CAAC,CAAA;QAC1D,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA;QACzD,OAAO,YAAY,IAAI,QAAQ,GAAG,eAAe,CAAA;IACnD,CAAC;IAES,sBAAsB,CAAC,MAAc,EAAE,UAAwC,EAAE,QAA8B;QACvH,OAAO,SAAS,CAAA;;qBAEC,MAAM;;KAEtB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { Interpolation, Theme } from '@emotion/react';
|
|
2
2
|
import { Animation } from '@gamepark/react-client';
|
|
3
|
-
import { DeleteItem, GridBoundaries,
|
|
3
|
+
import { DeleteItem, GridBoundaries, MoveItem } from '@gamepark/rules-api';
|
|
4
4
|
import { ItemContext } from '../../../locators';
|
|
5
5
|
import { ItemAnimations } from './ItemAnimations';
|
|
6
6
|
import { MaterialGameAnimationContext } from './MaterialGameAnimations';
|
|
7
|
+
import { Trajectory } from './Trajectory';
|
|
7
8
|
export declare class DeleteItemAnimations<P extends number = number, M extends number = number, L extends number = number> extends ItemAnimations<P, M, L> {
|
|
8
9
|
protected duration: number;
|
|
9
10
|
protected droppedItemDuration: number;
|
|
10
|
-
|
|
11
|
+
protected trajectory?: Trajectory<P, M, L> | undefined;
|
|
12
|
+
constructor(duration?: number, droppedItemDuration?: number, trajectory?: Trajectory<P, M, L> | undefined);
|
|
11
13
|
getPreDuration(move: MoveItem<P, M, L>, context: MaterialGameAnimationContext<P, M, L>): number;
|
|
12
14
|
getItemAnimation(context: ItemContext<P, M, L>, animation: Animation<DeleteItem<M>>, boundaries: GridBoundaries): Interpolation<Theme>;
|
|
13
|
-
protected getKeyframesToDestination(destination: string, _animation: Animation<ItemMove<P, M, L>>, _context: ItemContext<P, M, L>): {
|
|
14
|
-
name: string;
|
|
15
|
-
styles: string;
|
|
16
|
-
anim: 1;
|
|
17
|
-
toString: () => string;
|
|
18
|
-
} & string;
|
|
19
15
|
}
|