generated from nhcarrigan/template
feat: limit players to one active exploration at a time
Server-side: check if any area is already in_progress before allowing a new exploration to start. Client-side: derive hasActiveExploration from the full areas list and disable all Explore buttons (with a tooltip) whilst another area is underway. Closes #9.
This commit is contained in:
@@ -75,8 +75,9 @@ exploreRouter.post("/start", async (context) => {
|
|||||||
return context.json({ error: "Exploration area not found in state" }, 404);
|
return context.json({ error: "Exploration area not found in state" }, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (area.status === "in_progress") {
|
const anyInProgress = state.exploration.areas.some((a) => a.status === "in_progress");
|
||||||
return context.json({ error: "Exploration already in progress" }, 400);
|
if (anyInProgress) {
|
||||||
|
return context.json({ error: "An exploration is already in progress" }, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (area.status === "locked") {
|
if (area.status === "locked") {
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ export const ExplorationPanel = (): React.JSX.Element => {
|
|||||||
|
|
||||||
const zoneAreas = EXPLORATION_AREAS.filter((a) => a.zoneId === activeZoneId);
|
const zoneAreas = EXPLORATION_AREAS.filter((a) => a.zoneId === activeZoneId);
|
||||||
|
|
||||||
|
const hasActiveExploration =
|
||||||
|
explorationState?.areas.some((a) => a.status === "in_progress") ?? false;
|
||||||
|
|
||||||
const handleStart = async (areaId: string): Promise<void> => {
|
const handleStart = async (areaId: string): Promise<void> => {
|
||||||
setPendingAreaId(areaId);
|
setPendingAreaId(areaId);
|
||||||
try {
|
try {
|
||||||
@@ -137,8 +140,9 @@ export const ExplorationPanel = (): React.JSX.Element => {
|
|||||||
{status === "available" && (
|
{status === "available" && (
|
||||||
<button
|
<button
|
||||||
className="start-quest-button"
|
className="start-quest-button"
|
||||||
disabled={isPending}
|
disabled={isPending || hasActiveExploration}
|
||||||
onClick={() => { void handleStart(area.id); }}
|
onClick={() => { void handleStart(area.id); }}
|
||||||
|
title={hasActiveExploration ? "An exploration is already in progress" : undefined}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
{isPending ? "Departing..." : `Explore (${formatDuration(area.durationSeconds)})`}
|
{isPending ? "Departing..." : `Explore (${formatDuration(area.durationSeconds)})`}
|
||||||
|
|||||||
Reference in New Issue
Block a user