move random functions to rng class, fix some imports

This commit is contained in:
Zutatensuppe 2021-05-17 01:12:39 +02:00
parent 07c08019f5
commit 432e1b6668
16 changed files with 71 additions and 80 deletions

View file

@ -1,9 +1,9 @@
import GameCommon from './../common/GameCommon'
import Util from './../common/Util'
import { Rng } from '../common/Rng'
import { Rng } from './../common/Rng'
import GameLog from './GameLog'
import { createPuzzle } from './Puzzle'
import Protocol from '../common/Protocol'
import Protocol from './../common/Protocol'
import GameStorage from './GameStorage'
async function createGameObject(gameId: string, targetTiles: number, image: { file: string, url: string }, ts: number, scoreMode: number) {

View file

@ -1,6 +1,6 @@
import fs from 'fs'
import { logger } from '../common/Util.js'
import { DATA_DIR } from '../server/Dirs.js'
import { logger } from './../common/Util'
import { DATA_DIR } from './../server/Dirs'
const log = logger('GameLog.js')

View file

@ -1,4 +1,4 @@
import { logger } from '../common/Util.js'
import { logger } from './../common/Util'
import WebSocket from 'ws'
const log = logger('GameSocket.js')

View file

@ -1,7 +1,7 @@
import fs from 'fs'
import GameCommon from './../common/GameCommon'
import Util, { logger } from './../common/Util'
import { Rng } from '../common/Rng'
import { Rng } from './../common/Rng'
import { DATA_DIR } from './Dirs'
import Time from './../common/Time'

View file

@ -3,7 +3,7 @@ import fs from 'fs'
import exif from 'exif'
import sharp from 'sharp'
import {UPLOAD_DIR, UPLOAD_URL} from './Dirs.js'
import {UPLOAD_DIR, UPLOAD_URL} from './Dirs'
const resizeImage = async (filename: string) => {
if (!filename.toLowerCase().match(/\.(jpe?g|webp|png)$/)) {

View file

@ -1,6 +1,6 @@
import Util from '../common/Util'
import { Rng } from '../common/Rng'
import Images from './Images.js'
import Util from './../common/Util'
import { Rng } from './../common/Rng'
import Images from './Images'
interface PuzzleInfo {
width: number
@ -89,7 +89,7 @@ async function createPuzzle(
}
// then shuffle the positions
positions = Util.shuffle(rng, positions)
positions = rng.shuffle(positions)
tiles = tiles.map(tile => {
return Util.encodeTile({
@ -167,9 +167,9 @@ function determinePuzzleTileShapes(
let coord = Util.coordByTileIdx(info, i)
shapes[i] = {
top: coord.y === 0 ? 0 : shapes[i - info.tilesX].bottom * -1,
right: coord.x === info.tilesX - 1 ? 0 : Util.choice(rng, tabs),
right: coord.x === info.tilesX - 1 ? 0 : rng.choice(tabs),
left: coord.x === 0 ? 0 : shapes[i - 1].right * -1,
bottom: coord.y === info.tilesY - 1 ? 0 : Util.choice(rng, tabs),
bottom: coord.y === info.tilesY - 1 ? 0 : rng.choice(tabs),
}
}
return shapes.map(Util.encodeShape)

View file

@ -1,5 +1,5 @@
import WebSocket from 'ws'
import { logger } from '../common/Util.js'
import { logger } from './../common/Util'
const log = logger('WebSocketServer.js')

View file

@ -10,13 +10,9 @@ import v8 from 'v8'
import fs from 'fs'
import GameLog from './GameLog'
import GameSockets from './GameSockets'
import Time from '../common/Time'
import Time from './../common/Time'
import Images from './Images'
import {
UPLOAD_DIR,
UPLOAD_URL,
PUBLIC_DIR,
} from './Dirs'
import { UPLOAD_DIR, UPLOAD_URL, PUBLIC_DIR } from './Dirs'
import GameCommon from '../common/GameCommon'
import GameStorage from './GameStorage'