Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ OPENRADLR_LANDING_IMPRINT_URL=
OPENRADLR_LANDING_PLAUSIBLE_DOMAIN=

# --- OpenBikeNet (optional) -----------------------------------------------------
# Shares the velodrome with riders of other apps. Sent: rider name, position, speed,
# power and cadence of the riders on the velodrome. Empty = not connected.
# Shares the tracks (the velodromes) with riders of other apps. Sent: rider name, position,
# speed, power and cadence of the riders on the tracks. Empty = not connected.
# OPENRADLR_OBN_URL=wss://obn.example/v0
OPENRADLR_OBN_URL=

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ All settings live in `.env`; see [`.env.example`](.env.example) for descriptions
| `OPENRADLR_REQUIRE_STRAVA` | `false` | Riders must connect Strava to join |
| `OPENRADLR_ALLOW_SIMULATED_TRAINER` | `true` | Offer the simulated trainer (set `false` in production) |
| `OPENRADLR_ALLOW_PADDLE_MODE` | `true` | Offer phone paddles (tap left/right for power; no Strava, no ride files) |
| `OPENRADLR_OBN_URL` | – | `wss://` URL of an OpenBikeNet server: shares the velodrome with riders of other apps (see [deploy.md](docs/deploy.md#openbikenet-optional)) |
| `OPENRADLR_OBN_URL` | – | `wss://` URL of an OpenBikeNet server: shares the tracks (velodromes) with riders of other apps (see [deploy.md](docs/deploy.md#openbikenet-optional)) |
| `OPENRADLR_PRIVACY_URL` | – | Link to your privacy policy in the start menu |
| `OPENRADLR_ANALYTICS_DOMAIN` / `_SCRIPT` | – | Opt-in Plausible analytics for the client: your site name, and the script URL if you self-host Plausible (off when the domain is empty) |
| `OPENRADLR_STUDIO` | `true` | Host the spin studio (group classes) next to the routes |
Expand Down
1 change: 1 addition & 0 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ <h3 id="unfinished-strava-panel-title" data-i18n="strava.title">Strava</h3>
<header class="stage-head">
<h1 id="routes-title" data-i18n="menu.routes.title">Where do you want to ride?</h1>
<p id="stage-stats" class="stage-stats"></p>
<div id="route-directions" class="figure-chips route-directions" role="group" aria-label="Which way round" data-i18n-attr="aria-label:menu.direction.label" hidden></div>
<p id="shared-note" class="lede shared-note" hidden></p>
<p id="routes-lede" class="lede" data-i18n="menu.stage.rideLede">Everyone on the same route rides together — friends, strangers and bots.</p>
</header>
Expand Down
5 changes: 5 additions & 0 deletions client/public/js/i18n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ export default {
"menu.server.unreachable": "Server nicht erreichbar",
"menu.shared": "Geteilt",
"menu.shared.note": "Fahrer anderer Apps fahren hier mit. Mit ihnen geteilt: dein Name, deine Position, Geschwindigkeit, Leistung und Trittfrequenz.",
"menu.direction.label": "Fahrtrichtung",
"menu.direction.anticlockwise": "Gegen den Uhrzeigersinn",
"menu.direction.clockwise": "Im Uhrzeigersinn",
"menu.riders.one": "{n} Fahrer",
"menu.riders.other": "{n} Fahrer",
"menu.server.full": "Voll · {riders} online",
Expand All @@ -232,6 +235,8 @@ export default {
"route.cape-loop.description": "Entlang der Strände an der Südküste, über die niedrigen Klippen des südöstlichen Kaps und zurück durch das Tal und die westlichen Buchten.",
"route.col-de-la-forge.description": "Über die Hügel zur Forge Hut auf dem Pass, dann eine lange, schnelle Abfahrt zurück ins Tal.",
"route.forge-circuit.description": "Von der Forge Hut die Westseite hinunter, zurück über die Höhenstraße und wieder hinauf zum Pass.",
"route.herne-hill.description": "Die 450-m-Freiluftbahn des Herne Hill Velodrome in London, gegen den Uhrzeigersinn wie im Rennen; geteilt mit Fahrern aus anderen Apps, wenn dieser Server mit OpenBikeNet verbunden ist.",
"route.herne-hill-clockwise.description": "Herne Hill Velodrome andersherum, von derselben Start-/Ziellinie aus; geteilt mit Fahrern aus anderen Apps, wenn dieser Server mit OpenBikeNet verbunden ist.",
"route.island-tour.description": "Der lange Weg rundherum: das Flusstal, der Pass von Westen, die Höhenstraße und zurück durch das westliche Tal.",
"route.lanzarote-lava-180.description": "Eine 180-km-Runde um Lanzarote mit etwa 2.500 Höhenmetern, angelehnt an die Raddistanz des berühmten Langdistanz-Triathlons der Insel. Streckenreihenfolge unbestätigt: aus öffentlichen Führern zusammengestellt, wartet auf die Prüfung durch jemanden, der sie kennt.",
"route.riverside-flats.description": "Schnell und flach das Flusstal entlang, wie gemacht fürs Windschattenfahren und für Sprints.",
Expand Down
5 changes: 5 additions & 0 deletions client/public/js/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ export default {
"menu.server.unreachable": "Server unreachable",
"menu.shared": "Shared",
"menu.shared.note": "Riders from other apps ride here too. Shared with them: your name, position, speed, power and cadence.",
"menu.direction.label": "Which way round",
"menu.direction.anticlockwise": "Anticlockwise",
"menu.direction.clockwise": "Clockwise",
"menu.riders.one": "{n} rider",
"menu.riders.other": "{n} riders",
"menu.server.full": "Full · {riders} online",
Expand All @@ -232,6 +235,8 @@ export default {
"route.cape-loop.description": "Along the beaches of the south coast, over the low cliffs of the south-eastern cape and back by the valley and the western bays.",
"route.col-de-la-forge.description": "Over the hills to the Forge Hut on the col, then a long, fast descent back to the valley.",
"route.forge-circuit.description": "From the Forge Hut down the west side, back along the high road and up to the col again.",
"route.herne-hill.description": "The 450 m outdoor track of Herne Hill Velodrome in London, ridden anticlockwise as in racing; shared with riders from other apps when this server is connected to OpenBikeNet.",
"route.herne-hill-clockwise.description": "Herne Hill Velodrome the other way round, from the same start/finish line; shared with riders from other apps when this server is connected to OpenBikeNet.",
"route.island-tour.description": "The long way round: the river valley, the col from the west, the high road and back down the west valley.",
"route.lanzarote-lava-180.description": "A 180 km loop around Lanzarote with about 2,500 m of climbing, in the spirit of the island's famous long-distance triathlon bike leg. Course order unconfirmed: built from public guides, pending a check by someone who knows it.",
"route.riverside-flats.description": "Fast and flat down the river valley, made for drafting and sprints.",
Expand Down
13 changes: 9 additions & 4 deletions client/public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { drawRaceTimeline } from "./view/raceTimelineView.js";
import { drawMapPreview } from "./view/mapPreview.js";
import { MenuStage } from "./view/menuStage.js";
import { BUILD } from "./build.js";
import { buildLabel, communityDistance, pickRoute, renderRoutes, routesOf, serverStatus, stageHeadline, stageLede, stageStats, workoutRoute, devicesVisible, privacyUrl, serverName, joinAction, stravaLine, activityOf, activityTabs, pickForActivity, renderActivityTabs, routesFor, shownActivity, showsCards, sharedNote } from "./view/startMenu.js";
import { buildLabel, communityDistance, pickRoute, renderRoutes, routesOf, serverStatus, stageHeadline, stageLede, stageStats, workoutRoute, devicesVisible, privacyUrl, serverName, joinAction, stravaLine, activityOf, activityTabs, pickForActivity, renderActivityTabs, routesFor, shownActivity, showsCards, sharedNote, rideCards, cardIdOf, cardPick, directionsOf, renderDirections } from "./view/startMenu.js";
import { PRESETS } from "./workout/presets.js";
import { renderWorkoutCards } from "./view/workoutCards.js";
import { WorkoutSession, endAfterAsking } from "./workout/workoutSession.js";
Expand Down Expand Up @@ -1058,13 +1058,18 @@ function renderStartMenu() {
const shared = sharedNote(selected);
$("shared-note").hidden = !shared;
$("shared-note").textContent = shared;
const cards = routesFor(activity, routes);
const cards = rideCards(routesFor(activity, routes));
$("route-list").hidden = !showsCards(activity, cards);
renderRoutes($("route-list"), cards, selected?.id ?? null, (id) => {
const pick = (id) => {
app.routeId = id;
writeSetting(ROUTE_KEY, id);
renderStartMenu();
});
};
renderRoutes($("route-list"), cards, cardIdOf(selected, routes), (id) => pick(cardPick(id, selected, routes)));
// A track ridden both ways round: which way, under its name.
const directions = activity === "events" ? [] : directionsOf(selected, routes);
$("route-directions").hidden = directions.length === 0;
renderDirections($("route-directions"), directions, pick);
app.menu?.select(routes, selected?.id ?? null);
renderEvents(events);
renderUnfinished();
Expand Down
64 changes: 63 additions & 1 deletion client/public/js/view/startMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const activityLabels = () => ({ ride: t("menu.tab.ride"), studio: t("menu.tab.st
*/
export function activityTabs(routes, events) {
const tabs = ["ride", "studio", "workout"]
.map((id) => ({ id, label: activityLabels()[id], count: routesFor(id, routes).length, live: false }))
.map((id) => ({ id, label: activityLabels()[id], count: rideCards(routesFor(id, routes)).length, live: false }))
.filter((tab) => tab.count > 0);
if (events.length) tabs.push({ id: "events", label: activityLabels().events, count: events.length, live: events.some((row) => row.joinable || row.countdown === t("events.running")) });
return tabs;
Expand Down Expand Up @@ -231,6 +231,68 @@ export function sharedNote(route) {
return route?.shared === true ? t("menu.shared.note") : "";
}

/** `herne-hill-clockwise` is `herne-hill` ridden the other way round (docs/routes.md). */
const CLOCKWISE = "-clockwise";
const baseId = (id) => (id.endsWith(CLOCKWISE) ? id.slice(0, -CLOCKWISE.length) : id);

/** A track and its other way round, both served, or null. */
function waysRound(route, routes) {
if (!route?.id) return null;
const id = baseId(route.id);
const anticlockwise = routes.find((r) => r.id === id);
const clockwise = routes.find((r) => r.id === `${id}${CLOCKWISE}`);
return anticlockwise && clockwise ? [anticlockwise, clockwise] : null;
}

/** The cards: a track ridden both ways round is one, with the riders of both. */
export function rideCards(routes) {
return routes.flatMap((route) => {
const pair = waysRound(route, routes);
if (!pair) return [route];
if (route === pair[1]) return [];
const [a, b] = pair;
return [{ ...a, players: (a.players ?? 0) + (b.players ?? 0), phone_players: (a.phone_players ?? 0) + (b.phone_players ?? 0) }];
});
}

/** The card a route is on. */
export function cardIdOf(route, routes) {
return route ? (waysRound(route, routes)?.[0].id ?? route.id) : null;
}

/** The route a click on a card picks: the track's card keeps the way round already picked. */
export function cardPick(cardId, selected, routes) {
return selected && cardIdOf(selected, routes) === cardId ? selected.id : cardId;
}

/** The ways round the picked track, to choose from under its name; none for any other route. */
export function directionsOf(route, routes) {
const pair = waysRound(route, routes);
if (!pair) return [];
return pair.map((r, i) => ({ id: r.id, label: t(i === 0 ? "menu.direction.anticlockwise" : "menu.direction.clockwise"), riders: routeRiders(r), picked: r.id === route.id }));
}

/**
* Renders the ways round as chips, the picked one pressed.
* @param {HTMLElement} list
* @param {{id: string, label: string, riders: string, picked: boolean}[]} directions from `directionsOf`
* @param {(id: string) => void} onSelect
*/
export function renderDirections(list, directions, onSelect) {
drawWhenChanged(list, JSON.stringify(directions), onSelect, (select) =>
list.replaceChildren(
...directions.map((direction) => {
const button = element("button", "figure-chip");
button.type = "button";
button.setAttribute("aria-pressed", String(direction.picked));
button.append(element("strong", null, direction.label), element("span", "muted", direction.riders));
button.addEventListener("click", () => select(direction.id));
return button;
}),
),
);
}

/** What a route card shows. */
export function routeCard(route) {
const studio = route.kind === "studio";
Expand Down
10 changes: 6 additions & 4 deletions client/public/js/view3d/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,17 @@ export function buildWorld(route, { others = [], network = null, biome = tempera
biome = resolveBiome(typeof biome === "string" ? biome : biome.id);
const density = biome.flora.density;
const roads = network ? network.roads() : null;
// Every route of the map keeps its asphalt clear, whichever is ridden, so the world looks the same from all of them.
const mapRoutes = [route, ...others.filter((o) => o.id !== route.id)];
// Tracks (#107): routes of the map that aren't walks over its roads, drawn and levelled like them.
const tracks = network ? mapRoutes.filter((r) => !network.routes.some((w) => w.id === r.id)) : [];
// Everything drawn as a road (the ridden route first), and what the shared
// things are built along.
const routes = network ? [route, ...roads] : [route, ...others.filter((o) => o.id !== route.id)];
const routes = network ? [route, ...roads, ...tracks.filter((t) => t !== route)] : mapRoutes;
const ordered = network ? roads : [...routes].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
const seed = network ? network.seed : mapSeed(route);
const zonesOf = new Map(routes.map((r) => [r, resolveZones(r)]));
// Every route of the map keeps its asphalt clear, whichever is ridden, so the world looks the same from all of them.
const mapRoutes = [route, ...others.filter((o) => o.id !== route.id)];
const base = network ? networkTerrain(network, roads, { keepClear: mapRoutes }) : terrainModel(ordered, { seed });
const base = network ? networkTerrain(network, [...roads, ...tracks], { keepClear: mapRoutes }) : terrainModel(ordered, { seed });
const sea = waterLevel(base.index);
const rivers = ordered.flatMap((r) => zonesOf.get(r).rivers.map((z) => ({ ...buildRiverPath(r, base, z.at, r.seed >>> 0, sea), route: r })));
const terrain = rivers.length > 0 ? withRivers(base, rivers, sea - RIVER.mouthDepth) : { ...base, riverDistance: () => Infinity };
Expand Down
4 changes: 4 additions & 0 deletions client/public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ kbd {
display: none;
}

.route-directions {
margin: 0 0 8px;
}

.stage-head .lede {
margin: 0;
max-width: 62ch;
Expand Down
34 changes: 33 additions & 1 deletion client/test/startMenu.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { pickRoute, routeCharacter, routeStats, routesOf, serverStatus, studioTagline, buildLabel, communityDistance, routeRiders, workoutRoute, workoutTagline, stageStats, stageHeadline, stageLede, devicesVisible, privacyUrl, serverName, activityOf, routesFor, pickForActivity, activityTabs, shownActivity, showsCards, routeCard, stravaLine, joinAction, routeDescription, sharedNote } from "../public/js/view/startMenu.js";
import { pickRoute, routeCharacter, routeStats, routesOf, serverStatus, studioTagline, buildLabel, communityDistance, routeRiders, workoutRoute, workoutTagline, stageStats, stageHeadline, stageLede, devicesVisible, privacyUrl, serverName, activityOf, routesFor, pickForActivity, activityTabs, shownActivity, showsCards, routeCard, stravaLine, joinAction, routeDescription, sharedNote, rideCards, cardIdOf, cardPick, directionsOf } from "../public/js/view/startMenu.js";
import { PRESETS } from "../public/js/workout/presets.js";

const routes = [
Expand Down Expand Up @@ -260,6 +260,38 @@ test("a shared route shows the shared badge and note", () => {
assert.equal(sharedNote(velodrome), "Riders from other apps ride here too. Shared with them: your name, position, speed, power and cadence.");
});

const herneHill = { id: "herne-hill", name: "Herne Hill Velodrome", length_m: 450, players: 2, phone_players: 1, shared: true };
const clockwise = { id: "herne-hill-clockwise", name: "Herne Hill Velodrome (clockwise)", length_m: 450, players: 1, shared: true };
const withTrack = [routes[0], herneHill, clockwise];

test("a track ridden both ways round is one card, with the riders of both", () => {
const cards = rideCards(withTrack);
assert.deepEqual(cards.map((r) => r.id), ["rolling-hills", "herne-hill"]);
assert.deepEqual([cards[1].players, cards[1].phone_players], [3, 1]);
assert.equal(cardIdOf(clockwise, withTrack), "herne-hill");
assert.equal(cardIdOf(herneHill, withTrack), "herne-hill");
assert.equal(cardIdOf(routes[0], withTrack), "rolling-hills");
assert.equal(cardIdOf(null, withTrack), null);
// A server that has only one way round shows it as it is.
assert.deepEqual(rideCards([clockwise]), [clockwise]);
});

test("picking the track's card keeps the way round already picked", () => {
assert.equal(cardPick("herne-hill", clockwise, withTrack), "herne-hill-clockwise");
assert.equal(cardPick("herne-hill", routes[0], withTrack), "herne-hill");
assert.equal(cardPick("rolling-hills", clockwise, withTrack), "rolling-hills");
});

test("the way round is a choice of its own, with the riders going each way", () => {
assert.deepEqual(directionsOf(clockwise, withTrack), [
{ id: "herne-hill", label: "Anticlockwise", riders: "2 riders · 1 📱", picked: false },
{ id: "herne-hill-clockwise", label: "Clockwise", riders: "1 rider", picked: true },
]);
assert.deepEqual(directionsOf(routes[0], withTrack), []);
assert.deepEqual(directionsOf(clockwise, [clockwise]), []);
assert.deepEqual(directionsOf(null, withTrack), []);
});

test("other routes don't", () => {
assert.equal(routeCard(routes[0]).shared, false);
assert.equal(sharedNote(routes[0]), "");
Expand Down
Loading
Loading