move hover from gui to canvas reducer

This commit is contained in:
HF 2022-08-17 21:48:50 +02:00
parent df44445720
commit df223f5932
9 changed files with 28 additions and 28 deletions

View File

@ -17,7 +17,7 @@ function renderCoordinates(cell) {
const CoordinatesBox = () => { const CoordinatesBox = () => {
const view = useSelector((state) => state.canvas.view); const view = useSelector((state) => state.canvas.view);
const hover = useSelector((state) => state.gui.hover); const hover = useSelector((state) => state.canvas.hover);
const dispatch = useDispatch(); const dispatch = useDispatch();
return ( return (

View File

@ -391,7 +391,7 @@ class PixelPlainterControls {
const { deltaY } = event; const { deltaY } = event;
const { store } = this; const { store } = this;
const state = store.getState(); const state = store.getState();
const { hover } = state.gui; const { hover } = state.canvas;
let zoompoint = null; let zoompoint = null;
if (hover) { if (hover) {
zoompoint = hover; zoompoint = hover;
@ -427,7 +427,7 @@ class PixelPlainterControls {
lastPosY - (deltaY / scale), lastPosY - (deltaY / scale),
])); ]));
} else { } else {
const { hover } = state.gui; const { hover } = state.canvas;
const screenCoor = screenToWorld( const screenCoor = screenToWorld(
state, state,
this.viewport, this.viewport,
@ -580,7 +580,7 @@ class PixelPlainterControls {
case 'Control': case 'Control':
case 'Shift': { case 'Shift': {
const state = store.getState(); const state = store.getState();
const { hover } = state.gui; const { hover } = state.canvas;
if (hover) { if (hover) {
if (event.key === 'Control') { if (event.key === 'Control') {
// ctrl // ctrl

View File

@ -83,7 +83,7 @@ function createKeyPressHandler(store) {
: t`Unmuted Sound`)); : t`Unmuted Sound`));
return; return;
case 'r': { case 'r': {
const { hover } = store.getState().gui; const { hover } = store.getState().canvas;
const text = hover.join('_'); const text = hover.join('_');
copy(text); copy(text);
store.dispatch(notify(t`Copied!`)); store.dispatch(notify(t`Copied!`));

View File

@ -32,6 +32,7 @@ export type CanvasState = {
historicalCanvasSize: number, historicalCanvasSize: number,
historicalDate: string, historicalDate: string,
historicalTime: string, historicalTime: string,
hover: Array,
// object with all canvas informations from all canvases like colors and size // object with all canvas informations from all canvases like colors and size
canvases: Object, canvases: Object,
// last canvas view, scale, selectedColor and viewscale // last canvas view, scale, selectedColor and viewscale
@ -138,6 +139,7 @@ const initialState = {
historicalDate: null, historicalDate: null,
historicalTime: null, historicalTime: null,
showHiddenCanvases: false, showHiddenCanvases: false,
hover: null,
prevCanvasCoords: {}, prevCanvasCoords: {},
}; };
@ -261,6 +263,21 @@ export default function canvasReducer(
}; };
} }
case 'SET_HOVER': {
const { hover } = action;
return {
...state,
hover,
};
}
case 'UNSET_HOVER': {
return {
...state,
hover: null,
};
}
case 'SELECT_CANVAS': { case 'SELECT_CANVAS': {
let { canvasId } = action; let { canvasId } = action;
const { canvases, prevCanvasCoords, canvasId: prevCanvasId } = state; const { canvases, prevCanvasCoords, canvasId: prevCanvasId } = state;

View File

@ -1,7 +1,6 @@
const initialState = { const initialState = {
showGrid: false, showGrid: false,
showPixelNotify: false, showPixelNotify: false,
hover: null,
autoZoomIn: false, autoZoomIn: false,
isPotato: false, isPotato: false,
isLightGrid: false, isLightGrid: false,
@ -110,21 +109,6 @@ export default function gui(
}; };
} }
case 'SET_HOVER': {
const { hover } = action;
return {
...state,
hover,
};
}
case 'UNSET_HOVER': {
return {
...state,
hover: null,
};
}
case 'TOGGLE_MUTE': case 'TOGGLE_MUTE':
return { return {
...state, ...state,

View File

@ -27,7 +27,6 @@ const guiPersist = persistReducer({
storage, storage,
version: CURRENT_VERSION, version: CURRENT_VERSION,
migrate, migrate,
blacklist: ['hover'],
}, gui); }, gui);
const ranksPersist = persistReducer({ const ranksPersist = persistReducer({

View File

@ -419,7 +419,6 @@ class Renderer {
const { const {
showGrid, showGrid,
showPixelNotify, showPixelNotify,
hover,
isPotato, isPotato,
isLightGrid, isLightGrid,
} = state.gui; } = state.gui;
@ -430,6 +429,7 @@ class Renderer {
view, view,
viewscale, viewscale,
canvasSize, canvasSize,
hover,
} = state.canvas; } = state.canvas;
const [x, y] = view; const [x, y] = view;

View File

@ -429,7 +429,7 @@ class Renderer {
onDocumentMouseDownOrTouchStart() { onDocumentMouseDownOrTouchStart() {
this.pressTime = Date.now(); this.pressTime = Date.now();
const state = this.store.getState(); const state = this.store.getState();
this.mouseMoveStart = state.gui.hover; this.mouseMoveStart = state.canvas.hover;
} }
onDocumentTouchMove() { onDocumentTouchMove() {
@ -501,7 +501,7 @@ class Renderer {
const state = store.getState(); const state = store.getState();
const [px, py, pz] = mouseMoveStart; const [px, py, pz] = mouseMoveStart;
const [qx, qy, qz] = state.gui.hover; const [qx, qy, qz] = state.canvas.hover;
if (px !== qx || py !== qy || pz !== qz) { if (px !== qx || py !== qy || pz !== qz) {
return; return;
} }
@ -587,7 +587,7 @@ class Renderer {
} }
const [px, py, pz] = this.mouseMoveStart; const [px, py, pz] = this.mouseMoveStart;
const [qx, qy, qz] = state.gui.hover; const [qx, qy, qz] = state.canvas.hover;
if (px !== qx || py !== qy || pz !== qz) { if (px !== qx || py !== qy || pz !== qz) {
return; return;
} }

View File

@ -15,7 +15,7 @@ export function renderPlaceholder(
) { ) {
const viewportCtx = $viewport.getContext('2d'); const viewportCtx = $viewport.getContext('2d');
const { hover } = state.gui; const { hover } = state.canvas;
const { palette, selectedColor } = state.canvas; const { palette, selectedColor } = state.canvas;
const [sx, sy] = worldToScreen(state, $viewport, hover); const [sx, sy] = worldToScreen(state, $viewport, hover);
@ -49,7 +49,7 @@ export function renderPotatoPlaceholder(
) { ) {
const viewportCtx = $viewport.getContext('2d'); const viewportCtx = $viewport.getContext('2d');
const { hover } = state.gui; const { hover } = state.canvas;
const { palette, selectedColor } = state.canvas; const { palette, selectedColor } = state.canvas;
const [sx, sy] = worldToScreen(state, $viewport, hover); const [sx, sy] = worldToScreen(state, $viewport, hover);