diff --git a/TODO.md b/TODO.md index f0c2668..cf1f774 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,7 @@ - [x] **Modal name popup**. When a Pi-Rat gains a name, they get a modal popup they have to fill out before continuing, rather than an optional box on their character sheet -- [ ] **Cancel Revise**. In character creation, if you click "Revise" and then don't want to make any changes after all, there should be a cancel button that throws away any edits you've made since you clicked revise. +- [x] **Cancel Revise**. In character creation, if you click "Revise" and then don't want to make any changes after all, there should be a cancel button that throws away any edits you've made since you clicked revise. - [ ] **Teaching mode**. The creator/admin should have an option to seed themselves as the player who is forced to be the Deep for the first scene diff --git a/frontend/src/components/CharacterCreationPhase.svelte b/frontend/src/components/CharacterCreationPhase.svelte index 2f06fb3..c0ebece 100644 --- a/frontend/src/components/CharacterCreationPhase.svelte +++ b/frontend/src/components/CharacterCreationPhase.svelte @@ -40,6 +40,11 @@ editingBasic = true; } + // Discard any edits made since clicking Revise and return to the saved view. + function cancelReviseBasic() { + editingBasic = false; + } + // Like/Hate tasks are assigned automatically when character creation starts. // This is a fallback for games that entered the phase before assignments existed. onMount(async () => { @@ -63,6 +68,10 @@ let tech1 = '', tech2 = '', tech3 = ''; let savingTechs = false; let techError = ''; + // True while editing previously-submitted techniques (vs. first-time entry), + // so we know to offer a Cancel button. techSnapshot holds the saved values. + let revisingTechs = false; + let techSnapshot = []; async function submitTechniques() { savingTechs = true; @@ -71,6 +80,7 @@ await apiRequest(`/game/${state.game.id}/player/${state.player.id}/submit-techniques`, 'POST', { tech1, tech2, tech3 }); + revisingTechs = false; } catch(e) { techError = e.message; } finally { @@ -79,12 +89,33 @@ } async function reviseTechniques() { + techSnapshot = [...createdTechniques]; [tech1 = '', tech2 = '', tech3 = ''] = createdTechniques; + revisingTechs = true; techError = ''; try { await apiRequest(`/game/${state.game.id}/player/${state.player.id}/unsubmit-techniques`, 'POST'); } catch(e) { techError = e.message; + revisingTechs = false; + } + } + + // Throw away edits and re-submit the techniques as they were before Revise. + async function cancelReviseTechniques() { + savingTechs = true; + techError = ''; + try { + await apiRequest(`/game/${state.game.id}/player/${state.player.id}/submit-techniques`, 'POST', { + tech1: techSnapshot[0] || '', + tech2: techSnapshot[1] || '', + tech3: techSnapshot[2] || '' + }); + revisingTechs = false; + } catch(e) { + techError = e.message; + } finally { + savingTechs = false; } } @@ -127,6 +158,9 @@ let jackTech = '', queenTech = '', kingTech = ''; let assigningFace = false; let faceError = ''; + // True while revising a previously-assigned J/Q/K layout, so we offer Cancel. + let revisingFace = false; + let faceSnapshot = {}; async function assignFaceTechniques() { assigningFace = true; @@ -137,6 +171,7 @@ queen: queenTech, king: kingTech }); + revisingFace = false; } catch(e) { faceError = e.message; } finally { @@ -145,14 +180,39 @@ } async function reviseFaceTechniques() { + faceSnapshot = { + jack: state.player.tech_jack, + queen: state.player.tech_queen, + king: state.player.tech_king + }; jackTech = state.player.tech_jack; queenTech = state.player.tech_queen; kingTech = state.player.tech_king; + revisingFace = true; faceError = ''; try { await apiRequest(`/game/${state.game.id}/player/${state.player.id}/unassign-face-techniques`, 'POST'); } catch(e) { faceError = e.message; + revisingFace = false; + } + } + + // Throw away edits and re-assign the J/Q/K layout as it was before Revise. + async function cancelReviseFaceTechniques() { + assigningFace = true; + faceError = ''; + try { + await apiRequest(`/game/${state.game.id}/player/${state.player.id}/assign-face-techniques`, 'POST', { + jack: faceSnapshot.jack, + queen: faceSnapshot.queen, + king: faceSnapshot.king + }); + revisingFace = false; + } catch(e) { + faceError = e.message; + } finally { + assigningFace = false; } } @@ -245,7 +305,12 @@ {#if devMode}{/if} - +