Skip to content

Commit

Permalink
fetch all worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
supreme2580 committed Dec 13, 2024
1 parent 67a7876 commit eea9c10
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions frontend/src/canvas/CanvasContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { devnetMode } from '../utils/Consts.js';
import CanvasContainerItem from './CanvasContainerItem.js';

const CanvasContainer = (props) => {
const GRID_SIZE = 6; // 6x6 grid
const CENTER_POS = Math.floor(GRID_SIZE / 2);
const GRID_SIZE = Math.ceil(Math.sqrt(props.worlds?.length || 1));

// Calculate minimum scale based on grid size and viewport
const calculateMinScale = () => {
Expand Down Expand Up @@ -575,7 +574,7 @@ const CanvasContainer = (props) => {
className='CanvasContainer__grid'
style={{
display: 'grid',
// gridTemplateColumns: `repeat(${GRID_SIZE}, ${props.width}px)`,
gridTemplateColumns: `repeat(${GRID_SIZE}, ${props.width}px)`,
gridGap: '20px',
position: 'absolute',
top: '50%',
Expand All @@ -584,18 +583,12 @@ const CanvasContainer = (props) => {
transformOrigin: 'center'
}}
>
{/* {Array.from({ length: GRID_SIZE * GRID_SIZE }, (_, index) => { */}
{Array.from({ length: 1 }, (_, index) => {
const row = Math.floor(index / GRID_SIZE);
const col = index % GRID_SIZE;
const isCenter = row === CENTER_POS && col === CENTER_POS;
const worldId = isCenter
? props.openedWorldId
: `world-${row}-${col}`;
{props.worlds?.map((world) => {
const isCenter = world.worldId === props.openedWorldId;

return (
<div
key={`grid-${row}-${col}`}
key={`grid-${world.worldId}`}
style={{
position: 'relative',
width: `${props.width}px`,
Expand All @@ -604,11 +597,13 @@ const CanvasContainer = (props) => {
cursor: 'pointer',
opacity: isCenter ? 1 : 0.7
}}
onMouseEnter={() => setHoveredWorld(worldId)}
onMouseEnter={() => setHoveredWorld(world.worldId)}
onMouseLeave={() => setHoveredWorld(null)}
onClick={() => {
if (!isCenter) {
console.log(`Clicked world at position ${row},${col}`);
props.setOpenedWorldId(world.worldId);
// Update URL
window.history.pushState({}, '', `/worlds/${world.worldId}`);
}
}}
>
Expand All @@ -623,8 +618,9 @@ const CanvasContainer = (props) => {
selectedBackgroundColor={selectedBackgroundColor}
{...props}
pixelClicked={isCenter ? pixelClicked : () => {}}
openedWorldId={worldId}
showTitle={hoveredWorld === worldId}
openedWorldId={world.worldId}
showTitle={hoveredWorld === world.worldId}
worldName={world.name}
/>
</div>
);
Expand Down

0 comments on commit eea9c10

Please sign in to comment.