react-native-games 1.1.0 → 1.2.0

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.
Files changed (212) hide show
  1. package/README.md +58 -7
  2. package/lib/module/games/balloon-blaster/BalloonBlaster.js +1 -167
  3. package/lib/module/games/balloon-blaster/BalloonBlaster.js.map +1 -1
  4. package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js +1 -182
  5. package/lib/module/games/balloon-blaster/BalloonBlasterConstants.js.map +1 -1
  6. package/lib/module/games/balloon-blaster/BalloonBlasterService.js +1 -318
  7. package/lib/module/games/balloon-blaster/BalloonBlasterStore.js +1 -183
  8. package/lib/module/games/balloon-blaster/components/BalloonComponent.js +1 -237
  9. package/lib/module/games/balloon-blaster/components/GameArea.js +1 -156
  10. package/lib/module/games/balloon-blaster/components/GameBackground.js +1 -476
  11. package/lib/module/games/balloon-blaster/components/ScoreBoard.js +1 -112
  12. package/lib/module/games/balloon-blaster/components/ScoreBoard.js.map +1 -1
  13. package/lib/module/games/balloon-blaster/components/index.js +1 -7
  14. package/lib/module/games/candy-crush/CandyCrush.js +1 -131
  15. package/lib/module/games/candy-crush/CandyCrush.js.map +1 -1
  16. package/lib/module/games/candy-crush/CandyCrushConstants.js +1 -125
  17. package/lib/module/games/candy-crush/CandyCrushConstants.js.map +1 -1
  18. package/lib/module/games/candy-crush/CandyCrushService.js +1 -370
  19. package/lib/module/games/candy-crush/CandyCrushStore.js +1 -303
  20. package/lib/module/games/candy-crush/components/CandyItem.js +1 -191
  21. package/lib/module/games/candy-crush/components/GameBackground.js +1 -85
  22. package/lib/module/games/candy-crush/components/GameGrid.js +1 -314
  23. package/lib/module/games/candy-crush/components/ScoreBoard.js +1 -79
  24. package/lib/module/games/candy-crush/components/index.js +1 -7
  25. package/lib/module/games/candy-crush/index.js +1 -6
  26. package/lib/module/games/colors-sort/ColorsSort.js +1 -143
  27. package/lib/module/games/colors-sort/ColorsSort.js.map +1 -1
  28. package/lib/module/games/colors-sort/ColorsSortConstants.js +1 -72
  29. package/lib/module/games/colors-sort/ColorsSortConstants.js.map +1 -1
  30. package/lib/module/games/colors-sort/ColorsSortService.js +1 -255
  31. package/lib/module/games/colors-sort/ColorsSortStore.js +1 -257
  32. package/lib/module/games/colors-sort/ColorsSortStore.js.map +1 -1
  33. package/lib/module/games/colors-sort/components/ColorContainer.js +1 -140
  34. package/lib/module/games/colors-sort/components/GameBackground.js +1 -135
  35. package/lib/module/games/colors-sort/components/ScoreBoard.js +1 -70
  36. package/lib/module/games/colors-sort/components/index.js +1 -6
  37. package/lib/module/games/dino-jump/DinoJump.js +1 -209
  38. package/lib/module/games/dino-jump/DinoJump.js.map +1 -1
  39. package/lib/module/games/dino-jump/DinoJumpConstants.js +1 -189
  40. package/lib/module/games/dino-jump/DinoJumpConstants.js.map +1 -1
  41. package/lib/module/games/dino-jump/DinoJumpService.js +1 -270
  42. package/lib/module/games/dino-jump/DinoJumpStore.js +1 -381
  43. package/lib/module/games/dino-jump/components/DinoSprite.js +1 -418
  44. package/lib/module/games/dino-jump/components/DinoSprite.js.map +1 -1
  45. package/lib/module/games/dino-jump/components/GameArea.js +1 -68
  46. package/lib/module/games/dino-jump/components/GameBackground.js +1 -444
  47. package/lib/module/games/dino-jump/components/ObstacleSprite.js +1 -306
  48. package/lib/module/games/dino-jump/components/ScoreBoard.js +1 -105
  49. package/lib/module/games/dino-jump/components/ScoreBoard.js.map +1 -1
  50. package/lib/module/games/dino-jump/components/StarSprite.js +1 -45
  51. package/lib/module/games/dino-jump/components/index.js +1 -9
  52. package/lib/module/games/flappy-bird/FlappyBird.js +1 -126
  53. package/lib/module/games/flappy-bird/FlappyBird.js.map +1 -1
  54. package/lib/module/games/flappy-bird/FlappyBirdConstants.js +1 -90
  55. package/lib/module/games/flappy-bird/FlappyBirdConstants.js.map +1 -1
  56. package/lib/module/games/flappy-bird/FlappyBirdStore.js +1 -300
  57. package/lib/module/games/flappy-bird/components/Bird.js +1 -87
  58. package/lib/module/games/flappy-bird/components/GameArea.js +1 -87
  59. package/lib/module/games/flappy-bird/components/GameBackground.js +1 -79
  60. package/lib/module/games/flappy-bird/components/Pipes.js +1 -172
  61. package/lib/module/games/flappy-bird/components/ScoreBoard.js +1 -73
  62. package/lib/module/games/flappy-bird/components/index.js +1 -8
  63. package/lib/module/games/fruit-merger/FruitMerger.js +1 -120
  64. package/lib/module/games/fruit-merger/FruitMerger.js.map +1 -1
  65. package/lib/module/games/fruit-merger/FruitMergerConstants.js +1 -119
  66. package/lib/module/games/fruit-merger/FruitMergerConstants.js.map +1 -1
  67. package/lib/module/games/fruit-merger/FruitMergerService.js +1 -13
  68. package/lib/module/games/fruit-merger/FruitMergerStore.js +1 -315
  69. package/lib/module/games/fruit-merger/components/FruitItem.js +1 -102
  70. package/lib/module/games/fruit-merger/components/GameArea.js +1 -103
  71. package/lib/module/games/fruit-merger/components/GameBackground.js +1 -498
  72. package/lib/module/games/fruit-merger/components/ScoreBoard.js +1 -58
  73. package/lib/module/games/fruit-merger/components/index.js +1 -7
  74. package/lib/module/games/fruit-ninja/FruitNinja.js +1 -134
  75. package/lib/module/games/fruit-ninja/FruitNinja.js.map +1 -1
  76. package/lib/module/games/fruit-ninja/FruitNinjaConstants.js +1 -148
  77. package/lib/module/games/fruit-ninja/FruitNinjaConstants.js.map +1 -1
  78. package/lib/module/games/fruit-ninja/FruitNinjaService.js +1 -311
  79. package/lib/module/games/fruit-ninja/FruitNinjaStore.js +1 -191
  80. package/lib/module/games/fruit-ninja/FruitNinjaStore.js.map +1 -1
  81. package/lib/module/games/fruit-ninja/components/FruitComponent.js +1 -99
  82. package/lib/module/games/fruit-ninja/components/GameArea.js +1 -215
  83. package/lib/module/games/fruit-ninja/components/GameBackground.js +1 -1267
  84. package/lib/module/games/fruit-ninja/components/ScoreBoard.js +1 -92
  85. package/lib/module/games/fruit-ninja/components/ScoreBoard.js.map +1 -1
  86. package/lib/module/games/fruit-ninja/components/index.js +1 -7
  87. package/lib/module/games/game-2048/Game2048.js +1 -149
  88. package/lib/module/games/game-2048/Game2048.js.map +1 -1
  89. package/lib/module/games/game-2048/Game2048Constants.js +1 -263
  90. package/lib/module/games/game-2048/Game2048Constants.js.map +1 -1
  91. package/lib/module/games/game-2048/Game2048Service.js +1 -457
  92. package/lib/module/games/game-2048/Game2048Store.js +1 -236
  93. package/lib/module/games/game-2048/components/GameBackground.js +1 -247
  94. package/lib/module/games/game-2048/components/GameGrid.js +1 -139
  95. package/lib/module/games/game-2048/components/GameTile.js +1 -72
  96. package/lib/module/games/game-2048/components/ScoreBoard.js +1 -52
  97. package/lib/module/games/game-2048/components/index.js +1 -7
  98. package/lib/module/games/maze-runner/MazeRunner.js +1 -267
  99. package/lib/module/games/maze-runner/MazeRunner.js.map +1 -1
  100. package/lib/module/games/maze-runner/MazeRunnerConstants.js +1 -100
  101. package/lib/module/games/maze-runner/MazeRunnerConstants.js.map +1 -1
  102. package/lib/module/games/maze-runner/MazeRunnerService.js +1 -586
  103. package/lib/module/games/maze-runner/components/EnhancedBallComponent.js +1 -150
  104. package/lib/module/games/maze-runner/components/EnhancedGameArea.js +1 -370
  105. package/lib/module/games/maze-runner/components/GameBackground.js +1 -175
  106. package/lib/module/games/maze-runner/components/ScoreBoard.js +1 -61
  107. package/lib/module/games/maze-runner/components/SkiaPipeComponent.js +1 -209
  108. package/lib/module/games/maze-runner/components/StaticGameBackground.js +1 -169
  109. package/lib/module/games/maze-runner/components/WallComponent.js +1 -91
  110. package/lib/module/games/maze-runner/components/index.js +1 -8
  111. package/lib/module/games/popit-fidget/PopitFidget.js +1 -285
  112. package/lib/module/games/popit-fidget/PopitFidget.js.map +1 -1
  113. package/lib/module/games/popit-fidget/PopitFidgetConstants.js +1 -113
  114. package/lib/module/games/popit-fidget/PopitFidgetConstants.js.map +1 -1
  115. package/lib/module/games/popit-fidget/PopitFidgetService.js +1 -132
  116. package/lib/module/games/popit-fidget/PopitFidgetStore.js +1 -125
  117. package/lib/module/games/popit-fidget/components/BubbleComponent.js +1 -198
  118. package/lib/module/games/popit-fidget/components/FidgetGrid.js +1 -165
  119. package/lib/module/games/popit-fidget/components/GameBackground.js +1 -177
  120. package/lib/module/games/popit-fidget/components/ScoreBoard.js +1 -61
  121. package/lib/module/games/popit-fidget/components/index.js +1 -7
  122. package/lib/module/games/sliding-numbers/SlidingNumbers.js +1 -159
  123. package/lib/module/games/sliding-numbers/SlidingNumbers.js.map +1 -1
  124. package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js +1 -207
  125. package/lib/module/games/sliding-numbers/SlidingNumbersConstants.js.map +1 -1
  126. package/lib/module/games/sliding-numbers/SlidingNumbersService.js +1 -248
  127. package/lib/module/games/sliding-numbers/SlidingNumbersStore.js +1 -274
  128. package/lib/module/games/sliding-numbers/components/GameBackground.js +1 -259
  129. package/lib/module/games/sliding-numbers/components/NumbersGrid.js +1 -174
  130. package/lib/module/games/sliding-numbers/components/NumbersTile.js +1 -116
  131. package/lib/module/games/sliding-numbers/components/ScoreBoard.js +1 -64
  132. package/lib/module/games/sliding-numbers/components/index.js +1 -7
  133. package/lib/module/games/snake/Snake.js +1 -189
  134. package/lib/module/games/snake/Snake.js.map +1 -1
  135. package/lib/module/games/snake/SnakeConstants.js +1 -138
  136. package/lib/module/games/snake/SnakeConstants.js.map +1 -1
  137. package/lib/module/games/snake/SnakeService.js +1 -148
  138. package/lib/module/games/snake/SnakeStore.js +1 -182
  139. package/lib/module/games/snake/components/GameBackground.js +1 -221
  140. package/lib/module/games/snake/components/GameGrid.js +1 -153
  141. package/lib/module/games/snake/components/ScoreBoard.js +1 -51
  142. package/lib/module/games/snake/components/index.js +1 -6
  143. package/lib/module/games/snake/index.js +1 -6
  144. package/lib/module/games/space-fighter/SpaceFighter.js +1 -165
  145. package/lib/module/games/space-fighter/SpaceFighter.js.map +1 -1
  146. package/lib/module/games/space-fighter/SpaceFighterConstants.js +1 -108
  147. package/lib/module/games/space-fighter/SpaceFighterConstants.js.map +1 -1
  148. package/lib/module/games/space-fighter/SpaceFighterService.js +1 -326
  149. package/lib/module/games/space-fighter/SpaceFighterStore.js +1 -209
  150. package/lib/module/games/space-fighter/components/AsteroidComponent.js +1 -113
  151. package/lib/module/games/space-fighter/components/GameArea.js +1 -289
  152. package/lib/module/games/space-fighter/components/GameBackground.js +1 -239
  153. package/lib/module/games/space-fighter/components/ScoreBoard.js +1 -136
  154. package/lib/module/games/space-fighter/components/Spacecraft3D.js +1 -202
  155. package/lib/module/games/space-fighter/components/SpacecraftPath.js +1 -52
  156. package/lib/module/games/space-fighter/components/index.js +1 -9
  157. package/lib/module/games/whack-a-mole/WhackAMole.js +1 -270
  158. package/lib/module/games/whack-a-mole/WhackAMole.js.map +1 -1
  159. package/lib/module/games/whack-a-mole/WhackAMoleConstants.js +1 -115
  160. package/lib/module/games/whack-a-mole/WhackAMoleConstants.js.map +1 -1
  161. package/lib/module/games/whack-a-mole/WhackAMoleService.js +1 -120
  162. package/lib/module/games/whack-a-mole/WhackAMoleStore.js +1 -172
  163. package/lib/module/games/whack-a-mole/components/GameBackground.js +1 -477
  164. package/lib/module/games/whack-a-mole/components/GameGrid.js +1 -97
  165. package/lib/module/games/whack-a-mole/components/GameHole.js +1 -196
  166. package/lib/module/games/whack-a-mole/components/MoleCharacter.js +1 -241
  167. package/lib/module/games/whack-a-mole/components/ScoreBoard.js +1 -67
  168. package/lib/module/games/whack-a-mole/components/ScoreBoard.js.map +1 -1
  169. package/lib/module/games/whack-a-mole/components/index.js +1 -8
  170. package/lib/module/helpers/AnimationFrame.js +1 -120
  171. package/lib/module/helpers/AnimationTracker.js +1 -89
  172. package/lib/module/helpers/ErrorHandler.js +1 -269
  173. package/lib/module/helpers/GameControlButton.js +1 -219
  174. package/lib/module/helpers/GameOverModal.js +1 -144
  175. package/lib/module/helpers/GameOverModal.js.map +1 -1
  176. package/lib/module/helpers/GameSettingsModal.js +1 -287
  177. package/lib/module/helpers/ParticleBlast.js +1 -134
  178. package/lib/module/helpers/ScoreBoardContainer.js +1 -34
  179. package/lib/module/helpers/index.js +1 -12
  180. package/lib/module/index.js +1 -22
  181. package/lib/module/services/GamesConstants.js +1 -178
  182. package/lib/module/services/GamesService.js +1 -112
  183. package/lib/module/services/GamesService.js.map +1 -1
  184. package/lib/module/services/HapticsService.js +1 -77
  185. package/lib/module/services/SoundsService.js +1 -302
  186. package/lib/module/services/UtilsService.js +1 -32
  187. package/lib/typescript/src/games/balloon-blaster/BalloonBlaster.d.ts.map +1 -1
  188. package/lib/typescript/src/games/balloon-blaster/BalloonBlasterConstants.d.ts +1 -1
  189. package/lib/typescript/src/games/balloon-blaster/components/ScoreBoard.d.ts.map +1 -1
  190. package/lib/typescript/src/games/candy-crush/CandyCrushConstants.d.ts +7 -7
  191. package/lib/typescript/src/games/colors-sort/ColorsSort.d.ts.map +1 -1
  192. package/lib/typescript/src/games/colors-sort/ColorsSortStore.d.ts.map +1 -1
  193. package/lib/typescript/src/games/dino-jump/DinoJump.d.ts.map +1 -1
  194. package/lib/typescript/src/games/dino-jump/components/DinoSprite.d.ts.map +1 -1
  195. package/lib/typescript/src/games/flappy-bird/FlappyBird.d.ts.map +1 -1
  196. package/lib/typescript/src/games/flappy-bird/FlappyBirdConstants.d.ts.map +1 -1
  197. package/lib/typescript/src/games/fruit-merger/FruitMerger.d.ts.map +1 -1
  198. package/lib/typescript/src/games/fruit-merger/FruitMergerConstants.d.ts.map +1 -1
  199. package/lib/typescript/src/games/fruit-ninja/FruitNinja.d.ts.map +1 -1
  200. package/lib/typescript/src/games/fruit-ninja/components/ScoreBoard.d.ts.map +1 -1
  201. package/lib/typescript/src/games/game-2048/Game2048.d.ts.map +1 -1
  202. package/lib/typescript/src/games/maze-runner/MazeRunner.d.ts.map +1 -1
  203. package/lib/typescript/src/games/popit-fidget/PopitFidget.d.ts.map +1 -1
  204. package/lib/typescript/src/games/sliding-numbers/SlidingNumbers.d.ts.map +1 -1
  205. package/lib/typescript/src/games/space-fighter/SpaceFighter.d.ts.map +1 -1
  206. package/lib/typescript/src/games/whack-a-mole/WhackAMole.d.ts.map +1 -1
  207. package/lib/typescript/src/games/whack-a-mole/WhackAMoleConstants.d.ts +1 -1
  208. package/lib/typescript/src/games/whack-a-mole/components/ScoreBoard.d.ts.map +1 -1
  209. package/lib/typescript/src/helpers/GameOverModal.d.ts +3 -0
  210. package/lib/typescript/src/helpers/GameOverModal.d.ts.map +1 -1
  211. package/lib/typescript/src/services/GamesConstants.d.ts +7 -7
  212. package/package.json +2 -2
@@ -1,89 +1 @@
1
- "use strict";
2
-
3
- import { useRef } from 'react';
4
-
5
- /**
6
- * Animation state interface for tracking game object animations
7
- */
8
-
9
- /**
10
- * Default animation state values
11
- */
12
- export const DEFAULT_ANIMATION_STATE = {
13
- scale: 1,
14
- opacity: 1,
15
- rotation: 0,
16
- translateX: 0,
17
- translateY: 0
18
- };
19
-
20
- /**
21
- * Animation tracker class for managing game object animations
22
- * Extends Map to maintain compatibility with existing game services
23
- */
24
- export class AnimationTracker extends Map {
25
- constructor() {
26
- super();
27
- }
28
-
29
- /**
30
- * Override set to merge with default animation state
31
- */
32
- set(id, state) {
33
- const currentState = super.get(id) || {
34
- ...DEFAULT_ANIMATION_STATE
35
- };
36
- const newState = {
37
- ...currentState,
38
- ...state
39
- };
40
- super.set(id, newState);
41
- return this;
42
- }
43
-
44
- /**
45
- * Initialize animation for object if it doesn't exist
46
- */
47
- initialize(id, initialState) {
48
- if (!this.has(id)) {
49
- const state = {
50
- ...DEFAULT_ANIMATION_STATE,
51
- ...initialState
52
- };
53
- super.set(id, state);
54
- return state;
55
- }
56
- return this.get(id);
57
- }
58
-
59
- /**
60
- * Update multiple objects at once
61
- */
62
- updateBatch(updates) {
63
- updates.forEach(({
64
- id,
65
- state
66
- }) => {
67
- this.set(id, state);
68
- });
69
- }
70
- }
71
-
72
- /**
73
- * React hook for creating and managing animation trackers
74
- */
75
- export function useAnimationTracker() {
76
- return useRef(new AnimationTracker()).current;
77
- }
78
-
79
- /**
80
- * React hook for creating multiple animation trackers
81
- */
82
- export function useAnimationTrackers(trackerNames) {
83
- const trackers = useRef(trackerNames.reduce((acc, name) => {
84
- acc[name] = new AnimationTracker();
85
- return acc;
86
- }, {})).current;
87
- return trackers;
88
- }
89
- //# sourceMappingURL=AnimationTracker.js.map
1
+ "use strict";import{useRef}from 'react';export const DEFAULT_ANIMATION_STATE ={scale:1,opacity:1,rotation:0,translateX:0,translateY:0};export class AnimationTracker extends Map{constructor(){super();}set(id,state){const currentState = super.get(id)||{...DEFAULT_ANIMATION_STATE};const newState ={...currentState,...state};super.set(id,newState);return this;}initialize(id,initialState){if(!this.has(id)){const state ={...DEFAULT_ANIMATION_STATE,...initialState};super.set(id,state);return state;}return this.get(id);}updateBatch(updates){updates.forEach(({id,state})=>{this.set(id,state);});}}export function useAnimationTracker(){return useRef(new AnimationTracker()).current;}export function useAnimationTrackers(trackerNames){const trackers = useRef(trackerNames.reduce((acc,name)=>{acc[name] = new AnimationTracker();return acc;},{})).current;return trackers;}
@@ -1,269 +1 @@
1
- "use strict";
2
-
3
- import { useCallback, useRef } from 'react';
4
-
5
- /**
6
- * Error types for game-specific error handling
7
- */
8
- export let GameErrorType = /*#__PURE__*/function (GameErrorType) {
9
- GameErrorType["INITIALIZATION_ERROR"] = "INITIALIZATION_ERROR";
10
- GameErrorType["ANIMATION_ERROR"] = "ANIMATION_ERROR";
11
- GameErrorType["STORAGE_ERROR"] = "STORAGE_ERROR";
12
- GameErrorType["SOUND_ERROR"] = "SOUND_ERROR";
13
- GameErrorType["HAPTIC_ERROR"] = "HAPTIC_ERROR";
14
- GameErrorType["GESTURE_ERROR"] = "GESTURE_ERROR";
15
- GameErrorType["PERFORMANCE_ERROR"] = "PERFORMANCE_ERROR";
16
- GameErrorType["NETWORK_ERROR"] = "NETWORK_ERROR";
17
- GameErrorType["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
18
- return GameErrorType;
19
- }({});
20
-
21
- /**
22
- * Game error interface
23
- */
24
-
25
- /**
26
- * Error handler configuration
27
- */
28
-
29
- /**
30
- * Default error handler configuration
31
- */
32
- export const DEFAULT_ERROR_CONFIG = {
33
- enableLogging: __DEV__,
34
- enableConsoleOutput: __DEV__,
35
- maxErrorHistory: 50,
36
- enableCrashRecovery: true
37
- };
38
-
39
- /**
40
- * Game error handler class
41
- */
42
- export class GameErrorHandler {
43
- errorHistory = [];
44
- errorCounts = new Map();
45
- constructor(config = {}) {
46
- this.config = {
47
- ...DEFAULT_ERROR_CONFIG,
48
- ...config
49
- };
50
- }
51
-
52
- /**
53
- * Handle a game error
54
- */
55
- handleError(type, message, gameId, context) {
56
- const error = {
57
- type,
58
- message,
59
- gameId,
60
- timestamp: Date.now(),
61
- stack: new Error().stack,
62
- context
63
- };
64
-
65
- // Add to error history
66
- this.errorHistory.push(error);
67
- if (this.errorHistory.length > this.config.maxErrorHistory) {
68
- this.errorHistory.shift();
69
- }
70
-
71
- // Update error counts
72
- const currentCount = this.errorCounts.get(type) || 0;
73
- this.errorCounts.set(type, currentCount + 1);
74
-
75
- // Log error if enabled
76
- if (this.config.enableLogging && this.config.enableConsoleOutput) {
77
- this.logError(error);
78
- }
79
-
80
- // Call custom error handler if provided
81
- if (this.config.onError) {
82
- try {
83
- this.config.onError(error);
84
- } catch (handlerError) {
85
- console.error('Error in custom error handler:', handlerError);
86
- }
87
- }
88
- }
89
-
90
- /**
91
- * Wrap a function with error handling
92
- */
93
- wrapFunction(fn, errorType, gameId) {
94
- return (...args) => {
95
- try {
96
- const result = fn(...args);
97
-
98
- // Handle async functions
99
- if (result && typeof result.catch === 'function') {
100
- return result.catch(error => {
101
- this.handleError(errorType, error.message || 'Async function error', gameId, {
102
- functionName: fn.name,
103
- args
104
- });
105
- throw error;
106
- });
107
- }
108
- return result;
109
- } catch (error) {
110
- this.handleError(errorType, error instanceof Error ? error.message : 'Unknown error', gameId, {
111
- functionName: fn.name,
112
- args
113
- });
114
- throw error;
115
- }
116
- };
117
- }
118
-
119
- /**
120
- * Safe execution with error recovery
121
- */
122
- safeExecute(fn, fallback, errorType, gameId) {
123
- try {
124
- return fn();
125
- } catch (error) {
126
- this.handleError(errorType, error instanceof Error ? error.message : 'Safe execution failed', gameId, {
127
- fallback
128
- });
129
- return fallback;
130
- }
131
- }
132
-
133
- /**
134
- * Safe async execution with error recovery
135
- */
136
- async safeExecuteAsync(fn, fallback, errorType, gameId) {
137
- try {
138
- return await fn();
139
- } catch (error) {
140
- this.handleError(errorType, error instanceof Error ? error.message : 'Safe async execution failed', gameId, {
141
- fallback
142
- });
143
- return fallback;
144
- }
145
- }
146
-
147
- /**
148
- * Get error statistics
149
- */
150
- getErrorStats() {
151
- const errorsByType = {};
152
- for (const [type, count] of this.errorCounts.entries()) {
153
- errorsByType[type] = count;
154
- }
155
- return {
156
- totalErrors: this.errorHistory.length,
157
- errorsByType,
158
- recentErrors: this.errorHistory.slice(-10)
159
- };
160
- }
161
-
162
- /**
163
- * Clear error history
164
- */
165
- clearHistory() {
166
- this.errorHistory = [];
167
- this.errorCounts.clear();
168
- }
169
-
170
- /**
171
- * Update configuration
172
- */
173
- updateConfig(config) {
174
- this.config = {
175
- ...this.config,
176
- ...config
177
- };
178
- }
179
-
180
- /**
181
- * Log error to console
182
- */
183
- logError(error) {
184
- const prefix = error.gameId ? `[${error.gameId}]` : '[Game]';
185
- console.error(`${prefix} ${error.type}: ${error.message}`, {
186
- timestamp: new Date(error.timestamp).toISOString(),
187
- context: error.context,
188
- stack: error.stack
189
- });
190
- }
191
- }
192
-
193
- /**
194
- * Global error handler instance
195
- */
196
- export const globalErrorHandler = new GameErrorHandler();
197
-
198
- /**
199
- * React hook for error handling in game components
200
- */
201
- export function useGameErrorHandler(gameId, config = {}) {
202
- const handlerRef = useRef(null);
203
-
204
- // Initialize handler
205
- if (!handlerRef.current) {
206
- handlerRef.current = new GameErrorHandler(config);
207
- }
208
- const handleError = useCallback((type, message, context) => {
209
- handlerRef.current?.handleError(type, message, gameId, context);
210
- }, [gameId]);
211
- const wrapFunction = useCallback((fn, errorType) => {
212
- return handlerRef.current?.wrapFunction(fn, errorType, gameId) || fn;
213
- }, [gameId]);
214
- const safeExecute = useCallback((fn, fallback, errorType) => {
215
- return handlerRef.current?.safeExecute(fn, fallback, errorType, gameId) || fallback;
216
- }, [gameId]);
217
- const safeExecuteAsync = useCallback((fn, fallback, errorType) => {
218
- return handlerRef.current?.safeExecuteAsync(fn, fallback, errorType, gameId) || Promise.resolve(fallback);
219
- }, [gameId]);
220
- return {
221
- handleError,
222
- wrapFunction,
223
- safeExecute,
224
- safeExecuteAsync,
225
- errorStats: handlerRef.current?.getErrorStats() || {
226
- totalErrors: 0,
227
- errorsByType: {},
228
- recentErrors: []
229
- }
230
- };
231
- }
232
-
233
- /**
234
- * Error boundary utility for wrapping functions with error handling
235
- */
236
- export function withErrorHandling(fn, gameId, errorType = GameErrorType.UNKNOWN_ERROR) {
237
- return globalErrorHandler.wrapFunction(fn, errorType, gameId);
238
- }
239
-
240
- /**
241
- * Utility functions for common error scenarios
242
- */
243
- export const ErrorUtils = {
244
- /**
245
- * Handle animation errors safely
246
- */
247
- safeAnimate: (animationFn, gameId, fallback) => {
248
- globalErrorHandler.safeExecute(animationFn, fallback ? fallback() : undefined, GameErrorType.ANIMATION_ERROR, gameId);
249
- },
250
- /**
251
- * Handle sound errors safely
252
- */
253
- safePlaySound: (soundFn, gameId) => {
254
- globalErrorHandler.safeExecute(soundFn, undefined, GameErrorType.SOUND_ERROR, gameId);
255
- },
256
- /**
257
- * Handle haptic errors safely
258
- */
259
- safeHaptic: (hapticFn, gameId) => {
260
- globalErrorHandler.safeExecute(hapticFn, undefined, GameErrorType.HAPTIC_ERROR, gameId);
261
- },
262
- /**
263
- * Handle gesture errors safely
264
- */
265
- safeGesture: (gestureFn, gameId) => {
266
- globalErrorHandler.safeExecute(gestureFn, undefined, GameErrorType.GESTURE_ERROR, gameId);
267
- }
268
- };
269
- //# sourceMappingURL=ErrorHandler.js.map
1
+ "use strict";import{useCallback,useRef}from 'react';export let GameErrorType = function(GameErrorType){GameErrorType["INITIALIZATION_ERROR"] = "INITIALIZATION_ERROR";GameErrorType["ANIMATION_ERROR"] = "ANIMATION_ERROR";GameErrorType["STORAGE_ERROR"] = "STORAGE_ERROR";GameErrorType["SOUND_ERROR"] = "SOUND_ERROR";GameErrorType["HAPTIC_ERROR"] = "HAPTIC_ERROR";GameErrorType["GESTURE_ERROR"] = "GESTURE_ERROR";GameErrorType["PERFORMANCE_ERROR"] = "PERFORMANCE_ERROR";GameErrorType["NETWORK_ERROR"] = "NETWORK_ERROR";GameErrorType["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";return GameErrorType;}({});export const DEFAULT_ERROR_CONFIG ={enableLogging:__DEV__,enableConsoleOutput:__DEV__,maxErrorHistory:50,enableCrashRecovery:true};export class GameErrorHandler{errorHistory = [];errorCounts = new Map();constructor(config ={}){this.config ={...DEFAULT_ERROR_CONFIG,...config};}handleError(type,message,gameId,context){const error ={type,message,gameId,timestamp:Date.now(),stack:new Error().stack,context};this.errorHistory.push(error);if(this.errorHistory.length > this.config.maxErrorHistory){this.errorHistory.shift();}const currentCount = this.errorCounts.get(type)|| 0;this.errorCounts.set(type,currentCount + 1);if(this.config.enableLogging && this.config.enableConsoleOutput){this.logError(error);}if(this.config.onError){try{this.config.onError(error);}catch(handlerError){console.error('Error in custom error handler:',handlerError);}}}wrapFunction(fn,errorType,gameId){return(...args)=>{try{const result = fn(...args);if(result && typeof result.catch === 'function'){return result.catch(error =>{this.handleError(errorType,error.message || 'Async function error',gameId,{functionName:fn.name,args});throw error;});}return result;}catch(error){this.handleError(errorType,error instanceof Error ? error.message:'Unknown error',gameId,{functionName:fn.name,args});throw error;}};}safeExecute(fn,fallback,errorType,gameId){try{return fn();}catch(error){this.handleError(errorType,error instanceof Error ? error.message:'Safe execution failed',gameId,{fallback});return fallback;}}async safeExecuteAsync(fn,fallback,errorType,gameId){try{return await fn();}catch(error){this.handleError(errorType,error instanceof Error ? error.message:'Safe async execution failed',gameId,{fallback});return fallback;}}getErrorStats(){const errorsByType ={};for(const [type,count] of this.errorCounts.entries()){errorsByType[type] = count;}return{totalErrors:this.errorHistory.length,errorsByType,recentErrors:this.errorHistory.slice(-10)};}clearHistory(){this.errorHistory = [];this.errorCounts.clear();}updateConfig(config){this.config ={...this.config,...config};}logError(error){const prefix = error.gameId ? `[${error.gameId}]`:'[Game]';console.error(`${prefix}${error.type}:${error.message}`,{timestamp:new Date(error.timestamp).toISOString(),context:error.context,stack:error.stack});}}export const globalErrorHandler = new GameErrorHandler();export function useGameErrorHandler(gameId,config ={}){const handlerRef = useRef(null);if(!handlerRef.current){handlerRef.current = new GameErrorHandler(config);}const handleError = useCallback((type,message,context)=>{handlerRef.current?.handleError(type,message,gameId,context);},[gameId]);const wrapFunction = useCallback((fn,errorType)=>{return handlerRef.current?.wrapFunction(fn,errorType,gameId)|| fn;},[gameId]);const safeExecute = useCallback((fn,fallback,errorType)=>{return handlerRef.current?.safeExecute(fn,fallback,errorType,gameId)|| fallback;},[gameId]);const safeExecuteAsync = useCallback((fn,fallback,errorType)=>{return handlerRef.current?.safeExecuteAsync(fn,fallback,errorType,gameId)|| Promise.resolve(fallback);},[gameId]);return{handleError,wrapFunction,safeExecute,safeExecuteAsync,errorStats:handlerRef.current?.getErrorStats()||{totalErrors:0,errorsByType:{},recentErrors:[]}};}export function withErrorHandling(fn,gameId,errorType = GameErrorType.UNKNOWN_ERROR){return globalErrorHandler.wrapFunction(fn,errorType,gameId);}export const ErrorUtils ={safeAnimate:(animationFn,gameId,fallback)=>{globalErrorHandler.safeExecute(animationFn,fallback ? fallback():undefined,GameErrorType.ANIMATION_ERROR,gameId);},safePlaySound:(soundFn,gameId)=>{globalErrorHandler.safeExecute(soundFn,undefined,GameErrorType.SOUND_ERROR,gameId);},safeHaptic:(hapticFn,gameId)=>{globalErrorHandler.safeExecute(hapticFn,undefined,GameErrorType.HAPTIC_ERROR,gameId);},safeGesture:(gestureFn,gameId)=>{globalErrorHandler.safeExecute(gestureFn,undefined,GameErrorType.GESTURE_ERROR,gameId);}};
@@ -1,219 +1 @@
1
- "use strict";
2
-
3
- import React, { useRef, useEffect, useMemo } from 'react';
4
- import { View, TouchableOpacity, Text, StyleSheet, Animated } from 'react-native';
5
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
- export const GameControlButton = /*#__PURE__*/React.memo(({
7
- isPlaying,
8
- gameOver,
9
- onStartGame,
10
- onStopGame,
11
- startButtonText = 'START GAME',
12
- stopButtonText = 'STOP GAME',
13
- startButtonSubtext = 'Begin playing!',
14
- stopButtonSubtext = 'End current game',
15
- startButtonColor = '#10b981',
16
- stopButtonColor = '#dc2626',
17
- startButtonBorderColor = '#34d399',
18
- stopButtonBorderColor = '#f87171'
19
- }) => {
20
- const scaleAnim = useRef(new Animated.Value(1)).current;
21
- const pulseAnim = useRef(new Animated.Value(1)).current;
22
- const glowAnim = useRef(new Animated.Value(0)).current;
23
- useEffect(() => {
24
- if (!isPlaying) {
25
- const pulseAnimation = Animated.loop(Animated.sequence([Animated.timing(pulseAnim, {
26
- toValue: 1.05,
27
- duration: 1000,
28
- useNativeDriver: true
29
- }), Animated.timing(pulseAnim, {
30
- toValue: 1,
31
- duration: 1000,
32
- useNativeDriver: true
33
- })]));
34
- pulseAnimation.start();
35
- return () => pulseAnimation.stop();
36
- }
37
- return () => {};
38
- }, [isPlaying, gameOver, pulseAnim]);
39
-
40
- // Glow animation for stop button
41
- useEffect(() => {
42
- if (isPlaying) {
43
- const glowAnimation = Animated.loop(Animated.sequence([Animated.timing(glowAnim, {
44
- toValue: 1,
45
- duration: 800,
46
- useNativeDriver: false
47
- }), Animated.timing(glowAnim, {
48
- toValue: 0,
49
- duration: 800,
50
- useNativeDriver: false
51
- })]));
52
- glowAnimation.start();
53
- return () => glowAnimation.stop();
54
- }
55
- return () => {};
56
- }, [isPlaying, glowAnim]);
57
- const handlePressIn = () => {
58
- Animated.spring(scaleAnim, {
59
- toValue: 0.95,
60
- useNativeDriver: true
61
- }).start();
62
- };
63
- const handlePressOut = () => {
64
- Animated.spring(scaleAnim, {
65
- toValue: 1,
66
- friction: 3,
67
- tension: 40,
68
- useNativeDriver: true
69
- }).start();
70
- };
71
-
72
- // Memoize glow color interpolation to prevent continuous re-renders
73
- const glowColor = useMemo(() => glowAnim.interpolate({
74
- inputRange: [0, 1],
75
- outputRange: [`${stopButtonColor}30`, `${stopButtonColor}CC`]
76
- }), [glowAnim, stopButtonColor]);
77
- return /*#__PURE__*/_jsx(View, {
78
- style: styles.controlButtonContainer,
79
- children: /*#__PURE__*/_jsxs(View, {
80
- style: styles.gameControls,
81
- children: [!isPlaying && /*#__PURE__*/_jsx(Animated.View, {
82
- style: [{
83
- transform: [{
84
- scale: pulseAnim
85
- }]
86
- }],
87
- children: /*#__PURE__*/_jsx(TouchableOpacity, {
88
- style: [styles.button, styles.startButton, {
89
- backgroundColor: startButtonColor,
90
- borderColor: startButtonBorderColor
91
- }],
92
- onPress: onStartGame,
93
- onPressIn: handlePressIn,
94
- onPressOut: handlePressOut,
95
- activeOpacity: 0.8,
96
- children: /*#__PURE__*/_jsxs(Animated.View, {
97
- style: [styles.buttonContent, {
98
- transform: [{
99
- scale: scaleAnim
100
- }]
101
- }],
102
- children: [/*#__PURE__*/_jsx(Text, {
103
- style: styles.buttonText,
104
- children: startButtonText
105
- }), /*#__PURE__*/_jsx(Text, {
106
- style: styles.buttonSubtext,
107
- children: startButtonSubtext
108
- })]
109
- })
110
- })
111
- }), isPlaying && /*#__PURE__*/_jsx(Animated.View, {
112
- style: [styles.stopButtonContainer, {
113
- shadowColor: glowColor
114
- }],
115
- children: /*#__PURE__*/_jsx(TouchableOpacity, {
116
- style: [styles.button, styles.stopButton, {
117
- backgroundColor: stopButtonColor,
118
- borderColor: stopButtonBorderColor
119
- }],
120
- onPress: onStopGame,
121
- onPressIn: handlePressIn,
122
- onPressOut: handlePressOut,
123
- activeOpacity: 0.8,
124
- children: /*#__PURE__*/_jsxs(Animated.View, {
125
- style: [styles.buttonContent, {
126
- transform: [{
127
- scale: scaleAnim
128
- }]
129
- }],
130
- children: [/*#__PURE__*/_jsx(Text, {
131
- style: styles.buttonText,
132
- children: stopButtonText
133
- }), /*#__PURE__*/_jsx(Text, {
134
- style: styles.buttonSubtext,
135
- children: stopButtonSubtext
136
- })]
137
- })
138
- })
139
- })]
140
- })
141
- });
142
- });
143
- const styles = StyleSheet.create({
144
- controlButtonContainer: {
145
- position: 'absolute',
146
- bottom: 0,
147
- left: 20,
148
- right: 20,
149
- zIndex: 100,
150
- pointerEvents: 'box-none' // Allow touches on button but pass through elsewhere
151
- },
152
- gameControls: {
153
- justifyContent: 'center',
154
- alignItems: 'center',
155
- paddingVertical: 20,
156
- paddingHorizontal: 20
157
- },
158
- button: {
159
- paddingHorizontal: 32,
160
- paddingVertical: 20,
161
- borderRadius: 30,
162
- shadowColor: '#000',
163
- shadowOffset: {
164
- width: 0,
165
- height: 8
166
- },
167
- shadowOpacity: 0.4,
168
- shadowRadius: 12,
169
- elevation: 8,
170
- justifyContent: 'center',
171
- alignItems: 'center',
172
- minHeight: 70,
173
- minWidth: 200,
174
- borderWidth: 3,
175
- position: 'relative',
176
- overflow: 'hidden'
177
- },
178
- startButton: {
179
- // Colors will be applied via props
180
- },
181
- stopButton: {
182
- // Colors will be applied via props
183
- },
184
- stopButtonContainer: {
185
- shadowOffset: {
186
- width: 0,
187
- height: 0
188
- },
189
- shadowOpacity: 0.6,
190
- shadowRadius: 20,
191
- elevation: 10
192
- },
193
- buttonContent: {
194
- alignItems: 'center',
195
- justifyContent: 'center'
196
- },
197
- buttonText: {
198
- fontSize: 20,
199
- fontWeight: '800',
200
- color: '#ffffff',
201
- textAlign: 'center',
202
- textShadowColor: 'rgba(0, 0, 0, 0.3)',
203
- textShadowOffset: {
204
- width: 1,
205
- height: 1
206
- },
207
- textShadowRadius: 2,
208
- letterSpacing: 1
209
- },
210
- buttonSubtext: {
211
- fontSize: 12,
212
- fontWeight: '600',
213
- color: 'rgba(255, 255, 255, 0.8)',
214
- textAlign: 'center',
215
- marginTop: 4,
216
- letterSpacing: 0.5
217
- }
218
- });
219
- //# sourceMappingURL=GameControlButton.js.map
1
+ "use strict";import React,{useRef,useEffect,useMemo}from 'react';import{View,TouchableOpacity,Text,StyleSheet,Animated}from 'react-native';import{jsx as _jsx,jsxs as _jsxs}from "react/jsx-runtime";export const GameControlButton = React.memo(({isPlaying,gameOver,onStartGame,onStopGame,startButtonText = 'START GAME',stopButtonText = 'STOP GAME',startButtonSubtext = 'Begin playing!',stopButtonSubtext = 'End current game',startButtonColor = '#10b981',stopButtonColor = '#dc2626',startButtonBorderColor = '#34d399',stopButtonBorderColor = '#f87171'})=>{const scaleAnim = useRef(new Animated.Value(1)).current;const pulseAnim = useRef(new Animated.Value(1)).current;const glowAnim = useRef(new Animated.Value(0)).current;useEffect(()=>{if(!isPlaying){const pulseAnimation = Animated.loop(Animated.sequence([Animated.timing(pulseAnim,{toValue:1.05,duration:1000,useNativeDriver:true}),Animated.timing(pulseAnim,{toValue:1,duration:1000,useNativeDriver:true})]));pulseAnimation.start();return()=> pulseAnimation.stop();}return()=>{};},[isPlaying,gameOver,pulseAnim]);useEffect(()=>{if(isPlaying){const glowAnimation = Animated.loop(Animated.sequence([Animated.timing(glowAnim,{toValue:1,duration:800,useNativeDriver:false}),Animated.timing(glowAnim,{toValue:0,duration:800,useNativeDriver:false})]));glowAnimation.start();return()=> glowAnimation.stop();}return()=>{};},[isPlaying,glowAnim]);const handlePressIn =()=>{Animated.spring(scaleAnim,{toValue:0.95,useNativeDriver:true}).start();};const handlePressOut =()=>{Animated.spring(scaleAnim,{toValue:1,friction:3,tension:40,useNativeDriver:true}).start();};const glowColor = useMemo(()=> glowAnim.interpolate({inputRange:[0,1],outputRange:[`${stopButtonColor}30`,`${stopButtonColor}CC`]}),[glowAnim,stopButtonColor]);return _jsx(View,{style:styles.controlButtonContainer,children:_jsxs(View,{style:styles.gameControls,children:[!isPlaying && _jsx(Animated.View,{style:[{transform:[{scale:pulseAnim}]}],children:_jsx(TouchableOpacity,{style:[styles.button,styles.startButton,{backgroundColor:startButtonColor,borderColor:startButtonBorderColor}],onPress:onStartGame,onPressIn:handlePressIn,onPressOut:handlePressOut,activeOpacity:0.8,children:_jsxs(Animated.View,{style:[styles.buttonContent,{transform:[{scale:scaleAnim}]}],children:[_jsx(Text,{style:styles.buttonText,children:startButtonText}),_jsx(Text,{style:styles.buttonSubtext,children:startButtonSubtext})]})})}),isPlaying && _jsx(Animated.View,{style:[styles.stopButtonContainer,{shadowColor:glowColor}],children:_jsx(TouchableOpacity,{style:[styles.button,styles.stopButton,{backgroundColor:stopButtonColor,borderColor:stopButtonBorderColor}],onPress:onStopGame,onPressIn:handlePressIn,onPressOut:handlePressOut,activeOpacity:0.8,children:_jsxs(Animated.View,{style:[styles.buttonContent,{transform:[{scale:scaleAnim}]}],children:[_jsx(Text,{style:styles.buttonText,children:stopButtonText}),_jsx(Text,{style:styles.buttonSubtext,children:stopButtonSubtext})]})})})]})});});const styles = StyleSheet.create({controlButtonContainer:{position:'absolute',bottom:0,left:20,right:20,zIndex:100,pointerEvents:'box-none'},gameControls:{justifyContent:'center',alignItems:'center',paddingVertical:20,paddingHorizontal:20},button:{paddingHorizontal:32,paddingVertical:20,borderRadius:30,shadowColor:'#000',shadowOffset:{width:0,height:8},shadowOpacity:0.4,shadowRadius:12,elevation:8,justifyContent:'center',alignItems:'center',minHeight:70,minWidth:200,borderWidth:3,position:'relative',overflow:'hidden'},startButton:{},stopButton:{},stopButtonContainer:{shadowOffset:{width:0,height:0},shadowOpacity:0.6,shadowRadius:20,elevation:10},buttonContent:{alignItems:'center',justifyContent:'center'},buttonText:{fontSize:20,fontWeight:'800',color:'#ffffff',textAlign:'center',textShadowColor:'rgba(0,0,0,0.3)',textShadowOffset:{width:1,height:1},textShadowRadius:2,letterSpacing:1},buttonSubtext:{fontSize:12,fontWeight:'600',color:'rgba(255,255,255,0.8)',textAlign:'center',marginTop:4,letterSpacing:0.5}});