refactor stuff

This commit is contained in:
HF 2022-08-15 21:35:55 +02:00
parent 5d38af340e
commit 63bf9b15ff
9 changed files with 44 additions and 32 deletions

View File

@ -41,7 +41,7 @@ export function toggleGrid() {
export function togglePixelNotify() {
return {
type: 'TOGGLE_PIXEL_NOTIFY',
type: 'TOGGLE_PXL_NOTIFY',
};
}
@ -106,10 +106,9 @@ export function toggleOpenMenu() {
};
}
export function setAllowSettingPixel(allowSettingPixel) {
export function requestPlaceTimeout() {
return {
type: 'ALLOW_SETTING_PIXEL',
allowSettingPixel,
type: 'REQ_PLACE_TIMEOUT',
};
}
@ -179,27 +178,19 @@ export function moveDirection([vx, vy]) {
}
export function moveNorth() {
return (dispatch) => {
dispatch(moveDirection([0, -1]));
};
return moveDirection([0, -1]);
}
export function moveWest() {
return (dispatch) => {
dispatch(moveDirection([-1, 0]));
};
return moveDirection([-1, 0]);
}
export function moveSouth() {
return (dispatch) => {
dispatch(moveDirection([0, 1]));
};
return moveDirection([0, 1]);
}
export function moveEast() {
return (dispatch) => {
dispatch(moveDirection([1, 0]));
};
return moveDirection([1, 0]);
}
export function setScale(scale, zoompoint) {
@ -322,9 +313,17 @@ export function receiveChatMessage(
* check socket/packets/PixelReturn.js for args
*/
export function storeReceivePixelReturn(args) {
args.type = 'REC_PIXEL_RETURN';
args.type = 'REC_PXL_RETURN';
return args;
}
export function requestPlacePixels(i, j, pixels) {
return {
type: 'REQ_PLACE_PXLS',
i,
j,
pixels,
};
}
export function logoutUser(
) {

View File

@ -119,7 +119,7 @@ export default (store) => (next) => (action) => {
break;
}
case 'REC_PIXEL_RETURN': {
case 'REC_PXL_RETURN': {
switch (action.retCode) {
case 0: {
// successfully placed pixel

View File

@ -10,7 +10,7 @@ export default (store) => (next) => (action) => {
const ret = next(action);
switch (action.type) {
case 'REC_PIXEL_RETURN': {
case 'REC_PXL_RETURN': {
const renderer = getRenderer();
const {
retCode,

View File

@ -95,7 +95,7 @@ export default (store) => (next) => (action) => {
}
case 'TOGGLE_GRID':
case 'ALLOW_SETTING_PIXEL': {
case 'ALLOW_SETTING_PXL': {
const renderer = getRenderer();
renderer.forceNextSubrender = true;
break;
@ -114,7 +114,7 @@ export default (store) => (next) => (action) => {
break;
}
case 'REC_PIXEL_RETURN': {
case 'REC_PXL_RETURN': {
const renderer = getRenderer();
renderer.forceNextSubrender = true;
const { coolDownSeconds } = action;

View File

@ -24,6 +24,14 @@ export default (store) => (next) => (action) => {
break;
}
case 'REQ_PLACE_PXLS': {
const {
i, j, pixels,
} = action;
SocketClient.requestPlacePixels(i, j, pixels);
break;
}
default:
// nothing
}

View File

@ -28,7 +28,7 @@ export default function gui(
};
}
case 'TOGGLE_PIXEL_NOTIFY': {
case 'TOGGLE_PXL_NOTIFY': {
return {
...state,
showPixelNotify: !state.showPixelNotify,

View File

@ -24,7 +24,7 @@ export default function ranks(
action,
) {
switch (action.type) {
case 'REC_PIXEL_RETURN': {
case 'REC_PXL_RETURN': {
const {
rankedPxlCnt,
} = action;

View File

@ -40,15 +40,21 @@ export default function user(
};
}
case 'ALLOW_SETTING_PIXEL': {
const { allowSettingPixel } = action;
case 'REQ_PLACE_TIMEOUT': {
return {
...state,
allowSettingPixel,
allowSettingPixel: true,
};
}
case 'REC_PIXEL_RETURN': {
case 'REQ_PLACE_PXLS': {
return {
...state,
allowSettingPixel: false,
};
}
case 'REC_PXL_RETURN': {
const {
wait: duration,
} = action;

View File

@ -9,14 +9,14 @@
* */
import { t } from 'ttag';
import {
setAllowSettingPixel,
requestPlaceTimeout,
pAlert,
storeReceivePixelReturn,
requestPlacePixels,
} from '../store/actions';
import {
notify,
} from '../store/actions/thunks';
import SocketClient from '../socket/SocketClient';
let pixelTimeout = null;
/*
@ -49,7 +49,7 @@ function requestFromQueue(store) {
pixelTimeout = setTimeout(() => {
pixelQueue = [];
pixelTimeout = null;
store.dispatch(setAllowSettingPixel(true));
store.dispatch(requestPlaceTimeout());
store.dispatch(pAlert(
t`Error :(`,
t`Didn't get an answer from pixelplanet. Maybe try to refresh?`,
@ -59,8 +59,7 @@ function requestFromQueue(store) {
lastRequestValues = pixelQueue.shift();
const { i, j, pixels } = lastRequestValues;
SocketClient.requestPlacePixels(i, j, pixels);
store.dispatch(setAllowSettingPixel(false));
store.dispatch(requestPlacePixels(i, j, pixels));
}
/*