xcore-casino
Version:
Casino Core module
126 lines (83 loc) • 2.96 kB
Markdown
# casino-wasm-core
Core WASM module for casino games implementation.
## Installation
```bash
npm install xcore-casino
```
## WASM Loading
The package uses WebAssembly to interact with the casino core functionality. To properly initialize the WASM module:
```typescript
import { WasmLoader } from 'xcore-casino';
// Set the correct path to your WASM file (very important!)
WasmLoader.wasmPath = '/path/to/casino.wasm';
// Optional: Enable debug mode for verbose logging
WasmLoader.debug = true;
// Optional: Increase timeout duration for slow connections
WasmLoader.timeoutDuration = 15000; // 15 seconds
// Load the WASM module
try {
await WasmLoader.asyncLoad();
console.log('WASM module loaded successfully!');
// Get the casino instance
const casino = WasmLoader.getCasino();
// Use the casino instance
// ...
} catch (error) {
console.error('Failed to load WASM module:', error);
// Get diagnostics
const diagnostics = WasmLoader.getDiagnostics();
console.log('WASM Loader Diagnostics:', diagnostics);
// Check WASM file availability
const fileCheck = await WasmLoader.checkWasmFileAvailability();
console.log('WASM File Check:', fileCheck);
}
```
### WASM Caching
The WASM loader automatically caches the WASM file to prevent multiple downloads of the same file. This improves performance and reduces network usage. If you need to force a fresh download:
```typescript
// Clear the WASM cache
WasmLoader.clearCache();
// Or force a complete reload including cache clearing
await WasmLoader.forceReload();
```
### Troubleshooting WASM Loading Issues
If you encounter issues loading the WASM module:
1. **Ensure the WASM file is accessible** - Check that the path to your WASM file is correct and that the file is being served with the appropriate MIME type (`application/wasm`).
2. **Enable debug mode** - Set `WasmLoader.debug = true` before calling `asyncLoad()` to get detailed logging.
3. **Increase timeout duration** - If you're on a slow connection, increase the timeout duration with `WasmLoader.timeoutDuration = 15000` (15 seconds).
4. **Check browser compatibility** - Use `checkWasmSupport()` to verify that the browser supports WebAssembly.
5. **Force reload** - If the WASM module gets stuck, you can try forcing a reload with `WasmLoader.forceReload()`.
## Development
### Prerequisites
- Node.js >= 16
- npm >= 7
- Rust toolchain (for WASM compilation)
### Setup
1. Clone the repository
2. Install dependencies:
```bash
npm install
```
### Build
```bash
# Build WASM module and TypeScript
npm run build:all
# Build only TypeScript
npm run build
# Generate TypeScript declaration files
npm run build:types
```
### Test
```bash
npm test
```
### Lint
```bash
npm run lint
```
### Format
```bash
npm run format
```
## License
MIT