extract rgba resolving to provider
This commit is contained in:
parent
102c084328
commit
e8238c6ea7
4 changed files with 107 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
|||
import {hslToString, ThemeContext} from '../theme.ts';
|
||||
import {useContext, useEffect, useRef} from 'react';
|
||||
import {useEffect, useRef} from 'react';
|
||||
import './PixelGridCanvas.css';
|
||||
import {useRgbaThemeContext} from '../theme.tsx';
|
||||
|
||||
const pixelsPerRow = 352;
|
||||
const pixelsPerCol = 160;
|
||||
|
@ -20,12 +20,6 @@ function getPixelDataIndexes(bitIndex: number) {
|
|||
};
|
||||
}
|
||||
|
||||
function normalizeColor(context: CanvasRenderingContext2D, color: string) {
|
||||
context.fillStyle = color;
|
||||
context.fillRect(0, 0, 1, 1);
|
||||
return context.getImageData(0, 0, 1, 1).data;
|
||||
}
|
||||
|
||||
function parseAdditionalDataNibble(nibble: number) {
|
||||
const isPlayerMask = 1;
|
||||
const entityTypeMask = 12;
|
||||
|
@ -107,7 +101,7 @@ function drawPixelsToCanvas(
|
|||
export default function PixelGridCanvas({pixels}: {
|
||||
readonly pixels: Uint8ClampedArray;
|
||||
}) {
|
||||
const theme = useContext(ThemeContext);
|
||||
const theme = useRgbaThemeContext();
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -137,12 +131,12 @@ export default function PixelGridCanvas({pixels}: {
|
|||
pixels,
|
||||
additional: additionalData,
|
||||
colors: {
|
||||
background: normalizeColor(drawContext, hslToString(theme.background)),
|
||||
foreground: normalizeColor(drawContext, hslToString(theme.primary)),
|
||||
player: normalizeColor(drawContext, hslToString(theme.secondary)),
|
||||
tanks: normalizeColor(drawContext, hslToString(theme.tertiary)),
|
||||
powerUps: normalizeColor(drawContext, hslToString(theme.tertiary)),
|
||||
bullets: normalizeColor(drawContext, hslToString(theme.tertiary))
|
||||
background: theme.background,
|
||||
foreground: theme.primary,
|
||||
player: theme.secondary,
|
||||
tanks: theme.tertiary,
|
||||
powerUps: theme.tertiary,
|
||||
bullets: theme.tertiary
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {ChangeEventHandler} from "react";
|
||||
import './TextInput.css';
|
||||
|
||||
export default function TextInput(props: {
|
||||
export default function TextInput( {onChange, className, value, placeholder, onEnter }: {
|
||||
onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
|
||||
className?: string;
|
||||
value: string;
|
||||
|
@ -9,13 +9,14 @@ export default function TextInput(props: {
|
|||
onEnter?: () => void;
|
||||
}) {
|
||||
return <input
|
||||
{...props}
|
||||
type="text"
|
||||
className={'TextInput ' + (props.className?? '')}
|
||||
|
||||
className={'TextInput ' + (className?? '')}
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
onChange={onChange}
|
||||
onKeyUp={event => {
|
||||
if (props.onEnter && event.key === 'Enter')
|
||||
props.onEnter();
|
||||
if (onEnter && event.key === 'Enter')
|
||||
onEnter();
|
||||
}}
|
||||
/>;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue