allow Admin to paint unset pixels

This commit is contained in:
HF 2022-07-09 16:10:14 +02:00
parent 6052b00861
commit bda8e20b15
2 changed files with 12 additions and 8 deletions

View File

@ -18,14 +18,14 @@ function getStylesByWindowSize(
paletteOpen, paletteOpen,
windowSize, windowSize,
colors, colors,
clrIgnore, clrHide,
compactPalette, compactPalette,
) { ) {
const { const {
width: windowWidth, width: windowWidth,
height: windowHeight, height: windowHeight,
} = windowSize; } = windowSize;
const numCal = colors.length - clrIgnore; const numCal = colors.length - clrHide;
let flexDirection; let flexDirection;
let spanSize; let spanSize;
@ -97,12 +97,14 @@ const Palette = () => {
colors, colors,
clrIgnore, clrIgnore,
selectedColor, selectedColor,
userlvl,
] = useSelector((state) => [ ] = useSelector((state) => [
state.gui.paletteOpen, state.gui.paletteOpen,
state.gui.compactPalette, state.gui.compactPalette,
state.canvas.palette.colors, state.canvas.palette.colors,
state.canvas.clrIgnore, state.canvas.clrIgnore,
state.canvas.selectedColor, state.canvas.selectedColor,
state.user.userlvl,
], shallowEqual); ], shallowEqual);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -116,11 +118,13 @@ const Palette = () => {
if (!paletteOpen) setRender(false); if (!paletteOpen) setRender(false);
}; };
const clrHide = (userlvl === 1) ? 0 : clrIgnore;
const [paletteStyle, spanStyle] = getStylesByWindowSize( const [paletteStyle, spanStyle] = getStylesByWindowSize(
(render && paletteOpen), (render && paletteOpen),
useWindowSize(), useWindowSize(),
colors, colors,
clrIgnore, clrHide,
compactPalette, compactPalette,
); );
@ -131,7 +135,7 @@ const Palette = () => {
style={paletteStyle} style={paletteStyle}
onTransitionEnd={onTransitionEnd} onTransitionEnd={onTransitionEnd}
> >
{colors.slice(clrIgnore).map((color, index) => ( {colors.slice(clrHide).map((color, index) => (
<span <span
style={{ style={{
backgroundColor: color, backgroundColor: color,
@ -139,13 +143,13 @@ const Palette = () => {
}} }}
role="button" role="button"
tabIndex={0} tabIndex={0}
aria-label={`color ${index + 2}`} aria-label={`color ${index + clrHide}`}
key={color} key={color}
className={selectedColor === (index + clrIgnore) className={selectedColor === (index + clrHide)
? 'selected' ? 'selected'
: 'unselected'} : 'unselected'}
color={color} color={color}
onClick={() => dispatch(selectColor(index + clrIgnore))} onClick={() => dispatch(selectColor(index + clrHide))}
/> />
))} ))}
</div> </div>

View File

@ -156,7 +156,7 @@ export async function drawByOffsets(
throw new Error(4); throw new Error(4);
} }
if (color >= canvas.colors.length if (color >= canvas.colors.length
|| (color < clrIgnore && !(canvas.v && color === 0)) || (color < clrIgnore && !isAdmin && !(canvas.v && color === 0))
) { ) {
// color out of bounds // color out of bounds
throw new Error(5); throw new Error(5);