half radar implementation

This commit is contained in:
aronmal 2023-01-13 13:34:14 +01:00
parent f5e1fe7e85
commit 1c22ffb829
Signed by: aronmal
GPG key ID: 816B7707426FC612
3 changed files with 57 additions and 16 deletions

View file

@ -3,11 +3,29 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { CSSProperties } from 'react'; import { CSSProperties } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { TargetType } from '../interfaces'; import { TargetType } from '../interfaces';
import { faRadar } from '@fortawesome/pro-thin-svg-icons';
function Target({ props: { preview, type, edges, imply }, target: { x, y, show } }: { props: { preview?: boolean, type: string, edges: string[], imply: boolean }, target: TargetType }) { function Target({ props: {
preview,
type,
edges,
imply,
x,
y,
show
} }: {
props: {
preview?: boolean,
type: string,
edges: string[],
imply: boolean,
} & TargetType
}) {
const isRadar = type === 'radar'
const style = !isRadar ? { '--x': x, '--y': y } : { '--x1': x - 1, '--x2': x + 2, '--y1': y - 1, '--y2': y + 2 }
return ( return (
<div className={classNames('hit-svg', preview ? 'target-preview' : 'target', type, { show: show }, ...edges, { imply: imply })} style={{ '--x': x, '--y': y } as CSSProperties}> <div className={classNames('hit-svg', preview ? 'target-preview' : 'target', type, { show: show }, ...edges, { edge: !isRadar || !preview }, { imply: imply })} style={style as CSSProperties}>
<FontAwesomeIcon icon={faCrosshairs} /> <FontAwesomeIcon icon={!isRadar ? faCrosshairs : faRadar} />
</div> </div>
) )
} }

View file

@ -5,8 +5,8 @@ import Item from './Item';
import Target from './Target'; import Target from './Target';
export const modes = { export const modes = {
none: { xEnable: true, yEnable: true, type: 'none' }, none: { xEnable: false, yEnable: false, type: 'none' },
radar: { xEnable: true, yEnable: true, type: 'radar' }, radar: { xEnable: false, yEnable: false, type: 'radar' },
hTorpedo: { xEnable: true, yEnable: false, type: 'torpedo' }, hTorpedo: { xEnable: true, yEnable: false, type: 'torpedo' },
vTorpedo: { xEnable: false, yEnable: true, type: 'torpedo' }, vTorpedo: { xEnable: false, yEnable: true, type: 'torpedo' },
missle: { xEnable: false, yEnable: false, type: 'missle' } missle: { xEnable: false, yEnable: false, type: 'missle' }
@ -74,7 +74,7 @@ function useGameEvent(count: number) {
const Targets = useCallback((targets: TargetListType[], preview?: boolean) => { const Targets = useCallback((targets: TargetListType[], preview?: boolean) => {
const { type } = modes[mode] const { type } = modes[mode]
return targets.map(({ target, params }, i) => <Target key={i} props={{ type, preview, ...params }} target={target} />) return targets.map(({ target, params }, i) => <Target key={i} props={{ type, preview, ...params, ...target }} />)
}, [mode]) }, [mode])
useEffect(() => { useEffect(() => {
@ -162,7 +162,7 @@ function useGameEvent(count: number) {
// early return to start cooldown only when about to show up // early return to start cooldown only when about to show up
const autoTimeout = setTimeout(() => { const autoTimeout = setTimeout(() => {
setAppearOK(!targetPreview.show) setAppearOK(!targetPreview.show)
}, 500); }, 600);
// or abort if movement is repeated early // or abort if movement is repeated early
return () => { return () => {
@ -177,12 +177,12 @@ function useGameEvent(count: number) {
const eventBar = useMemo(() => { const eventBar = useMemo(() => {
const items: ItemsType[] = [ const items: ItemsType[] = [
{ icon: 'burger-menu', text: 'Menu' }, { icon: 'burger-menu', text: 'Menu' },
{ icon: 'radar', text: 'Radar scan', type: 'radar', amount: 1 }, { icon: 'radar', text: 'Radar scan', type: 'radar', amount: 1 },
{ icon: 'missle', text: 'Fire torpedo', type: 'hTorpedo', amount: 1 }, { icon: 'missle', text: 'Fire torpedo', type: 'hTorpedo', amount: 1 },
{ icon: 'scope', text: 'Fire missle', type: 'missle' }, { icon: 'scope', text: 'Fire missle', type: 'missle' },
{ icon: 'gear', text: 'Settings' } { icon: 'gear', text: 'Settings' }
] ]
return ( return (
<div className='event-bar'> <div className='event-bar'>
{items.map((e, i) => ( {items.map((e, i) => (

View file

@ -168,6 +168,29 @@ body {
@include transition(.5s); @include transition(.5s);
} }
&.radar {
--color: limegreen;
border: 5px solid var(--color);
grid-column-start: var(--x1) !important;
grid-column-end: var(--x2) !important;
grid-row-start: var(--y1) !important;
grid-row-end: var(--y2) !important;
&.imply {
box-shadow: 0 0 6px 6px #fff4;
}
&.target-preview {
--color: lawngreen;
background-color: #0001;
border: 5px dashed var(--color);
}
svg {
padding: 12.5%;
}
}
&.show { &.show {
opacity: 1; opacity: 1;
} }
@ -192,15 +215,15 @@ body {
border-bottom: 2px solid var(--color); border-bottom: 2px solid var(--color);
} }
&.imply.left { &.edge.imply.left {
border-left: 2px dashed white; border-left: 2px dashed white;
} }
&.imply.right { &.edge.imply.right {
border-right: 2px dashed white; border-right: 2px dashed white;
} }
&.imply.top { &.edge.imply.top {
border-top: 2px dashed white; border-top: 2px dashed white;
} }