Skip to main content

Xgenia Slot Template Functions

This section explains the core functions used in the Xgenia Slot Template, their purpose, and how data flows between them to create the complete slot game experience.

Data Flow Diagram​

Game Launch → Get Session → Get Game → Asset Loading
↓ ↓ ↓ ↓
SessionID UserID+Token Icons+Music Download Functions
↓ ↓ ↓ ↓
Authentication API Access Symbols Image Processing
↓ ↓ ↓ ↓
Bet Transactions → Result Processing → Icon Display → UI Update

Function Flowchart​

Function Flowchart


1. Game Initialization Functions​

1.1 Launch Game​

Purpose: Initializes a new game session with the backend server and establishes secure communication.

Launch Game Function

Connections Flow:

  1. From String Node → Receives GameID (example: "slot_classic_01")
  2. From String Node → Receives initial SessionID for authentication
  3. To API Endpoint → Sends POST request to launch endpoint
  4. From API Response → Receives authoritative SessionID from server
  5. To Get Session Function → Provides validated SessionID for next step

Data Example:

Input: GameID = "slot_classic_01"
Output: SessionID = "sess_abc123def456"

How it Works: Launch Game sends a POST request to the server with the GameID. The server validates the game exists, creates a secure session, and returns an authoritative SessionID. This SessionID becomes the key for all subsequent API calls, ensuring secure and authenticated communication throughout the game session.

1.2 Get Session​

Purpose: Retrieves authenticated user session data including balance, tokens, and user preferences.

Get Session Function

Connections Flow:

  1. From Launch Game → Receives validated SessionID
  2. To API Endpoint → Sends secure session request
  3. From API Response → Receives complete session data
  4. To Header Components → Provides Balance (example: 1000 credits)
  5. To Get Game Function → Provides UserID and Token for authentication
  6. To Bet Functions → Provides authentication credentials

Data Example:

Input: SessionID = "sess_abc123def456"
Output: Balance = 1000, UserID = "user123", Token = "jwt_token_here"

1.3 Get Game​

Purpose: Fetches game-specific assets and configuration data for the selected slot game.

Get Game Function

Connections Flow:

  1. From Get Session → Receives UserID, Token, and authentication
  2. From String Node → Receives GameID for asset identification
  3. To API Endpoint → Sends authenticated game data request
  4. From API Response → Receives Icons array and Music URL
  5. To Download Functions → Provides URLs for asset downloading
  6. To Audio Components → Provides Music URL for background audio

Data Example:

Input: GameID = "slot_classic_01", UserID = "user123"
Output: Icons = [Icon1.png, Icon2.png, ...], Music = "background.mp3"

2. Asset Loading Functions​

2.1 Get Config JSON​

Purpose: Downloads the game's remote configuration file containing asset URLs and game settings.

Get Config JSON Function

Connections Flow:

  1. From String Node → Receives GameID for URL construction
  2. To Cloud Storage → Constructs and fetches config.json URL
  3. From JSON Response → Receives BackgroundURL and FrameURL
  4. To Download Background → Provides BackgroundURL
  5. To Download Frame → Provides FrameURL

Data Example:

Input: GameID = "slot_classic_01"
URL: https://storage.googleapis.com/.../slot_classic_01/config.json
Output: BackgroundURL = "background.png", FrameURL = "frame.png"

2.2 Download Background​

Purpose: Fetches and processes the game's background image for display.

Download Background Function

Connections Flow:

  1. From Get Config JSON → Receives BackgroundURL
  2. To Image Fetch → Downloads image as blob data
  3. To Base64 Conversion → Converts to displayable format
  4. To Background Component → Provides processed image data

2.3 Download Frame​

Purpose: Fetches and processes the decorative slot machine frame image.

Download Frame Function

Connections Flow:

  1. From Get Config JSON → Receives FrameURL
  2. To Image Fetch → Downloads frame image
  3. To Base64 Conversion → Processes for display
  4. To Frame Component → Provides decorative overlay image

2.4 Download Audio​

Purpose: Fetches background music and sound effects for the current game theme.

Download Audio Function

Connections Flow:

  1. From Get Game → Receives Music URL based on GameID
  2. To Audio Fetch → Downloads audio file
  3. To Audio Manager → Provides processed audio data
  4. To Audio Controls → Enables play/pause functionality

3. Image Processing Functions​

3.1 Slice Image​

Purpose: Converts a single spritesheet image into individual slot symbol images for efficient display.

Slice Image Function

Connections Flow:

  1. From Get Game → Receives spritesheet URL containing all symbols
  2. To Canvas Processing → Slices spritesheet into individual icons
  3. From Grid Calculation → Uses 5x3 grid parameters (5 columns, 3 rows)
  4. To Icon Array → Outputs array of 15 individual symbol images
  5. To Icon Setter → Provides symbol library for result mapping

Data Example:

Input: Spritesheet with 15 symbols in 5x3 grid
Output: Array of 15 individual symbol images
[{ImageSrc: "data:image/png;base64...", Index: "Icon1"}, ...]

How it Works: Slice Image downloads a single spritesheet containing all game symbols, then uses HTML5 Canvas to cut it into individual symbol images. This approach improves performance by reducing the number of HTTP requests while maintaining high-quality graphics. Each sliced symbol is converted to base64 format for immediate use in the game interface.

3.2 Icon Setter From Server​

Purpose: Maps server bet results to specific slot symbols and arranges them in the 5x3 grid.

Icon Setter Function

Connections Flow:

  1. From Bet Transactions → Receives ResultArrayOne (example: 1234567890123456)
  2. From Slice Image → Receives array of available symbol images
  3. To Result Processing → Converts numeric result to symbol positions
  4. To Grid Layout → Arranges symbols in 5 columns × 3 rows format
  5. To Slot Frame → Provides final symbol arrangement for display

Data Processing Example:

Input: ResultArrayOne = 1234567890123456
Process: Maps each digit to corresponding symbol
Output: 15 symbols arranged in 5x3 grid
Grid: [Symbol1][Symbol2][Symbol3][Symbol4][Symbol5]
[Symbol6][Symbol7][Symbol8][Symbol9][Symbol0]
[Symbol1][Symbol2][Symbol3][Symbol4][Symbol5]

How it Works: The Icon Setter takes the numeric result from the server and converts each digit into a specific symbol using a mapping algorithm. It cycles through the result digits to fill all 15 positions in the 5x3 grid, applies any necessary offsets for symbol indexing, and outputs an array of image objects ready for display by the UI repeater component.


4. Gameplay Functions​

4.1 Bet Transactions​

Purpose: Executes the core gameplay loop by processing bets and returning spin results.

Bet Transactions Function

Connections Flow:

  1. From BET Button → Receives current bet amount (example: 10 credits)
  2. From Get Session → Receives UserID, SessionID, and Token for authentication
  3. From String Node → Receives GameID for game-specific processing
  4. To API Endpoint → Sends secure bet request to server
  5. From API Response → Receives spin results and updated balance
  6. To Icon Setter → Provides ResultArrayOne for symbol display
  7. To Header Components → Provides new Balance and TotalWin amounts
  8. To Audio Manager → Triggers spin sound effects

Data Example:

Input: Amount = 10, GameID = "slot_classic_01", UserID = "user123"
Output: TotalWin = 50, Balance = 1040, ResultArrayOne = 1234567890123456

How it Works: When the SPIN button is pressed in API mode, Bet Transactions validates the player's balance and sends a secure request to the server. The server uses a certified random number generator to determine the spin outcome, calculates wins based on the game's paytable, updates the player's balance, and returns the results. The function then distributes this data to update the UI components.

API Response Structure:

{
"balance": 1040,
"spin_results": {
"total_payout": 50,
"payline_results": [
[["1","2","3","4","5"],["6","7","8","9","0"],["1","2","3","4","5"]]
]
},
"userID": "user123",
"sessionID": "sess_abc123def456",
"game": "slot_classic_01",
"currency": "USD",
"timestamp": "2024-01-07T10:30:00Z"
}

Bet Transactions Outputs:

  • Balance → Updated player balance after spin (example: 1040)
  • TotalWinText → Win amount from spin (example: 50)
  • ResultArrayOne → Processed symbol result (example: 1234567890123456)
  • UserID → Player identifier for session tracking
  • SessionID → Current session identifier
  • Currency → Player's currency code
  • Transitions → Trigger for UI animations
  • DefaultPos → Reset position for next spin

4.2 Local True Random Number Generator​

Purpose: Generates random spin results locally when server API is unavailable or disabled.

Local True Random Number Generator Function

Connections Flow:

  1. From Spin Options Controller → Receives LocalSpin = true signal
  2. From BET Button → Receives current bet amount
  3. To Random Generation → Creates symbol combinations using local algorithms
  4. To Result Processing → Provides generated results instantly
  5. To UI Components → Updates display without server delay

4.3 Get Balance​

Purpose: Retrieves current player balance from the server for display and bet validation.

Get Balance Function

Connections Flow:

  1. From Get Session → Receives authentication credentials
  2. To Balance API → Sends balance inquiry request
  3. From API Response → Receives current balance amount
  4. To Header Display → Updates CREDIT display in real-time
  5. To Bet Validation → Provides balance for bet limit checks

5. Audio Management Functions​

5.1 Audio Manager​

Purpose: Controls background music and sound effects for enhanced gaming experience.

Audio Manager Function

Connections Flow:

  1. From Download Audio → Receives processed audio files
  2. From Header Button Group → Receives mute/unmute commands
  3. From Game Events → Triggers sound effects for wins, spins, button clicks
  4. To Audio Components → Controls volume, playback, and audio states
  5. To Local Storage → Saves audio preferences for future sessions

Audio Features:

  • Background Music: Continuous theme music with loop functionality
  • Sound Effects: Spin sounds, win celebrations, button feedback
  • Volume Control: Independent volume for music and effects
  • Mute Functionality: Quick audio on/off toggle
  • Audio Preloading: Ensures smooth playback without delays

5.2 Load Volumes Data​

Purpose: Manages audio volume settings and player preferences for personalized experience.

Load Volumes Data Function

Implementation:

  • Volume Persistence: Saves volume levels between sessions
  • Individual Controls: Separate settings for music and sound effects
  • Default Settings: Establishes optimal audio levels for new players
  • Real-time Updates: Instant volume changes without restart

6. Currency and Exchange Rate Functions​

6.1 Get Exchange Rate from API​

Purpose: Provides real-time currency conversion for international players.

Get Exchange Rate Function

Connections Flow:

  1. From Player Profile → Receives preferred currency (USD, EUR, IDR, etc.)
  2. To Exchange Rate API → Fetches current conversion rates
  3. From API Response → Receives real-time exchange data
  4. To Currency Converter → Provides conversion ratios
  5. To Header Display → Shows balance in player's preferred currency

Supported Features:

  • Multi-Currency Display: Support for major global currencies
  • Real-Time Rates: Live exchange rate updates
  • Automatic Conversion: Seamless currency switching
  • Rate Caching: Stores recent rates for offline functionality

6.2 Currency Converter​

Purpose: Converts game credits between different currencies for international accessibility.

Currency Converter Function

Conversion Process:

  1. Base Currency: Uses game's native currency (credits)
  2. Exchange Calculation: Applies current conversion rates
  3. Display Formatting: Shows amounts in player's preferred format
  4. Precision Handling: Maintains accuracy for financial calculations

Implementation Example:

Input: 1000 credits, Player Currency = EUR, Rate = 0.85
Process: 1000 × 0.85 = 850
Output: "€850" displayed in header

7. Utility Functions​

7.1 Scale Image​

Purpose: Automatically adjusts image sizes for different screen resolutions and device types.

Scale Image Function

Scaling Features:

  • Responsive Scaling: Adjusts to screen dimensions
  • Quality Preservation: Maintains image clarity across sizes
  • Performance Optimization: Reduces loading times for smaller screens
  • Aspect Ratio Maintenance: Prevents image distortion

7.2 Translations​

Purpose: Provides multi-language support for international player base.

Translations Function

Translation Features:

  • Language Detection: Automatic language selection based on browser settings
  • Dynamic Text Replacement: Real-time language switching
  • Cultural Adaptation: Region-specific formatting for numbers and currencies
  • Fallback Support: English default for unsupported languages

8. Toolkit Functions (Advanced Utilities)​

The template includes comprehensive utility functions organized in three toolkit categories to support advanced slot game development:

8.1 Math and Logic Toolkit​

Purpose: Advanced mathematical functions for game mechanics, animations, and calculations.

Math and Logic Toolkit Functions

Key Functions for Slot Games:

Random Float Generation:

  • Purpose: Generate random decimal numbers for Local TRNG mode
  • Usage: Creates unpredictable spin results when API mode is disabled
  • Example: Random between 0.0 and 1.0 for probability calculations

Clamp Number:

  • Purpose: Ensures betting amounts stay within valid ranges
  • Usage: Prevents players from betting below minimum or above maximum limits
  • Example: Clamp bet between 1 and 500 credits

Map Value to Range:

  • Purpose: Converts values between different scales for animations
  • Usage: Maps spin timer (0-100%) to rotation angles (0-360°)
  • Example: Progress bar animations and symbol transitions

Easing Functions:

  • Purpose: Creates smooth animation curves for better user experience
  • Available Types: Linear, easeInOutSine for natural motion
  • Usage: Symbol drop animations and button press feedback

Color Blend:

  • Purpose: Creates dynamic color effects for winning combinations
  • Usage: Highlights winning paylines with color transitions
  • Example: Blend from normal to gold when symbols match

Distance Calculation:

  • Purpose: Calculates touch/mouse interaction distances
  • Usage: Gesture recognition for mobile slot interactions
  • Example: Swipe detection for changing bet amounts

8.2 String Data Manipulation Toolkit​

Purpose: Data processing functions for game state management and user interface.

String Data Manipulation Functions

Key Array Functions:

  • Array Shuffle: Randomizes symbol order for display variations
  • Array Sample: Selects random symbols for bonus features
  • Array Group By: Organizes game statistics by category
  • Array Union/Intersection: Compares winning combinations

Key Object Functions:

  • Object Clone: Creates safe copies of game state data
  • Object Merge: Combines configuration settings
  • Object Pick/Omit: Filters sensitive data before sending to UI

Key String Functions:

  • String Slugify: Creates URL-friendly game IDs
  • String Escape HTML: Sanitizes user input for security
  • Word/Character Count: Validates input lengths for player names

8.3 Utility And Helpers Toolkit​

Purpose: Validation, security, and general utility functions for robust game operation.

Utility and Helpers Functions

Validation Functions:

  • Is Valid Email: Validates player registration emails
  • Is Number/Integer: Ensures bet amounts are valid numeric values
  • Is Empty: Checks for missing required game data

Security Functions:

  • UUID Generation: Creates unique identifiers for game sessions
  • MD5/SHA256 Hash: Generates checksums for data integrity
  • Base64 Encode/Decode: Secures data transmission

Data Processing:

  • JSON Parse (Safe): Safely processes server responses with error handling
  • JSON Stringify (Formatted): Creates readable configuration exports

Browser Utilities:

  • Local Storage Management: Saves game preferences and settings
  • Cookie Operations: Maintains session data across browser sessions
  • File Download: Exports game statistics or configuration files

9. Local True Random Number Generator (Detailed)​

Purpose: Provides client-side True Random Number Generation when server API is unavailable or for offline gameplay.

Local TRNG Detailed Function

Connections Flow:

  1. From Spin Options Controller → Receives LocalSpin = true signal
  2. From Math Toolkit → Uses Random Float Generation functions
  3. To Result Processing → Generates symbol combinations locally
  4. To Balance Update → Calculates wins/losses without server validation
  5. To UI Components → Provides immediate visual feedback

Algorithm Details:

  • Seed Generation: Uses timestamp + mouse movements for entropy
  • Distribution: Even probability across all symbol combinations
  • Win Rate: Configurable RTP (Return to Player) percentage
  • Validation: Local checks for bet amount and balance sufficiency

Data Example:

Input: Bet = 10 credits, LocalSpin = true
Process: Generate 15 random numbers (0-9) for 5x3 grid
Output: ResultArray = [2,7,1,9,3,8,4,6,0,2,7,1,9,3,8], Win = 20 credits

Advantages:

  • Instant Response: No network latency (1-10ms vs 100-500ms)
  • Offline Play: Works without internet connection
  • Reduced Load: Less server resources needed for high-traffic periods

Limitations:

  • No Compliance: Not suitable for regulated gambling
  • Local Validation: Security depends on client-side implementation
  • No Audit Trail: Results not recorded on authoritative server

10. Date and Time Functions​

The template includes comprehensive date manipulation functions for game sessions and statistics:

Date and Time Functions

10.1 Date Processing Functions​

Date Start/End Operations:

  • Start of Day/Month/Year: Establishes time boundaries for statistics
  • End of Day/Month/Year: Calculates closing periods for reports
  • Usage: Game session tracking and daily/monthly limits

Date Comparison Functions:

  • Is Before/After: Compares dates for bonus expiration
  • Is Weekend: Adjusts game rules for weekend events
  • Days in Month: Calculates monthly reward cycles

Time Formatting:

  • Time Ago: Shows "2 hours ago" for last game session
  • Timestamp Conversion: Converts between Unix timestamps and readable dates
  • Locale Support: Indonesian language support for date displays

10.2 Session Time Management​

Purpose: Tracks game session duration and implements responsible gaming features.

Implementation:

  • Session Start: Records when player begins playing
  • Duration Tracking: Monitors continuous play time
  • Break Reminders: Suggests breaks after extended sessions
  • Daily Limits: Enforces maximum daily play time if configured

Data Flow:

Session Start → Time Tracking → Duration Check → Break Alert
↓ ↓ ↓ ↓
Timestamp Calculate Compare Show
Recording Elapsed to Limit Message

11. Browser Integration Functions​

11.1 DOM Manipulation for Game UI​

Element Positioning:

  • Get Element Position: Locates game components for animations
  • Scroll to Element: Ensures important UI elements are visible
  • Window Size Detection: Adapts game layout to screen dimensions

Interactive Features:

  • Focus Management: Controls keyboard navigation between game elements
  • Class Toggling: Switches between game states (playing, paused, winning)
  • Dynamic Styling: Applies visual effects based on game events

11.2 Data Persistence​

Cookie Management:

  • Player Preferences: Saves sound settings, auto-spin options
  • Session Recovery: Restores game state after browser refresh
  • Security: Secure cookie settings for sensitive game data

Local Storage:

  • Game Statistics: Stores personal gameplay statistics
  • Asset Cache: Saves downloaded images for faster loading
  • Configuration: Maintains custom game settings

File Operations:

  • Export Statistics: Allows players to download game history
  • Configuration Backup: Saves custom settings to file
  • Screenshot Capture: Records winning moments for sharing

12. Performance Optimization Functions​

12.1 Asset Management​

Image Processing:

  • Compression: Reduces file sizes for faster loading
  • Format Conversion: Optimizes images for web display
  • Lazy Loading: Loads assets only when needed

Caching Strategy:

  • Browser Cache: Stores frequently used assets locally
  • Version Control: Updates assets when game versions change
  • Fallback Loading: Provides backup assets if primary fails

12.2 Memory Management​

Object Cleanup:

  • Resource Disposal: Frees memory from unused game objects
  • Event Listener Removal: Prevents memory leaks from abandoned components
  • Cache Limits: Maintains optimal memory usage

Performance Monitoring:

  • Frame Rate Tracking: Ensures smooth animations
  • Load Time Measurement: Optimizes asset loading sequences
  • Error Recovery: Handles and recovers from performance issues

Function Integration Overview​

Performance Optimization Functions

Summary​

The Xgenia Slot Template functions work together in a sophisticated ecosystem that provides:

Core Gameplay: Seamless integration between server API and local TRNG modes Asset Management: Efficient loading and processing of game resources User Experience: Responsive design with audio, currency, and language support Advanced Tools: Comprehensive toolkit functions for custom development Performance: Optimized memory management and caching strategies Security: Built-in validation, authentication, and data protection

This modular function architecture allows for easy maintenance, testing, and customization while ensuring secure and reliable gameplay experience.