Use one instance count for all beta games
This commit is contained in:
+15
-6
@@ -6,7 +6,7 @@ export interface BetaDraft {
|
||||
picks: Array<{ scriptId: number | null; versionId: number | null }>;
|
||||
servers: string[]; testPlan: BetaPlan;
|
||||
selectionMode: 'automatic' | 'manual';
|
||||
instancesPerGame: Record<string, number | null>;
|
||||
instanceCount: number | null;
|
||||
label?: string;
|
||||
}
|
||||
/** Validate draft structure, preserving incomplete numeric fields for correction. */
|
||||
@@ -23,9 +23,17 @@ export function readBetaDraft(raw: string | null): BetaDraft | null {
|
||||
if (d.instancesPerGame !== undefined && (!d.instancesPerGame || typeof d.instancesPerGame !== 'object'
|
||||
|| Array.isArray(d.instancesPerGame) || !Object.entries(d.instancesPerGame).every(([game, count]) =>
|
||||
['t5', 't6'].includes(game) && (count === null || typeof count === 'number' && Number.isFinite(count))))) return null;
|
||||
if (d.instanceCount !== undefined && d.instanceCount !== null
|
||||
&& (typeof d.instanceCount !== 'number' || !Number.isFinite(d.instanceCount))) return null;
|
||||
const previousCounts = Object.values(d.instancesPerGame ?? {}) as Array<number | null>;
|
||||
const instanceCount = d.instanceCount !== undefined ? d.instanceCount
|
||||
: previousCounts.includes(null) ? null : previousCounts.length ? Math.max(...previousCounts as number[]) : 1;
|
||||
// Existing drafts represent explicit selections and must not silently switch modes.
|
||||
return { ...d, selectionMode: d.selectionMode ?? (d.servers.length ? 'manual' : 'automatic'),
|
||||
instancesPerGame: d.instancesPerGame ?? {}, step: Math.max(0, Math.min(3, Number(d.step) || 0)) };
|
||||
const selectionMode = d.selectionMode ?? (d.servers.length ? 'manual' : 'automatic');
|
||||
// Revisit server setup when old per-game counts cannot be retained as one value.
|
||||
const changedCounts = selectionMode === 'automatic' && d.instanceCount === undefined && new Set(previousCounts).size > 1;
|
||||
return { ...d, selectionMode,
|
||||
instanceCount, step: Math.max(0, Math.min(changedCounts ? 1 : 3, Number(d.step) || 0)) };
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
@@ -48,9 +56,10 @@ export function betaApplicableGames(files: readonly BetaFileScope[], servers: re
|
||||
].filter((game): game is string => game === 't5' || game === 't6'))].sort();
|
||||
}
|
||||
|
||||
/** Keep incomplete counts recoverable and default newly applicable games to one. */
|
||||
export function betaInstanceCounts(games: readonly string[], saved: Record<string, number | null>): Record<string, number | null> {
|
||||
return Object.fromEntries(games.map(game => [game, saved[game] === undefined ? 1 : saved[game]]));
|
||||
/** Expand the shared count only to games represented by the selected files. */
|
||||
export function betaInstanceCounts(games: readonly string[], count: number | null): Record<string, number> {
|
||||
if (count === null || !Number.isSafeInteger(count) || count < 1 || count > 1000) return {};
|
||||
return Object.fromEntries(games.map(game => [game, count]));
|
||||
}
|
||||
|
||||
export function compatibleBetaServers(selected: Iterable<string>, candidates: readonly string[]): { kept: Set<string>; removed: string[] } {
|
||||
|
||||
Reference in New Issue
Block a user