Skip to content

Commit

Permalink
Merge pull request benlikescode#1 from Yaffles/dev
Browse files Browse the repository at this point in the history
Added No Panning and changed world map for streaks
  • Loading branch information
Yaffles authored Jul 27, 2024
2 parents 8c0614f + 7935109 commit c3e9a5b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
58 changes: 57 additions & 1 deletion components/StreetView/StreetView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useEffect, useRef, useState } from 'react'
import React, { ButtonHTMLAttributes, FC, useEffect, useRef, useState } from 'react'
import { Game } from '@backend/models'
import { GameStatus } from '@components/GameStatus'
import { GuessMap } from '@components/GuessMap'
Expand Down Expand Up @@ -84,6 +84,7 @@ const Streetview: FC<Props> = ({ gameData, setGameData, view, setView }) => {
})

setLoading(false)
console.log('Pano loaded')
}

const handleSubmitGuess = async (timedOut?: boolean) => {
Expand Down Expand Up @@ -162,6 +163,61 @@ const Streetview: FC<Props> = ({ gameData, setGameData, view, setView }) => {
}
}, [view])

const handleMouseDown = (e: MouseEvent) => {
if (!gameData.gameSettings.canPan) {
e.stopPropagation();
}
};

const handleTouchStart = (e: TouchEvent) => {
if (!gameData.gameSettings.canPan) {
e.stopPropagation();
}
};

useEffect(() => {
if (view !== 'Game') return

const div = document.getElementById('streetview');
if (!div) return;

div.addEventListener('mousedown', handleMouseDown, { capture: true });
div.addEventListener('touchstart', handleTouchStart, { capture: true });

// Only add event listeners if `canPan` is false
console.log(div.getElementsByClassName('gm-control-active').length);

// Cleanup event listeners on unmount or dependency change
return () => {
div.removeEventListener('mousedown', handleMouseDown, { capture: true });
div.removeEventListener('touchstart', handleTouchStart, { capture: true });
};
}, [view, gameData.gameSettings.canPan]);


function disableCompassControls() {
var compassControls = document.getElementsByClassName('gm-control-active');
console.log(compassControls);
for (var i = 0; i < compassControls.length; i++) {
let compassControl = compassControls[i] as HTMLElement;
compassControl.addEventListener('click', (e) => {
e.stopPropagation();
});
}
}

useEffect(() => {
if (loading) return;

const div = document.getElementById('streetview');
if (!div) return;

if (!gameData.gameSettings.canPan) {
disableCompassControls();
}

} , [loading, gameData.gameSettings.canPan]);

return (
<StyledStreetView showMap={!loading}>
{loading && <LoadingPage />}
Expand Down
5 changes: 5 additions & 0 deletions components/modals/GameSettingsModal/GameSettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ const GameSettingsModal: FC<Props> = ({ isOpen, closeModal, mapDetails, gameMode
<ToggleSwitch isActive={canZoom} setIsActive={setCanZoom} />
<div className="movementOptionLabel">Zoom</div>
</div>

<div className="movementOption">
<ToggleSwitch isActive={canPan} setIsActive={setCanPan} />
<div className="movementOptionLabel">Pan</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion utils/constants/random.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const OFFICIAL_WORLD_ID = '6533cef7dda2d10f45e377bd'
export const OFFICIAL_WORLD_ID = '66a230bde441aba03e06f5e2'
export const COUNTRY_STREAKS_ID = 'streaks'

export const GUEST_ACCOUNT_ID = '636ed6784ec6f85e6f18591e'
Expand Down

0 comments on commit c3e9a5b

Please sign in to comment.