remove flow type definition that are used inconsistently
This commit is contained in:
parent
3f46edf50a
commit
e59df4fb62
|
@ -2,7 +2,6 @@
|
||||||
* Collect api fetch commands for actions here
|
* Collect api fetch commands for actions here
|
||||||
* (chunk and tiles requests in ui/ChunkLoader*.js)
|
* (chunk and tiles requests in ui/ChunkLoader*.js)
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { t } from 'ttag';
|
import { t } from 'ttag';
|
||||||
|
@ -107,7 +106,7 @@ async function makeAPIGETRequest(url) {
|
||||||
* @param block true if block, false if unblock
|
* @param block true if block, false if unblock
|
||||||
* @return error string or null if successful
|
* @return error string or null if successful
|
||||||
*/
|
*/
|
||||||
export async function requestBlock(userId: number, block: boolean) {
|
export async function requestBlock(userId, block) {
|
||||||
const res = await makeAPIPOSTRequest(
|
const res = await makeAPIPOSTRequest(
|
||||||
'api/block',
|
'api/block',
|
||||||
{ userId, block },
|
{ userId, block },
|
||||||
|
@ -123,7 +122,7 @@ export async function requestBlock(userId: number, block: boolean) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* start new DM channel with user
|
* start new DM channel with user
|
||||||
* @param query Object with either userId: number or userName: string
|
* @param query Object with either userId or userName: string
|
||||||
* @return channel Array on success, error string if not
|
* @return channel Array on success, error string if not
|
||||||
*/
|
*/
|
||||||
export async function requestStartDm(query) {
|
export async function requestStartDm(query) {
|
||||||
|
@ -145,7 +144,7 @@ export async function requestStartDm(query) {
|
||||||
* @param block true if blocking all dms, false if unblocking
|
* @param block true if blocking all dms, false if unblocking
|
||||||
* @return error string or null if successful
|
* @return error string or null if successful
|
||||||
*/
|
*/
|
||||||
export async function requestBlockDm(block: boolean) {
|
export async function requestBlockDm(block) {
|
||||||
const res = await makeAPIPOSTRequest(
|
const res = await makeAPIPOSTRequest(
|
||||||
'api/blockdm',
|
'api/blockdm',
|
||||||
{ block },
|
{ block },
|
||||||
|
@ -164,7 +163,7 @@ export async function requestBlockDm(block: boolean) {
|
||||||
* @param channelId 8nteger id of channel
|
* @param channelId 8nteger id of channel
|
||||||
* @return error string or null if successful
|
* @return error string or null if successful
|
||||||
*/
|
*/
|
||||||
export async function requestLeaveChan(channelId: boolean) {
|
export async function requestLeaveChan(channelId) {
|
||||||
const res = await makeAPIPOSTRequest(
|
const res = await makeAPIPOSTRequest(
|
||||||
'api/leavechan',
|
'api/leavechan',
|
||||||
{ channelId },
|
{ channelId },
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import { t } from 'ttag';
|
import { t } from 'ttag';
|
||||||
|
|
||||||
import type {
|
|
||||||
Action,
|
|
||||||
ThunkAction,
|
|
||||||
PromiseAction,
|
|
||||||
} from './types';
|
|
||||||
import type { Cell } from '../core/Cell';
|
|
||||||
import type { ColorIndex } from '../core/Palette';
|
|
||||||
import {
|
import {
|
||||||
requestStartDm,
|
requestStartDm,
|
||||||
requestBlock,
|
requestBlock,
|
||||||
|
@ -17,11 +8,11 @@ import {
|
||||||
} from './fetch';
|
} from './fetch';
|
||||||
|
|
||||||
export function sweetAlert(
|
export function sweetAlert(
|
||||||
title: string,
|
title,
|
||||||
text: string,
|
text,
|
||||||
icon: string,
|
icon,
|
||||||
confirmButtonText: string,
|
confirmButtonText,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'ALERT',
|
type: 'ALERT',
|
||||||
title,
|
title,
|
||||||
|
@ -31,178 +22,178 @@ export function sweetAlert(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function closeAlert(): Action {
|
export function closeAlert() {
|
||||||
return {
|
return {
|
||||||
type: 'CLOSE_ALERT',
|
type: 'CLOSE_ALERT',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleHistoricalView(): Action {
|
export function toggleHistoricalView() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_HISTORICAL_VIEW',
|
type: 'TOGGLE_HISTORICAL_VIEW',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleHiddenCanvases(): Action {
|
export function toggleHiddenCanvases() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_HIDDEN_CANVASES',
|
type: 'TOGGLE_HIDDEN_CANVASES',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleGrid(): Action {
|
export function toggleGrid() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_GRID',
|
type: 'TOGGLE_GRID',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function togglePixelNotify(): Action {
|
export function togglePixelNotify() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_PIXEL_NOTIFY',
|
type: 'TOGGLE_PIXEL_NOTIFY',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleAutoZoomIn(): Action {
|
export function toggleAutoZoomIn() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_AUTO_ZOOM_IN',
|
type: 'TOGGLE_AUTO_ZOOM_IN',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleMute(): Action {
|
export function toggleMute() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_MUTE',
|
type: 'TOGGLE_MUTE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleCompactPalette(): Action {
|
export function toggleCompactPalette() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_COMPACT_PALETTE',
|
type: 'TOGGLE_COMPACT_PALETTE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleChatNotify(): Action {
|
export function toggleChatNotify() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_CHAT_NOTIFY',
|
type: 'TOGGLE_CHAT_NOTIFY',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function togglePotatoMode(): Action {
|
export function togglePotatoMode() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_POTATO_MODE',
|
type: 'TOGGLE_POTATO_MODE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleLightGrid(): Action {
|
export function toggleLightGrid() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_LIGHT_GRID',
|
type: 'TOGGLE_LIGHT_GRID',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleOpenPalette(): Action {
|
export function toggleOpenPalette() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_OPEN_PALETTE',
|
type: 'TOGGLE_OPEN_PALETTE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectStyle(style: string): Action {
|
export function selectStyle(style) {
|
||||||
return {
|
return {
|
||||||
type: 'SELECT_STYLE',
|
type: 'SELECT_STYLE',
|
||||||
style,
|
style,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleOpenMenu(): Action {
|
export function toggleOpenMenu() {
|
||||||
return {
|
return {
|
||||||
type: 'TOGGLE_OPEN_MENU',
|
type: 'TOGGLE_OPEN_MENU',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setRequestingPixel(requestingPixel: boolean): Action {
|
export function setRequestingPixel(requestingPixel: boolean) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_REQUESTING_PIXEL',
|
type: 'SET_REQUESTING_PIXEL',
|
||||||
requestingPixel,
|
requestingPixel,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setNotification(notification: string): Action {
|
export function setNotification(notification) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_NOTIFICATION',
|
type: 'SET_NOTIFICATION',
|
||||||
notification,
|
notification,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unsetNotification(): Action {
|
export function unsetNotification() {
|
||||||
return {
|
return {
|
||||||
type: 'UNSET_NOTIFICATION',
|
type: 'UNSET_NOTIFICATION',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setHover(hover: Cell): Action {
|
export function setHover(hover) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_HOVER',
|
type: 'SET_HOVER',
|
||||||
hover,
|
hover,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unsetHover(): Action {
|
export function unsetHover() {
|
||||||
return {
|
return {
|
||||||
type: 'UNSET_HOVER',
|
type: 'UNSET_HOVER',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setWait(wait: ?number): Action {
|
export function setWait(wait: ?number) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_WAIT',
|
type: 'SET_WAIT',
|
||||||
wait,
|
wait,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setMobile(mobile: boolean): Action {
|
export function setMobile(mobile: boolean) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_MOBILE',
|
type: 'SET_MOBILE',
|
||||||
mobile,
|
mobile,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function windowResize(): Action {
|
export function windowResize() {
|
||||||
return {
|
return {
|
||||||
type: 'WINDOW_RESIZE',
|
type: 'WINDOW_RESIZE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectColor(color: ColorIndex): Action {
|
export function selectColor(color) {
|
||||||
return {
|
return {
|
||||||
type: 'SELECT_COLOR',
|
type: 'SELECT_COLOR',
|
||||||
color,
|
color,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectCanvas(canvasId: number): Action {
|
export function selectCanvas(canvasId) {
|
||||||
return {
|
return {
|
||||||
type: 'SELECT_CANVAS',
|
type: 'SELECT_CANVAS',
|
||||||
canvasId,
|
canvasId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function placedPixels(amount: number): Action {
|
export function placedPixels(amount) {
|
||||||
return {
|
return {
|
||||||
type: 'PLACED_PIXELS',
|
type: 'PLACED_PIXELS',
|
||||||
amount,
|
amount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pixelWait(): Action {
|
export function pixelWait() {
|
||||||
return {
|
return {
|
||||||
type: 'PIXEL_WAIT',
|
type: 'PIXEL_WAIT',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pixelFailure(): Action {
|
export function pixelFailure() {
|
||||||
return {
|
return {
|
||||||
type: 'PIXEL_FAILURE',
|
type: 'PIXEL_FAILURE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveOnline(online: number): Action {
|
export function receiveOnline(online) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_ONLINE',
|
type: 'RECEIVE_ONLINE',
|
||||||
online,
|
online,
|
||||||
|
@ -210,14 +201,14 @@ export function receiveOnline(online: number): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveChatMessage(
|
export function receiveChatMessage(
|
||||||
name: string,
|
name,
|
||||||
text: string,
|
text,
|
||||||
country: string,
|
country,
|
||||||
channel: number,
|
channel,
|
||||||
user: number,
|
user,
|
||||||
isPing: boolean,
|
isPing: boolean,
|
||||||
isRead: boolean,
|
isRead: boolean,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_CHAT_MESSAGE',
|
type: 'RECEIVE_CHAT_MESSAGE',
|
||||||
name,
|
name,
|
||||||
|
@ -231,7 +222,7 @@ export function receiveChatMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
let lastNotify = null;
|
let lastNotify = null;
|
||||||
export function notify(notification: string) {
|
export function notify(notification) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
dispatch(setNotification(notification));
|
dispatch(setNotification(notification));
|
||||||
if (lastNotify) {
|
if (lastNotify) {
|
||||||
|
@ -244,14 +235,14 @@ export function notify(notification: string) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setViewCoordinates(view: Cell): Action {
|
export function setViewCoordinates(view) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_VIEW_COORDINATES',
|
type: 'SET_VIEW_COORDINATES',
|
||||||
view,
|
view,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function move([dx, dy]: Cell): ThunkAction {
|
export function move([dx, dy]) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const { view } = getState().canvas;
|
const { view } = getState().canvas;
|
||||||
|
|
||||||
|
@ -260,7 +251,7 @@ export function move([dx, dy]: Cell): ThunkAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveDirection([vx, vy]: Cell): ThunkAction {
|
export function moveDirection([vx, vy]) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const { viewscale } = getState().canvas;
|
const { viewscale } = getState().canvas;
|
||||||
|
|
||||||
|
@ -269,31 +260,31 @@ export function moveDirection([vx, vy]: Cell): ThunkAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveNorth(): ThunkAction {
|
export function moveNorth() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(moveDirection([0, -1]));
|
dispatch(moveDirection([0, -1]));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveWest(): ThunkAction {
|
export function moveWest() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(moveDirection([-1, 0]));
|
dispatch(moveDirection([-1, 0]));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveSouth(): ThunkAction {
|
export function moveSouth() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(moveDirection([0, 1]));
|
dispatch(moveDirection([0, 1]));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveEast(): ThunkAction {
|
export function moveEast() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(moveDirection([1, 0]));
|
dispatch(moveDirection([1, 0]));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setScale(scale: number, zoompoint: Cell): Action {
|
export function setScale(scale, zoompoint) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_SCALE',
|
type: 'SET_SCALE',
|
||||||
scale,
|
scale,
|
||||||
|
@ -301,7 +292,7 @@ export function setScale(scale: number, zoompoint: Cell): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function zoomIn(zoompoint): ThunkAction {
|
export function zoomIn(zoompoint) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const { scale } = getState().canvas;
|
const { scale } = getState().canvas;
|
||||||
const zoomscale = scale >= 1.0 ? scale * 1.1 : scale * 1.04;
|
const zoomscale = scale >= 1.0 ? scale * 1.1 : scale * 1.04;
|
||||||
|
@ -309,7 +300,7 @@ export function zoomIn(zoompoint): ThunkAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function zoomOut(zoompoint): ThunkAction {
|
export function zoomOut(zoompoint) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const { scale } = getState().canvas;
|
const { scale } = getState().canvas;
|
||||||
const zoomscale = scale >= 1.0 ? scale / 1.1 : scale / 1.04;
|
const zoomscale = scale >= 1.0 ? scale / 1.1 : scale / 1.04;
|
||||||
|
@ -317,7 +308,7 @@ export function zoomOut(zoompoint): ThunkAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestBigChunk(center: Cell): Action {
|
export function requestBigChunk(center) {
|
||||||
return {
|
return {
|
||||||
type: 'REQUEST_BIG_CHUNK',
|
type: 'REQUEST_BIG_CHUNK',
|
||||||
center,
|
center,
|
||||||
|
@ -325,8 +316,8 @@ export function requestBigChunk(center: Cell): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function preLoadedBigChunk(
|
export function preLoadedBigChunk(
|
||||||
center: Cell,
|
center,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'PRE_LOADED_BIG_CHUNK',
|
type: 'PRE_LOADED_BIG_CHUNK',
|
||||||
center,
|
center,
|
||||||
|
@ -334,9 +325,9 @@ export function preLoadedBigChunk(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveBigChunk(
|
export function receiveBigChunk(
|
||||||
center: Cell,
|
center,
|
||||||
chunk: Uint8Array,
|
chunk: Uint8Array,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_BIG_CHUNK',
|
type: 'RECEIVE_BIG_CHUNK',
|
||||||
center,
|
center,
|
||||||
|
@ -344,7 +335,7 @@ export function receiveBigChunk(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveBigChunkFailure(center: Cell, error: Error): Action {
|
export function receiveBigChunkFailure(center, error: Error) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_BIG_CHUNK_FAILURE',
|
type: 'RECEIVE_BIG_CHUNK_FAILURE',
|
||||||
center,
|
center,
|
||||||
|
@ -353,8 +344,8 @@ export function receiveBigChunkFailure(center: Cell, error: Error): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveCoolDown(
|
export function receiveCoolDown(
|
||||||
wait: number,
|
wait,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_COOLDOWN',
|
type: 'RECEIVE_COOLDOWN',
|
||||||
wait,
|
wait,
|
||||||
|
@ -362,11 +353,11 @@ export function receiveCoolDown(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updatePixel(
|
export function updatePixel(
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
offset: number,
|
offset,
|
||||||
color: ColorIndex,
|
color,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'UPDATE_PIXEL',
|
type: 'UPDATE_PIXEL',
|
||||||
i,
|
i,
|
||||||
|
@ -377,8 +368,8 @@ export function updatePixel(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loginUser(
|
export function loginUser(
|
||||||
me: Object,
|
me,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'LOGIN',
|
type: 'LOGIN',
|
||||||
...me,
|
...me,
|
||||||
|
@ -386,8 +377,8 @@ export function loginUser(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveMe(
|
export function receiveMe(
|
||||||
me: Object,
|
me,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_ME',
|
type: 'RECEIVE_ME',
|
||||||
...me,
|
...me,
|
||||||
|
@ -395,15 +386,15 @@ export function receiveMe(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logoutUser(
|
export function logoutUser(
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'LOGOUT',
|
type: 'LOGOUT',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function receiveStats(
|
export function receiveStats(
|
||||||
rankings: Object,
|
rankings,
|
||||||
): Action {
|
) {
|
||||||
const { ranking: totalRanking, dailyRanking: totalDailyRanking } = rankings;
|
const { ranking: totalRanking, dailyRanking: totalDailyRanking } = rankings;
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_STATS',
|
type: 'RECEIVE_STATS',
|
||||||
|
@ -413,8 +404,8 @@ export function receiveStats(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setName(
|
export function setName(
|
||||||
name: string,
|
name,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_NAME',
|
type: 'SET_NAME',
|
||||||
name,
|
name,
|
||||||
|
@ -423,7 +414,7 @@ export function setName(
|
||||||
|
|
||||||
export function setMailreg(
|
export function setMailreg(
|
||||||
mailreg: boolean,
|
mailreg: boolean,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_MAILREG',
|
type: 'SET_MAILREG',
|
||||||
mailreg,
|
mailreg,
|
||||||
|
@ -431,15 +422,15 @@ export function setMailreg(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function remFromMessages(
|
export function remFromMessages(
|
||||||
message: string,
|
message,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'REM_FROM_MESSAGES',
|
type: 'REM_FROM_MESSAGES',
|
||||||
message,
|
message,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchStats(): PromiseAction {
|
export function fetchStats() {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
const response = await fetch('api/ranking', { credentials: 'include' });
|
const response = await fetch('api/ranking', { credentials: 'include' });
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
@ -450,7 +441,7 @@ export function fetchStats(): PromiseAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchMe(): PromiseAction {
|
export function fetchMe() {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
const response = await fetch('api/me', {
|
const response = await fetch('api/me', {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
|
@ -464,9 +455,9 @@ export function fetchMe(): PromiseAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
function receiveChatHistory(
|
function receiveChatHistory(
|
||||||
cid: number,
|
cid,
|
||||||
history: Array,
|
history,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'RECEIVE_CHAT_HISTORY',
|
type: 'RECEIVE_CHAT_HISTORY',
|
||||||
cid,
|
cid,
|
||||||
|
@ -474,14 +465,14 @@ function receiveChatHistory(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setChatFetching(fetching: boolean): Action {
|
function setChatFetching(fetching: boolean) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_CHAT_FETCHING',
|
type: 'SET_CHAT_FETCHING',
|
||||||
fetching,
|
fetching,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setApiFetching(fetching: boolean): Action {
|
function setApiFetching(fetching: boolean) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_API_FETCHING',
|
type: 'SET_API_FETCHING',
|
||||||
fetching,
|
fetching,
|
||||||
|
@ -489,8 +480,8 @@ function setApiFetching(fetching: boolean): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchChatMessages(
|
export function fetchChatMessages(
|
||||||
cid: number,
|
cid,
|
||||||
): PromiseAction {
|
) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
dispatch(setChatFetching(true));
|
dispatch(setChatFetching(true));
|
||||||
const response = await fetch(`api/chathistory?cid=${cid}&limit=50`, {
|
const response = await fetch(`api/chathistory?cid=${cid}&limit=50`, {
|
||||||
|
@ -510,20 +501,20 @@ export function fetchChatMessages(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCoolDown(coolDown): Action {
|
function setCoolDown(coolDown) {
|
||||||
return {
|
return {
|
||||||
type: 'COOLDOWN_SET',
|
type: 'COOLDOWN_SET',
|
||||||
coolDown,
|
coolDown,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function endCoolDown(): Action {
|
function endCoolDown() {
|
||||||
return {
|
return {
|
||||||
type: 'COOLDOWN_END',
|
type: 'COOLDOWN_END',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPendingActions(state): Array<Action> {
|
function getPendingActions(state) {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
@ -539,7 +530,7 @@ function getPendingActions(state): Array<Action> {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initTimer(): ThunkAction {
|
export function initTimer() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
function tick() {
|
function tick() {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -556,16 +547,16 @@ export function initTimer(): ThunkAction {
|
||||||
* fullscreen means to open as modal
|
* fullscreen means to open as modal
|
||||||
*/
|
*/
|
||||||
export function openWindow(
|
export function openWindow(
|
||||||
windowType: string,
|
windowType,
|
||||||
title: string,
|
title,
|
||||||
fullscreen: boolean,
|
fullscreen: boolean,
|
||||||
cloneable: boolean,
|
cloneable: boolean,
|
||||||
args: Object,
|
args,
|
||||||
xPos: number = null,
|
xPos = null,
|
||||||
yPos: number = null,
|
yPos = null,
|
||||||
width: number = null,
|
width = null,
|
||||||
height: number = null,
|
height = null,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'OPEN_WINDOW',
|
type: 'OPEN_WINDOW',
|
||||||
windowType,
|
windowType,
|
||||||
|
@ -580,7 +571,7 @@ export function openWindow(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showModal(modalType: string, title: string): Action {
|
export function showModal(modalType, title) {
|
||||||
return openWindow(
|
return openWindow(
|
||||||
modalType,
|
modalType,
|
||||||
title,
|
title,
|
||||||
|
@ -590,14 +581,14 @@ export function showModal(modalType: string, title: string): Action {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showSettingsModal(): Action {
|
export function showSettingsModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'SETTINGS',
|
'SETTINGS',
|
||||||
'',
|
'',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showUserAreaModal(): Action {
|
export function showUserAreaModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'USERAREA',
|
'USERAREA',
|
||||||
'',
|
'',
|
||||||
|
@ -621,34 +612,34 @@ export function setWindowTitle(windowId, title) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showRegisterModal(): Action {
|
export function showRegisterModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'REGISTER',
|
'REGISTER',
|
||||||
t`Register New Account`,
|
t`Register New Account`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showForgotPasswordModal(): Action {
|
export function showForgotPasswordModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'FORGOT_PASSWORD',
|
'FORGOT_PASSWORD',
|
||||||
t`Restore my Password`,
|
t`Restore my Password`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showHelpModal(): Action {
|
export function showHelpModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'HELP',
|
'HELP',
|
||||||
t`Welcome to PixelPlanet.fun`,
|
t`Welcome to PixelPlanet.fun`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export function showArchiveModal(): Action {
|
export function showArchiveModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'ARCHIVE',
|
'ARCHIVE',
|
||||||
t`Look at past Canvases`,
|
t`Look at past Canvases`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showCanvasSelectionModal(): Action {
|
export function showCanvasSelectionModal() {
|
||||||
return showModal(
|
return showModal(
|
||||||
'CANVAS_SELECTION',
|
'CANVAS_SELECTION',
|
||||||
'',
|
'',
|
||||||
|
@ -656,11 +647,11 @@ export function showCanvasSelectionModal(): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showContextMenu(
|
export function showContextMenu(
|
||||||
menuType: string,
|
menuType,
|
||||||
xPos: number,
|
xPos,
|
||||||
yPos: number,
|
yPos,
|
||||||
args: Object,
|
args,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'SHOW_CONTEXT_MENU',
|
type: 'SHOW_CONTEXT_MENU',
|
||||||
menuType,
|
menuType,
|
||||||
|
@ -670,28 +661,28 @@ export function showContextMenu(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openChatChannel(cid: number): Action {
|
export function openChatChannel(cid) {
|
||||||
return {
|
return {
|
||||||
type: 'OPEN_CHAT_CHANNEL',
|
type: 'OPEN_CHAT_CHANNEL',
|
||||||
cid,
|
cid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function closeChatChannel(cid: number): Action {
|
export function closeChatChannel(cid) {
|
||||||
return {
|
return {
|
||||||
type: 'CLOSE_CHAT_CHANNEL',
|
type: 'CLOSE_CHAT_CHANNEL',
|
||||||
cid,
|
cid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addChatChannel(channel: Object): Action {
|
export function addChatChannel(channel) {
|
||||||
return {
|
return {
|
||||||
type: 'ADD_CHAT_CHANNEL',
|
type: 'ADD_CHAT_CHANNEL',
|
||||||
channel,
|
channel,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function blockUser(userId: number, userName: string): Action {
|
export function blockUser(userId, userName) {
|
||||||
return {
|
return {
|
||||||
type: 'BLOCK_USER',
|
type: 'BLOCK_USER',
|
||||||
userId,
|
userId,
|
||||||
|
@ -699,7 +690,7 @@ export function blockUser(userId: number, userName: string): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unblockUser(userId: number, userName: string): Action {
|
export function unblockUser(userId, userName) {
|
||||||
return {
|
return {
|
||||||
type: 'UNBLOCK_USER',
|
type: 'UNBLOCK_USER',
|
||||||
userId,
|
userId,
|
||||||
|
@ -707,35 +698,35 @@ export function unblockUser(userId: number, userName: string): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function blockingDm(blockDm: boolean): Action {
|
export function blockingDm(blockDm: boolean) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_BLOCKING_DM',
|
type: 'SET_BLOCKING_DM',
|
||||||
blockDm,
|
blockDm,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeChatChannel(cid: number): Action {
|
export function removeChatChannel(cid) {
|
||||||
return {
|
return {
|
||||||
type: 'REMOVE_CHAT_CHANNEL',
|
type: 'REMOVE_CHAT_CHANNEL',
|
||||||
cid,
|
cid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function muteChatChannel(cid: number): Action {
|
export function muteChatChannel(cid) {
|
||||||
return {
|
return {
|
||||||
type: 'MUTE_CHAT_CHANNEL',
|
type: 'MUTE_CHAT_CHANNEL',
|
||||||
cid,
|
cid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unmuteChatChannel(cid: number): Action {
|
export function unmuteChatChannel(cid) {
|
||||||
return {
|
return {
|
||||||
type: 'UNMUTE_CHAT_CHANNEL',
|
type: 'UNMUTE_CHAT_CHANNEL',
|
||||||
cid,
|
cid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setChatChannel(windowId: number, cid: number): Action {
|
export function setChatChannel(windowId, cid) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_CHAT_CHANNEL',
|
type: 'SET_CHAT_CHANNEL',
|
||||||
windowId,
|
windowId,
|
||||||
|
@ -743,7 +734,7 @@ export function setChatChannel(windowId: number, cid: number): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setChatInputMessage(windowId: number, msg: string): Action {
|
export function setChatInputMessage(windowId, msg) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_CHAT_INPUT_MSG',
|
type: 'SET_CHAT_INPUT_MSG',
|
||||||
windowId,
|
windowId,
|
||||||
|
@ -751,7 +742,7 @@ export function setChatInputMessage(windowId: number, msg: string): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addToChatInputMessage(windowId: number, msg: string): Action {
|
export function addToChatInputMessage(windowId, msg) {
|
||||||
return {
|
return {
|
||||||
type: 'ADD_CHAT_INPUT_MSG',
|
type: 'ADD_CHAT_INPUT_MSG',
|
||||||
windowId,
|
windowId,
|
||||||
|
@ -759,48 +750,48 @@ export function addToChatInputMessage(windowId: number, msg: string): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function closeWindow(windowId): Action {
|
export function closeWindow(windowId) {
|
||||||
return {
|
return {
|
||||||
type: 'CLOSE_WINDOW',
|
type: 'CLOSE_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeWindow(windowId): Action {
|
export function removeWindow(windowId) {
|
||||||
return {
|
return {
|
||||||
type: 'REMOVE_WINDOW',
|
type: 'REMOVE_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function focusWindow(windowId): Action {
|
export function focusWindow(windowId) {
|
||||||
return {
|
return {
|
||||||
type: 'FOCUS_WINDOW',
|
type: 'FOCUS_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function cloneWindow(windowId): Action {
|
export function cloneWindow(windowId) {
|
||||||
return {
|
return {
|
||||||
type: 'CLONE_WINDOW',
|
type: 'CLONE_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function maximizeWindow(windowId): Action {
|
export function maximizeWindow(windowId) {
|
||||||
return {
|
return {
|
||||||
type: 'MAXIMIZE_WINDOW',
|
type: 'MAXIMIZE_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function restoreWindow(): Action {
|
export function restoreWindow() {
|
||||||
return {
|
return {
|
||||||
type: 'RESTORE_WINDOW',
|
type: 'RESTORE_WINDOW',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function moveWindow(windowId, xDiff, yDiff): Action {
|
export function moveWindow(windowId, xDiff, yDiff) {
|
||||||
return {
|
return {
|
||||||
type: 'MOVE_WINDOW',
|
type: 'MOVE_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
|
@ -809,7 +800,7 @@ export function moveWindow(windowId, xDiff, yDiff): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resizeWindow(windowId, xDiff, yDiff): Action {
|
export function resizeWindow(windowId, xDiff, yDiff) {
|
||||||
return {
|
return {
|
||||||
type: 'RESIZE_WINDOW',
|
type: 'RESIZE_WINDOW',
|
||||||
windowId,
|
windowId,
|
||||||
|
@ -818,7 +809,7 @@ export function resizeWindow(windowId, xDiff, yDiff): Action {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function closeAllWindowTypes(windowType: string): Action {
|
export function closeAllWindowTypes(windowType) {
|
||||||
return {
|
return {
|
||||||
type: 'CLOSE_ALL_WINDOW_TYPE',
|
type: 'CLOSE_ALL_WINDOW_TYPE',
|
||||||
windowType,
|
windowType,
|
||||||
|
@ -826,9 +817,9 @@ export function closeAllWindowTypes(windowType: string): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hideAllWindowTypes(
|
export function hideAllWindowTypes(
|
||||||
windowType: string,
|
windowType,
|
||||||
hide: boolean,
|
hide: boolean,
|
||||||
): Action {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'HIDE_ALL_WINDOW_TYPE',
|
type: 'HIDE_ALL_WINDOW_TYPE',
|
||||||
windowType,
|
windowType,
|
||||||
|
@ -836,7 +827,7 @@ export function hideAllWindowTypes(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openChatWindow(): Action {
|
export function openChatWindow() {
|
||||||
return openWindow(
|
return openWindow(
|
||||||
'CHAT',
|
'CHAT',
|
||||||
'',
|
'',
|
||||||
|
@ -851,9 +842,9 @@ export function openChatWindow(): Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* query: Object with either userId: number or userName: string
|
* query with either userId or userName
|
||||||
*/
|
*/
|
||||||
export function startDm(windowId, query): PromiseAction {
|
export function startDm(windowId, query) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
dispatch(setApiFetching(true));
|
dispatch(setApiFetching(true));
|
||||||
const res = await requestStartDm(query);
|
const res = await requestStartDm(query);
|
||||||
|
@ -873,7 +864,7 @@ export function startDm(windowId, query): PromiseAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function gotCoolDownDelta(delta: number) {
|
export function gotCoolDownDelta(delta) {
|
||||||
return {
|
return {
|
||||||
type: 'COOLDOWN_DELTA',
|
type: 'COOLDOWN_DELTA',
|
||||||
delta,
|
delta,
|
||||||
|
@ -881,8 +872,8 @@ export function gotCoolDownDelta(delta: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setUserBlock(
|
export function setUserBlock(
|
||||||
userId: number,
|
userId,
|
||||||
userName: string,
|
userName,
|
||||||
block: boolean,
|
block: boolean,
|
||||||
) {
|
) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
|
@ -925,7 +916,7 @@ export function setBlockingDm(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setLeaveChannel(
|
export function setLeaveChannel(
|
||||||
cid: number,
|
cid,
|
||||||
) {
|
) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
dispatch(setApiFetching(true));
|
dispatch(setApiFetching(true));
|
||||||
|
@ -944,25 +935,25 @@ export function setLeaveChannel(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hideContextMenu(): Action {
|
export function hideContextMenu() {
|
||||||
return {
|
return {
|
||||||
type: 'HIDE_CONTEXT_MENU',
|
type: 'HIDE_CONTEXT_MENU',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function reloadUrl(): Action {
|
export function reloadUrl() {
|
||||||
return {
|
return {
|
||||||
type: 'RELOAD_URL',
|
type: 'RELOAD_URL',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onViewFinishChange(): Action {
|
export function onViewFinishChange() {
|
||||||
return {
|
return {
|
||||||
type: 'ON_VIEW_FINISH_CHANGE',
|
type: 'ON_VIEW_FINISH_CHANGE',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectHistoricalTime(date: string, time: string) {
|
export function selectHistoricalTime(date, time) {
|
||||||
return {
|
return {
|
||||||
type: 'SET_HISTORICAL_TIME',
|
type: 'SET_HISTORICAL_TIME',
|
||||||
date,
|
date,
|
||||||
|
@ -970,7 +961,7 @@ export function selectHistoricalTime(date: string, time: string) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function urlChange(): PromiseAction {
|
export function urlChange() {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
dispatch(reloadUrl());
|
dispatch(reloadUrl());
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import type { Cell } from '../core/Cell';
|
|
||||||
import type { ColorIndex } from '../core/Palette';
|
import type { ColorIndex } from '../core/Palette';
|
||||||
import type { State } from '../reducers';
|
import type { State } from '../reducers';
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ export type Action =
|
||||||
| { type: 'SET_NOTIFICATION', notification: string }
|
| { type: 'SET_NOTIFICATION', notification: string }
|
||||||
| { type: 'UNSET_NOTIFICATION' }
|
| { type: 'UNSET_NOTIFICATION' }
|
||||||
| { type: 'SET_REQUESTING_PIXEL', requestingPixel: boolean }
|
| { type: 'SET_REQUESTING_PIXEL', requestingPixel: boolean }
|
||||||
| { type: 'SET_HOVER', hover: Cell }
|
| { type: 'SET_HOVER', hover: Array }
|
||||||
| { type: 'UNSET_HOVER' }
|
| { type: 'UNSET_HOVER' }
|
||||||
| { type: 'SET_WAIT', wait: ?number }
|
| { type: 'SET_WAIT', wait: ?number }
|
||||||
| { type: 'RECEIVE_COOLDOWN', wait: number }
|
| { type: 'RECEIVE_COOLDOWN', wait: number }
|
||||||
|
@ -44,12 +43,12 @@ export type Action =
|
||||||
| { type: 'PLACED_PIXELS', amount: number }
|
| { type: 'PLACED_PIXELS', amount: number }
|
||||||
| { type: 'PIXEL_WAIT' }
|
| { type: 'PIXEL_WAIT' }
|
||||||
| { type: 'PIXEL_FAILURE' }
|
| { type: 'PIXEL_FAILURE' }
|
||||||
| { type: 'SET_VIEW_COORDINATES', view: Cell }
|
| { type: 'SET_VIEW_COORDINATES', view: Array }
|
||||||
| { type: 'SET_SCALE', scale: number, zoompoint: Cell }
|
| { type: 'SET_SCALE', scale: number, zoompoint: Array }
|
||||||
| { type: 'REQUEST_BIG_CHUNK', center: Cell }
|
| { type: 'REQUEST_BIG_CHUNK', center: Array }
|
||||||
| { type: 'PRE_LOADED_BIG_CHUNK', center: Cell }
|
| { type: 'PRE_LOADED_BIG_CHUNK', center: Array }
|
||||||
| { type: 'RECEIVE_BIG_CHUNK', center: Cell, chunk: Uint8Array }
|
| { type: 'RECEIVE_BIG_CHUNK', center: Array, chunk: Uint8Array }
|
||||||
| { type: 'RECEIVE_BIG_CHUNK_FAILURE', center: Cell, error: Error }
|
| { type: 'RECEIVE_BIG_CHUNK_FAILURE', center: Array, error: Error }
|
||||||
| { type: 'UPDATE_PIXEL',
|
| { type: 'UPDATE_PIXEL',
|
||||||
i: number,
|
i: number,
|
||||||
j: number,
|
j: number,
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
export type Index = number; // TODO integer >= 0
|
|
||||||
export type Cell = [number, number, number];
|
|
|
@ -1,8 +1,8 @@
|
||||||
/* @flow */
|
/*
|
||||||
|
* draw pixel on canvas
|
||||||
|
*/
|
||||||
import { using } from 'bluebird';
|
import { using } from 'bluebird';
|
||||||
|
|
||||||
import type { User } from '../data/models';
|
|
||||||
import { redlock } from '../data/redis';
|
import { redlock } from '../data/redis';
|
||||||
import {
|
import {
|
||||||
getPixelFromChunkOffset,
|
getPixelFromChunkOffset,
|
||||||
|
@ -34,12 +34,12 @@ import { THREE_CANVAS_HEIGHT, THREE_TILE_SIZE, TILE_SIZE } from './constants';
|
||||||
* @return Promise<Object>
|
* @return Promise<Object>
|
||||||
*/
|
*/
|
||||||
export async function drawByOffsets(
|
export async function drawByOffsets(
|
||||||
user: User,
|
user,
|
||||||
canvasId: number,
|
canvasId,
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
pixels: Array,
|
pixels,
|
||||||
): Promise<Object> {
|
) {
|
||||||
let wait = 0;
|
let wait = 0;
|
||||||
let coolDown = 0;
|
let coolDown = 0;
|
||||||
let retCode = 0;
|
let retCode = 0;
|
||||||
|
@ -199,13 +199,13 @@ export async function drawByOffsets(
|
||||||
* @returns {Promise.<Object>}
|
* @returns {Promise.<Object>}
|
||||||
*/
|
*/
|
||||||
export async function drawByCoords(
|
export async function drawByCoords(
|
||||||
user: User,
|
user,
|
||||||
canvasId: number,
|
canvasId,
|
||||||
color: ColorIndex,
|
color,
|
||||||
x: number,
|
x,
|
||||||
y: number,
|
y,
|
||||||
z: number = null,
|
z = null,
|
||||||
): Promise<Object> {
|
) {
|
||||||
if (!({}.hasOwnProperty.call(canvases, canvasId))) {
|
if (!({}.hasOwnProperty.call(canvases, canvasId))) {
|
||||||
return {
|
return {
|
||||||
error: 'This canvas does not exist',
|
error: 'This canvas does not exist',
|
||||||
|
@ -369,13 +369,13 @@ export async function drawByCoords(
|
||||||
* @param z (optional for 3d canvas)
|
* @param z (optional for 3d canvas)
|
||||||
*/
|
*/
|
||||||
export function drawSafeByCoords(
|
export function drawSafeByCoords(
|
||||||
user: User,
|
user,
|
||||||
canvasId: number,
|
canvasId,
|
||||||
color: ColorIndex,
|
color,
|
||||||
x: number,
|
x,
|
||||||
y: number,
|
y,
|
||||||
z: number = null,
|
z = null,
|
||||||
): Promise<Object> {
|
) {
|
||||||
// can just check for one unique occurence,
|
// can just check for one unique occurence,
|
||||||
// we use ip, because id for logged out users is
|
// we use ip, because id for logged out users is
|
||||||
// always null
|
// always null
|
||||||
|
@ -407,12 +407,12 @@ export function drawSafeByCoords(
|
||||||
* @return Promise<Object>
|
* @return Promise<Object>
|
||||||
*/
|
*/
|
||||||
export function drawSafeByOffsets(
|
export function drawSafeByOffsets(
|
||||||
user: User,
|
user,
|
||||||
canvasId: number,
|
canvasId,
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
pixels: Array,
|
pixels,
|
||||||
): Promise<Object> {
|
) {
|
||||||
// can just check for one unique occurence,
|
// can just check for one unique occurence,
|
||||||
// we use ip, because id for logged out users is
|
// we use ip, because id for logged out users is
|
||||||
// always null
|
// always null
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Set pixels on canvas.
|
* Set pixels on canvas.
|
||||||
* Pixels get collected in a cache for 5ms and sent to players at once.
|
* Pixels get collected in a cache for 5ms and sent to players at once.
|
||||||
* @flow
|
|
||||||
* */
|
* */
|
||||||
import RedisCanvas from '../data/models/RedisCanvas';
|
import RedisCanvas from '../data/models/RedisCanvas';
|
||||||
import {
|
import {
|
||||||
|
@ -22,11 +21,11 @@ import canvases from './canvases.json';
|
||||||
* @param offset Offset of pixel withing chunk
|
* @param offset Offset of pixel withing chunk
|
||||||
*/
|
*/
|
||||||
export function setPixelByOffset(
|
export function setPixelByOffset(
|
||||||
canvasId: number,
|
canvasId,
|
||||||
color: ColorIndex,
|
color,
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
offset: number,
|
offset,
|
||||||
) {
|
) {
|
||||||
RedisCanvas.setPixelInChunk(i, j, offset, color, canvasId);
|
RedisCanvas.setPixelInChunk(i, j, offset, color, canvasId);
|
||||||
pixelCache.append(canvasId, color, i, j, offset);
|
pixelCache.append(canvasId, color, i, j, offset);
|
||||||
|
@ -42,11 +41,11 @@ export function setPixelByOffset(
|
||||||
* @param z optional, if given its 3d canvas
|
* @param z optional, if given its 3d canvas
|
||||||
*/
|
*/
|
||||||
export function setPixelByCoords(
|
export function setPixelByCoords(
|
||||||
canvasId: number,
|
canvasId,
|
||||||
color: ColorIndex,
|
color,
|
||||||
x: number,
|
x,
|
||||||
y: number,
|
y,
|
||||||
z: number = null,
|
z = null,
|
||||||
) {
|
) {
|
||||||
const canvasSize = canvases[canvasId].size;
|
const canvasSize = canvases[canvasId].size;
|
||||||
const [i, j] = getChunkOfPixel(canvasSize, x, y, z);
|
const [i, j] = getChunkOfPixel(canvasSize, x, y, z);
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
/* @flow
|
/*
|
||||||
*
|
|
||||||
* creation of tiles
|
* creation of tiles
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
import type { Cell } from './Cell';
|
|
||||||
import logger from './logger';
|
import logger from './logger';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import canvases from './canvases.json';
|
import canvases from './canvases.json';
|
||||||
|
@ -31,14 +29,14 @@ import { mod, getMaxTiledZoom } from './utils';
|
||||||
const CanvasUpdaters = {};
|
const CanvasUpdaters = {};
|
||||||
|
|
||||||
class CanvasUpdater {
|
class CanvasUpdater {
|
||||||
TileLoadingQueues: Array;
|
TileLoadingQueues;
|
||||||
palette: Palette;
|
palette;
|
||||||
id: number;
|
id;
|
||||||
canvas: Object;
|
canvas;
|
||||||
firstZoomtileWidth: number;
|
firstZoomtileWidth;
|
||||||
canvasTileFolder: string;
|
canvasTileFolder;
|
||||||
|
|
||||||
constructor(id: number) {
|
constructor(id) {
|
||||||
this.updateZoomlevelTiles = this.updateZoomlevelTiles.bind(this);
|
this.updateZoomlevelTiles = this.updateZoomlevelTiles.bind(this);
|
||||||
|
|
||||||
this.TileLoadingQueues = [];
|
this.TileLoadingQueues = [];
|
||||||
|
@ -54,7 +52,7 @@ class CanvasUpdater {
|
||||||
/*
|
/*
|
||||||
* @param zoom tilezoomlevel to update
|
* @param zoom tilezoomlevel to update
|
||||||
*/
|
*/
|
||||||
async updateZoomlevelTiles(zoom: number) {
|
async updateZoomlevelTiles(zoom) {
|
||||||
const queue = this.TileLoadingQueues[zoom];
|
const queue = this.TileLoadingQueues[zoom];
|
||||||
if (typeof queue === 'undefined') return;
|
if (typeof queue === 'undefined') return;
|
||||||
|
|
||||||
|
@ -104,7 +102,7 @@ class CanvasUpdater {
|
||||||
* register changed chunk, queue corespongind tile to reload
|
* register changed chunk, queue corespongind tile to reload
|
||||||
* @param chunk Chunk coordinates
|
* @param chunk Chunk coordinates
|
||||||
*/
|
*/
|
||||||
registerChunkChange(chunk: Cell) {
|
registerChunkChange(chunk) {
|
||||||
const queue = this.TileLoadingQueues[Math.max(this.maxTiledZoom - 1, 0)];
|
const queue = this.TileLoadingQueues[Math.max(this.maxTiledZoom - 1, 0)];
|
||||||
if (typeof queue === 'undefined') return;
|
if (typeof queue === 'undefined') return;
|
||||||
|
|
||||||
|
@ -154,7 +152,7 @@ class CanvasUpdater {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerChunkChange(canvasId: number, chunk: Cell) {
|
export function registerChunkChange(canvasId, chunk) {
|
||||||
if (CanvasUpdaters[canvasId]) {
|
if (CanvasUpdaters[canvasId]) {
|
||||||
CanvasUpdaters[canvasId].registerChunkChange(chunk);
|
CanvasUpdaters[canvasId].registerChunkChange(chunk);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import type { Cell } from './Cell';
|
|
||||||
import type { State } from '../reducers';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
TILE_SIZE,
|
TILE_SIZE,
|
||||||
|
@ -15,7 +11,7 @@ import {
|
||||||
* @param m
|
* @param m
|
||||||
* @returns {number} remainder
|
* @returns {number} remainder
|
||||||
*/
|
*/
|
||||||
export function mod(n: number, m: number): number {
|
export function mod(n, m) {
|
||||||
return ((n % m) + m) % m;
|
return ((n % m) + m) % m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,18 +26,18 @@ export function getRandomInt(min, max) {
|
||||||
return min + (Math.floor(Math.random() * range));
|
return min + (Math.floor(Math.random() * range));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function distMax([x1, y1]: Cell, [x2, y2]: Cell): number {
|
export function distMax([x1, y1], [x2, y2]) {
|
||||||
return Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
|
return Math.max(Math.abs(x1 - x2), Math.abs(y1 - y2));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clamp(n: number, min: number, max: number): number {
|
export function clamp(n, min, max) {
|
||||||
return Math.max(min, Math.min(n, max));
|
return Math.max(min, Math.min(n, max));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* convert YYYY-MM-DD to YYYYMMDD
|
* convert YYYY-MM-DD to YYYYMMDD
|
||||||
*/
|
*/
|
||||||
export function dateToString(date: string) {
|
export function dateToString(date) {
|
||||||
// YYYY-MM-DD
|
// YYYY-MM-DD
|
||||||
return date.substr(0, 4) + date.substr(5, 2) + date.substr(8, 2);
|
return date.substr(0, 4) + date.substr(5, 2) + date.substr(8, 2);
|
||||||
}
|
}
|
||||||
|
@ -61,11 +57,11 @@ export function getToday() {
|
||||||
// z is assumed to be height here
|
// z is assumed to be height here
|
||||||
// in ui and rendeer, y is height
|
// in ui and rendeer, y is height
|
||||||
export function getChunkOfPixel(
|
export function getChunkOfPixel(
|
||||||
canvasSize: number,
|
canvasSize,
|
||||||
x: number,
|
x,
|
||||||
y: number,
|
y,
|
||||||
z: number = null,
|
z = null,
|
||||||
): Cell {
|
) {
|
||||||
const tileSize = (z === null) ? TILE_SIZE : THREE_TILE_SIZE;
|
const tileSize = (z === null) ? TILE_SIZE : THREE_TILE_SIZE;
|
||||||
const width = (z == null) ? y : z;
|
const width = (z == null) ? y : z;
|
||||||
const cx = Math.floor((x + (canvasSize / 2)) / tileSize);
|
const cx = Math.floor((x + (canvasSize / 2)) / tileSize);
|
||||||
|
@ -74,25 +70,25 @@ export function getChunkOfPixel(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTileOfPixel(
|
export function getTileOfPixel(
|
||||||
tileScale: number,
|
tileScale,
|
||||||
pixel: Cell,
|
pixel,
|
||||||
canvasSize: number = null,
|
canvasSize = null,
|
||||||
): Cell {
|
) {
|
||||||
const target = pixel.map(
|
const target = pixel.map(
|
||||||
(x) => Math.floor((x + canvasSize / 2) / TILE_SIZE * tileScale),
|
(x) => Math.floor((x + canvasSize / 2) / TILE_SIZE * tileScale),
|
||||||
);
|
);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMaxTiledZoom(canvasSize: number): number {
|
export function getMaxTiledZoom(canvasSize) {
|
||||||
if (!canvasSize) return 0;
|
if (!canvasSize) return 0;
|
||||||
return Math.log2(canvasSize / TILE_SIZE) / TILE_ZOOM_LEVEL * 2;
|
return Math.log2(canvasSize / TILE_SIZE) / TILE_ZOOM_LEVEL * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getHistoricalCanvasSize(
|
export function getHistoricalCanvasSize(
|
||||||
historicalDate: string,
|
historicalDate,
|
||||||
canvasSize: number,
|
canvasSize,
|
||||||
historicalSizes: Array,
|
historicalSizes,
|
||||||
) {
|
) {
|
||||||
if (historicalDate && historicalSizes) {
|
if (historicalDate && historicalSizes) {
|
||||||
let i = historicalSizes.length;
|
let i = historicalSizes.length;
|
||||||
|
@ -107,7 +103,7 @@ export function getHistoricalCanvasSize(
|
||||||
return canvasSize;
|
return canvasSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCanvasBoundaries(canvasSize: number): number {
|
export function getCanvasBoundaries(canvasSize) {
|
||||||
const canvasMinXY = -canvasSize / 2;
|
const canvasMinXY = -canvasSize / 2;
|
||||||
const canvasMaxXY = canvasSize / 2 - 1;
|
const canvasMaxXY = canvasSize / 2 - 1;
|
||||||
return [canvasMinXY, canvasMaxXY];
|
return [canvasMinXY, canvasMaxXY];
|
||||||
|
@ -116,11 +112,11 @@ export function getCanvasBoundaries(canvasSize: number): number {
|
||||||
// z is assumed to be height here
|
// z is assumed to be height here
|
||||||
// in ui and rendeer, y is height
|
// in ui and rendeer, y is height
|
||||||
export function getOffsetOfPixel(
|
export function getOffsetOfPixel(
|
||||||
canvasSize: number,
|
canvasSize,
|
||||||
x: number,
|
x,
|
||||||
y: number,
|
y,
|
||||||
z: number = null,
|
z = null,
|
||||||
): number {
|
) {
|
||||||
const tileSize = (z === null) ? TILE_SIZE : THREE_TILE_SIZE;
|
const tileSize = (z === null) ? TILE_SIZE : THREE_TILE_SIZE;
|
||||||
const width = (z == null) ? y : z;
|
const width = (z == null) ? y : z;
|
||||||
let offset = (z === null) ? 0 : (y * tileSize * tileSize);
|
let offset = (z === null) ? 0 : (y * tileSize * tileSize);
|
||||||
|
@ -138,7 +134,7 @@ export function getOffsetOfPixel(
|
||||||
* @param ident ident string
|
* @param ident ident string
|
||||||
* @return key
|
* @return key
|
||||||
*/
|
*/
|
||||||
export function getIdFromObject(obj: Object, ident: string): number {
|
export function getIdFromObject(obj, ident) {
|
||||||
const ids = Object.keys(obj);
|
const ids = Object.keys(obj);
|
||||||
for (let i = 0; i < ids.length; i += 1) {
|
for (let i = 0; i < ids.length; i += 1) {
|
||||||
const key = ids[i];
|
const key = ids[i];
|
||||||
|
@ -152,12 +148,12 @@ export function getIdFromObject(obj: Object, ident: string): number {
|
||||||
// z is returned as height here
|
// z is returned as height here
|
||||||
// in ui and rendeer, y is height
|
// in ui and rendeer, y is height
|
||||||
export function getPixelFromChunkOffset(
|
export function getPixelFromChunkOffset(
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
offset: number,
|
offset,
|
||||||
canvasSize: number,
|
canvasSize,
|
||||||
is3d: boolean = false,
|
is3d: boolean = false,
|
||||||
): Cell {
|
) {
|
||||||
const tileSize = (is3d) ? THREE_TILE_SIZE : TILE_SIZE;
|
const tileSize = (is3d) ? THREE_TILE_SIZE : TILE_SIZE;
|
||||||
const cx = offset % tileSize;
|
const cx = offset % tileSize;
|
||||||
const off = offset - cx;
|
const off = offset - cx;
|
||||||
|
@ -172,17 +168,17 @@ export function getPixelFromChunkOffset(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCellInsideChunk(
|
export function getCellInsideChunk(
|
||||||
canvasSize: number,
|
canvasSize,
|
||||||
pixel: Cell,
|
pixel,
|
||||||
): Cell {
|
) {
|
||||||
return pixel.map((x) => mod(x + canvasSize / 2, TILE_SIZE));
|
return pixel.map((x) => mod(x + canvasSize / 2, TILE_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function screenToWorld(
|
export function screenToWorld(
|
||||||
state: State,
|
state,
|
||||||
$viewport: HTMLCanvasElement,
|
$viewport,
|
||||||
[x, y]: Cell,
|
[x, y],
|
||||||
): Cell {
|
) {
|
||||||
const { view, viewscale } = state.canvas;
|
const { view, viewscale } = state.canvas;
|
||||||
const [viewX, viewY] = view;
|
const [viewX, viewY] = view;
|
||||||
const { width, height } = $viewport;
|
const { width, height } = $viewport;
|
||||||
|
@ -193,10 +189,10 @@ export function screenToWorld(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function worldToScreen(
|
export function worldToScreen(
|
||||||
state: State,
|
state,
|
||||||
$viewport: HTMLCanvasElement,
|
$viewport,
|
||||||
[x, y]: Cell,
|
[x, y],
|
||||||
): Cell {
|
) {
|
||||||
const { view, viewscale } = state.canvas;
|
const { view, viewscale } = state.canvas;
|
||||||
const [viewX, viewY] = view;
|
const [viewX, viewY] = view;
|
||||||
const { width, height } = $viewport;
|
const { width, height } = $viewport;
|
||||||
|
@ -207,11 +203,11 @@ export function worldToScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function durationToString(
|
export function durationToString(
|
||||||
ms: number,
|
ms,
|
||||||
smallest: boolean = false,
|
smallest: boolean = false,
|
||||||
): string {
|
) {
|
||||||
const seconds = Math.ceil(ms / 1000);
|
const seconds = Math.ceil(ms / 1000);
|
||||||
let timestring: string;
|
let timestring;
|
||||||
if (seconds < 60 && smallest) {
|
if (seconds < 60 && smallest) {
|
||||||
timestring = seconds;
|
timestring = seconds;
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,7 +218,7 @@ export function durationToString(
|
||||||
}
|
}
|
||||||
|
|
||||||
const postfix = ['k', 'M', 'B'];
|
const postfix = ['k', 'M', 'B'];
|
||||||
export function numberToString(num: number): string {
|
export function numberToString(num) {
|
||||||
if (!num) {
|
if (!num) {
|
||||||
return 'N/A';
|
return 'N/A';
|
||||||
}
|
}
|
||||||
|
@ -246,7 +242,7 @@ export function numberToString(num: number): string {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function numberToStringFull(num: number): string {
|
export function numberToStringFull(num) {
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
return `${num} :-(`;
|
return `${num} :-(`;
|
||||||
} if (num < 1000) {
|
} if (num < 1000) {
|
||||||
|
@ -262,7 +258,7 @@ export function numberToStringFull(num: number): string {
|
||||||
/*
|
/*
|
||||||
* generates a color based on a given string
|
* generates a color based on a given string
|
||||||
*/
|
*/
|
||||||
export function colorFromText(str: string) {
|
export function colorFromText(str) {
|
||||||
if (!str) return '#000000';
|
if (!str) return '#000000';
|
||||||
|
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
|
@ -312,7 +308,7 @@ function escapeRegExp(string) {
|
||||||
* @param name name
|
* @param name name
|
||||||
* @return regular expression to search for name in message
|
* @return regular expression to search for name in message
|
||||||
*/
|
*/
|
||||||
export function createNameRegExp(name: string) {
|
export function createNameRegExp(name) {
|
||||||
if (!name) return null;
|
if (!name) return null;
|
||||||
return new RegExp(`(^|\\s+)(@${escapeRegExp(name)})(\\s+|$)`, 'g');
|
return new RegExp(`(^|\\s+)(@${escapeRegExp(name)})(\\s+|$)`, 'g');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,4 @@
|
||||||
/* @flow */
|
const initialState = {
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
|
||||||
|
|
||||||
export type AlertState = {
|
|
||||||
alertOpen: boolean,
|
|
||||||
alertType: ?string,
|
|
||||||
alertTitle: ?string,
|
|
||||||
alertMessage: ?string,
|
|
||||||
alertBtn: ?string,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: AlertState = {
|
|
||||||
alertOpen: false,
|
alertOpen: false,
|
||||||
alertType: null,
|
alertType: null,
|
||||||
alertTitle: null,
|
alertTitle: null,
|
||||||
|
@ -19,9 +7,9 @@ const initialState: AlertState = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function alert(
|
export default function alert(
|
||||||
state: AlertState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): AlertState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'ALERT': {
|
case 'ALERT': {
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -1,23 +1,15 @@
|
||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
const initialState = {
|
||||||
|
|
||||||
|
|
||||||
export type AudioState = {
|
|
||||||
mute: boolean,
|
|
||||||
chatNotify: boolean,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: AudioState = {
|
|
||||||
mute: false,
|
mute: false,
|
||||||
chatNotify: true,
|
chatNotify: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function audio(
|
export default function audio(
|
||||||
state: AudioState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): AudioState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'TOGGLE_MUTE':
|
case 'TOGGLE_MUTE':
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
|
||||||
import type { Cell } from '../core/Cell';
|
|
||||||
import type { ColorIndex } from '../core/Palette';
|
|
||||||
import Palette from '../core/Palette';
|
import Palette from '../core/Palette';
|
||||||
import {
|
import {
|
||||||
clamp,
|
clamp,
|
||||||
|
@ -23,13 +18,13 @@ import {
|
||||||
export type CanvasState = {
|
export type CanvasState = {
|
||||||
canvasId: number,
|
canvasId: number,
|
||||||
canvasIdent: string,
|
canvasIdent: string,
|
||||||
selectedColor: ColorIndex,
|
selectedColor: number,
|
||||||
is3D: boolean,
|
is3D: boolean,
|
||||||
canvasSize: number,
|
canvasSize: number,
|
||||||
canvasStartDate: string,
|
canvasStartDate: string,
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
clrIgnore: number,
|
clrIgnore: number,
|
||||||
view: Cell,
|
view: Array,
|
||||||
scale: number,
|
scale: number,
|
||||||
viewscale: number,
|
viewscale: number,
|
||||||
isHistoricalView: boolean,
|
isHistoricalView: boolean,
|
||||||
|
@ -135,7 +130,7 @@ function getViewFromURL(canvases: Object) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: CanvasState = {
|
const initialState = {
|
||||||
...getViewFromURL(DEFAULT_CANVASES),
|
...getViewFromURL(DEFAULT_CANVASES),
|
||||||
isHistoricalView: false,
|
isHistoricalView: false,
|
||||||
historicalDate: null,
|
historicalDate: null,
|
||||||
|
@ -146,8 +141,8 @@ const initialState: CanvasState = {
|
||||||
|
|
||||||
|
|
||||||
export default function canvasReducer(
|
export default function canvasReducer(
|
||||||
state: CanvasState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): CanvasState {
|
): CanvasState {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SET_SCALE': {
|
case 'SET_SCALE': {
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import { MAX_CHAT_MESSAGES } from '../core/constants';
|
import { MAX_CHAT_MESSAGES } from '../core/constants';
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
const initialState = {
|
||||||
|
|
||||||
export type ChatState = {
|
|
||||||
/*
|
/*
|
||||||
* {
|
* {
|
||||||
* cid: [
|
* cid: [
|
||||||
|
@ -21,23 +17,17 @@ export type ChatState = {
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
channels: Object,
|
|
||||||
// [[uId, userName], [userId2, userName2],...]
|
|
||||||
blocked: Array,
|
|
||||||
// { cid: [message1,message2,message3,...]}
|
|
||||||
messages: Object,
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: ChatState = {
|
|
||||||
channels: {},
|
channels: {},
|
||||||
|
// [[uId, userName], [userId2, userName2],...]
|
||||||
blocked: [],
|
blocked: [],
|
||||||
|
// { cid: [message1,message2,message3,...]}
|
||||||
messages: {},
|
messages: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function chat(
|
export default function chat(
|
||||||
state: ChatState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): ChatState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'RECEIVE_ME':
|
case 'RECEIVE_ME':
|
||||||
case 'LOGIN': {
|
case 'LOGIN': {
|
||||||
|
|
|
@ -1,36 +1,27 @@
|
||||||
/*
|
/*
|
||||||
* local save state for chat stuff
|
* local save state for chat stuff
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
|
||||||
|
|
||||||
const TIME_DIFF_THREASHOLD = 15000;
|
const TIME_DIFF_THREASHOLD = 15000;
|
||||||
|
|
||||||
export type ChatReadState = {
|
const initialState = {
|
||||||
// channels that are muted
|
// channels that are muted
|
||||||
// [cid, cid2, ...]
|
// [cid, cid2, ...]
|
||||||
mute: Array,
|
mute: [],
|
||||||
// timestamps of last read
|
// timestamps of last read
|
||||||
// {cid: lastTs, ...}
|
// {cid: lastTs, ...}
|
||||||
readTs: Object,
|
readTs: {},
|
||||||
// booleans if channel is unread
|
// booleans if channel is unread
|
||||||
// {cid: unread, ...}
|
// {cid: unread, ...}
|
||||||
unread: Object,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: ChatReadState = {
|
|
||||||
mute: [],
|
|
||||||
readTs: {},
|
|
||||||
unread: {},
|
unread: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function chatRead(
|
export default function chatRead(
|
||||||
state: ModalState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): ChatReadState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'RECEIVE_ME':
|
case 'RECEIVE_ME':
|
||||||
case 'LOGIN': {
|
case 'LOGIN': {
|
||||||
|
|
|
@ -1,20 +1,9 @@
|
||||||
/**
|
/**
|
||||||
* https://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions/35641680#35641680
|
* https://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions/35641680#35641680
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
const initialState = {
|
||||||
|
|
||||||
export type ContextMenuState = {
|
|
||||||
menuOpen: boolean,
|
|
||||||
menuType: ?string,
|
|
||||||
xPos: number,
|
|
||||||
yPos: number,
|
|
||||||
args: Object,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: ContextMenuState = {
|
|
||||||
menuOpen: false,
|
menuOpen: false,
|
||||||
menuType: null,
|
menuType: null,
|
||||||
xPos: 0,
|
xPos: 0,
|
||||||
|
@ -24,9 +13,9 @@ const initialState: ContextMenuState = {
|
||||||
|
|
||||||
|
|
||||||
export default function contextMenu(
|
export default function contextMenu(
|
||||||
state: ModalState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): ContextMenuState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SHOW_CONTEXT_MENU': {
|
case 'SHOW_CONTEXT_MENU': {
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -1,27 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* keeps track of some api fetching states
|
* keeps track of some api fetching states
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
const initialState = {
|
||||||
|
|
||||||
export type FetchingState = {
|
|
||||||
fetchingChunks: number,
|
|
||||||
fetchingChat: boolean,
|
|
||||||
fetchinApi: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: FetchingState = {
|
|
||||||
fetchingChunks: 0,
|
fetchingChunks: 0,
|
||||||
fetchingChat: false,
|
fetchingChat: false,
|
||||||
fetchinApi: false,
|
fetchinApi: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function fetching(
|
export default function fetching(
|
||||||
state: FetchingState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): FetchingState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SET_CHAT_FETCHING': {
|
case 'SET_CHAT_FETCHING': {
|
||||||
const { fetching: fetchingChat } = action;
|
const { fetching: fetchingChat } = action;
|
||||||
|
|
|
@ -1,23 +1,4 @@
|
||||||
/* @flow */
|
const initialState = {
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
|
||||||
import type { Cell } from '../core/Cell';
|
|
||||||
|
|
||||||
|
|
||||||
export type GUIState = {
|
|
||||||
showGrid: boolean,
|
|
||||||
showPixelNotify: boolean,
|
|
||||||
hover: ?Cell,
|
|
||||||
autoZoomIn: boolean,
|
|
||||||
isPotato: boolean,
|
|
||||||
isLightGrid: boolean,
|
|
||||||
compactPalette: boolean,
|
|
||||||
paletteOpen: boolean,
|
|
||||||
menuOpen: boolean,
|
|
||||||
style: string,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: GUIState = {
|
|
||||||
showGrid: false,
|
showGrid: false,
|
||||||
showPixelNotify: false,
|
showPixelNotify: false,
|
||||||
hover: null,
|
hover: null,
|
||||||
|
@ -32,9 +13,9 @@ const initialState: GUIState = {
|
||||||
|
|
||||||
|
|
||||||
export default function gui(
|
export default function gui(
|
||||||
state: GUIState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): GUIState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'TOGGLE_GRID': {
|
case 'TOGGLE_GRID': {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -14,29 +14,6 @@ import contextMenu from './contextMenu';
|
||||||
import chatRead from './chatRead';
|
import chatRead from './chatRead';
|
||||||
import fetching from './fetching';
|
import fetching from './fetching';
|
||||||
|
|
||||||
import type { AudioState } from './audio';
|
|
||||||
import type { CanvasState } from './canvas';
|
|
||||||
import type { GUIState } from './gui';
|
|
||||||
import type { UserState } from './user';
|
|
||||||
import type { RanksState } from './ranks';
|
|
||||||
import type { AlertState } from './alert';
|
|
||||||
import type { ChatState } from './chat';
|
|
||||||
import type { ContextMenuState } from './contextMenu';
|
|
||||||
import type { FetchingState } from './fetching';
|
|
||||||
|
|
||||||
export type State = {
|
|
||||||
audio: AudioState,
|
|
||||||
canvas: CanvasState,
|
|
||||||
gui: GUIState,
|
|
||||||
user: UserState,
|
|
||||||
ranks: RanksState,
|
|
||||||
alert: AlertState,
|
|
||||||
chat: ChatState,
|
|
||||||
contextMenu: ContextMenuState,
|
|
||||||
chatRead: ChatReadState,
|
|
||||||
fetching: FetchingState,
|
|
||||||
};
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
key: 'primary',
|
key: 'primary',
|
||||||
storage: localForage,
|
storage: localForage,
|
||||||
|
|
|
@ -1,32 +1,19 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
const initialState = {
|
||||||
|
|
||||||
export type RanksState = {
|
|
||||||
totalPixels: number,
|
|
||||||
dailyTotalPixels: number,
|
|
||||||
ranking: number,
|
|
||||||
dailyRanking: number,
|
|
||||||
// global stats
|
|
||||||
online: ?number,
|
|
||||||
totalRanking: Object,
|
|
||||||
totalDailyRanking: Object,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: RanksState = {
|
|
||||||
totalPixels: 0,
|
totalPixels: 0,
|
||||||
dailyTotalPixels: 0,
|
dailyTotalPixels: 0,
|
||||||
ranking: 1488,
|
ranking: 1488,
|
||||||
dailyRanking: 1488,
|
dailyRanking: 1488,
|
||||||
|
// global stats
|
||||||
online: 1,
|
online: 1,
|
||||||
totalRanking: {},
|
totalRanking: {},
|
||||||
totalDailyRanking: {},
|
totalDailyRanking: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ranks(
|
export default function ranks(
|
||||||
state: RanksState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): RanksState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'PLACED_PIXELS': {
|
case 'PLACED_PIXELS': {
|
||||||
let { totalPixels, dailyTotalPixels } = state;
|
let { totalPixels, dailyTotalPixels } = state;
|
||||||
|
|
|
@ -1,55 +1,31 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
|
||||||
|
|
||||||
import { createNameRegExp } from '../core/utils';
|
import { createNameRegExp } from '../core/utils';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
export type UserState = {
|
|
||||||
name: string,
|
|
||||||
center: Cell,
|
|
||||||
wait: ?Date,
|
|
||||||
coolDown: ?number, // ms
|
|
||||||
lastCoolDownEnd: ?Date,
|
|
||||||
requestingPixel: boolean,
|
|
||||||
// messages are sent by api/me, like not_verified status
|
|
||||||
messages: Array,
|
|
||||||
mailreg: boolean,
|
|
||||||
// minecraft
|
|
||||||
minecraftname: string,
|
|
||||||
// blocking all Dms
|
|
||||||
blockDm: boolean,
|
|
||||||
// if user is using touchscreen
|
|
||||||
isOnMobile: boolean,
|
|
||||||
// small notifications for received cooldown
|
|
||||||
notification: string,
|
|
||||||
// 1: Admin, 2: Mod, 0: ordinary user
|
|
||||||
userlvl: number,
|
|
||||||
// regExp for detecting ping
|
|
||||||
nameRegExp: RegExp,
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialState: UserState = {
|
|
||||||
name: null,
|
name: null,
|
||||||
center: [0, 0],
|
center: [0, 0],
|
||||||
wait: null,
|
wait: null,
|
||||||
coolDown: null,
|
coolDown: null, // ms
|
||||||
lastCoolDownEnd: null,
|
lastCoolDownEnd: null,
|
||||||
requestingPixel: true,
|
requestingPixel: true,
|
||||||
|
// messages are sent by api/me, like not_verified status
|
||||||
messages: [],
|
messages: [],
|
||||||
mailreg: false,
|
mailreg: false,
|
||||||
minecraftname: null,
|
// blocking all Dms
|
||||||
blockDm: false,
|
blockDm: false,
|
||||||
|
// if user is using touchscreen
|
||||||
isOnMobile: false,
|
isOnMobile: false,
|
||||||
|
// small notifications for received cooldown
|
||||||
notification: null,
|
notification: null,
|
||||||
|
// 1: Admin, 2: Mod, 0: ordinary user
|
||||||
userlvl: 0,
|
userlvl: 0,
|
||||||
|
// regExp for detecting ping
|
||||||
nameRegExp: null,
|
nameRegExp: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function user(
|
export default function user(
|
||||||
state: UserState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): UserState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'COOLDOWN_SET': {
|
case 'COOLDOWN_SET': {
|
||||||
const { coolDown } = action;
|
const { coolDown } = action;
|
||||||
|
@ -112,7 +88,6 @@ export default function user(
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
mailreg,
|
mailreg,
|
||||||
minecraftname,
|
|
||||||
blockDm,
|
blockDm,
|
||||||
userlvl,
|
userlvl,
|
||||||
} = action;
|
} = action;
|
||||||
|
@ -123,7 +98,6 @@ export default function user(
|
||||||
name,
|
name,
|
||||||
messages,
|
messages,
|
||||||
mailreg,
|
mailreg,
|
||||||
minecraftname,
|
|
||||||
blockDm,
|
blockDm,
|
||||||
userlvl,
|
userlvl,
|
||||||
nameRegExp,
|
nameRegExp,
|
||||||
|
@ -136,7 +110,6 @@ export default function user(
|
||||||
name: null,
|
name: null,
|
||||||
messages: [],
|
messages: [],
|
||||||
mailreg: false,
|
mailreg: false,
|
||||||
minecraftname: null,
|
|
||||||
blockDm: false,
|
blockDm: false,
|
||||||
userlvl: 0,
|
userlvl: 0,
|
||||||
nameRegExp: null,
|
nameRegExp: null,
|
||||||
|
@ -161,14 +134,6 @@ export default function user(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'SET_MINECRAFT_NAME': {
|
|
||||||
const { minecraftname } = action;
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
minecraftname,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'SET_NOTIFICATION': {
|
case 'SET_NOTIFICATION': {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* state for open windows and modal and its content
|
* state for open windows and modal and its content
|
||||||
*
|
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Action } from '../actions/types';
|
|
||||||
|
|
||||||
import { clamp } from '../core/utils';
|
import { clamp } from '../core/utils';
|
||||||
|
|
||||||
const SCREEN_MARGIN_S = 30;
|
const SCREEN_MARGIN_S = 30;
|
||||||
|
@ -87,17 +83,17 @@ function sortWindows(newState) {
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WindowsState = {
|
const initialState = {
|
||||||
// if windows get shown, false on small screens
|
// if windows get shown, false on small screens
|
||||||
showWindows: boolean,
|
showWindows: true,
|
||||||
// highest zIndex of window
|
// highest zIndex of window
|
||||||
zMax: number,
|
zMax: 0,
|
||||||
// modal is considerd as "fullscreen window"
|
// modal is considerd as "fullscreen window"
|
||||||
// its windowId is considered 0 and args are under args[0]
|
// its windowId is considered 0 and args are under args[0]
|
||||||
modal: {
|
modal: {
|
||||||
windowType: ?string,
|
windowType: null,
|
||||||
title: ?string,
|
title: null,
|
||||||
open: boolean,
|
open: false,
|
||||||
// used to remember and restore the size
|
// used to remember and restore the size
|
||||||
// of a maximized window when restoring
|
// of a maximized window when restoring
|
||||||
// {
|
// {
|
||||||
|
@ -107,7 +103,7 @@ export type WindowsState = {
|
||||||
// height: number,
|
// height: number,
|
||||||
// cloneable: boolean,
|
// cloneable: boolean,
|
||||||
// }
|
// }
|
||||||
prevWinSize: Object,
|
prevWinSize: {},
|
||||||
},
|
},
|
||||||
// [
|
// [
|
||||||
// {
|
// {
|
||||||
|
@ -124,32 +120,19 @@ export type WindowsState = {
|
||||||
// cloneable: boolean,
|
// cloneable: boolean,
|
||||||
// },
|
// },
|
||||||
// ]
|
// ]
|
||||||
windows: Array,
|
windows: [],
|
||||||
// {
|
// {
|
||||||
// windowId: {
|
// windowId: {
|
||||||
// ...
|
// ...
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
args: Object,
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialState: WindowsState = {
|
|
||||||
showWindows: true,
|
|
||||||
zMax: 0,
|
|
||||||
modal: {
|
|
||||||
windowType: null,
|
|
||||||
title: null,
|
|
||||||
open: false,
|
|
||||||
prevWinSize: {},
|
|
||||||
},
|
|
||||||
windows: [],
|
|
||||||
args: {},
|
args: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function windows(
|
export default function windows(
|
||||||
state: WindowsState = initialState,
|
state = initialState,
|
||||||
action: Action,
|
action,
|
||||||
): WindowsState {
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'OPEN_WINDOW': {
|
case 'OPEN_WINDOW': {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
/* @flow */
|
|
||||||
|
|
||||||
import type { Cell } from '../core/Cell';
|
|
||||||
import type { Palette } from '../core/Palette';
|
|
||||||
|
|
||||||
import { TILE_SIZE } from '../core/constants';
|
import { TILE_SIZE } from '../core/constants';
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,10 +6,10 @@ class ChunkRGB {
|
||||||
image: HTMLCanvasElement;
|
image: HTMLCanvasElement;
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
timestamp: number;
|
timestamp: number;
|
||||||
palette: Palette;
|
palette;
|
||||||
isBasechunk: boolean;
|
isBasechunk: boolean;
|
||||||
|
|
||||||
constructor(palette: Palette, zoom = 0, cx = 0, cy = 0) {
|
constructor(palette, zoom = 0, cx = 0, cy = 0) {
|
||||||
// isBasechunk gets set to true by RECEIVE_BIG_CHUNK
|
// isBasechunk gets set to true by RECEIVE_BIG_CHUNK
|
||||||
// if true => chunk got requested from api/chunk and
|
// if true => chunk got requested from api/chunk and
|
||||||
// receives websocket pixel updates
|
// receives websocket pixel updates
|
||||||
|
@ -79,11 +74,11 @@ class ChunkRGB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getIndexFromCell([x, y]: Cell): number {
|
static getIndexFromCell([x, y]): number {
|
||||||
return x + (TILE_SIZE * y);
|
return x + (TILE_SIZE * y);
|
||||||
}
|
}
|
||||||
|
|
||||||
getColorIndex(cell: Cell): ColorIndex {
|
getColorIndex(cell) {
|
||||||
const [x, y] = cell;
|
const [x, y] = cell;
|
||||||
const ctx = this.image.getContext('2d');
|
const ctx = this.image.getContext('2d');
|
||||||
|
|
||||||
|
@ -91,7 +86,7 @@ class ChunkRGB {
|
||||||
return this.palette.getClosestIndexOfColor(rgb[0], rgb[1], rgb[2]);
|
return this.palette.getClosestIndexOfColor(rgb[0], rgb[1], rgb[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasColorIn(cell: Cell, color: ColorIndex): boolean {
|
hasColorIn(cell, color): boolean {
|
||||||
const index = ChunkRGB.getIndexFromCell(cell);
|
const index = ChunkRGB.getIndexFromCell(cell);
|
||||||
|
|
||||||
const ctx = this.image.getContext('2d');
|
const ctx = this.image.getContext('2d');
|
||||||
|
@ -101,7 +96,7 @@ class ChunkRGB {
|
||||||
return (intView[index] === this.palette.abgr[color]);
|
return (intView[index] === this.palette.abgr[color]);
|
||||||
}
|
}
|
||||||
|
|
||||||
setColor(cell: Cell, color: ColorIndex): boolean {
|
setColor(cell, color): boolean {
|
||||||
const [x, y] = cell;
|
const [x, y] = cell;
|
||||||
const ctx = this.image.getContext('2d');
|
const ctx = this.image.getContext('2d');
|
||||||
ctx.fillStyle = this.palette.colors[color];
|
ctx.fillStyle = this.palette.colors[color];
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Renders 2D canvases
|
* Renders 2D canvases
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Cell } from '../core/Cell';
|
|
||||||
import type { State } from '../reducers';
|
|
||||||
import { TILE_ZOOM_LEVEL, TILE_SIZE } from '../core/constants';
|
import { TILE_ZOOM_LEVEL, TILE_SIZE } from '../core/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -42,7 +39,7 @@ class Renderer {
|
||||||
canvasId: number = null;
|
canvasId: number = null;
|
||||||
chunkLoader: Object = null;
|
chunkLoader: Object = null;
|
||||||
//--
|
//--
|
||||||
centerChunk: Cell;
|
centerChunk;
|
||||||
tiledScale: number;
|
tiledScale: number;
|
||||||
tiledZoom: number;
|
tiledZoom: number;
|
||||||
hover: boolean;
|
hover: boolean;
|
||||||
|
@ -120,7 +117,7 @@ class Renderer {
|
||||||
this.controls = new PixelPainterControls(this, this.viewport, store);
|
this.controls = new PixelPainterControls(this, this.viewport, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCanvasData(state: State) {
|
updateCanvasData(state) {
|
||||||
const {
|
const {
|
||||||
canvasId,
|
canvasId,
|
||||||
} = state.canvas;
|
} = state.canvas;
|
||||||
|
@ -238,9 +235,9 @@ class Renderer {
|
||||||
i: number,
|
i: number,
|
||||||
j: number,
|
j: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
color: ColorIndex,
|
color,
|
||||||
) {
|
) {
|
||||||
const state: State = this.store.getState();
|
const state = this.store.getState();
|
||||||
const {
|
const {
|
||||||
canvasSize,
|
canvasSize,
|
||||||
palette,
|
palette,
|
||||||
|
@ -299,7 +296,7 @@ class Renderer {
|
||||||
|
|
||||||
|
|
||||||
renderChunks(
|
renderChunks(
|
||||||
state: State,
|
state,
|
||||||
) {
|
) {
|
||||||
const context = this.canvas.getContext('2d');
|
const context = this.canvas.getContext('2d');
|
||||||
if (!context) return;
|
if (!context) return;
|
||||||
|
@ -400,7 +397,7 @@ class Renderer {
|
||||||
if (!this.chunkLoader) {
|
if (!this.chunkLoader) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const state: State = this.store.getState();
|
const state = this.store.getState();
|
||||||
if (state.canvas.isHistoricalView) {
|
if (state.canvas.isHistoricalView) {
|
||||||
this.renderHistorical(state);
|
this.renderHistorical(state);
|
||||||
} else {
|
} else {
|
||||||
|
@ -412,7 +409,7 @@ class Renderer {
|
||||||
// keep in mind that everything we got here gets executed 60 times per second
|
// keep in mind that everything we got here gets executed 60 times per second
|
||||||
// avoiding unneccessary stuff is important
|
// avoiding unneccessary stuff is important
|
||||||
renderMain(
|
renderMain(
|
||||||
state: State,
|
state,
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
viewport,
|
viewport,
|
||||||
|
@ -533,7 +530,7 @@ class Renderer {
|
||||||
|
|
||||||
|
|
||||||
renderHistoricalChunks(
|
renderHistoricalChunks(
|
||||||
state: State,
|
state,
|
||||||
) {
|
) {
|
||||||
const context = this.canvas.getContext('2d');
|
const context = this.canvas.getContext('2d');
|
||||||
if (!context) return;
|
if (!context) return;
|
||||||
|
@ -662,7 +659,7 @@ class Renderer {
|
||||||
// keep in mind that everything we got here gets executed 60 times per second
|
// keep in mind that everything we got here gets executed 60 times per second
|
||||||
// avoiding unneccessary stuff is important
|
// avoiding unneccessary stuff is important
|
||||||
renderHistorical(
|
renderHistorical(
|
||||||
state: State,
|
state,
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
viewport,
|
viewport,
|
||||||
|
|
|
@ -229,7 +229,7 @@ class Renderer {
|
||||||
return this.threeRenderer.domElement;
|
return this.threeRenderer.domElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCanvasData(state: State) {
|
updateCanvasData(state) {
|
||||||
const {
|
const {
|
||||||
canvasId,
|
canvasId,
|
||||||
view,
|
view,
|
||||||
|
|
|
@ -65,10 +65,10 @@ export function requestFromQueue(store) {
|
||||||
|
|
||||||
export function receivePixelUpdate(
|
export function receivePixelUpdate(
|
||||||
store,
|
store,
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
offset: number,
|
offset,
|
||||||
color: ColorIndex,
|
color,
|
||||||
) {
|
) {
|
||||||
for (let p = 0; p < clientPredictions.length; p += 1) {
|
for (let p = 0; p < clientPredictions.length; p += 1) {
|
||||||
const predPxl = clientPredictions[p];
|
const predPxl = clientPredictions[p];
|
||||||
|
@ -91,9 +91,9 @@ export function receivePixelUpdate(
|
||||||
*/
|
*/
|
||||||
function revertPredictionsAt(
|
function revertPredictionsAt(
|
||||||
store,
|
store,
|
||||||
sI: number,
|
sI,
|
||||||
sJ: number,
|
sJ,
|
||||||
sOffset: number,
|
sOffset,
|
||||||
) {
|
) {
|
||||||
let p = 0;
|
let p = 0;
|
||||||
while (p < clientPredictions.length) {
|
while (p < clientPredictions.length) {
|
||||||
|
@ -123,11 +123,11 @@ function revertPredictionsAt(
|
||||||
|
|
||||||
export function tryPlacePixel(
|
export function tryPlacePixel(
|
||||||
store,
|
store,
|
||||||
i: number,
|
i,
|
||||||
j: number,
|
j,
|
||||||
offset: number,
|
offset,
|
||||||
color: ColorIndex,
|
color,
|
||||||
curColor: ColorIndex,
|
curColor,
|
||||||
) {
|
) {
|
||||||
store.dispatch(updatePixel(i, j, offset, color));
|
store.dispatch(updatePixel(i, j, offset, color));
|
||||||
clientPredictions.push([i, j, offset, curColor, color]);
|
clientPredictions.push([i, j, offset, curColor, color]);
|
||||||
|
@ -155,9 +155,9 @@ export function tryPlacePixel(
|
||||||
|
|
||||||
export function receivePixelReturn(
|
export function receivePixelReturn(
|
||||||
store,
|
store,
|
||||||
retCode: number,
|
retCode,
|
||||||
wait: number,
|
wait,
|
||||||
coolDownSeconds: number,
|
coolDownSeconds,
|
||||||
pxlCnt,
|
pxlCnt,
|
||||||
) {
|
) {
|
||||||
clearTimeout(pixelTimeout);
|
clearTimeout(pixelTimeout);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user