Overview
The case opening system provides an engaging slot-machine style animation that displays items scrolling across the screen before landing on the winning item. The system integrates with the provably fair API to ensure transparent and verifiable randomness.Architecture
Server Determines Winner
Backend uses provably fair algorithm to calculate the winning item using cryptographic seeds
Animate to Winner
CSS transition scrolls the reel over 8 seconds with easing function to land on winner
Component Structure
The case opener is built using theCaseOpener component located at:
Key Configuration Constants
components/case-opener.tsx
Animation Mechanics
Reel Construction
When a spin starts, the component builds a reel array:components/case-opener.tsx
The winner is always placed at index 75 in a 110-item reel. The animation then scrolls to center this item in the viewport.
Transform Calculation
The animation uses CSS transforms to scroll the reel:components/case-opener.tsx
The cubic-bezier easing
(0.15, 0, 0.10, 1) creates a realistic “slow down” effect, mimicking physical slot machines.Sound Effects
The system includes two audio cues:- Tick Sound: Plays each time the reel crosses to a new item
- Finish Sound: Plays when winner modal appears
components/case-opener.tsx
Rarity System
Items have color-coded rarity indicators:components/case-opener.tsx
Legendary
Yellow border and glow - Highest value items
Epic
Purple border and glow - High value items
Rare
Blue border and glow - Medium value items
Common
White/gray border - Standard items
Winner Modal
After the animation completes, a modal displays:components/case-opener.tsx
- Rarity-based background glow
- Item image with drop shadow
- Item name and value
- “Sell” button (currently displays sell price)
API Integration
The component communicates with the backend API:Performance Optimizations
CSS Will-Change
CSS Will-Change
The reel container uses
willChange: 'transform' to hint the browser to optimize for transform animations.RequestAnimationFrame
RequestAnimationFrame
Sound effects are triggered using
requestAnimationFrame to sync with browser paint cycles, avoiding jank.Audio Cloning
Audio Cloning
Each tick sound is cloned from the base Audio object to allow rapid successive plays without interruption.
User Experience Features
Mute Toggle
Players can toggle sound effects:components/case-opener.tsx
Visual Indicators
- Top/Bottom Arrows: Mark the center line where the winner will land
- Center Line: Vertical line shows exact selection point
- Side Fades: Gradient overlays create depth and focus attention on center
components/case-opener.tsx
Next Steps
Provably Fair
Learn how cryptographic verification ensures fair outcomes
Wallet System
Understand balance management and transactions
