2026-04-10 21:53:50 +02:00
|
|
|
/**
|
|
|
|
|
* This file is part of the SplendidBear Websites' projects.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2026 @ www.splendidbear.org
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-04-10 17:57:26 +02:00
|
|
|
import React, { memo } from 'react';
|
2026-04-10 21:53:50 +02:00
|
|
|
import { IMAGES } from '@mine-utils';
|
2026-04-10 17:57:26 +02:00
|
|
|
|
|
|
|
|
const bombSrc = area => {
|
|
|
|
|
if (null === area) return null;
|
|
|
|
|
const vert = ['left', 'center', 'right'][area[0]] ?? null;
|
|
|
|
|
const hor = ['top', 'middle', 'bottom'][area[1]] ?? null;
|
2026-04-10 19:09:05 +02:00
|
|
|
if (null === vert || null === hor) return IMAGES.bombEmpty;
|
|
|
|
|
return IMAGES.bombPos(hor, vert);
|
2026-04-10 17:57:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const GridField = memo(function GridField({ cell, onClick, onMouseEnter }) {
|
|
|
|
|
const { currentImage, currentObj, active, lastClickedRed, lastClickedBlue, bombTargetArea } = cell;
|
|
|
|
|
|
|
|
|
|
const fieldClass = 'field'
|
|
|
|
|
+ (active ? ' active' : '')
|
|
|
|
|
+ (active && 'm' === currentObj ? ' mine' : '')
|
|
|
|
|
+ ' color-' + currentObj;
|
|
|
|
|
|
|
|
|
|
const inner = isNaN(currentImage)
|
|
|
|
|
? (
|
|
|
|
|
<div className="flag-mine"><img src={currentImage} alt="" />
|
|
|
|
|
<div className="flag-mine-base" />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
: currentImage ? <div className="flag-number">{currentImage}</div> : null;
|
|
|
|
|
|
|
|
|
|
const bSrc = bombSrc(bombTargetArea);
|
|
|
|
|
const showLast = lastClickedRed || lastClickedBlue;
|
|
|
|
|
const lastClass = 'field-' + (lastClickedRed ? 'red' : 'blue') + '-last last-clicked';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="field-wrapper" onClick={onClick} onMouseEnter={onMouseEnter}>
|
2026-04-10 19:09:05 +02:00
|
|
|
<img className="field-target" src={IMAGES.target} alt="" />
|
2026-04-10 17:57:26 +02:00
|
|
|
{bSrc && <img className="field-bomb-target" src={bSrc} alt="" />}
|
2026-04-10 19:09:05 +02:00
|
|
|
{showLast && <img className={lastClass} src={IMAGES.last(lastClickedRed ? 'red' : 'blue')} alt="" />}
|
2026-04-10 17:57:26 +02:00
|
|
|
<div className={fieldClass}>
|
|
|
|
|
<div className="field-corner">{inner}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default GridField;
|