Skip to content

feat: add downtime tracking to Actor #32

Description

@theholocoder

Implement the minimal downtime foundation on the Actor (PC) sheet. This includes storing the last active in-world time and computing available downtime days based on Foundry world time.

This step introduces both data storage and derived logic, while keeping the scope small and testable.


Scope

  • Add a downtime data structure on Actor flags
  • Add UI to view and set last active time
  • Compute available downtime days (derived, not persisted)
  • Keep implementation compatible with PF2e Actor sheets

Data Model

Stored on:
actor.flags.<moduleName>.downtime

{
  "lastActiveTime": number | null
}

Notes:

  • lastActiveTime uses Foundry world time (in seconds)
  • availableDays must NOT be stored (derived only)

Logic

Implement a helper function:

computeDowntimeDays(lastActiveTime: number, currentTime: number): number

Behavior:

  • Returns Math.floor((currentTime - lastActiveTime) / 86400)
  • If lastActiveTime is null or undefined → return 0

UI

Add a “Downtime” section to the Actor sheet (tab or panel, PF2e sheet).

Display

  • Last Active Date (formatted if possible, raw fallback otherwise)
  • Available Days (derived value)

Controls

  • Button: Set as Active Now

    • Sets lastActiveTime = game.time.worldTime
  • Button: Recalculate

    • Forces UI refresh (no data change)

Behavior

  • Available Days updates when:

    • lastActiveTime changes
    • world time changes (manual refresh is acceptable for now)

Acceptance Criteria

  • Clicking “Set as Active Now” stores current world time in flags
  • Available Days is correctly computed from world time
  • No stored value for availableDays (derived only)
  • UI reflects updated values after interaction
  • No errors if lastActiveTime is not set

Notes

  • This is part of a new feature called "downtime"
  • Keep implementation simple and isolated
  • Prefer pure functions for computation
  • Ensure compatibility with future extensions (activities, history, multi-actor views)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions