advanced-games-library
Version:
Advanced Gaming Library for React Native - Four Complete Games with iOS Compatibility Fixes
448 lines (407 loc) • 13 kB
TypeScript
/**
* Advanced Games Library - TypeScript Declarations
* @version 2.0.0
*/
import { ReactNode, ComponentType } from 'react';
import { ViewStyle, TextStyle, ImageSourcePropType } from 'react-native';
// Base Types
export interface GameConfig {
gameId?: string;
difficulty?: 'easy' | 'medium' | 'hard' | 'expert';
customization?: {
theme?: Record<string, any>;
brandName?: string;
primaryColor?: string;
};
rules?: Record<string, any>;
gridSize?: number;
useNumbers?: boolean;
imageUrl?: ImageSourcePropType;
totalRounds?: number;
}
export interface GameState {
isComplete: boolean;
moves: number;
score: number;
tiles: Array<{
id: string;
value: number | string;
position: { row: number; col: number };
correctPosition: { row: number; col: number };
isEmpty?: boolean;
}>;
startTime?: number;
endTime?: number;
}
export interface GameResult {
completed: boolean;
score: number;
moves: number;
time: number;
completionTime?: number;
benchmark?: Record<string, any>;
}
// Component Props for all games
export interface DemoGameProps {
message?: string;
displayTime?: number;
onGameComplete?: (result: any) => void;
onGameStart?: () => void;
showMenu?: boolean;
autoStart?: boolean;
title?: string;
subtitle?: string;
theme?: {
primaryColor?: string;
secondaryColor?: string;
backgroundColor?: string;
textColor?: string;
};
}
export interface SimplePuzzleGameProps {
gridSize?: number;
difficulty?: 'easy' | 'medium' | 'hard';
onGameComplete?: (result: any) => void;
onGameStart?: () => void;
onMove?: (moveData: any) => void;
showMenu?: boolean;
autoStart?: boolean;
title?: string;
subtitle?: string;
showStats?: boolean;
enableHints?: boolean;
enableReset?: boolean;
theme?: {
primaryColor?: string;
secondaryColor?: string;
backgroundColor?: string;
textColor?: string;
};
}
export interface ReactionTimeGameProps {
difficulty?: 'easy' | 'medium' | 'hard' | 'expert';
totalRounds?: number;
onGameComplete?: (result: any) => void;
onGameStart?: () => void;
onRoundComplete?: (roundData: any) => void;
showMenu?: boolean;
autoStart?: boolean;
title?: string;
subtitle?: string;
showStats?: boolean;
enablePractice?: boolean;
theme?: {
primaryColor?: string;
secondaryColor?: string;
backgroundColor?: string;
textColor?: string;
successColor?: string;
warningColor?: string;
};
}
export interface MemoryMatchGameProps {
gridSize?: number;
difficulty?: 'easy' | 'medium' | 'hard' | 'expert';
onGameComplete?: (result: any) => void;
onGameStart?: () => void;
onCardFlip?: (cardData: any) => void;
showMenu?: boolean;
autoStart?: boolean;
title?: string;
subtitle?: string;
showStats?: boolean;
enableHints?: boolean;
enableReset?: boolean;
theme?: {
primaryColor?: string;
secondaryColor?: string;
backgroundColor?: string;
textColor?: string;
cardColor?: string;
matchedColor?: string;
};
}
export interface ImagePuzzleGameProps {
gridSize?: number;
difficulty?: 'easy' | 'medium' | 'hard';
imageUrl?: string;
onGameComplete?: (result: any) => void;
onGameStart?: () => void;
onMove?: (moveData: any) => void;
showMenu?: boolean;
autoStart?: boolean;
title?: string;
subtitle?: string;
showStats?: boolean;
enableHints?: boolean;
enableReset?: boolean;
theme?: {
primaryColor?: string;
secondaryColor?: string;
backgroundColor?: string;
textColor?: string;
};
}
export interface GameContainerProps {
title: string;
subtitle?: string;
progress?: number;
showHeader?: boolean;
performanceMonitoring?: boolean;
memoryOptimization?: boolean;
errorRecovery?: boolean;
children: ReactNode;
style?: ViewStyle;
}
export interface PuzzleBoardProps {
gameState: GameState;
gridSize: number;
onTilePress: (row: number, col: number) => void;
canMoveTile?: (position: { row: number; col: number }) => boolean;
useNumbers?: boolean;
imageUrl?: ImageSourcePropType;
showHints?: boolean;
animateLastMove?: boolean;
style?: ViewStyle;
}
// Game Classes
export declare class SimplePuzzleGame {
constructor();
initialize(config: GameConfig): Promise<void>;
start(): Promise<void>;
reset(): void;
getGameState(): GameState;
moveTile(position: { row: number; col: number }): boolean;
canMoveTile(position: { row: number; col: number }): boolean;
getHint(): { row: number; col: number } | null;
on(event: string, callback: (data: any) => void): void;
off(event: string, callback: (data: any) => void): void;
emit(event: string, data?: any): void;
}
export declare class MultiplayerPuzzleGame extends SimplePuzzleGame {
constructor(playerId: string);
createRoom(playerName: string): Promise<string>;
joinRoom(roomId: string, playerName: string): Promise<void>;
leaveRoom(): Promise<void>;
sendMove(position: { row: number; col: number }): Promise<void>;
}
// Game Components - הקומפוננטות הראשיות לשימוש חיצוני
export declare const DemoGameComponent: ComponentType<DemoGameProps>;
export declare const SimplePuzzleGameComponent: ComponentType<SimplePuzzleGameProps>;
export declare const ReactionTimeGameComponent: ComponentType<ReactionTimeGameProps>;
export declare const MemoryMatchGameComponent: ComponentType<MemoryMatchGameProps>;
export declare const ImagePuzzleGameComponent: ComponentType<ImagePuzzleGameProps>;
// Aliases for backward compatibility
export declare const SimplePuzzleComponent: ComponentType<SimplePuzzleGameProps>;
export declare const SimplePuzzleScreen: ComponentType<SimplePuzzleGameProps>;
export declare const MultiplayerGameDemo: ComponentType<any>;
export declare const GameContainer: ComponentType<GameContainerProps>;
export declare const GameHeader: ComponentType<any>;
export declare const GameButton: ComponentType<any>;
export declare const GameModal: ComponentType<any>;
export declare const GameWidgets: ComponentType<any>;
export declare const PuzzleBoard: ComponentType<PuzzleBoardProps>;
export declare const PuzzleTile: ComponentType<any>;
// Hooks
export interface GameEngineState {
isActive: boolean;
score: number;
level: number;
duration: number;
status: 'idle' | 'playing' | 'paused' | 'ended';
}
export interface UseGameEngineReturn {
gameState: GameEngineState;
startGame: (config?: Record<string, any>) => void;
pauseGame: () => void;
resumeGame: () => void;
endGame: (finalScore?: number) => void;
updateScore: (points: number) => void;
updateLevel: (newLevel: number) => void;
}
export interface PerformanceData {
fps: number;
memoryUsage: number;
renderTime: number;
networkLatency: number;
lastUpdate: string;
}
export interface UsePerformanceMonitorReturn {
performanceData: PerformanceData;
startMonitoring: (interval?: number) => void;
stopMonitoring: () => void;
getPerformanceScore: () => number;
getPerformanceStatus: () => {
status: 'excellent' | 'good' | 'poor';
color: string;
emoji: string;
};
}
export declare function useGameEngine(): UseGameEngineReturn;
export declare function usePerformanceMonitor(): UsePerformanceMonitorReturn;
// Services
export declare class GameManager {
static getInstance(): GameManager;
initialize(config: Record<string, any>): Promise<void>;
createGame(gameType: string, config: GameConfig): Promise<any>;
destroyGame(gameId: string): Promise<void>;
}
export declare class AnalyticsService {
static getInstance(): AnalyticsService;
trackEvent(event: {
event: string;
gameId: string;
properties: Record<string, any>;
}): void;
initialize(config: Record<string, any>): void;
}
export declare class PlayerService {
static getInstance(): PlayerService;
getPlayer(playerId: string): Promise<any>;
updatePlayer(playerId: string, data: Record<string, any>): Promise<void>;
}
export declare class StorageService {
static getInstance(): StorageService;
save(key: string, data: any): Promise<void>;
load(key: string): Promise<any>;
remove(key: string): Promise<void>;
}
export declare class CustomizationService {
static getInstance(): CustomizationService;
setTheme(theme: Record<string, any>): void;
getTheme(): Record<string, any>;
setBranding(branding: Record<string, any>): void;
getBranding(): Record<string, any>;
}
// Utilities
export enum ErrorCategory {
INITIALIZATION = 'initialization',
RENDERING = 'rendering',
USER_INPUT = 'user_input',
NETWORK = 'network',
GAME_LOGIC = 'game_logic'
}
export enum ErrorSeverity {
LOW = 'low',
MEDIUM = 'medium',
HIGH = 'high',
CRITICAL = 'critical'
}
export declare const performanceMonitor: {
startGameSession(gameId: string): void;
endGameSession(gameId: string): Record<string, any>;
recordGameLoadTime(gameId: string, time: number): void;
recordRenderTime(gameId: string, time: number): void;
recordInputLatency(gameId: string, time: number): void;
generateReport(): Record<string, any>;
enableRemoteReporting(url: string): void;
};
export declare const gameErrorHandler: {
handleError(
error: Error | any,
category: ErrorCategory,
severity: ErrorSeverity,
context?: Record<string, any>
): Promise<void>;
onError(callback: (error: any) => void): void;
enableProductionMode(): void;
};
export declare const gameDataCache: {
cacheGameState(gameId: string, state: any): Promise<void>;
getGameState(gameId: string): Promise<any>;
cachePlayerData(playerId: string, data: any): Promise<void>;
getPlayerData(playerId: string): Promise<any>;
clearCache(): Promise<void>;
};
export declare const memoryOptimized: {
getCurrentMemoryStatus(): {
current: { percentage: number };
trend: string;
riskLevel: 'low' | 'medium' | 'high';
};
optimizeMemory(): Promise<{ memoryFreed: number }>;
enableProductionMode(): void;
};
// Simple API Objects
export declare const GameEngine: {
version: string;
initialize: (config?: Record<string, any>) => Promise<{ success: boolean }>;
destroy: () => Promise<{ success: boolean }>;
};
export declare const PerformanceMonitor: {
version: string;
start: (options?: Record<string, any>) => { sessionId: string };
stop: (sessionId?: string) => { duration: number; metrics: Record<string, any> };
getMetrics: () => {
fps: number;
memoryUsage: number;
renderTime: number;
networkLatency: number;
};
};
export declare const NetworkManager: {
version: string;
connect: (config?: Record<string, any>) => Promise<{ connected: boolean; roomId: string }>;
disconnect: () => Promise<{ disconnected: boolean }>;
sendMessage: (message: any) => Promise<{ sent: boolean; messageId: string }>;
};
export declare const GameUtils: {
generateId: () => string;
formatScore: (score: number) => string;
formatTime: (seconds: number) => string;
validateConfig: (config: any) => boolean;
deepClone: <T>(obj: T) => T;
debounce: <T extends (...args: any[]) => any>(func: T, wait: number) => T;
};
// Main Library
export interface LibraryConfig {
enableAnalytics?: boolean;
enablePerformanceMonitoring?: boolean;
enableAdvancedMemoryManagement?: boolean;
enableErrorRecovery?: boolean;
enableNetworking?: boolean;
customization?: {
brandName?: string;
primaryColor?: string;
};
networkConfig?: Record<string, any>;
}
export interface LibraryInitResult {
success: boolean;
version: string;
features: {
performanceMonitoring: boolean;
memoryManagement: boolean;
errorRecovery: boolean;
networking: boolean;
analytics: boolean;
};
}
export declare const GamesLibrary: {
version: string;
initialize: (config?: LibraryConfig) => Promise<LibraryInitResult>;
destroy: () => Promise<{ success: boolean }>;
getInfo: () => {
name: string;
version: string;
description: string;
author: string;
license: string;
};
};
// React Components
export declare const DemoGameComponent: React.ComponentType<DemoGameProps>;
export declare const SimplePuzzleGameComponent: React.ComponentType<SimplePuzzleGameProps>;
export declare const SimplePuzzleScreen: React.ComponentType<SimplePuzzleGameProps>;
export declare const MemoryMatchGame: React.ComponentType<MemoryMatchGameProps>;
export declare const ReactionTimeGame: React.ComponentType<ReactionTimeGameProps>;
export declare const ImagePuzzleGame: React.ComponentType<ImagePuzzleGameProps>;
export declare const GameContainer: React.ComponentType<GameContainerProps>;
export declare const GameHeader: React.ComponentType<any>;
export declare const GameModal: React.ComponentType<any>;
export declare const GameWidgets: React.ComponentType<any>;
export declare const MultiplayerGameDemo: React.ComponentType<any>;
export declare const DemoGameTestApp: React.ComponentType<any>;
// Default Export
declare const _default: typeof GamesLibrary;
export default _default;