Add DMG palette cycling with 'C' key#411
Conversation
… gameplay by pressing the 'C' key. This feature only applies to DMG (non-CGB) mode.
What does this PR do?
Adds a palette cycling feature for DMG mode that allows users to switch
between 4 predefined color palettes by pressing the 'C' key during emulation.
Available palettes:
1. Gray (Default) — Original PyBoy palette
2. Classic Green (DMG) — Original Game Boy green tint
3. Parchment — Warm beige tones, easy on the eyes
4. Mossy — Muted green with earthy tones
Changes made:
pyboy/utils.py
- Added "CYCLE_PALETTE" event to WindowEvent enum.
pyboy/pyboy.py
- Added DMG_PALETTES and DMG_PALETTE_NAMES lists.
- Added _current_palette_idx tracking in __init__.
- Added _cycle_palette() method that updates BGP, OBP0 and OBP1 palette registers.
- Added CYCLE_PALETTE event handling in _handle_events().
pyboy/plugins/window_sdl2.py
- Mapped 'C' key to CYCLE_PALETTE event in KEY_UP dictionary.
pyboy/plugins/window_open_gl.py
- Mapped 'C' key to CYCLE_PALETTE event in _glkeyboard() method.
Notes:
- Only works in DMG mode. CGB mode is intentionally ignored.
- No changes to lcd.py or any core emulation logic.
- Palette changes are applied by updating PaletteRegister.palette_mem_rgb
and forcing a lookup table recalculation.
- New palettes can be easily added to the DMG_PALETTES list.
Updated comments for clarity regarding palette checks and state saving/loading errors.
Baekalfen
left a comment
There was a problem hiding this comment.
Thanks for the PR! It's a good beginning, but it needs a little work
pyboy/pyboy.py
Outdated
There was a problem hiding this comment.
Wouldn't this be an obvious use of a dictionary instead?
pyboy/pyboy.py
Outdated
pyboy/pyboy.py
Outdated
There was a problem hiding this comment.
Dictionaries are ordered in Python. I'd think we could make something with iterators that is more elegant
pyboy/pyboy.py
Outdated
There was a problem hiding this comment.
You don't need a range, you can iterate bgr_palette directly.
pyboy/pyboy.py
Outdated
There was a problem hiding this comment.
Create a helper-function in PaletteRegister that takes the palette and forces the update internally.
tests/test_palette_cycling.py
Outdated
There was a problem hiding this comment.
It's better to do it "wrong" like all other tests, than to improve just a single test.
Otherwise the PR should be a refactor of all tests.
tests/test_palette_cycling.py
Outdated
There was a problem hiding this comment.
As for testing strategy, it's important to test boundary conditions. The middle of a range is not as interesting.
Always test the initial case, and the end case -- i.e. the wrap around. That's where the bugs usually happen.
tests/test_palette_cycling.py
Outdated
tests/test_palette_cycling.py
Outdated
There was a problem hiding this comment.
Rather check this end-to-end, through a screen image. You can check a few pixel values. That is what counts. We don't want to test specific internal state of an object.
Also, this wouldn't work when PyBoy is compiled. Screen images will.
tests/test_palette_cycling.py
Outdated
There was a problem hiding this comment.
Don't do this. Use the any_rom_cgb fixture.
Add method to set custom palette colors and recalculate lookup table.
|
I think I fixed all that you mentioned |
What does this PR do?
Adds a palette cycling feature for DMG mode. Users can press 'C'
to switch between 4 predefined color palettes during emulation.
Available palettes:
Changes:
pyboy/utils.py— Added CYCLE_PALETTE eventpyboy/pyboy.py— Added palette list, cycling method, event handlingpyboy/plugins/window_sdl2.py— Mapped 'C' keytests/test_palette_cycling.py— Added testsNotes: