feat: snap to stops in easy mode
All checks were successful
deploy to cloudflare pages / deploy (push) Successful in 32s

This commit is contained in:
uku 2024-10-26 13:03:09 +02:00
parent 1dc77d6d2a
commit 3ff96cc411
Signed by: uku
SSH key fingerprint: SHA256:4P0aN6M8ajKukNi6aPOaX0LacanGYtlfjmN+m/sHY/o
3 changed files with 16 additions and 11 deletions

View file

@ -8,7 +8,7 @@ export interface GameOptions {
export interface GameData {
lines: [GeoJSON.Feature, string][];
stops: GeoJSON.Feature[];
stops: [number, number][];
stopName: string;
gameId: string;
}

View file

@ -32,8 +32,9 @@ export const load: PageServerLoad = async ({ fetch, url, platform }) => {
const lineCodes = new Set<string>(lineColors.map(([f, _]) => f.properties!.code_ligne));
const crossingStops = await getMergedStops(fetch, lineCodes);
const strippedStops = crossingStops.map((f) => {
return { ...f, properties: {} };
const strippedStops: [number, number][] = crossingStops.map((f) => {
const coords = (f.geometry as GeoJSON.Point).coordinates;
return [coords[1], coords[0]];
});
const randomStop = crossingStops[Math.floor(Math.random() * crossingStops.length)];

View file

@ -23,6 +23,13 @@
function createMap(node: HTMLElement) {
map = L.map(node).setView(center, 13);
function setMarker(pos: L.LatLng) {
if (map && playerMarker && !results) {
playerMarker.setLatLng(pos);
latlng = pos;
}
}
L.tileLayer(`https://basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}{r}.png`, {
attribution:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>',
@ -33,17 +40,14 @@
data.gameData.lines.forEach(([feature, color]) => {
L.geoJSON(feature, { style: { color } }).addTo(map!);
});
data.gameData.stops.forEach((f) => L.geoJSON(f).addTo(map!));
data.gameData.stops.forEach((coords) => {
const marker = L.marker(coords).addTo(map!);
marker.on("click", (e) => setMarker(e.latlng));
});
const playerMarker = L.marker([0, 0]).addTo(map);
map.on("click", (e) => {
if (map && playerMarker && !results) {
playerMarker.setLatLng(e.latlng);
latlng = e.latlng;
}
});
map.on("click", (e) => setMarker(e.latlng));
map.on("keydown", (e) => {
if (latlng.lat !== 0 && latlng.lng !== 0 && e.originalEvent.key === " ") {
checkLocation();