diff --git a/src/actions/index.js b/src/actions/index.js index b3186ca..acdb97f 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -362,14 +362,14 @@ export function receiveCoolDown( * draw pixel on canvas * @param i, j, offset Chunk and offset in chunk * @param color integer Color Index - * @param notify Bool if pixel notification appears (false when my own pixel) + * @param notifyPxl Bool if pixel notification appears (false when my own pixel) */ export function updatePixel( i, j, offset, color, - notify = true, + notifyPxl = true, ) { return { type: 'UPDATE_PIXEL', @@ -377,7 +377,7 @@ export function updatePixel( j, offset, color, - notify, + notify: notifyPxl, }; } diff --git a/src/components/CanvasItem.jsx b/src/components/CanvasItem.jsx index 7b41479..45af014 100644 --- a/src/components/CanvasItem.jsx +++ b/src/components/CanvasItem.jsx @@ -41,7 +41,10 @@ const CanvasItem = ({ {t`Stacking till`}:  {canvas.cds / 1000}s
{t`Ranked`}:  - {(canvas.ranked) ? t`Yes` : t`No`}
+ { + (canvas.ranked) ? t`Yes` : t`No` + } +
{(canvas.req !== -1) ? {t`Requirements`}:
: null} {(canvas.req !== -1) ? {t`User Account`} : null} diff --git a/src/components/OnlineBox.jsx b/src/components/OnlineBox.jsx index e870f7f..894d984 100644 --- a/src/components/OnlineBox.jsx +++ b/src/components/OnlineBox.jsx @@ -28,8 +28,6 @@ const OnlineBox = () => { ], shallowEqual); const dispatch = useDispatch(); - const onlineUsers = (onlineCanvas) ? online[canvasId] : online.total; - return (
{ > {online.total} - ) - } + )}   {(name != null) && ( {numberToString(totalPixels)} - )} + )}
); }; diff --git a/src/core/Void.js b/src/core/Void.js index 9663b36..2266ddb 100644 --- a/src/core/Void.js +++ b/src/core/Void.js @@ -4,7 +4,6 @@ * users fight it with background pixels * if it reaches the TARGET_RADIUS size, the event is lost * - * @flow */ import socketEvents from '../socket/SocketEvents'; import PixelUpdate from '../socket/packets/PixelUpdateServer'; @@ -19,17 +18,24 @@ const EVENT_DURATION_MIN = 10; // const EVENT_DURATION_MIN = 1; class Void { - i: number; - j: number; - maxClr: number; - msTimeout: number; - pixelStack: Array; - area: Object; - userArea: Object; - curRadius: number; - curAngle: number; - curAngleDelta: number; - ended: boolean; + // chunk coords + i; + j; + // number highest possible colorIndex + maxClr; + // timeout between pixels in ms + msTimeout; + // array of pixels that we place before continue building (instant-defense) + pixelStack; + // Uint8Array to log pixels in area + area; + userArea; + // current numberical data + curRadius; + curAngle; + curAngleDelta; + // boolean if ended + ended; constructor(centerCell) { // chunk coordinates @@ -39,16 +45,13 @@ class Void { this.ended = false; this.maxClr = canvases[CANVAS_ID].colors.length; const area = TARGET_RADIUS ** 2 * Math.PI; - const online = socketEvents.onlineCounter; + const online = socketEvents.onlineCounter.total || 0; // require an average of 0.25 px / min / user const requiredSpeed = Math.floor(online / 1.8); const ppm = Math.ceil(area / EVENT_DURATION_MIN + requiredSpeed); - // timeout between pixels this.msTimeout = 60 * 1000 / ppm; - // area where we log placed pixels this.area = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3); this.userArea = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3); - // array of pixels that we place before continue building (instant-defense) this.pixelStack = []; this.curRadius = 0; this.curAngle = 0; diff --git a/src/socket/SocketEvents.js b/src/socket/SocketEvents.js index c28753a..e6fde4a 100644 --- a/src/socket/SocketEvents.js +++ b/src/socket/SocketEvents.js @@ -1,5 +1,4 @@ -/* @flow - * +/* * Events for WebSockets */ import EventEmitter from 'events'; @@ -13,31 +12,34 @@ class SocketEvents extends EventEmitter { super(); /* * { + * total: totalUsersOnline, * canvasId: onlineUsers, * ... * } */ - this.onlineCounter = {}; + this.onlineCounter = { + total: 0, + }; } /* * broadcast message via websocket - * @param message Message to send + * @param message Buffer Message to send */ - broadcast(message: Buffer) { + broadcast(message) { this.emit('broadcast', message); } /* * broadcast pixel message via websocket - * @param canvasId ident of canvas - * @param chunkid id consisting of i,j chunk coordinates + * @param canvasId number ident of canvas + * @param chunkid number id consisting of i,j chunk coordinates * @param pxls buffer with offset and color of one or more pixels */ broadcastPixels( - canvasId: number, - chunkId: number, - pixels: Buffer, + canvasId, + chunkId, + pixels, ) { const buffer = PixelUpdate.dehydrate(chunkId, pixels); this.emit('pixelUpdate', canvasId, chunkId, buffer); @@ -50,9 +52,9 @@ class SocketEvents extends EventEmitter { * @param channelId numerical channel id */ recvChatMessage( - user: Object, - message: string, - channelId: number, + user, + message, + channelId, ) { this.emit('recvChatMessage', user, message, channelId); } @@ -65,12 +67,12 @@ class SocketEvents extends EventEmitter { * (usefull if the api is supposed to not answer to its own messages) */ broadcastChatMessage( - name: string, - message: string, - channelId: number, - id: number, - country: string = 'xx', - sendapi: boolean = true, + name, + message, + channelId, + id, + country = 'xx', + sendapi = true, ) { this.emit( 'chatMessage', @@ -87,12 +89,12 @@ class SocketEvents extends EventEmitter { * send chat message to a single user in channel */ broadcastSUChatMessage( - targetUserId: number, - name: string, - message: string, - channelId: number, - id: number, - country: string = 'xx', + targetUserId, + name, + message, + channelId, + id, + country = 'xx', ) { this.emit( 'suChatMessage', @@ -112,9 +114,9 @@ class SocketEvents extends EventEmitter { * @param channelArray array with channel info [name, type, lastTs] */ broadcastAddChatChannel( - userId: number, - channelId: number, - channelArray: Array, + userId, + channelId, + channelArray, ) { this.emit( 'addChatChannel', @@ -131,8 +133,8 @@ class SocketEvents extends EventEmitter { * (i.e. false if the user already gets it via api response) */ broadcastRemoveChatChannel( - userId: number, - channelId: number, + userId, + channelId, ) { this.emit('remChatChannel', userId, channelId); } @@ -140,15 +142,16 @@ class SocketEvents extends EventEmitter { /* * reload user on websocket to get changes */ - reloadUser(name: string) { + reloadUser(name) { this.emit('reloadUser', name); } /* * broadcast online counter - * @param online Number of users online + * @param online Object of total and canvas online users + * (see this.onlineCounter) */ - broadcastOnlineCounter(online: number) { + broadcastOnlineCounter(online) { this.onlineCounter = online; const buffer = OnlineCounter.dehydrate(online); this.emit('broadcast', buffer); diff --git a/src/socket/SocketServer.js b/src/socket/SocketServer.js index f486b6a..d519e00 100644 --- a/src/socket/SocketServer.js +++ b/src/socket/SocketServer.js @@ -4,6 +4,7 @@ import WebSocket from 'ws'; import logger from '../core/logger'; +// eslint-disable-next-line import/no-unresolved import canvases from './canvases.json'; import Counter from '../utils/Counter'; import { getIPFromRequest } from '../utils/ip';