chg: dev: more, massive refactor for front-end #4
This commit is contained in:
@@ -2,13 +2,13 @@ import React from 'react';
|
||||
import { useGame } from '../../contexts/GameContext';
|
||||
import GridField from './GridField';
|
||||
import UserControl from '../user/UserControl';
|
||||
import { BOMB_SYMBOLS, bombRadius } from '../../constants';
|
||||
import { BOMB_SYMBOLS, bombRadius } from '../../utils/constants';
|
||||
|
||||
const GridControl = ({ onClick, resign }) => {
|
||||
const {
|
||||
overlay, overlayTitle, overlaySubTitle,
|
||||
webPlayer, activePlayer, mines, foundMines, bombSelected,
|
||||
red, blue, cells, setCells, onBombToggle,
|
||||
webPlayer, activePlayer, bombSelected,
|
||||
cells, setCells,
|
||||
} = useGame();
|
||||
|
||||
const handleHover = (row, col) => {
|
||||
@@ -39,13 +39,6 @@ const GridControl = ({ onClick, resign }) => {
|
||||
</div>
|
||||
</div>
|
||||
<UserControl
|
||||
webPlayer={webPlayer}
|
||||
activePlayer={activePlayer}
|
||||
mines={mines}
|
||||
foundMines={foundMines}
|
||||
red={red}
|
||||
blue={blue}
|
||||
onBombToggle={onBombToggle}
|
||||
resign={resign}
|
||||
/>
|
||||
<div className="grid-container">
|
||||
@@ -58,7 +51,7 @@ const GridControl = ({ onClick, resign }) => {
|
||||
onClick={() => onClick([r, c])}
|
||||
onMouseEnter={() => handleHover(r, c)}
|
||||
/>
|
||||
))
|
||||
)),
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import React, { memo } from 'react';
|
||||
import { IMG } from '../../constants';
|
||||
import { IMAGES } from '../../utils/constants';
|
||||
|
||||
const bombSrc = area => {
|
||||
if (null === area) return null;
|
||||
const vert = ['left', 'center', 'right'][area[0]] ?? null;
|
||||
const hor = ['top', 'middle', 'bottom'][area[1]] ?? null;
|
||||
if (null === vert || null === hor) return IMG + 'bg-bomb-empty-outbg.png';
|
||||
return `${IMG}bg-bomb-${hor}-${vert}-outbg.png`;
|
||||
if (null === vert || null === hor) return IMAGES.bombEmpty;
|
||||
return IMAGES.bombPos(hor, vert);
|
||||
};
|
||||
|
||||
const GridField = memo(function GridField({ cell, onClick, onMouseEnter }) {
|
||||
@@ -28,13 +28,12 @@ const GridField = memo(function GridField({ cell, onClick, onMouseEnter }) {
|
||||
const bSrc = bombSrc(bombTargetArea);
|
||||
const showLast = lastClickedRed || lastClickedBlue;
|
||||
const lastClass = 'field-' + (lastClickedRed ? 'red' : 'blue') + '-last last-clicked';
|
||||
const lastSrc = lastClickedRed ? IMG + 'bg-last-red-outbg.png' : IMG + 'bg-last-blue-outbg.png';
|
||||
|
||||
return (
|
||||
<div className="field-wrapper" onClick={onClick} onMouseEnter={onMouseEnter}>
|
||||
<img className="field-target" src={IMG + 'bg-target-outbg.png'} alt="" />
|
||||
<img className="field-target" src={IMAGES.target} alt="" />
|
||||
{bSrc && <img className="field-bomb-target" src={bSrc} alt="" />}
|
||||
{showLast && <img className={lastClass} src={lastSrc} alt="" />}
|
||||
{showLast && <img className={lastClass} src={IMAGES.last(lastClickedRed ? 'red' : 'blue')} alt="" />}
|
||||
<div className={fieldClass}>
|
||||
<div className="field-corner">{inner}</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user