2024-06-18 04:36:44 -05:00
|
|
|
import {Container} from '@pixi/display';
|
|
|
|
import {Graphics} from '@pixi/graphics';
|
2024-06-25 01:46:07 -05:00
|
|
|
import {PixiComponent} from '@pixi/react';
|
2024-07-14 21:07:46 -05:00
|
|
|
|
2024-07-20 04:32:33 -05:00
|
|
|
import {useRadians} from '@/react/context/radians.js';
|
2024-06-18 04:36:44 -05:00
|
|
|
|
2024-08-01 00:40:06 -05:00
|
|
|
import {deferredLighting} from './lights.js';
|
|
|
|
|
2024-06-18 04:36:44 -05:00
|
|
|
const tileSize = {x: 16, y: 16};
|
|
|
|
|
|
|
|
const TargetingGhostInternal = PixiComponent('TargetingGhost', {
|
2024-06-25 01:46:07 -05:00
|
|
|
create: () => {
|
|
|
|
// Solid target square.
|
2024-06-24 10:53:01 -05:00
|
|
|
const target = new Graphics();
|
2024-06-25 01:46:07 -05:00
|
|
|
target.lineStyle(1, 0xffffff);
|
|
|
|
target.drawRect(0.5, 0.5, tileSize.x, tileSize.y);
|
|
|
|
target.pivot = {x: tileSize.x / 2, y: tileSize.y / 2};
|
|
|
|
// Inner spinny part.
|
2024-06-24 10:53:01 -05:00
|
|
|
const targetInner = new Graphics();
|
2024-06-25 01:46:07 -05:00
|
|
|
targetInner.lineStyle(3, 0x333333);
|
|
|
|
targetInner.beginFill(0xdddddd);
|
|
|
|
targetInner.pivot = {x: tileSize.x / 2, y: tileSize.y / 2};
|
|
|
|
targetInner.drawRect(0, 0, tileSize.x, tileSize.y);
|
|
|
|
targetInner.position.x = 0.5;
|
|
|
|
targetInner.position.y = 0.5;
|
|
|
|
// ...
|
2024-06-18 04:36:44 -05:00
|
|
|
const container = new Container();
|
2024-07-31 21:07:17 -05:00
|
|
|
container.alpha = 0.4;
|
2024-06-25 01:46:07 -05:00
|
|
|
container.addChild(target, targetInner);
|
2024-08-01 00:40:06 -05:00
|
|
|
container.parentGroup = deferredLighting.diffuseGroup;
|
2024-06-18 04:36:44 -05:00
|
|
|
return container;
|
|
|
|
},
|
2024-06-25 01:46:07 -05:00
|
|
|
applyProps: (container, oldProps, {x, y, radians}) => {
|
|
|
|
container.position.set(x, y);
|
|
|
|
container.children[1].rotation = radians / 4;
|
|
|
|
container.children[1].scale.set(0.3 + 0.2 * (Math.cos(radians) + 1));
|
2024-06-18 04:36:44 -05:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-06-28 08:53:20 -05:00
|
|
|
export default function TargetingGhost({projected, tileLayer}) {
|
2024-07-14 21:07:46 -05:00
|
|
|
const radians = useRadians();
|
2024-06-25 01:46:07 -05:00
|
|
|
const ghosts = [];
|
2024-06-27 02:14:47 -05:00
|
|
|
const {area} = tileLayer;
|
2024-06-25 06:20:45 -05:00
|
|
|
for (const {x, y} of projected) {
|
2024-06-27 02:14:47 -05:00
|
|
|
if (x < 0 || y < 0 || x >= area.x || y >= area.y) {
|
2024-06-25 06:20:45 -05:00
|
|
|
continue;
|
2024-06-25 01:46:07 -05:00
|
|
|
}
|
2024-06-25 06:20:45 -05:00
|
|
|
ghosts.push(
|
|
|
|
<TargetingGhostInternal
|
|
|
|
key={JSON.stringify({x, y})}
|
|
|
|
x={x * tileSize.x + tileSize.x * 0.5}
|
|
|
|
y={y * tileSize.y + tileSize.y * 0.5}
|
2024-07-14 21:07:46 -05:00
|
|
|
radians={radians / 2}
|
2024-06-25 06:20:45 -05:00
|
|
|
/>
|
|
|
|
);
|
2024-06-25 01:46:07 -05:00
|
|
|
}
|
|
|
|
return <>{ghosts}</>;
|
2024-06-18 04:36:44 -05:00
|
|
|
}
|