Change way of imply param
This commit is contained in:
parent
42e4af46e9
commit
b2c72ebb0d
2 changed files with 18 additions and 18 deletions
|
@ -3,9 +3,9 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import { CSSProperties } from 'react';
|
import { CSSProperties } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
function Target({ props: { preview, type, edges }, target: { x, y, show } }: { props: { preview?: boolean, type: string, edges: string[] }, target: { x: number, y: number, show: boolean } }) {
|
function Target({ props: { preview, type, edges, imply }, target: { x, y, show } }: { props: { preview?: boolean, type: string, edges: string[], imply: boolean }, target: { x: number, y: number, show: boolean } }) {
|
||||||
return (
|
return (
|
||||||
<div className={classNames('hit-svg', preview ? 'target-preview' : 'target', type, { show: show }, ...edges)} style={{ '--x': x, '--y': y } as CSSProperties}>
|
<div className={classNames('hit-svg', preview ? 'target-preview' : 'target', type, { show: show }, ...edges, { imply: imply })} style={{ '--x': x, '--y': y } as CSSProperties}>
|
||||||
<FontAwesomeIcon icon={faCrosshairs} />
|
<FontAwesomeIcon icon={faCrosshairs} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,16 +14,18 @@ function useGameEvent(count: number) {
|
||||||
const [hits, DispatchHits] = useReducer(hitReducer, [] as HitType[]);
|
const [hits, DispatchHits] = useReducer(hitReducer, [] as HitType[]);
|
||||||
const [mode, setMode] = useState<keyof typeof modes>('none')
|
const [mode, setMode] = useState<keyof typeof modes>('none')
|
||||||
const [targetList, setTargetList] = useState<{
|
const [targetList, setTargetList] = useState<{
|
||||||
show: boolean;
|
show: boolean,
|
||||||
x: number;
|
x: number,
|
||||||
y: number;
|
y: number,
|
||||||
edges: string[];
|
edges: string[],
|
||||||
|
imply: boolean
|
||||||
}[]>([])
|
}[]>([])
|
||||||
const [targetPreviewList, setTargetPreviewList] = useState<{
|
const [targetPreviewList, setTargetPreviewList] = useState<{
|
||||||
show: boolean;
|
show: boolean,
|
||||||
x: number;
|
x: number,
|
||||||
y: number;
|
y: number,
|
||||||
edges: string[];
|
edges: string[],
|
||||||
|
imply: boolean
|
||||||
}[]>([])
|
}[]>([])
|
||||||
|
|
||||||
const modes = useMemo(() => ({
|
const modes = useMemo(() => ({
|
||||||
|
@ -68,9 +70,9 @@ function useGameEvent(count: number) {
|
||||||
return { fields, type }
|
return { fields, type }
|
||||||
}, [modes, mode])
|
}, [modes, mode])
|
||||||
|
|
||||||
const Targets = useCallback((targets: { show: boolean, x: number, y: number, edges: string[] }[], preview?: boolean) => {
|
const Targets = useCallback((targets: { show: boolean, x: number, y: number, edges: string[], imply: boolean }[], preview?: boolean) => {
|
||||||
const { type } = scopeGrid
|
const { type } = scopeGrid
|
||||||
return targets.map(({ edges, ...target }, i) => <Target key={i} props={{ type, preview, edges }} target={target} />)
|
return targets.map(({ edges, imply, ...target }, i) => <Target key={i} props={{ type, preview, edges, imply }} target={target} />)
|
||||||
}, [scopeGrid])
|
}, [scopeGrid])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -83,13 +85,12 @@ function useGameEvent(count: number) {
|
||||||
y < 2,
|
y < 2,
|
||||||
y > count,
|
y > count,
|
||||||
].reduce((prev, curr) => prev || curr, false)
|
].reduce((prev, curr) => prev || curr, false)
|
||||||
// console.log(!isHit(hits, x, y).length, !borders)
|
|
||||||
return !border
|
return !border
|
||||||
}).map(field => {
|
}).map(field => {
|
||||||
const { x, y } = field
|
const { x, y } = field
|
||||||
if (isHit(hits, x, y).length)
|
if (isHit(hits, x, y).length)
|
||||||
return { ...field, edges: [...field.edges, 'imply'] }
|
return { ...field, imply: true }
|
||||||
return field
|
return { ...field, imply: false }
|
||||||
})
|
})
|
||||||
setTargetList(e => {
|
setTargetList(e => {
|
||||||
if (JSON.stringify(e) === JSON.stringify(result))
|
if (JSON.stringify(e) === JSON.stringify(result))
|
||||||
|
@ -108,13 +109,12 @@ function useGameEvent(count: number) {
|
||||||
y < 2,
|
y < 2,
|
||||||
y > count + 1,
|
y > count + 1,
|
||||||
].reduce((prev, curr) => prev || curr, false)
|
].reduce((prev, curr) => prev || curr, false)
|
||||||
// console.log(!isHit(hits, x, y).length, !isSet(x, y), !borders)
|
|
||||||
return !border
|
return !border
|
||||||
}).map(field => {
|
}).map(field => {
|
||||||
const { x, y } = field
|
const { x, y } = field
|
||||||
if (isHit(hits, x, y).length || isSet(x, y))
|
if (isHit(hits, x, y).length || isSet(x, y))
|
||||||
return { ...field, edges: [...field.edges, 'imply'] }
|
return { ...field, imply: true }
|
||||||
return field
|
return { ...field, imply: false }
|
||||||
})
|
})
|
||||||
if (!targetPreviewPos.shouldShow)
|
if (!targetPreviewPos.shouldShow)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue