The sources of the project follows this structure:
/src
/app
/{domain}
/actions.ts
/actions.spec.ts
| if (typeof window === 'object') { | |
| // Browser | |
| } else if (typeof importScripts === 'function') { | |
| // WebWorker | |
| } else if (typeof process === 'object' && typeof require === 'function') { | |
| // NodeJS | |
| } else { | |
| // shell | |
| } |
| import React from 'react'; | |
| export default ({ condition, children }) => condition ? React.Children.only(children); : null; |
| var libUrl = null; | |
| var scriptTag = Array.prototype.slice | |
| .call(document.getElementsByTagName("script")) | |
| .filter(x => /\?proxy?/.test(x.src)); | |
| if (scriptTag.length > 0) { | |
| libUrl = scriptTag[0].src.split("m.js")[0]; | |
| } else { | |
| throw new Error("missing '?proxy' query parameter in your proxy url!"); | |
| } |
| // Server | |
| const app = require('express')() | |
| const server = require('http').createServer(app) | |
| const wss = new WebSocketServer({ server }) | |
| const clients: Set<RemoteScene> = new Set() | |
| wss.on('connection', (ws, req) => { | |
| const transport = WebSocketTransport(ws) | |
| const client = new RemoteScene(transport) | |
| clients.add(client) |
| // Sea | |
| const { Sea } = require('shoaling') | |
| const sea = new Sea(38, 1200, 300, 1200) // simulate 38 fish on a 'sea' of 1200x1200 (X and Z) and 300 deep (Y) | |
| sea.start(64) // update every 64 milliseconds | |
| setInterval(() => { | |
| render(sea) | |
| clients.forEach(client => client.forceUpdate()) | |
| }, 100) // render scene every 100 ms |
| import { createElement, ScriptableScene, ISimplifiedNode } from 'metaverse-api' | |
| import { Sea } from './components/Sea' | |
| let cachedScene: ISimplifiedNode | null = null | |
| export function render(sea: any) { | |
| cachedScene = Sea({sea}) | |
| } | |
| export default class RemoteScene extends ScriptableScene { | |
| async render() { |
| function Vector(x, y, z) { | |
| this.x = x || 0; | |
| this.y = y || 0; | |
| this.z = z || 0; | |
| } | |
| Vector.prototype = { | |
| negative: function() { | |
| return new Vector(-this.x, -this.y, -this.z); | |
| }, |
-import { groupMovesByColor } from '~/modules/game/selectors';
+import { groupMovesByColor } from '../modules/game/selectors';| // scene/server/Store.ts | |
| const store = require('../../../src/store').default | |
| const { | |
| initSquares, | |
| squareClick | |
| } = require('../../../src/modules/squares/actions') | |
| store.dispatch(initSquares()) | |
| export { initSquares, squareClick } | |
| export default store |