Skip to content

PC-CLAIM-4: Foundry actor sync detects player-character-claiming addon, routes to PC sub-type#64

Merged
keyxmakerx merged 1 commit into
mainfrom
claude/cool-darwin-vy7sut
Jun 19, 2026
Merged

PC-CLAIM-4: Foundry actor sync detects player-character-claiming addon, routes to PC sub-type#64
keyxmakerx merged 1 commit into
mainfrom
claude/cool-darwin-vy7sut

Conversation

@keyxmakerx

Copy link
Copy Markdown
Owner

Why

Stages 2 & 3 (Chronicle-side, now merged) plumbed the player-character-claiming addon, the claimable flag, and the GM/player UI for it — but the Foundry module still pushed every character actor to the generic character type with no owner, ignoring both the addon state and the "Player Characters" sub-type that Stage 2 created. This is Stage 4 of 4 of the staged Player Character Claiming feature.

What's in here

1. Addon detection — sync-manager.mjs

_fetchAddons() runs after _detectSystem() and before any module init(), calling GET /addons and caching whether player-character-claiming is enabled. isPcClaimingEnabled() exposes the result. Gracefully degrades when the endpoint isn't deployed (flag stays false).

2. PC sub-type routing — actor-sync.mjs

  • _resolveCharacterTypeId() now also resolves _pcSubtypeId in the same /entity-types call when the addon is on — finds the direct child of _characterTypeId whose slug/name matches "player-characters" via the exported _findPcSubtypeId() pure helper.
  • _handleCreateActor() gates _resolveOwnerUserId() on isPcClaimingEnabled():
    • Addon offownerUserId = null (no auto-claim, parent character type used)
    • Addon on + player owner → uses the PC sub-type via exported _pickEntityTypeId(), includes owner_user_id in the POST
    • Addon on + no player owner → parent character type, no owner
  • _isCharacterEntity() refactored: ID-based check is now authoritative when IDs are resolved, accepting both parent type and PC sub-type; slug/name remain as fallbacks for minimal/pre-init payloads.
  • onInitialSync() queries both _characterTypeId and _pcSubtypeId so existing actor links under either type are refreshed.
  • hasPlayerOwnedPcs() added for the dashboard hint.

3. Dashboard hint — sync-dashboard.mjs + templates/sync-dashboard.hbs

_buildCharacterData() returns pcClaimingHint: true when the addon is off AND at least one player-owned character actor exists. The Characters tab shows a single non-spammy info bar: "Enable Player Character Claiming in Chronicle to sync player claims." Visible only when the condition is true; never fires as a repeated notification.

Verification

  • node -c clean on all 3 changed scripts
  • node --test tools/test-pc-claiming.mjs: 29/29 (new, covers _findPcSubtypeId, _pickEntityTypeId, _isCharacterEntity, hasPlayerOwnedPcs, isPcClaimingEnabled, _fetchAddons)
  • Full suite node --test tools/test-*.mjs: 445/445

No conflicts with Chronicle PC-CLAIM-3 (#482)

PR #482 (now merged) was entirely server-side UI — owner display on the entity page, GM roster, per-type checkbox. It made no API shape changes to the endpoints this module calls (GET /addons, POST /entities, GET /entity-types). Our branch is branched directly from the post-merge main.

🤖 Generated with Claude Code

https://claude.ai/code/session_019WVEMu2d2t2ZyqGsGDJnLv


Generated by Claude Code

…ter-claiming addon

- sync-manager.mjs: _fetchAddons() calls GET /addons after _detectSystem() and
  before module init; exposes isPcClaimingEnabled() to all modules. Gracefully
  degrades when the endpoint is not yet deployed.

- actor-sync.mjs:
  • _resolveCharacterTypeId() resolves _pcSubtypeId in the same /entity-types
    call when the addon is on, via exported _findPcSubtypeId() pure helper.
  • _handleCreateActor() gates owner resolution on isPcClaimingEnabled() (addon
    off → no auto-claim); routes player-owned actors to the PC sub-type via
    exported _pickEntityTypeId() pure helper.
  • _isCharacterEntity() refactored: ID-based check is now authoritative,
    accepting both parent character type and PC sub-type; slug/name are fallbacks.
  • onInitialSync() queries both character type and PC sub-type.
  • hasPlayerOwnedPcs() added for dashboard hint.

- sync-dashboard.mjs + templates/sync-dashboard.hbs: one-line info hint
  "Enable Player Character Claiming in Chronicle to sync player claims."
  shown in the Characters tab when addon is off and player-owned PCs exist.

- tools/test-pc-claiming.mjs: 29 unit tests, all pass (445 total suite green).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019WVEMu2d2t2ZyqGsGDJnLv
@keyxmakerx keyxmakerx merged commit 4de43c3 into main Jun 19, 2026
1 check passed
keyxmakerx added a commit that referenced this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants