From d33f849e26cbce790e2b422508775f27029c61dd Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 27 Jun 2024 02:14:47 -0500 Subject: [PATCH] refactor: share less --- app/react-components/ecs.jsx | 8 ++++---- app/react-components/targeting-ghost.jsx | 6 +++--- app/react-components/targeting-grid.jsx | 11 +++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/react-components/ecs.jsx b/app/react-components/ecs.jsx index a57ef5b..69d8dd3 100644 --- a/app/react-components/ecs.jsx +++ b/app/react-components/ecs.jsx @@ -63,7 +63,7 @@ export default function EcsComponent() { } const entity = ecs.get(mainEntity); const {Camera} = entity; - const {TileLayers} = ecs.get(1); + const {TileLayers: {layers: [layer]}} = ecs.get(1); const [cx, cy] = [ Math.round(Camera.x - RESOLUTION.x / 2), Math.round(Camera.y - RESOLUTION.y / 2), @@ -73,19 +73,19 @@ export default function EcsComponent() { x={-cx} y={-cy} > - + {activeTool && ( )} {activeTool && ( )} diff --git a/app/react-components/targeting-ghost.jsx b/app/react-components/targeting-ghost.jsx index bd038f5..7581531 100644 --- a/app/react-components/targeting-ghost.jsx +++ b/app/react-components/targeting-ghost.jsx @@ -33,7 +33,7 @@ const TargetingGhostInternal = PixiComponent('TargetingGhost', { }, }) -export default function TargetingGhost({ecs, entity, projection}) { +export default function TargetingGhost({entity, projection, tileLayer}) { const [radians, setRadians] = useState(0); useEffect(() => { const handle = setInterval(() => { @@ -43,12 +43,12 @@ export default function TargetingGhost({ecs, entity, projection}) { clearInterval(handle); }; }, []); - const {TileLayers: {layers: [layer]}} = ecs.get(1); const {Position, Wielder} = entity; const projected = Wielder.project(Position.tile, projection) const ghosts = []; + const {area} = tileLayer; for (const {x, y} of projected) { - if (x < 0 || y < 0 || x >= layer.area.x || y >= layer.area.y) { + if (x < 0 || y < 0 || x >= area.x || y >= area.y) { continue; } ghosts.push( diff --git a/app/react-components/targeting-grid.jsx b/app/react-components/targeting-grid.jsx index e4992c0..068fd5a 100644 --- a/app/react-components/targeting-grid.jsx +++ b/app/react-components/targeting-grid.jsx @@ -28,7 +28,7 @@ function makeFade(renderer) { } const TargetingGridInternal = PixiComponent('TargetingGrid', { - create: ({app, ecs}) => { + create: ({app, tileLayer}) => { const fade = makeFade(app.renderer); const grid = new Graphics(); const lineWidth = 1; @@ -59,11 +59,10 @@ const TargetingGridInternal = PixiComponent('TargetingGrid', { innerGrid.mask = fade; const container = new Container(); container.addChild(fade, grid, innerGrid); - // Clamp within layer area. + // Clamp within tile layer area. const area = new Graphics(); area.beginFill(0xffffff); - const {TileLayers: {layers: [layer]}} = ecs.get(1) - const {x, y} = layer.area; + const {x, y} = tileLayer.area; area.drawRect(0, 0, x * tileSize.x, y * tileSize.y); container.mask = area; const top = new Container(); @@ -86,7 +85,7 @@ const TargetingGridInternal = PixiComponent('TargetingGrid', { }, }) -export default function TargetingGrid({ecs, entity}) { +export default function TargetingGrid({entity, tileLayer}) { const app = useApp(); const [radians, setRadians] = useState(0); useEffect(() => { @@ -100,9 +99,9 @@ export default function TargetingGrid({ecs, entity}) { return ( ); }