Dwarf details panel: click dwarf to see needs, skills, current job, and thoughts

Question

Grade: Education Subject: psoren pwarf
Dwarf details panel: click dwarf to see needs, skills, current job, and thoughts
Asked by:
80 Viewed 80 Answers

Answer (80)

Best Answer
(1596)

Overview

Implement the dwarf details side panel that opens when the player clicks on a dwarf entity in the game view. This is the primary way to monitor individual dwarf welfare.

Acceptance Criteria

  • [ ] Clicking dwarf entity on map → opens DwarfPanel on right side
  • [ ] Panel displays:
    • Dwarf name (e.g. "Urist McAxe")
    • Current AI state (e.g. "Mining", "Sleeping", "Idle")
    • Needs bars: Hunger, Thirst, Sleep — color-coded (green → yellow → red as need decreases)
    • Skills list: top 5 skills with level bars
    • Current job description (if any)
    • Active labors (checkboxes, player can toggle)
    • Mood indicator (happy face to crying face based on happiness score)
    • Recent thoughts (last 5 from ThoughtLog)
  • [ ] Clicking another dwarf while panel open: switches to that dwarf
  • [ ] Escape or X button closes panel

Files to Touch

  • src/ui/DwarfPanel.tsx (create)
  • tests/ui/DwarfPanel.test.tsx (create)

Test Plan

  • Render DwarfPanel with mock dwarf data → assert all fields present
  • Hunger at 0.2 → assert hunger bar is red
  • Toggle labor checkbox → assert Labor bitmask updated on dwarf entity
  • 6 thoughts in log → assert only 5 most recent shown

Dependencies

Depends on #41 (dwarf components), #54 (mood), #43 (AI states), #5 (renderer — click detection)

(1856)

Answer:

To implement the dwarf details side panel, follow these steps:

  1. Create new components:

    • Create a new file src/ui/DwarfPanel.tsx for the DwarfPanel component.
    • Create a new file tests/ui/DwarfPanel.test.tsx for testing the DwarfPanel component.
  2. Implement DwarfPanel:

    • In src/ui/DwarfPanel.tsx, create a functional component called DwarfPanel.
    • Use props to receive the selected dwarf data.
    • Render the dwarf name, current AI state, needs bars, skills list, current job description, active labors, mood indicator, and recent thoughts.
  3. Implement rendering and event handling:

    • Use React hooks to handle clicking a dwarf entity and opening the DwarfPanel.
    • Implement functionality to switch to another dwarf when a new one is clicked while the panel is open.
    • Add an escape key or X button to close the panel.
  4. Test DwarfPanel:

    • Render the DwarfPanel with mock dwarf data and assert all fields are present.
    • Check that the hunger bar is red when the hunger need is at 0.2.
    • Assert that toggling a labor checkbox updates the dwarf entity's labor bitmask.
    • Assert that only the five most recent thoughts are shown when there are six in the log.
  5. Dependencies:

    • Depends on #41 (dwarf components) for access to dwarf data.
    • Depends on #54 (mood) to display mood indicators.
    • Depends on #43 (AI states) for current AI state information.
    • Depends on #5 (renderer) for click detection and rendering the panel.