Dev mode revamp
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { apiRequest } from '../lib/api';
|
||||
import { extraMenuLinks } from '../lib/menu';
|
||||
import { getSuggestion } from '../lib/suggestions';
|
||||
|
||||
import LobbyPhase from '../components/LobbyPhase.svelte';
|
||||
import CharacterCreationPhase from '../components/CharacterCreationPhase.svelte';
|
||||
@@ -58,12 +59,60 @@
|
||||
intervalId = setInterval(fetchState, 30000);
|
||||
});
|
||||
|
||||
// Surface the creator-only Admin link in the corner menu
|
||||
$: extraMenuLinks.set(
|
||||
state?.player?.is_creator
|
||||
? [{ label: '🛠️ Admin', href: `#/game/${gameId}/admin`, title: 'Open the Admin Panel' }]
|
||||
: []
|
||||
);
|
||||
// Creator-only corner menu entries: Dev Mode toggle (all phases), the
|
||||
// Skip Character Creation shortcut (Dev Mode only), and the Admin link.
|
||||
async function toggleDevMode() {
|
||||
try {
|
||||
await apiRequest(`/game/${gameId}/player/${playerId}/dev-mode`, 'POST', {
|
||||
enabled: !state.game.dev_mode
|
||||
});
|
||||
} catch (err) {
|
||||
error = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
async function skipCharacterCreation() {
|
||||
// Suggested values for everyone's free-text fields; the backend only
|
||||
// applies them to fields players haven't filled in themselves.
|
||||
const fills = {};
|
||||
for (const p of state.players) {
|
||||
fills[p.id] = {
|
||||
avatar_look: getSuggestion('look'),
|
||||
avatar_smell: getSuggestion('smell'),
|
||||
first_words: getSuggestion('first_words'),
|
||||
good_at_math: getSuggestion('good_at_math'),
|
||||
like: getSuggestion('like'),
|
||||
hate: getSuggestion('hate'),
|
||||
};
|
||||
}
|
||||
try {
|
||||
await apiRequest(`/game/${gameId}/player/${playerId}/skip-character-creation`, 'POST', {
|
||||
fills: JSON.stringify(fills)
|
||||
});
|
||||
} catch (err) {
|
||||
error = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
const items = [];
|
||||
if (state?.player?.is_creator) {
|
||||
items.push({
|
||||
label: `🧪 Dev Mode: ${state.game.dev_mode ? 'On' : 'Off'}`,
|
||||
action: toggleDevMode,
|
||||
title: 'Toggle Dev Mode testing shortcuts for the whole table',
|
||||
});
|
||||
if (state.game.dev_mode && (state.game.phase === 'character_creation' || state.game.phase === 'swap_techniques')) {
|
||||
items.push({
|
||||
label: '⏭️ Skip Character Creation',
|
||||
action: skipCharacterCreation,
|
||||
title: 'Auto-fill anything unfinished for all players and jump to scene setup',
|
||||
});
|
||||
}
|
||||
items.push({ label: '🛠️ Admin', href: `#/game/${gameId}/admin`, title: 'Open the Admin Panel' });
|
||||
}
|
||||
extraMenuLinks.set(items);
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
destroyed = true;
|
||||
|
||||
Reference in New Issue
Block a user