-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwasm-loader.js
More file actions
51 lines (42 loc) · 1.38 KB
/
wasm-loader.js
File metadata and controls
51 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Loader for WebAssembly module
let wasmModule = null;
// Load the WebAssembly module
export async function loadWasmModule() {
if (wasmModule) return wasmModule;
try {
// In development, we'll load the debug version
const isDev = import.meta.env.DEV;
const imports = {};
// Dynamic import based on environment
const module = isDev
? await import('./build/debug.js')
: await import('./build/release.js');
// Directly use the module instead of trying to call a default export
wasmModule = module;
console.log('WASM module loaded successfully');
return wasmModule;
} catch (error) {
console.error('Failed to load WASM module:', error);
// Return a fallback module with the same interface
return createFallbackModule();
}
}
// Fallback implementation if WASM fails to load
function createFallbackModule() {
console.warn('Using JavaScript fallback instead of WASM');
return {
calculateMoveScore: (value) => value,
isValidMove: (board, size, direction) => {
// Simplified fallback implementation
return true;
},
performMove: (board, size, direction) => {
// Simplified fallback - just return that something moved
return true;
},
getAIHint: (board, size) => {
// Simple random direction as fallback
return Math.floor(Math.random() * 4);
}
};
}