Story 4.1: Task 1 Complete - PlayerPrivacyManager Core Logic

- Created src/contracts/privacy-settings.js with:
  - PrivacySettings typedef
  - PRIVACY_SETTINGS_DEFAULT (both flags false)
  - PRIVACY_SETTING_KEYS and FEATURE_NAME_MAP constants
  - createPrivacySettings() factory
  - isValidPrivacySettings() validator
  - validateSettingKey(), validateSettingValue(), validateFeatureName() helpers
- Created src/core/PlayerPrivacyManager.js with:
  - Constructor with FoundryAdapter DI validation
  - getSettings(userId) - retrieves settings from user flags
  - setSetting(userId, key, value) - async, validates, persists via user.setFlag
  - isOptedIn(userId, feature) - convenience method for feature checks
  - getAllSettings() - aggregates all users' settings (GM view)
  - onChange(callback) - subscription pattern for change events
  - teardown() - cleanup
- Created tests/unit/contracts/privacy-settings.test.js - 44 tests
- Created tests/unit/core/PlayerPrivacyManager.test.js - 35 tests
- All tests passing, lint clean
- Updated sprint-status.yaml: 4-1 from ready-for-dev to in-progress
- Updated story file: Task 1 subtasks 1.1-1.8 marked complete

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-05-23 21:11:55 +02:00
parent e81c05a3db
commit 61f362004e
13 changed files with 1971 additions and 29 deletions
@@ -1,6 +1,6 @@
# Story 4.1: Player Privacy Panel & Automation Opt-ins
**Status:** ready-for-dev
**Status:** in-progress
**Epic:** 4 - Player Privacy Panel
@@ -20,7 +20,7 @@
| **Story ID** | 4.1 |
| **Story Key** | 4-1-player-privacy-panel-and-automation-opt-ins |
| **Title** | Player Privacy Panel & Automation Opt-ins |
| **Status** | ready-for-dev |
| **Status** | in-progress |
| **Priority** | High |
| **Assigned Agent** | DEV (Amelia) |
| **Created** | 2026-05-24 |
@@ -126,30 +126,31 @@
**Files:** `src/core/PlayerPrivacyManager.js`, `src/contracts/privacy-settings.js`, `tests/unit/core/PlayerPrivacyManager.test.js`
**Subtasks:**
- [ ] 1.1: Create `src/contracts/privacy-settings.js` with opt-in flag contracts
- [x] 1.1: Create `src/contracts/privacy-settings.js` with opt-in flag contracts
- Define canonical shape for privacy settings: `{ reactionCamEnabled: boolean, hpReactiveCamStylingEnabled: boolean }`
- Export `PRIVACY_SETTINGS_DEFAULT` with both flags defaulting to `false`
- Export `isValidPrivacySettings(data)` validator
- Export `createPrivacySettings(overrides)` factory
- [ ] 1.2: Write TDD red tests for PlayerPrivacyManager methods
- [ ] 1.3: Create `PlayerPrivacyManager` class with constructor `(adapter)`
- Export `PRIVACY_SETTING_KEYS`, `FEATURE_NAME_MAP`, `validateSettingKey()`, `validateSettingValue()`, `validateFeatureName()`
- [x] 1.2: Write TDD red tests for PlayerPrivacyManager methods
- [x] 1.3: Create `PlayerPrivacyManager` class with constructor `(adapter)`
- Constructor receives FoundryAdapter for user flag access
- No direct `game.*` access (DI enforced)
- [ ] 1.4: Implement `getSettings(userId)` — retrieves privacy settings from user flags
- [x] 1.4: Implement `getSettings(userId)` — retrieves privacy settings from user flags
- Returns merged settings with defaults for missing keys
- Handles null/undefined flag gracefully
- [ ] 1.5: Implement `setSetting(userId, key, value)` — updates a single privacy setting
- [x] 1.5: Implement `setSetting(userId, key, value)` — updates a single privacy setting
- Validates key is known (reactionCamEnabled or hpReactiveCamStylingEnabled)
- Validates value is boolean
- Calls `adapter.users.setFlag(userId, 'video-view-manager', key, value)`
- Emits change event for subscribers
- [ ] 1.6: Implement `isOptedIn(userId, feature)` — convenience method for feature checks
- [x] 1.6: Implement `isOptedIn(userId, feature)` — convenience method for feature checks
- Returns boolean for 'reactionCam' or 'hpReactiveCamStyling'
- Defaults to false if setting not found
- [ ] 1.7: Implement `getAllSettings()` — returns all users' privacy settings (GM only)
- [x] 1.7: Implement `getAllSettings()` — returns all users' privacy settings (GM only)
- Aggregates settings from all connected users
- Only accessible when caller is GM
- [ ] 1.8: Green all PlayerPrivacyManager tests (12-15 tests passing)
- [x] 1.8: Green all PlayerPrivacyManager tests (35 tests passing)
**Acceptance Criteria:** AC-2, AC-3, AC-7, AC-8
@@ -68,6 +68,6 @@ development_status:
# Epic 4: Player Privacy Panel
epic-4: in-progress
4-1-player-privacy-panel-and-automation-opt-ins: ready-for-dev
4-1-player-privacy-panel-and-automation-opt-ins: in-progress
4-2-custom-portrait-fallback: backlog
epic-4-retrospective: optional