Skip to content

Commit

Permalink
Fixes crash when attempting to use a viewing area
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-bell committed Mar 19, 2024
1 parent 0dafa6d commit 450e41a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions frontend/src/classes/TownController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,20 @@ export function useTownSettings() {
*/
export function useInteractableAreaController<T>(interactableAreaID: string): T {
const townController = useTownController();
const interactableAreaController = townController.gameAreas.find(
const gameAreaController = townController.gameAreas.find(
eachArea => eachArea.id == interactableAreaID,
);
if (!interactableAreaController) {
if (!gameAreaController) {
//Look for a viewing area
const viewingAreaController = townController.viewingAreas.find(
eachArea => eachArea.id == interactableAreaID,
);
if (viewingAreaController) {
return viewingAreaController as unknown as T;
}
throw new Error(`Requested interactable area ${interactableAreaID} does not exist`);
}
return interactableAreaController as unknown as T;
return gameAreaController as unknown as T;
}

/**
Expand Down

0 comments on commit 450e41a

Please sign in to comment.