diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..177bc7d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} diff --git a/src/components/Interaction.tsx b/src/components/Interaction.tsx new file mode 100644 index 0000000..4923154 --- /dev/null +++ b/src/components/Interaction.tsx @@ -0,0 +1,138 @@ +/** @jsxImportSource @emotion/react */ +import { css } from "@emotion/react"; +import { + InfoInteraction, + LinkInteraction, + TraverseInteraction, +} from "../types/Interactions"; +import { useState } from "react"; + +import Parser from "../modules/Parser"; +import JohnsYard from "../test/johns-yard.json"; +import { TourGraph } from "../types/TourGraph"; + +const buttonCss = css` + padding: 7px 15px; + background-color: #0099ff; + color: white; + border: none; + width: 100%; + cursor: pointer; + transition: transform 0.2s; + border-radius: 10px; + margin: 5px 0; + font-size: 15px; + + &:active { + transform: scale(0.95); + } + + svg, + span { + display: inline-block; + vertical-align: middle; + } + + span { + margin-left: 5px; + font-weight: 700; + } +`; + +const infoCss = css` + padding: 7px 15px; + background-color: #0099ff; + color: white; + border: none; + width: 100%; + /* cursor: pointer; */ + transition: transform 0.2s; + border-radius: 10px; + margin: 5px 0; + font-size: 15px; + + /* &:active { + transform: scale(0.95); + } */ + + svg, + span { + display: inline-block; + vertical-align: middle; + } + + span { + margin-left: 5px; + font-weight: 700; + } +`; + +interface InfoInteractionProps { + interaction: InfoInteraction; +} + +interface LinkInteractionProps { + interaction: LinkInteraction; +} + +interface TraverseInteractionProps { + interaction: TraverseInteraction; + setLocation: any; +} + +// Remove onClicks from class and set them in here +export function InfoInteractionC(props: InfoInteractionProps) { + const { interaction } = props; + const [toggleButton, setToggleButton] = useState(false); + const { Icon, information } = interaction; + const onClick = () => setToggleButton(!toggleButton); + + return ( + <> + + {toggleButton &&
{information}
} + + ); +} + +export function LinkInteractionC(props: LinkInteractionProps) { + const { interaction } = props; + const { Icon, onClick } = interaction; + + return ( + <> + + + ); +} + +const getLocationFromId = (graph: TourGraph, id: number) => { + if (!graph) return null; + return graph.locations.find((loc) => loc.locationId === id) || null; +}; + +export function TraverseInteractionC(props: TraverseInteractionProps) { + const { interaction, setLocation } = props; + const { Icon } = interaction; + + // TODO: Instead of calling this again change to an emitter function + let parser = new Parser(); + let tourGraphs = parser.getGraph(JohnsYard); + let graph = tourGraphs[0]; + let location = getLocationFromId(graph, interaction.destinationId); + + return ( + <> + + + ); +} diff --git a/src/components/Overlay.tsx b/src/components/Overlay.tsx index 2b7475e..5000b27 100644 --- a/src/components/Overlay.tsx +++ b/src/components/Overlay.tsx @@ -32,6 +32,7 @@ interface OverlayProps { position: Vector3; distanceFactor: number; onClick(): void; + setLocation(): any; title: string; description: string; interactions: Interaction[]; @@ -45,6 +46,7 @@ export default function Overlay(props: OverlayProps) { title, description, interactions, + setLocation, } = props; return ( @@ -53,7 +55,10 @@ export default function Overlay(props: OverlayProps) {

{title}

{description}

- +
diff --git a/src/components/OverlayInteractions.tsx b/src/components/OverlayInteractions.tsx index 7ab7d91..d770da6 100644 --- a/src/components/OverlayInteractions.tsx +++ b/src/components/OverlayInteractions.tsx @@ -1,80 +1,36 @@ /** @jsxImportSource @emotion/react */ -import { css } from "@emotion/react"; -import { Link, ArrowRight, Info } from "react-feather"; import { Interaction, + InfoInteraction, LinkInteraction, TraverseInteraction, } from "../types/Interactions"; - -const buttonCss = css` - padding: 7px 15px; - background-color: #0099ff; - color: white; - border: none; - width: 100%; - cursor: pointer; - transition: transform 0.2s; - border-radius: 10px; - margin: 5px 0; - font-size: 15px; - - &:active { - transform: scale(0.95); - } - - svg, - span { - display: inline-block; - vertical-align: middle; - } - - span { - margin-left: 5px; - font-weight: 700; - } -`; - -// returns the proper icon for each interaction -function returnIcon(interaction: Interaction) { - if (interaction instanceof LinkInteraction) { - return Link; - } else if (interaction instanceof TraverseInteraction) { - return ArrowRight; - } - // default to the Info icon - return Info; -} - -// opens a new tab with the given link -function linkOnClick(link: string) { - window.open(link, "_blank"); -} - -// returns the proper onClick method for each interaction -function returnOnClick(interaction: Interaction) { - if (interaction instanceof LinkInteraction) { - return () => linkOnClick(interaction.url); - } else { - return () => {}; - } -} - +import { + LinkInteractionC, + InfoInteractionC, + TraverseInteractionC, +} from "./Interaction"; interface OverlayInteractionsProps { interactions: Interaction[]; + setLocation: any; } -export default function OverlayInteractions(args: OverlayInteractionsProps) { - let { interactions } = args; - let buttons = interactions.map((interaction, key) => { - const Icon = returnIcon(interaction); - let onClick = returnOnClick(interaction); - return ( - - ); +export default function OverlayInteractions(props: OverlayInteractionsProps) { + let { interactions, setLocation } = props; + let buttons = interactions.map((interaction: Interaction, key) => { + if (interaction instanceof InfoInteraction) { + return ; + } else if (interaction instanceof LinkInteraction) { + return ; + } else if (interaction instanceof TraverseInteraction) { + return ( + + ); + } }); return
{buttons}
; diff --git a/src/components/Panorama.tsx b/src/components/Panorama.tsx index 15ff4ce..0b1e1fd 100644 --- a/src/components/Panorama.tsx +++ b/src/components/Panorama.tsx @@ -4,14 +4,15 @@ import Overlay from "./Overlay"; import { Location } from "../types/Location"; import { OverlayData } from "../types/OverlayData"; -let textureCache: Texture | null = null; +// let textureCache: Texture | null = null; interface PanoramaProps { location: Location; + setLocation: any; } export default function Panorama(props: PanoramaProps) { - let { location } = props; + let { location, setLocation } = props; let { image, overlays } = location; // This reference will give us direct access to the mesh @@ -19,25 +20,20 @@ export default function Panorama(props: PanoramaProps) { let [texture, setTexture] = useState(new Texture()); function loadPanorama() { - if (textureCache) { - setTexture(textureCache); - return; - } + // removed since texture cache will always have a value after init + // if (textureCache) { + // setTexture(textureCache); + // return; + // } import(`../assets/${image}`).then((res) => { const texture = new TextureLoader().load(res.default); - textureCache = texture; + // textureCache = texture; setTexture(texture); }); } useEffect(loadPanorama, [image]); - // const [interaction, setInteraction] = useState(""); - - // const handleInteraction = (i) => { - // setInteraction(i); - // }; - let overlayComponents = overlays.map((overlay: OverlayData) => { return ( {}} - // onClick={() => handleInteraction(overlay.information)} + setLocation={setLocation} /> ); }); diff --git a/src/components/Tour.tsx b/src/components/Tour.tsx index 9e0a9c4..9026405 100644 --- a/src/components/Tour.tsx +++ b/src/components/Tour.tsx @@ -75,7 +75,7 @@ export default function Tour() { {!isPath && ( <> - + {/* */} void = () => {}; constructor(buttonText: string) { this.buttonText = buttonText; @@ -11,6 +15,8 @@ export class InfoInteraction extends Interaction { constructor(buttonText: string, information: string) { super(buttonText); this.information = information; + this.Icon = Info; + this.onClick = () => (this.isVisible = !this.isVisible); } } @@ -22,6 +28,7 @@ export class TraverseInteraction extends Interaction { super(buttonText); this.destinationId = destinationId; this.video = video; + this.Icon = ArrowRight; } } @@ -31,5 +38,7 @@ export class LinkInteraction extends Interaction { constructor(buttonText: string, url: string) { super(buttonText); this.url = url; + this.Icon = Link; + this.onClick = () => window.open(url, "_blank"); } }