Skip to content

Add text UI tick-speed toggle and guard -1 location lookups - #102

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/text-ui-tick-toggle-and-location-guard
Jul 19, 2026
Merged

Add text UI tick-speed toggle and guard -1 location lookups#102
dmccoystephenson merged 1 commit into
mainfrom
feature/text-ui-tick-toggle-and-location-guard

Conversation

@dmccoystephenson

@dmccoystephenson dmccoystephenson commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

  • The text UI's handleKeyDownEvent was missing the l key case present in the pygame branch, so --text-ui players had no way to toggle config.limitTickSpeed even though README documents the control generically. Added the case and updated TextRenderer.renderControls() to mention it.
  • Ophidian.getLocation() now guards against a locationID that isn't a real grid location (e.g. an entity's default -1 sentinel from Entity.__init__) instead of letting Grid.getLocation() raise an unhandled KeyError. movePreviousSnakePart() now returns immediately after quitApplication() instead of falling through to use a location that was never fetched.

Test plan

  • python -m pytest — 91 passed
  • New regression test test_text_ui_l_key_toggles_tick_speed_limit covers the text UI l key handling

Closes #101
Closes #22


This PR description was drafted during a Gardener session (Stephenson-Software/gardener).

- handleKeyDownEvent's text UI branch was missing the 'l' key case that
  the pygame branch already had, so --text-ui players had no way to
  toggle config.limitTickSpeed despite README documenting the control
  generically. Added the case, updated TextRenderer.renderControls(),
  and added a regression test.
- Ophidian.getLocation() now guards against a locationID that isn't a
  real grid location (e.g. an entity's default -1 sentinel from
  Entity.__init__) instead of letting Grid.getLocation() raise an
  unhandled KeyError, and movePreviousSnakePart() returns immediately
  after quitApplication() rather than falling through.

Closes #101
Closes #22
@dmccoystephenson

dmccoystephenson commented Jul 19, 2026

Copy link
Copy Markdown
Member Author

Self-review: both fixes are narrowly scoped and verified against source. getLocation()'s guard directly addresses issue #22 (an entity's default -1 locationID sentinel from Entity.__init__ would otherwise hit Grid.getLocation()'s raw dict lookup and raise KeyError), and the added return after quitApplication() in movePreviousSnakePart prevents falling through to use snakePart.lastPosition on the error path. The text UI l key case mirrors the existing pygame branch exactly and is covered by a new regression test; TextRenderer.renderControls() was updated to match, closing the graphical/text UI drift called out in issue #101 (and past PR #92/#95/#99 review feedback). 91/91 tests pass locally.

One pre-existing rough edge, not introduced by this PR and left out of scope (outside both linked issues): removeEntityFromLocation (src/ophidian.py:392) calls self.getLocation(entity) then location.isEntityPresent(entity) without checking for the -1 sentinel this PR's guard can now return. That was already an unhandled crash path before this change (previously KeyError from Grid.getLocation, now AttributeError on -1.isEntityPresent) — a candidate for the same guard if a future issue surfaces a real crash there.


This comment was drafted during a Gardener session (Stephenson-Software/gardener).

@dmccoystephenson
dmccoystephenson merged commit 11197d1 into main Jul 19, 2026
@dmccoystephenson
dmccoystephenson deleted the feature/text-ui-tick-toggle-and-location-guard branch July 19, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant