Bug: Cannot restart practicing a discipline after stopping it #163

Closed
opened 2026-05-27 15:50:49 +02:00 by Anexim · 2 comments
Owner

Bug Description

After stopping a discipline (deactivating it), the player cannot start practicing it again. Clicking "Start Practicing" does nothing.

Steps to Reproduce

  1. Start practicing any discipline (e.g. Raw Mana Mastery)
  2. Stop practicing it
  3. Click "Start Practicing" again → nothing happens

Root Cause

In DisciplinesTab.tsx, the handleToggle callback calls activate(id, { elements, signedPacts }) but never passes rawMana in the gameState object.

In discipline-math.tscanProceedDiscipline(), when the discipline's manaType is 'raw', it checks:

return (gameState.rawMana || 0) >= drain;

Since rawMana is undefined, this evaluates to 0 >= drainBase which is false for any discipline with drainBase > 0.

On first activation, disciplineState is undefined, so canProceedDiscipline short-circuits with return true. But after deactivation, the discipline state exists (with accumulated XP), so the mana check runs and silently fails.

Fix

Pass rawMana from the mana store into the gameState argument when calling activate in DisciplinesTab.tsx.

## Bug Description After stopping a discipline (deactivating it), the player cannot start practicing it again. Clicking "Start Practicing" does nothing. ## Steps to Reproduce 1. Start practicing any discipline (e.g. Raw Mana Mastery) 2. Stop practicing it 3. Click "Start Practicing" again → nothing happens ## Root Cause In `DisciplinesTab.tsx`, the `handleToggle` callback calls `activate(id, { elements, signedPacts })` but **never passes `rawMana`** in the gameState object. In `discipline-math.ts` → `canProceedDiscipline()`, when the discipline's `manaType` is `'raw'`, it checks: ```ts return (gameState.rawMana || 0) >= drain; ``` Since `rawMana` is `undefined`, this evaluates to `0 >= drainBase` which is `false` for any discipline with `drainBase > 0`. On first activation, `disciplineState` is `undefined`, so `canProceedDiscipline` short-circuits with `return true`. But after deactivation, the discipline state exists (with accumulated XP), so the mana check runs and silently fails. ## Fix Pass `rawMana` from the mana store into the `gameState` argument when calling `activate` in `DisciplinesTab.tsx`.
Anexim added the ai:in-progress label 2026-05-27 15:50:49 +02:00
n8n-gitea was assigned by Anexim 2026-05-27 15:50:49 +02:00
Author
Owner

Fix Applied

File changed: src/components/game/tabs/DisciplinesTab.tsx

Two changes:

  1. Added rawMana from useManaStore and passed it in the gameState object to activate()
  2. Fixed the useCallback dependency array to include rawMana and signedPacts (was missing both)

Root cause confirmed: canProceedDiscipline() in discipline-math.ts checks gameState.rawMana >= drain for raw mana disciplines. Since rawMana was never passed, it evaluated to 0 >= drainBasefalse, silently blocking reactivation. First-time activation worked because disciplineState is undefined, which short-circuits the check.

Regression test added: src/lib/game/__tests__/discipline-reactivate-bug.test.ts — 4 tests covering:

  • Raw discipline reactivation (reproduces the bug without rawMana, verifies fix with it)
  • Element discipline reactivation
  • Reactivation after processTick auto-pause
  • XP preservation across deactivate/reactivate cycles

All 906 tests pass (47 files).

## Fix Applied **File changed:** `src/components/game/tabs/DisciplinesTab.tsx` **Two changes:** 1. Added `rawMana` from `useManaStore` and passed it in the `gameState` object to `activate()` 2. Fixed the `useCallback` dependency array to include `rawMana` and `signedPacts` (was missing both) **Root cause confirmed:** `canProceedDiscipline()` in `discipline-math.ts` checks `gameState.rawMana >= drain` for raw mana disciplines. Since `rawMana` was never passed, it evaluated to `0 >= drainBase` → `false`, silently blocking reactivation. First-time activation worked because `disciplineState` is `undefined`, which short-circuits the check. **Regression test added:** `src/lib/game/__tests__/discipline-reactivate-bug.test.ts` — 4 tests covering: - Raw discipline reactivation (reproduces the bug without `rawMana`, verifies fix with it) - Element discipline reactivation - Reactivation after processTick auto-pause - XP preservation across deactivate/reactivate cycles All 906 tests pass (47 files).
Author
Owner

Fixed and pushed to master (commit 5f8a860). The fix passes rawMana from the mana store into the activate() call in DisciplinesTab, and fixes the useCallback dependency array to include rawMana and signedPacts. Regression tests added and all 906 tests pass.

Fixed and pushed to master (commit 5f8a860). The fix passes `rawMana` from the mana store into the `activate()` call in DisciplinesTab, and fixes the useCallback dependency array to include `rawMana` and `signedPacts`. Regression tests added and all 906 tests pass.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#163