Skip to content

Refine Settlement Population and Unit Selection Logic#70

Merged
b0x1 merged 6 commits intomainfrom
feature/settlement-unit-selection-logic-15065278462599339849
Apr 18, 2026
Merged

Refine Settlement Population and Unit Selection Logic#70
b0x1 merged 6 commits intomainfrom
feature/settlement-unit-selection-logic-15065278462599339849

Conversation

@b0x1
Copy link
Copy Markdown
Owner

@b0x1 b0x1 commented Apr 17, 2026

This PR updates the logic for how units and population are handled in settlements.

Key changes:

  1. Population Logic: Only units assigned to a building (JobType) or working in a field (FIELD_WORK) now count toward a settlement's population. Available units (Rure) are considered "outside" and do not count.
  2. Unit Visibility: Units working inside a settlement are now hidden from the tile selection panel. Only "available" units on the settlement tile are displayed.
  3. UI Auto-Selection: To improve UX, the tile selection panel is now automatically bypassed in non-ambiguous cases:
    • If a tile contains exactly one unit and no settlement, the unit is selected immediately.
    • If a tile contains an owned settlement and no available units, the settlement screen opens immediately.
    • The UnitSelector panel only appears if there is more than one selectable option (e.g., a settlement and a unit, or multiple units).
  4. Stability: Added defensive checks to Phaser scene updates to handle rapid state changes during verification.
  5. Documentation: Added clear comments in the Settlement entity describing these rules.

PR created automatically by Jules for task 15065278462599339849 started by @b0x1

- Implement `calculatePopulation` in `Settlement.ts` to only count working units (JobType or FIELD_WORK).
- Add detailed documentation to `Settlement.ts` explaining unit visibility and population rules.
- Update `TraversalUtils.findAllUnitsAt` to filter out working units from tile selection.
- Refine `UnitPanel.tsx` with auto-selection logic:
    - Auto-select unit if it's the only option on a non-settlement tile.
    - Auto-enter settlement if it's the only option on the tile.
    - Show `UnitSelector` only when multiple options (units or settlement) exist.
- Add defensive checks in `WorldScene.ts` to prevent crashes in headless environments.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules Bot and others added 5 commits April 17, 2026 23:41
- Implement `calculatePopulation` in `Settlement.ts` to only count working units (JobType or FIELD_WORK).
- Add detailed documentation to `Settlement.ts` explaining unit visibility and population rules.
- Update `TraversalUtils.findAllUnitsAt` to filter out working units from tile selection.
- Refine `UnitPanel.tsx` with auto-selection logic:
    - Auto-select unit if it's the only option on a non-settlement tile.
    - Auto-enter settlement if it's the only option on the tile.
    - Show `UnitSelector` only when multiple options (units or settlement) exist.
- Add defensive checks in `WorldScene.ts` to prevent crashes in headless environments.
- Fix linting errors in `Settlement.ts`, `TraversalUtils.ts`, and `WorldScene.ts`.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
- Implement `calculatePopulation` in `Settlement.ts` to only count working units (JobType or FIELD_WORK).
- Handle available units (RURE) as being "outside" and not counting toward population.
- Update `TraversalUtils.findAllUnitsAt` to hide working units from tile selection.
- Refine `UnitPanel.tsx` with auto-selection logic for single unit or settlement.
- Add "Enter Settlement" label and icons to `UnitSelector`.
- Add stability fixes in `WorldScene.ts` and documentation in `Settlement.ts`.
- Resolve CI failures by fixing linting errors and handling undefined occupations in tests.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
- Move auto-selection/entry logic from UnitPanel.tsx to selectionSlice.ts.
- Add skipAutoSelection option to selectTile to prevent immediate re-entry when exiting settlements.
- Fix MainMenuScene.ts crash by adding defensive checks and proper event listener cleanup on shutdown.
- Resolve linting errors in selectionSlice.ts and MainMenuScene.ts.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
- Move auto-selection/entry logic from UnitPanel.tsx to selectionSlice.ts.
- Add skipAutoSelection option to selectTile to prevent immediate re-entry when exiting settlements.
- Fix MainMenuScene.ts crash by adding defensive checks and proper event listener cleanup on shutdown.
- Resolve linting errors and remove temporary test files.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
- Implement `calculatePopulation` in `Settlement.ts` to only count working units (JobType or FIELD_WORK).
- Hide working units from the world map's tile selection panel via `TraversalUtils`.
- Move auto-selection/entry logic to `selectionSlice.ts` to improve UX and avoid ambiguity.
- Add `skipAutoSelection` option to `selectTile` to prevent re-entry loops when exiting settlements.
- Fix `MainMenuScene.ts` crash by properly cleaning up event listeners.
- Resolve build and linting errors.
- Add documentation to `Settlement.ts` explaining the new rules.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
@b0x1 b0x1 merged commit a98b8fe into main Apr 18, 2026
2 checks passed
@b0x1 b0x1 deleted the feature/settlement-unit-selection-logic-15065278462599339849 branch April 18, 2026 10:03
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.

1 participant