Skip to content

[P3] render_worker_overlay keys sprites by worker array index — fragile under future worker removal #364

Description

@itsmiso-ai

Ask: Switch render_worker_overlay to a stable per-worker identity (name + spawn_tick, or an explicit id) so sprite assignments survive future worker removal or insertion.

Expected files: scripts/main.gd

Problem:
render_worker_overlay keys its TextureRect sprites by the worker's position in the state.workers array (str(i)). The stale-key sweep correctly frees entries that fall off the end of the array, but it does not detect a mid-array insertion or removal: the surviving indices stay in active_indices and their sprites get reassigned to whichever worker now occupies that slot. Today this is latent because recruit_worker only appends, but any future feature that removes a worker (death, dismissal, demotion) would silently swap every other worker's sprite for the rest of the run.

The current code comment ("Keyed by worker array index (stable identity); names are not unique at 11+ workers.") acknowledges the names-are-not-unique problem but solves it with a key that is itself fragile.

Evidence:

  • scripts/main.gdrender_worker_overlay builds active_indices from range(workers.size()) and looks up worker_overlay_nodes[str(i)].
  • scripts/colony_sim.gdrecruit_worker only appends; the comment in main.gd flags name collisions at 11+ workers.

Acceptance:

  • Sprites are keyed by a worker identity that does not change when other workers are added or removed (e.g. name + ":" + str(spawn_tick), or a synthetic id assigned at recruitment).
  • Inserting a worker at the front of state.workers in a test does not cause any other worker's sprite to be replaced.
  • A regression test in tests/ (or an existing render-worker test) asserts the mapping is stable across worker-list mutations.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auditAudit, review, or investigation work.priority/p3Low priority.status/readyReady for Dispatch worker pickup.type/bugBug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions