remove util.js, common/Util.js
This commit is contained in:
parent
d592cef494
commit
3dc9edeee6
4 changed files with 9 additions and 13 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
// get a unique id
|
||||
export const uniqId = () => Date.now().toString(36) + Math.random().toString(36).substring(2)
|
||||
|
||||
|
|
@ -6,6 +6,7 @@ import Graphics from './Graphics.js'
|
|||
import Debug from './Debug.js'
|
||||
import Communication from './Communication.js'
|
||||
import Geometry from './../common/Geometry.js'
|
||||
import Util from './../common/Util.js'
|
||||
|
||||
if (typeof GAME_ID === 'undefined') throw '[ GAME_ID not set ]'
|
||||
if (typeof WS_ADDRESS === 'undefined') throw '[ WS_ADDRESS not set ]'
|
||||
|
|
@ -132,15 +133,11 @@ async function loadPuzzleBitmaps(puzzle) {
|
|||
return await createPuzzleTileBitmaps(bmpResized, puzzle.tiles, puzzle.info)
|
||||
}
|
||||
|
||||
function uniqId() {
|
||||
return Date.now().toString(36) + Math.random().toString(36).substring(2)
|
||||
}
|
||||
|
||||
function initme() {
|
||||
// return uniqId()
|
||||
let ID = localStorage.getItem("ID")
|
||||
if (!ID) {
|
||||
ID = uniqId()
|
||||
ID = Util.uniqId()
|
||||
localStorage.setItem("ID", ID)
|
||||
}
|
||||
return ID
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import sizeOf from 'image-size'
|
||||
import { choice, shuffle } from './util.js'
|
||||
import Util from './../common/Util.js'
|
||||
|
||||
// cut size of each puzzle tile in the
|
||||
// final resized version of the puzzle image
|
||||
|
|
@ -69,7 +69,7 @@ async function createPuzzle(targetTiles, image) {
|
|||
}
|
||||
|
||||
// then shuffle the positions
|
||||
positions = shuffle(positions)
|
||||
positions = Util.shuffle(positions)
|
||||
|
||||
tiles = tiles.map(tile => {
|
||||
return {
|
||||
|
|
@ -143,9 +143,9 @@ function determinePuzzleTileShapes(info) {
|
|||
for (let i = 0; i < info.tiles; i++) {
|
||||
shapes[i] = {
|
||||
top: info.coords[i].y === 0 ? 0 : shapes[i - info.tiles_x].bottom * -1,
|
||||
right: info.coords[i].x === info.tiles_x - 1 ? 0 : choice(tabs),
|
||||
right: info.coords[i].x === info.tiles_x - 1 ? 0 : Util.choice(tabs),
|
||||
left: info.coords[i].x === 0 ? 0 : shapes[i - 1].right * -1,
|
||||
bottom: info.coords[i].y === info.tiles_y - 1 ? 0 : choice(tabs),
|
||||
bottom: info.coords[i].y === info.tiles_y - 1 ? 0 : Util.choice(tabs),
|
||||
}
|
||||
}
|
||||
return shapes
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import WebSocketServer from './WebSocketServer.js'
|
|||
|
||||
import express from 'express'
|
||||
import config from './config.js'
|
||||
import { uniqId, choice } from './util.js'
|
||||
import Util from './../common/Util.js'
|
||||
import Game from './Game.js'
|
||||
|
||||
const EV_SERVER_STATE_CHANGED = 1
|
||||
|
|
@ -50,7 +50,7 @@ app.use('/', (req, res, next) => {
|
|||
html,body {margin: 0; overflow: hidden;}
|
||||
html, body, #main { background: #222 }
|
||||
</style></head><body>
|
||||
<a href="/g/${uniqId()}">New game :P</a>
|
||||
<a href="/g/${Util.uniqId()}">New game :P</a>
|
||||
${Object.keys(games).map(k => {
|
||||
return `<a href="/g/${k}">Game ${k}</a>`
|
||||
})}
|
||||
|
|
@ -81,7 +81,7 @@ wss.on('message', async ({socket, data}) => {
|
|||
switch (type) {
|
||||
case EV_CLIENT_INIT: {
|
||||
if (!Game.exists(gameId)) {
|
||||
await Game.createGame(gameId, TARGET_TILES, choice(IMAGES))
|
||||
await Game.createGame(gameId, TARGET_TILES, Util.choice(IMAGES))
|
||||
}
|
||||
Game.addPlayer(gameId, playerId)
|
||||
Game.addSocket(gameId, socket)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue