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