Skip to content

Commit

Permalink
Merge pull request #32 from Matt-Hurd/mhurd/feat/prepare_for_routing
Browse files Browse the repository at this point in the history
Mhurd/feat/prepare for routing
  • Loading branch information
Matt-Hurd authored Aug 16, 2023
2 parents 59b40c3 + c4a7c76 commit db2313b
Show file tree
Hide file tree
Showing 15 changed files with 34,507 additions and 37,474 deletions.
71,847 changes: 34,447 additions & 37,400 deletions public/assets/example_route/totk_hundo_centum/route.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions src/components/MapDisplay/MapDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const MapDisplay: React.FC = () => {
if (!route) return null;

const activePoint = route.branches[branchIndex].points[pointIndex];
const activeThing = route.things[activePoint.thingId];

const style = {
height: "100%",
Expand All @@ -30,17 +31,14 @@ const MapDisplay: React.FC = () => {

return (
<MapContainer style={style} bounds={outerBounds} zoom={0} maxZoom={7} minZoom={-5} crs={crs} keyboard={false}>
<RouteMarkers
branch={route.branches[branchIndex]}
activeThing={route.things[activePoint.layerId][activePoint.thingId]}
/>
<RouteMarkers branch={route.branches[branchIndex]} activeThing={activeThing} />
<RouteLines />
<MapUpdate activePoint={activePoint} />
<Pane name="tile_bg" style={{ zIndex: 1 }}>
<TileLayer url={route.game.layers[activePoint.layerId].imagePath} bounds={outerBounds} />

Check failure on line 38 in src/components/MapDisplay/MapDisplay.tsx

View workflow job for this annotation

GitHub Actions / deploy

Property 'layerId' does not exist on type 'Point'.
</Pane>
<Pane name="bg" style={{ zIndex: 0 }}>
<ImageOverlay url={route.url + route.game.layers[activePoint.layerId].baseImagePath} bounds={outerBounds} />
<ImageOverlay url={route.url + route.game.layers[activeThing.layerId].baseImagePath} bounds={outerBounds} />
</Pane>
<MapEvents />
</MapContainer>
Expand Down
5 changes: 1 addition & 4 deletions src/components/MapDisplay/MapUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export const MapUpdate: React.FC<MapUpdateProps> = ({ activePoint }) => {

useEffect(() => {
if (route)
map.setView([
-route.things[activePoint.layerId][activePoint.thingId].coordinates.x,
route.things[activePoint.layerId][activePoint.thingId].coordinates.y,
]);
map.setView([-route.things[activePoint.thingId].coordinates.x, route.things[activePoint.thingId].coordinates.y]);
}, [activePoint, map, route]);

return null;
Expand Down
12 changes: 7 additions & 5 deletions src/components/MapDisplay/RouteLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ const RouteLines: React.FC = () => {

if (!route) return null;

const point = route.branches[branchIndex].points[pointIndex];
const thing = route.things[point.thingId];
const visibleLayerId = thing.layerId;

const polylines = [];
const visibleLayerId = route.branches[branchIndex].points[pointIndex].layerId;
let lastLayerId = null;
let lastPosition = null;

if (branchIndex > 0 && pointIndex === 0) {
const previousBranch = route.branches[branchIndex - 1];
const lastPointOfPreviousBranch = previousBranch.points[previousBranch.points.length - 1];
const lastThingOfPreviousBranch =
route.things[lastPointOfPreviousBranch.layerId][lastPointOfPreviousBranch.thingId];
const lastThingOfPreviousBranch = route.things[lastPointOfPreviousBranch.thingId];
if (lastThingOfPreviousBranch) {
lastLayerId = lastThingOfPreviousBranch.layerId;
lastPosition = [-lastThingOfPreviousBranch.coordinates.x, lastThingOfPreviousBranch.coordinates.y];
Expand All @@ -33,7 +35,7 @@ const RouteLines: React.FC = () => {

for (let i = hideCompletedMarkers ? Math.max(0, pointIndex - 1) : 0; i < activeBranch.points.length; i++) {
const point = activeBranch.points[i];
const thing = route.things[point.layerId][point.thingId];
const thing = route.things[point.thingId];

if (!thing) continue;

Expand All @@ -60,7 +62,7 @@ const RouteLines: React.FC = () => {
if (branchIndex < route.branches.length - 1) {
const nextBranch = route.branches[branchIndex + 1];
const firstPointOfNextBranch = nextBranch.points[0];
const firstThingOfNextBranch = route.things[firstPointOfNextBranch.layerId][firstPointOfNextBranch.thingId];
const firstThingOfNextBranch = route.things[firstPointOfNextBranch.thingId];
if (firstThingOfNextBranch) {
if (firstThingOfNextBranch.layerId === visibleLayerId && lastPosition !== null) {
const position = [-firstThingOfNextBranch.coordinates.x, firstThingOfNextBranch.coordinates.y];
Expand Down
63 changes: 33 additions & 30 deletions src/components/MapDisplay/RouteMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,47 @@ export const RouteMarkers: React.FC<RouteMarkersProps> = ({ branch, activeThing
};

useEffect(() => {
if (activeThing && markerRefs.current.has(activeThing.id)) {
markerRefs.current.get(activeThing.id).openPopup();
if (activeThing && markerRefs.current.has(activeThing.uid)) {
markerRefs.current.get(activeThing.uid).openPopup();
}
}, [activeThing]);

if (!route) return null;

return (
<LayerGroup>
{branch.points.map((point, index) => (
<Marker
key={index}
opacity={
(hideCompletedMarkers ? pointIndex : 0) <= index &&
route.things[point.layerId][point.thingId].layerId === activeThing.layerId
? 1
: 0
{branch.points.map((point, index) => {
const currentThing = route.things[point.thingId];
const { coordinates, name, type } = currentThing;
const isKorok = type === "Korok";

let opacity = 0;
if (currentThing.layerId === activeThing.layerId) {
if (hideCompletedMarkers && pointIndex <= index) {
opacity = 1;
} else if (!hideCompletedMarkers) {
opacity = 1;
}
position={[
-route.things[point.layerId][point.thingId].coordinates.x,
route.things[point.layerId][point.thingId].coordinates.y,
]}
icon={getIconForThing(route.things[point.layerId][point.thingId])}
ref={(ref) => markerRefs.current.set(point.thingId, ref)}
>
<Popup autoPan={false}>
{route.things[point.layerId][point.thingId].name}
<br />
{route.things[point.layerId][point.thingId].type === "Korok"
? (route.things[point.layerId][point.thingId] as Korok).korokType
: point.shortNote}
<br />
{route.things[point.layerId][point.thingId].coordinates.y.toFixed(0)} |{" "}
{route.things[point.layerId][point.thingId].coordinates.x.toFixed(0)} |{" "}
{route.things[point.layerId][point.thingId].coordinates.z.toFixed(0)}
</Popup>
</Marker>
))}
}

return (
<Marker
key={index}
opacity={opacity}
position={[-coordinates.x, coordinates.y]}
icon={getIconForThing(currentThing)}
ref={(ref) => markerRefs.current.set(point.thingId, ref)}
>
<Popup autoPan={false}>
{name}
<br />
{isKorok ? (currentThing as Korok).korokType : point.shortNote}
<br />
{coordinates.y.toFixed(0)} | {coordinates.x.toFixed(0)} | {coordinates.z.toFixed(0)}
</Popup>
</Marker>
);
})}
</LayerGroup>
);
};
2 changes: 1 addition & 1 deletion src/components/OverlayDisplay/OverlayDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class OverlayDisplay extends React.Component<OverlayDisplayProps> {

for (let pidx = 0; pidx < pointCount; pidx++) {
const point = branch.points[pidx];
const thing = route.things[point.layerId][point.thingId] as Thing;
const thing = route.things[point.thingId] as Thing;

switch (thing.type) {
case "Korok":
Expand Down
4 changes: 2 additions & 2 deletions src/components/PointNotesDisplay/PointNotesDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const PointNotesDisplay: React.FC = () => {
if (!route) return;
const savedNotes = StorageManager.getItem(`${route.game}_${route.name}_${branchIndex}_${pointIndex}`);
const point = route.branches[branchIndex].points[pointIndex];
const thing = route.things[point.layerId][point.thingId];
const thing = route.things[point.thingId];
if (savedNotes) {
setNotes(savedNotes);
} else {
Expand All @@ -42,7 +42,7 @@ const PointNotesDisplay: React.FC = () => {

const handleNotesChange = (content: string) => {
const point = route.branches[branchIndex].points[pointIndex];
const thing = route.things[point.layerId][point.thingId];
const thing = route.things[point.thingId];
if (content === "<p><br></p>" || content === "<p></p>" || content === `<p>${getDefaultNote(point, thing)}</p>`) {
StorageManager.removeItem(`${route.game}_${route.name}_${branchIndex}_${pointIndex}`);
return;
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProgressDisplay/ProgressDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ const ProgressDisplay: React.FC = () => {
for (let bidx = 0; bidx <= branchIndex; bidx++) {
for (let pidx = 0; pidx < getMaxPointIdx(bidx, pointIndex); pidx++) {
const point = route.branches[bidx].points[pidx];
const thing = route.things[point.layerId][point.thingId];
const thing = route.things[point.thingId];

if (thing.type === "Shrine" && point.action !== "COMPLETE") continue;

if (!visitedThings.has(point.thingId + point.layerId)) {
visitedThings.add(point.thingId + point.layerId);
if (!visitedThings.has(point.thingId)) {
visitedThings.add(point.thingId);
const type = thing.type;
if (newCounts[type] !== undefined) {
if (type === "Korok") {
Expand Down
4 changes: 2 additions & 2 deletions src/components/RouteListDisplay/RouteListDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const RouteListDisplay: React.FC = () => {

const getNote = (point: Point) => {
if (point.shortNote !== "") return point.shortNote;
const thing = route.things[point.layerId][point.thingId];
const thing = route.things[point.thingId];
if (thing.type === "Korok") {
const korok = thing as Korok;
return korok.korokType;
Expand All @@ -45,7 +45,7 @@ const RouteListDisplay: React.FC = () => {
ref={bIdx === branchIndex && pIdx === pointIndex ? activePointRef : null}
>
<div className="routeList__pointId">{pIdx}</div>
<div className="routeList__pointName">{route.things[point.layerId][point.thingId].name}</div>
<div className="routeList__pointName">{route.things[point.thingId].name}</div>
<div className="routeList__pointNotes">{getNote(point)}</div>
</div>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/components/UpcomingDisplay/UpcomingDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const UpcomingDisplay: React.FC = () => {

for (let pidx = bidx === branchIndex ? pointIndex : 0; pidx < route.branches[bidx].points.length; pidx++) {
const point = route.branches[bidx].points[pidx];
const thing = route.things[point.layerId][point.thingId];
const thing = route.things[point.thingId];

if (thing.type === "Shrine" && point.action === "COMPLETE") {
const shrine = thing as Shrine;
Expand Down
1 change: 0 additions & 1 deletion src/models/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ enum Action {

export default class Point {
thingId: string = "";
layerId: string = "";
shortNote: string = "";
htmlNote: string = "";
action: Action = Action.None;
Expand Down
2 changes: 1 addition & 1 deletion src/models/Route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class Route {
url: string;
game: Game;
branches: Branch[] = [];
things: Record<string, Record<string, Thing>> = {};
things: Record<string, Thing> = {};

constructor(name: string, url: string, game: Game) {
this.name = name;
Expand Down
3 changes: 2 additions & 1 deletion src/models/Thing.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export default class Thing {
id: string = "";
uid: string = "";
name: string = "";
coordinates: { x: number; y: number; z: number } = { x: 0, y: 0, z: 0 };
layerId: string = "";
dependencyIds: string[] = [];
icon: string = "";
type: string = "";
isNativeObject: boolean = true;
}

export class Korok extends Thing {
Expand Down
4 changes: 2 additions & 2 deletions src/store/progressSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const incrementProgress = createAsyncThunk("progress/increment", async (_

if (state.route.data) {
const point = state.route.data.branches[progress.branchIndex].points[progress.pointIndex];
const thing = state.route.data.things[point.layerId][point.thingId];
const thing = state.route.data.things[point.thingId];
if (
liveSplit.isConnected() &&
((thing.type === "Shrine" && point.action === "COMPLETE") || thing.type === "Lightroot")
Expand Down Expand Up @@ -70,7 +70,7 @@ export const decrementProgress = createAsyncThunk("progress/decrement", async (_
}
if (newProgress) {
const point = state.route.data.branches[newProgress.branchIndex].points[newProgress.pointIndex];
const thing = state.route.data.things[point.layerId][point.thingId];
const thing = state.route.data.things[point.thingId];
if (
liveSplit.isConnected() &&
((thing.type === "Shrine" && point.action === "COMPLETE") || thing.type === "Lightroot")
Expand Down
18 changes: 2 additions & 16 deletions src/store/routeSlice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsyncThunk, createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Route, Thing } from "../models";
import { Route } from "../models";
import { AppDispatch, RootState } from ".";

interface RouteState {
Expand Down Expand Up @@ -32,20 +32,6 @@ export const loadRoute = createAsyncThunk<Route, string, { dispatch: AppDispatch
return response;
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const convertPayloadToRoute = (payload: any) => {
const newThings: Record<string, Record<string, Thing>> = {};
payload.things.forEach((thing: Thing) => {
if (!newThings[thing.layerId]) {
newThings[thing.layerId] = {};
}
newThings[thing.layerId][thing.id] = thing;
});

payload.things = newThings;
return payload;
};

const routeSlice = createSlice({
name: "route",
initialState,
Expand All @@ -57,7 +43,7 @@ const routeSlice = createSlice({
})
.addCase(loadRoute.fulfilled, (state, action: PayloadAction<Route>) => {
state.status = "succeeded";
state.data = convertPayloadToRoute(action.payload);
state.data = action.payload;
})
.addCase(loadRoute.rejected, (state, action) => {
state.status = "failed";
Expand Down

0 comments on commit db2313b

Please sign in to comment.