-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
265 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import usePrevious from "@/hooks/usePrevious"; | ||
import { useStore } from "@/store"; | ||
import { | ||
FlattenedSiteLayout, | ||
GameSite, | ||
MainSubscene, | ||
NodeID, | ||
Position, | ||
} from "@/types"; | ||
import { getLevelY } from "@/utils/site"; | ||
import React, { memo, useEffect, useState } from "react"; | ||
import Node from "./Node"; | ||
|
||
type LevelNodesProps = { | ||
flattenedLayout: FlattenedSiteLayout; | ||
site: GameSite; | ||
}; | ||
|
||
const LevelNodes = (props: LevelNodesProps) => { | ||
const currentLevel = useStore((state) => state.level); | ||
const paused = useStore((state) => state.mainSubscene === MainSubscene.Pause); | ||
const currentNode = useStore((state) => state.node); | ||
const prevData = usePrevious({ level: currentLevel }); | ||
|
||
const [nodes, setNodes] = useState<NodeID[]>( | ||
props.flattenedLayout[currentLevel] | ||
); | ||
const [pos, setPos] = useState<Position>([0, getLevelY(currentLevel), 0]); | ||
|
||
useEffect(() => { | ||
if (prevData?.level !== currentLevel && prevData?.level !== undefined) { | ||
if (Math.abs(prevData.level - currentLevel) === 1) { | ||
// if only changed one level | ||
setNodes(props.flattenedLayout[currentLevel]); | ||
setPos([0, getLevelY(currentLevel), 0]); | ||
} else { | ||
// if changed from level selection | ||
setTimeout(() => { | ||
setNodes(props.flattenedLayout[currentLevel]); | ||
setPos([0, getLevelY(currentLevel), 0]); | ||
}, 1500); | ||
} | ||
} | ||
}, [currentLevel, prevData?.level, props.flattenedLayout, props.site]); | ||
|
||
return ( | ||
<group position={pos}> | ||
{nodes.map((nodeId) => ( | ||
<Node | ||
id={nodeId} | ||
key={nodeId} | ||
active={nodeId === currentNode?.id && !paused} | ||
/> | ||
))} | ||
</group> | ||
); | ||
}; | ||
|
||
export default memo(LevelNodes); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { memo, useMemo } from "react"; | ||
import PurpleRing from "./PurpleRing"; | ||
import GrayRing from "./GrayRing"; | ||
import CyanCrystal from "./CyanCrystal"; | ||
import { useStore } from "@/store"; | ||
import { getLevelLimit, getLevelY } from "@/utils/site"; | ||
import range from "@/utils/range"; | ||
import { GameSite } from "@/types"; | ||
|
||
type RingsProps = { | ||
activateAllRings: boolean; | ||
site: GameSite; | ||
}; | ||
|
||
const Rings = (props: RingsProps) => { | ||
const level = useStore((state) => state.level); | ||
|
||
const visibleLevels: number[] = useMemo(() => { | ||
if (props.activateAllRings) { | ||
return range(1, getLevelLimit(props.site) + 1); | ||
} else { | ||
const start = Math.max(0, level - 2); | ||
const end = Math.min(getLevelLimit(props.site) + 1, level + 2); | ||
|
||
return range(start, end); | ||
} | ||
}, [level, props.activateAllRings, props.site]); | ||
|
||
return ( | ||
<> | ||
{visibleLevels.map((level: number) => ( | ||
<group position={[0, getLevelY(level), 0]} key={level}> | ||
<PurpleRing level={level} site={props.site} /> | ||
<GrayRing /> | ||
<CyanCrystal /> | ||
</group> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default memo(Rings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/components/canvas/objects/MainScene/StaticLevelNodes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import usePrevious from "@/hooks/usePrevious"; | ||
import { useStore } from "@/store"; | ||
import { FlattenedSiteLayout, GameSite } from "@/types"; | ||
import range from "@/utils/range"; | ||
import { getLevelLimit, getLevelY } from "@/utils/site"; | ||
import React, { memo, useEffect, useState } from "react"; | ||
import StaticNode from "./StaticNode"; | ||
|
||
type StaticLevelNodesProps = { | ||
flattenedLayout: FlattenedSiteLayout; | ||
site: GameSite; | ||
}; | ||
|
||
const StaticLevelNodes = (props: StaticLevelNodesProps) => { | ||
const currentLevel = useStore((state) => state.level); | ||
const prevData = usePrevious({ level: currentLevel }); | ||
|
||
const [visibleLevels, setVisibleLevels] = useState<number[]>( | ||
range( | ||
Math.max(currentLevel - 3, 0), | ||
Math.min(currentLevel + 3, getLevelLimit(props.site)) | ||
) | ||
); | ||
|
||
useEffect(() => { | ||
if (prevData?.level !== currentLevel && prevData?.level !== undefined) { | ||
const start = Math.max(currentLevel - 3, 1); | ||
const end = Math.min(currentLevel + 3, getLevelLimit(props.site)); | ||
if (Math.abs(prevData.level - currentLevel) === 1) { | ||
// if only changed one level | ||
setVisibleLevels(range(start, end)); | ||
} else { | ||
// if changed from level selection | ||
setTimeout(() => setVisibleLevels(range(start, end)), 1500); | ||
} | ||
} | ||
}, [currentLevel, prevData?.level, props.site]); | ||
|
||
return ( | ||
<> | ||
{visibleLevels.map((level) => ( | ||
<group position={[0, getLevelY(level), 0]} key={level}> | ||
{props.flattenedLayout[level].map((nodeId) => ( | ||
<StaticNode id={nodeId} key={nodeId} /> | ||
))} | ||
</group> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default memo(StaticLevelNodes); |
Oops, something went wrong.