@@ -6,6 +6,7 @@ import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer
66import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js" ;
77import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPass.js" ;
88import { isMobile } from "./device" ;
9+ import { Match } from "./game/match" ;
910
1011// Required for Github Pages deployment
1112THREE . DefaultLoadingManager . setURLModifier ( ( url ) => {
@@ -100,6 +101,11 @@ const oddMat = new THREE.MeshStandardMaterial({
100101
101102// === Scene setup ===
102103async function init ( ) {
104+ const game = isMobile ( ) ? await Match . join ( ) : await Match . host ( ) ;
105+ game . onAction = ( data ) => { currentTarget = new THREE . Vector3 ( - 4 + Math . random ( ) * 8 , currentTarget ?. y , - 4 + Math . random ( ) * 8 ) } ;
106+ window . addEventListener ( 'pagehide' , ( ) => game . dispose ( ) , { once : true } ) ;
107+ window . addEventListener ( 'beforeunload' , ( ) => game . dispose ( ) , { once : true } ) ;
108+
103109 const tileSrc = ( await loadGLB ( "/models/box.glb" ) ) . children [ 0 ] as THREE . Mesh ;
104110 const tileGeometry = ( tileSrc . geometry as THREE . BufferGeometry ) . clone ( ) ;
105111 tileGeometry . computeBoundingBox ( ) ;
@@ -209,6 +215,7 @@ async function init() {
209215 const intersects = raycaster . intersectObjects ( tiles , false ) ;
210216
211217 if ( intersects . length > 0 ) {
218+ game . play ( { type : 'Move' } ) ;
212219 const picked = intersects [ 0 ] ?. object as THREE . Mesh ;
213220 currentTarget = picked . getWorldPosition ( new THREE . Vector3 ( ) ) ;
214221 currentTarget . x += 0.4 ;
0 commit comments