pygkit 2.1.1__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. {pygkit-2.1.1/src/pygkit.egg-info → pygkit-2.3.0}/PKG-INFO +157 -6
  2. pygkit-2.3.0/README.md +184 -0
  3. {pygkit-2.1.1 → pygkit-2.3.0}/pyproject.toml +5 -2
  4. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/__init__.py +56 -2
  5. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/animation/sheet.py +91 -40
  6. pygkit-2.3.0/src/pygkit/debug/__init__.py +22 -0
  7. pygkit-2.3.0/src/pygkit/debug/config.py +101 -0
  8. pygkit-2.3.0/src/pygkit/debug/core.py +945 -0
  9. pygkit-2.3.0/src/pygkit/debug/overlay.py +386 -0
  10. pygkit-2.3.0/src/pygkit/debug/sinks.py +273 -0
  11. pygkit-2.3.0/src/pygkit/debug/types.py +32 -0
  12. pygkit-2.3.0/src/pygkit/effects/__init__.py +12 -0
  13. pygkit-2.3.0/src/pygkit/effects/outline.py +475 -0
  14. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/lighting/__init__.py +16 -4
  15. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/lighting/blend.py +12 -8
  16. pygkit-2.3.0/src/pygkit/lighting/group.py +133 -0
  17. pygkit-2.3.0/src/pygkit/lighting/lightmap.py +756 -0
  18. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/lighting/lights.py +363 -66
  19. pygkit-2.3.0/src/pygkit/lighting/occlusion.py +249 -0
  20. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/lighting/sprites.py +74 -9
  21. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/protocols.py +0 -2
  22. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/__init__.py +29 -2
  23. pygkit-2.3.0/src/pygkit/ui/base.py +507 -0
  24. pygkit-2.3.0/src/pygkit/ui/button.py +284 -0
  25. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/container.py +54 -15
  26. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/cooldown.py +36 -51
  27. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/dialog.py +23 -9
  28. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/layout.py +81 -10
  29. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/menubar.py +63 -21
  30. pygkit-2.3.0/src/pygkit/ui/panel.py +92 -0
  31. pygkit-2.3.0/src/pygkit/ui/progressbar.py +162 -0
  32. pygkit-2.3.0/src/pygkit/ui/theming.py +268 -0
  33. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/utils/__init__.py +6 -0
  34. pygkit-2.3.0/src/pygkit/utils/diagnostics.py +71 -0
  35. pygkit-2.3.0/src/pygkit.egg-info/PKG-INFO +894 -0
  36. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit.egg-info/SOURCES.txt +25 -0
  37. pygkit-2.3.0/src/pygkit.egg-info/pygkit.egg-info/dependency_links.txt +1 -0
  38. pygkit-2.1.1/PKG-INFO → pygkit-2.3.0/src/pygkit.egg-info/pygkit.egg-info/pkg-info +4 -28
  39. pygkit-2.3.0/src/pygkit.egg-info/pygkit.egg-info/requires.txt +1 -0
  40. pygkit-2.3.0/src/pygkit.egg-info/pygkit.egg-info/sources.txt +47 -0
  41. pygkit-2.3.0/src/pygkit.egg-info/requires.txt +25 -0
  42. pygkit-2.3.0/src/pygkit.egg-info/top_level.txt +1 -0
  43. pygkit-2.3.0/tests/test_background_images.py +161 -0
  44. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_box_model.py +33 -1
  45. pygkit-2.3.0/tests/test_button.py +292 -0
  46. pygkit-2.3.0/tests/test_container.py +148 -0
  47. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_cooldown.py +24 -7
  48. pygkit-2.3.0/tests/test_debug.py +531 -0
  49. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_dialog.py +17 -0
  50. pygkit-2.3.0/tests/test_effects.py +276 -0
  51. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_layout.py +120 -7
  52. pygkit-2.3.0/tests/test_lighting.py +1137 -0
  53. pygkit-2.3.0/tests/test_menubar.py +333 -0
  54. pygkit-2.3.0/tests/test_pack_spritesheet.py +100 -0
  55. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_packaging.py +16 -1
  56. pygkit-2.3.0/tests/test_panel.py +70 -0
  57. pygkit-2.3.0/tests/test_progressbar_image.py +144 -0
  58. pygkit-2.3.0/tests/test_theming.py +66 -0
  59. pygkit-2.1.1/README.md +0 -36
  60. pygkit-2.1.1/src/pygkit/lighting/lightmap.py +0 -170
  61. pygkit-2.1.1/src/pygkit/ui/base.py +0 -126
  62. pygkit-2.1.1/src/pygkit/ui/button.py +0 -228
  63. pygkit-2.1.1/src/pygkit/ui/progressbar.py +0 -64
  64. pygkit-2.1.1/src/pygkit.egg-info/requires.txt +0 -18
  65. pygkit-2.1.1/tests/test_button.py +0 -143
  66. pygkit-2.1.1/tests/test_container.py +0 -71
  67. pygkit-2.1.1/tests/test_lighting.py +0 -376
  68. pygkit-2.1.1/tests/test_menubar.py +0 -132
  69. {pygkit-2.1.1 → pygkit-2.3.0}/LICENSE +0 -0
  70. {pygkit-2.1.1 → pygkit-2.3.0}/setup.cfg +0 -0
  71. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/animation/__init__.py +0 -0
  72. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/animation/player.py +0 -0
  73. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/audio/__init__.py +0 -0
  74. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/audio/soundmanager.py +0 -0
  75. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/inventory/__init__.py +0 -0
  76. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/inventory/assets.py +0 -0
  77. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/inventory/core.py +0 -0
  78. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/inventory/data.py +0 -0
  79. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/inventory/ui.py +0 -0
  80. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/parallax/__init__.py +0 -0
  81. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/parallax/background.py +0 -0
  82. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/parallax/camera.py +0 -0
  83. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/signals/__init__.py +0 -0
  84. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/signals/core.py +0 -0
  85. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/transitions/__init__.py +0 -0
  86. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/transitions/base.py +0 -0
  87. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/transitions/effects.py +0 -0
  88. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/transitions/fades.py +0 -0
  89. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/transitions/wipes.py +0 -0
  90. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/ui/anchors.py +0 -0
  91. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/utils/interpolation.py +0 -0
  92. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/utils/text.py +0 -0
  93. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit/utils/timer.py +0 -0
  94. {pygkit-2.1.1 → pygkit-2.3.0}/src/pygkit.egg-info/dependency_links.txt +0 -0
  95. {pygkit-2.1.1/src → pygkit-2.3.0/src/pygkit.egg-info}/pygkit.egg-info/top_level.txt +0 -0
  96. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_anchors.py +0 -0
  97. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_animation.py +0 -0
  98. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_audio.py +0 -0
  99. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_interpolation.py +0 -0
  100. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_inventory.py +0 -0
  101. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_parallax.py +0 -0
  102. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_signals.py +0 -0
  103. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_text.py +0 -0
  104. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_timer.py +0 -0
  105. {pygkit-2.1.1 → pygkit-2.3.0}/tests/test_transitions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pygkit
3
- Version: 2.1.1
3
+ Version: 2.3.0
4
4
  Summary: General-purpose Pygame CE runtime kit: UI widgets, audio, timers, interpolation, and more.
5
5
  Author: pygkit contributors
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -694,6 +694,7 @@ Requires-Python: >=3.10
694
694
  Description-Content-Type: text/markdown
695
695
  License-File: LICENSE
696
696
  Requires-Dist: pygame-ce>=2.5
697
+ Requires-Dist: typing_extensions>=4.6; python_version < "3.11"
697
698
  Provides-Extra: ui
698
699
  Provides-Extra: audio
699
700
  Provides-Extra: animation
@@ -701,8 +702,10 @@ Provides-Extra: lighting
701
702
  Provides-Extra: transitions
702
703
  Provides-Extra: inventory
703
704
  Provides-Extra: parallax
705
+ Provides-Extra: debug
706
+ Provides-Extra: effects
704
707
  Provides-Extra: all
705
- Requires-Dist: pygkit[animation,audio,inventory,lighting,parallax,transitions,ui]; extra == "all"
708
+ Requires-Dist: pygkit[animation,audio,debug,effects,inventory,lighting,parallax,transitions,ui]; extra == "all"
706
709
  Dynamic: license-file
707
710
 
708
711
  # pygkit
@@ -718,15 +721,163 @@ import pygkit
718
721
  ## Features
719
722
 
720
723
  - **UI**: Box-model widgets with plugin compositing — progress bars, cooldown overlays, containers, dialog system, buttons, menubar container, anchor/row/grid placement helpers
724
+ - **Events**: Menubar/Container route mouse events to nested layouts; hit-testing is active from the first rendered frame
721
725
  - **Animation**: Multi-state `AnimationPlayer` where every state owns its own spritesheet — mixed image sizes and grids (e.g. `idle_spritesheet.png` vs `run_spritesheet.png`) in one player; pure image API, no JSON
722
726
  - **Dialog**: Typewriter effect with customizable speeds, speaker names, and progress indicators
723
727
  - **Inventory**: Grid-based item management with stacking, weight tracking, events, and serialization
724
728
  - **Audio**: SoundManager with channel pools, kind/key addressing, volume buses, fades
725
729
  - **Lighting**: low-resolution light map pipeline (`LightMap`), point lights
726
730
  with flicker, wind-reactive `DynamicLight` flames, and cone `Spotlight` —
727
- full RGB/RGBA blend modes, allocation-free per frame
731
+ rect occlusion, wall-surface reveal, persistent fog-of-war memory,
732
+ fades/wobble/light groups, full RGB/RGBA blend modes, and reusable
733
+ scratch surfaces
734
+ - **Effects**: cached sprite silhouette outlines with optional glow —
735
+ follows holes and disconnected parts, and works with or without the
736
+ light map
728
737
  - **Transitions**: Screen transitions with fade, wipe, and custom effects
729
- - **Utils**: Timer, interpolation/easing functions
738
+ - **Debug**: lazily loaded `Debug` session with coalesced logfmt/JSONL
739
+ logs, lazy HUD watches, and an immediate-mode overlay whose draw calls
740
+ are queued and flushed by one `debug.render(screen)` call before
741
+ `display.flip()`
742
+ - **Utils**: Timer, interpolation/easing functions, lazy debug values
743
+
744
+ ## Debug overlay
745
+
746
+ ```python
747
+ from pygkit import Debug
748
+
749
+ debug = Debug(file="debug.log", coalesce="session")
750
+ debug.set_camera(camera) # enables space="world"
751
+ debug.watch("player/pos", lambda: (hero.x, hero.y))
752
+
753
+ while running:
754
+ ...
755
+ debug.rect(hero.hitbox, color="red", space="world")
756
+ debug.render(screen) # last call before display.flip()
757
+ pygame.display.flip()
758
+ ```
759
+
760
+ Call `render` on the final presentation surface (after any scaling or
761
+ letterboxing), so the overlay is not scaled with the scene and stays on top.
762
+ Call `debug.handle_event(event)` in your event loop to enable F3/F4/F5.
763
+ `debug.log(...)`, `debug.event(...)`, `debug.watch(...)`, and the draw
764
+ helpers are cheap when disabled. Repeated entries are grouped with counts
765
+ in the file and in the on-screen log panel; events group by event name and
766
+ call site by default, and `key=` groups the same event across call sites.
767
+ `Debug` reads lazy values only when logging is enabled (or the HUD is
768
+ visible). Use `file_format="jsonl"` for one JSON object per line. Toggle
769
+ HUD, log panel, and shapes with F3/F4/F5.
770
+
771
+ ## Lighting
772
+
773
+ ```python
774
+ from pygkit.lighting import LightMap, PointLight, tile_rects
775
+
776
+ lightmap = LightMap((800, 600), scale=0.5, explored_dim=0.35)
777
+ lightmap.set_ambient((20, 25, 40), 0.15)
778
+ lightmap.set_occluders(tile_rects((32, 32), solid_cells))
779
+
780
+ torch = PointLight(radius=140, color=(255, 190, 120))
781
+ torch.set_flicker(frequency=8.0, amplitude=0.2, seed=1.0)
782
+
783
+ while running:
784
+ lightmap.clear()
785
+ torch.render(lightmap, player.x, player.y)
786
+ lightmap.reveal(player.x, player.y, 96)
787
+ lightmap.apply(scene)
788
+ ```
789
+
790
+ `tile_rects` turns solid `(column, row)` cells into scene-space rectangles;
791
+ any collision system can pass its own `pygame.Rect` list to
792
+ `set_occluders` instead. Lights cast hard shadows by default; set
793
+ `light.cast_shadows = False` for moonlight or ambient-style lights, or
794
+ `lightmap.shadows = False` to disable all light shadows.
795
+
796
+ Walls touched by light are drawn on their visible face by default
797
+ (`wall_reveal=True`), while the space behind each wall stays shadowed.
798
+ Set `lightmap.wall_reveal = False` for the original fully dark wall
799
+ footprint, or pass `wall_reveal=False` to one `reveal()` call. Use
800
+ per-tile occluders (`tile_rects(..., merge=False)`) when a thick wall
801
+ should reveal only its front row instead of the whole merged block.
802
+
803
+ `explored_dim` enables persistent fog-of-war memory: areas stay dimly
804
+ visible after a light leaves, while unexplored areas stay dark. Current
805
+ lights are remembered separately from ambient, so ambient light does not
806
+ reveal the map. Call `lightmap.reset_explored()` when loading a new level.
807
+ For pitch-black unexplored areas, keep ambient at `0`.
808
+
809
+ `reveal()` adds a persistent clearance brush that is independent of
810
+ lights. Call it each frame for the player, or once for a discovered room.
811
+ Clearance is stored separately from light-derived memory, so the original
812
+ tiles show at the brush color instead of being dimmed by `explored_dim`
813
+ (white = full brightness; pass a darker color for a dimmer reveal).
814
+ Occluders block it by default (`walls=False` ignores them), and
815
+ `current=True` also adds it to the current light layer. Call
816
+ `lightmap.clear_clearance()` to forget reveals while keeping light memory.
817
+
818
+ For an interactive example, run `python examples/lighting_fog_demo.py`:
819
+ move the mouse to explore, `F` toggles clearance, `L` toggles the lantern,
820
+ and `X` resets explored memory.
821
+
822
+ For a wall-reveal comparison, run `python examples/lighting_walls_demo.py`:
823
+ move the mouse to guide the lantern and press `W` to switch between lit
824
+ wall faces and the fully dark wall footprint.
825
+
826
+ Lights also support smooth property changes and organic motion:
827
+
828
+ ```python
829
+ torch.fade_to(0.0, duration=0.4)
830
+ torch.radius_to(220, duration=0.8)
831
+ torch.color_to((255, 120, 80), duration=0.6)
832
+ torch.set_wobble(amplitude=2.5, frequency=1.1)
833
+ torch.advance(dt) # drives flicker, wobble, and tweens
834
+ ```
835
+
836
+ `LightGroup` pairs lights with static positions or position callables and
837
+ updates/renders them together:
838
+
839
+ ```python
840
+ group = LightGroup()
841
+ group.add(torch, 120, 300)
842
+ group.add(player_light, lambda: (player.x, player.y))
843
+ group.update(dt)
844
+ group.render(lightmap)
845
+ ```
846
+
847
+ ## Sprite outlines
848
+
849
+ `SpriteOutline` builds a silhouette rim from the sprite's alpha mask and
850
+ caches it per sprite. Drawing a stable sprite costs one rim blit and,
851
+ optionally, one additive glow blit:
852
+
853
+ ```python
854
+ from pygkit.effects import SpriteOutline
855
+
856
+ outline = SpriteOutline(
857
+ (120, 220, 255),
858
+ thickness=2,
859
+ glow=4,
860
+ glow_color=(50, 150, 255),
861
+ )
862
+
863
+ # Emissive: draw after the light map, so it stays readable in darkness.
864
+ lightmap.apply(scene)
865
+ outline.draw(scene, player_sprite, player.x, player.y)
866
+
867
+ # Lit: draw before the light map, so lighting dims it.
868
+ # outline.draw(scene, player_sprite, player.x, player.y)
869
+ # lightmap.apply(scene)
870
+ ```
871
+
872
+ The rim includes holes and disconnected parts. Use `key=` when one surface
873
+ is reused for different animation frames, or call `clear_cache()` after
874
+ mutating a sprite in place. `outline_surface()` returns a one-shot padded
875
+ surface, and `outline_points()` wraps `Mask.outline()` for effects that
876
+ need a single contour point list.
877
+
878
+ For an interactive example, run `python examples/effects_outline_demo.py`:
879
+ move the mouse, `O` toggles outlines, `L` toggles the light map, and `E`
880
+ switches between emissive and lit outlines.
730
881
 
731
882
  ## Installation
732
883
 
@@ -737,7 +888,7 @@ pip install "pygkit[all]" # everything
737
888
  ```
738
889
 
739
890
  Available extras: `ui`, `audio`, `animation`, `lighting`,
740
- `transitions`, `inventory`, `parallax`, `all`. `import pygkit` alone loads
741
- core only; subsystems load lazily on first use.
891
+ `transitions`, `inventory`, `parallax`, `debug`, `effects`, `all`.
892
+ `import pygkit` alone loads core only; subsystems load lazily on first use.
742
893
 
743
894
  > Extra: lightning idea was extended version of [https://www.youtube.com/watch?v=LN7u20H7zK4](https://www.youtube.com/watch?v=LN7u20H7zK4) which was my first attempt of making lightning after learning blend modes.
pygkit-2.3.0/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # pygkit
2
+
3
+ General-purpose Pygame CE runtime kit: UI widgets, audio management, timers, interpolation, and utilities.
4
+
5
+ ## Quick Start
6
+
7
+ ```python
8
+ import pygkit
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **UI**: Box-model widgets with plugin compositing — progress bars, cooldown overlays, containers, dialog system, buttons, menubar container, anchor/row/grid placement helpers
14
+ - **Events**: Menubar/Container route mouse events to nested layouts; hit-testing is active from the first rendered frame
15
+ - **Animation**: Multi-state `AnimationPlayer` where every state owns its own spritesheet — mixed image sizes and grids (e.g. `idle_spritesheet.png` vs `run_spritesheet.png`) in one player; pure image API, no JSON
16
+ - **Dialog**: Typewriter effect with customizable speeds, speaker names, and progress indicators
17
+ - **Inventory**: Grid-based item management with stacking, weight tracking, events, and serialization
18
+ - **Audio**: SoundManager with channel pools, kind/key addressing, volume buses, fades
19
+ - **Lighting**: low-resolution light map pipeline (`LightMap`), point lights
20
+ with flicker, wind-reactive `DynamicLight` flames, and cone `Spotlight` —
21
+ rect occlusion, wall-surface reveal, persistent fog-of-war memory,
22
+ fades/wobble/light groups, full RGB/RGBA blend modes, and reusable
23
+ scratch surfaces
24
+ - **Effects**: cached sprite silhouette outlines with optional glow —
25
+ follows holes and disconnected parts, and works with or without the
26
+ light map
27
+ - **Transitions**: Screen transitions with fade, wipe, and custom effects
28
+ - **Debug**: lazily loaded `Debug` session with coalesced logfmt/JSONL
29
+ logs, lazy HUD watches, and an immediate-mode overlay whose draw calls
30
+ are queued and flushed by one `debug.render(screen)` call before
31
+ `display.flip()`
32
+ - **Utils**: Timer, interpolation/easing functions, lazy debug values
33
+
34
+ ## Debug overlay
35
+
36
+ ```python
37
+ from pygkit import Debug
38
+
39
+ debug = Debug(file="debug.log", coalesce="session")
40
+ debug.set_camera(camera) # enables space="world"
41
+ debug.watch("player/pos", lambda: (hero.x, hero.y))
42
+
43
+ while running:
44
+ ...
45
+ debug.rect(hero.hitbox, color="red", space="world")
46
+ debug.render(screen) # last call before display.flip()
47
+ pygame.display.flip()
48
+ ```
49
+
50
+ Call `render` on the final presentation surface (after any scaling or
51
+ letterboxing), so the overlay is not scaled with the scene and stays on top.
52
+ Call `debug.handle_event(event)` in your event loop to enable F3/F4/F5.
53
+ `debug.log(...)`, `debug.event(...)`, `debug.watch(...)`, and the draw
54
+ helpers are cheap when disabled. Repeated entries are grouped with counts
55
+ in the file and in the on-screen log panel; events group by event name and
56
+ call site by default, and `key=` groups the same event across call sites.
57
+ `Debug` reads lazy values only when logging is enabled (or the HUD is
58
+ visible). Use `file_format="jsonl"` for one JSON object per line. Toggle
59
+ HUD, log panel, and shapes with F3/F4/F5.
60
+
61
+ ## Lighting
62
+
63
+ ```python
64
+ from pygkit.lighting import LightMap, PointLight, tile_rects
65
+
66
+ lightmap = LightMap((800, 600), scale=0.5, explored_dim=0.35)
67
+ lightmap.set_ambient((20, 25, 40), 0.15)
68
+ lightmap.set_occluders(tile_rects((32, 32), solid_cells))
69
+
70
+ torch = PointLight(radius=140, color=(255, 190, 120))
71
+ torch.set_flicker(frequency=8.0, amplitude=0.2, seed=1.0)
72
+
73
+ while running:
74
+ lightmap.clear()
75
+ torch.render(lightmap, player.x, player.y)
76
+ lightmap.reveal(player.x, player.y, 96)
77
+ lightmap.apply(scene)
78
+ ```
79
+
80
+ `tile_rects` turns solid `(column, row)` cells into scene-space rectangles;
81
+ any collision system can pass its own `pygame.Rect` list to
82
+ `set_occluders` instead. Lights cast hard shadows by default; set
83
+ `light.cast_shadows = False` for moonlight or ambient-style lights, or
84
+ `lightmap.shadows = False` to disable all light shadows.
85
+
86
+ Walls touched by light are drawn on their visible face by default
87
+ (`wall_reveal=True`), while the space behind each wall stays shadowed.
88
+ Set `lightmap.wall_reveal = False` for the original fully dark wall
89
+ footprint, or pass `wall_reveal=False` to one `reveal()` call. Use
90
+ per-tile occluders (`tile_rects(..., merge=False)`) when a thick wall
91
+ should reveal only its front row instead of the whole merged block.
92
+
93
+ `explored_dim` enables persistent fog-of-war memory: areas stay dimly
94
+ visible after a light leaves, while unexplored areas stay dark. Current
95
+ lights are remembered separately from ambient, so ambient light does not
96
+ reveal the map. Call `lightmap.reset_explored()` when loading a new level.
97
+ For pitch-black unexplored areas, keep ambient at `0`.
98
+
99
+ `reveal()` adds a persistent clearance brush that is independent of
100
+ lights. Call it each frame for the player, or once for a discovered room.
101
+ Clearance is stored separately from light-derived memory, so the original
102
+ tiles show at the brush color instead of being dimmed by `explored_dim`
103
+ (white = full brightness; pass a darker color for a dimmer reveal).
104
+ Occluders block it by default (`walls=False` ignores them), and
105
+ `current=True` also adds it to the current light layer. Call
106
+ `lightmap.clear_clearance()` to forget reveals while keeping light memory.
107
+
108
+ For an interactive example, run `python examples/lighting_fog_demo.py`:
109
+ move the mouse to explore, `F` toggles clearance, `L` toggles the lantern,
110
+ and `X` resets explored memory.
111
+
112
+ For a wall-reveal comparison, run `python examples/lighting_walls_demo.py`:
113
+ move the mouse to guide the lantern and press `W` to switch between lit
114
+ wall faces and the fully dark wall footprint.
115
+
116
+ Lights also support smooth property changes and organic motion:
117
+
118
+ ```python
119
+ torch.fade_to(0.0, duration=0.4)
120
+ torch.radius_to(220, duration=0.8)
121
+ torch.color_to((255, 120, 80), duration=0.6)
122
+ torch.set_wobble(amplitude=2.5, frequency=1.1)
123
+ torch.advance(dt) # drives flicker, wobble, and tweens
124
+ ```
125
+
126
+ `LightGroup` pairs lights with static positions or position callables and
127
+ updates/renders them together:
128
+
129
+ ```python
130
+ group = LightGroup()
131
+ group.add(torch, 120, 300)
132
+ group.add(player_light, lambda: (player.x, player.y))
133
+ group.update(dt)
134
+ group.render(lightmap)
135
+ ```
136
+
137
+ ## Sprite outlines
138
+
139
+ `SpriteOutline` builds a silhouette rim from the sprite's alpha mask and
140
+ caches it per sprite. Drawing a stable sprite costs one rim blit and,
141
+ optionally, one additive glow blit:
142
+
143
+ ```python
144
+ from pygkit.effects import SpriteOutline
145
+
146
+ outline = SpriteOutline(
147
+ (120, 220, 255),
148
+ thickness=2,
149
+ glow=4,
150
+ glow_color=(50, 150, 255),
151
+ )
152
+
153
+ # Emissive: draw after the light map, so it stays readable in darkness.
154
+ lightmap.apply(scene)
155
+ outline.draw(scene, player_sprite, player.x, player.y)
156
+
157
+ # Lit: draw before the light map, so lighting dims it.
158
+ # outline.draw(scene, player_sprite, player.x, player.y)
159
+ # lightmap.apply(scene)
160
+ ```
161
+
162
+ The rim includes holes and disconnected parts. Use `key=` when one surface
163
+ is reused for different animation frames, or call `clear_cache()` after
164
+ mutating a sprite in place. `outline_surface()` returns a one-shot padded
165
+ surface, and `outline_points()` wraps `Mask.outline()` for effects that
166
+ need a single contour point list.
167
+
168
+ For an interactive example, run `python examples/effects_outline_demo.py`:
169
+ move the mouse, `O` toggles outlines, `L` toggles the light map, and `E`
170
+ switches between emissive and lit outlines.
171
+
172
+ ## Installation
173
+
174
+ ```bash
175
+ pip install pygkit # core: signals, utils, protocols
176
+ pip install "pygkit[ui]" # widgets, dialog, cooldowns
177
+ pip install "pygkit[all]" # everything
178
+ ```
179
+
180
+ Available extras: `ui`, `audio`, `animation`, `lighting`,
181
+ `transitions`, `inventory`, `parallax`, `debug`, `effects`, `all`.
182
+ `import pygkit` alone loads core only; subsystems load lazily on first use.
183
+
184
+ > Extra: lightning idea was extended version of [https://www.youtube.com/watch?v=LN7u20H7zK4](https://www.youtube.com/watch?v=LN7u20H7zK4) which was my first attempt of making lightning after learning blend modes.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pygkit"
7
- version = "2.1.1"
7
+ version = "2.3.0"
8
8
  description = "General-purpose Pygame CE runtime kit: UI widgets, audio, timers, interpolation, and more."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -12,6 +12,7 @@ license = { file = "LICENSE" }
12
12
  authors = [{ name = "pygkit contributors" }]
13
13
  dependencies = [
14
14
  "pygame-ce>=2.5",
15
+ 'typing_extensions>=4.6; python_version < "3.11"',
15
16
  ]
16
17
  classifiers = [
17
18
  "Development Status :: 3 - Alpha",
@@ -38,8 +39,10 @@ lighting = []
38
39
  transitions = []
39
40
  inventory = []
40
41
  parallax = []
42
+ debug = []
43
+ effects = []
41
44
  all = [
42
- "pygkit[ui, audio, animation, lighting, transitions, inventory, parallax]",
45
+ "pygkit[ui, audio, animation, lighting, transitions, inventory, parallax, debug, effects]",
43
46
  ]
44
47
 
45
48
  [project.urls]
@@ -16,16 +16,21 @@ from typing import Any
16
16
  from .protocols import Clickable, Drawable, Renderable, UIElement, Updateable, Widget
17
17
  from .signals import Signal, SignalBus, signal
18
18
  from .utils import (
19
+ Lazy,
19
20
  SimpleInterpolation,
20
21
  Timer,
21
22
  ease_in,
22
23
  ease_in_out,
23
24
  ease_out,
24
25
  fit,
26
+ lazy,
25
27
  lerp,
26
28
  load_font,
27
29
  outline,
28
30
  render_multiline,
31
+ resolve,
32
+ safe_repr,
33
+ safe_str,
29
34
  shadow,
30
35
  smoothstep,
31
36
  wrap,
@@ -46,6 +51,8 @@ _LAZY_ATTRS: dict[str, str] = {
46
51
  "PointLight": "lighting",
47
52
  "Spotlight": "lighting",
48
53
  "DynamicLight": "lighting",
54
+ "LightGroup": "lighting",
55
+ "tile_rects": "lighting",
49
56
  "glow_sprite": "lighting",
50
57
  "spotlight_sprite": "lighting",
51
58
  "dynamic_glow_sprite": "lighting",
@@ -61,7 +68,12 @@ _LAZY_ATTRS: dict[str, str] = {
61
68
  "RGBA_MIN": "lighting",
62
69
  "RGBA_MAX": "lighting",
63
70
  "LIGHT_ADD": "lighting",
71
+ "LIGHT_REMEMBER": "lighting",
72
+ "FOG_DIM": "lighting",
64
73
  "SCENE_MULT": "lighting",
74
+ "SpriteOutline": "effects",
75
+ "outline_surface": "effects",
76
+ "outline_points": "effects",
65
77
  "TransitionRunner": "transitions",
66
78
  "TransitionState": "transitions",
67
79
  "FadeToBlack": "transitions",
@@ -87,12 +99,24 @@ _LAZY_ATTRS: dict[str, str] = {
87
99
  "DialogLine": "ui",
88
100
  "TypewriterSpeed": "ui",
89
101
  "Button": "ui",
90
- "ButtonStyle": "ui",
102
+ "UIStyle": "ui",
103
+ "StatePaint": "ui",
104
+ "ResolvedStyle": "ui",
105
+ "ColorLike": "ui",
106
+ "GradientLike": "ui",
107
+ "ShadowLike": "ui",
108
+ "StateKey": "ui",
109
+ "resolve_style": "ui",
110
+ "validate_style": "ui",
91
111
  "Menubar": "ui",
92
112
  "AnchorLayout": "ui",
93
113
  "HBox": "ui",
94
114
  "VBox": "ui",
95
115
  "GridBox": "ui",
116
+ "STATE_KEYS": "ui",
117
+ "SKIN_STATE_KEYS": "ui",
118
+ "Skin": "ui",
119
+ "Panel": "ui",
96
120
  "ItemData": "inventory",
97
121
  "InventoryConfig": "inventory",
98
122
  "ItemStack": "inventory",
@@ -108,6 +132,9 @@ _LAZY_ATTRS: dict[str, str] = {
108
132
  "DragDropState": "inventory",
109
133
  "InventoryWidget": "inventory",
110
134
  "InventoryManager": "inventory",
135
+ "Debug": "debug",
136
+ "DebugConfig": "debug",
137
+ "DebugEntry": "debug",
111
138
  }
112
139
 
113
140
  __all__ = [
@@ -125,6 +152,8 @@ __all__ = [
125
152
  "PointLight",
126
153
  "Spotlight",
127
154
  "DynamicLight",
155
+ "LightGroup",
156
+ "tile_rects",
128
157
  "glow_sprite",
129
158
  "spotlight_sprite",
130
159
  "dynamic_glow_sprite",
@@ -140,7 +169,12 @@ __all__ = [
140
169
  "RGBA_MIN",
141
170
  "RGBA_MAX",
142
171
  "LIGHT_ADD",
172
+ "LIGHT_REMEMBER",
173
+ "FOG_DIM",
143
174
  "SCENE_MULT",
175
+ "SpriteOutline",
176
+ "outline_surface",
177
+ "outline_points",
144
178
  "TransitionRunner",
145
179
  "TransitionState",
146
180
  "FadeToBlack",
@@ -166,12 +200,24 @@ __all__ = [
166
200
  "DialogLine",
167
201
  "TypewriterSpeed",
168
202
  "Button",
169
- "ButtonStyle",
203
+ "UIStyle",
204
+ "StatePaint",
205
+ "ResolvedStyle",
206
+ "ColorLike",
207
+ "GradientLike",
208
+ "ShadowLike",
209
+ "StateKey",
210
+ "resolve_style",
211
+ "validate_style",
170
212
  "Menubar",
171
213
  "AnchorLayout",
172
214
  "HBox",
173
215
  "VBox",
174
216
  "GridBox",
217
+ "STATE_KEYS",
218
+ "SKIN_STATE_KEYS",
219
+ "Skin",
220
+ "Panel",
175
221
  "ItemData",
176
222
  "InventoryConfig",
177
223
  "ItemStack",
@@ -187,6 +233,14 @@ __all__ = [
187
233
  "DragDropState",
188
234
  "InventoryWidget",
189
235
  "InventoryManager",
236
+ "Debug",
237
+ "DebugConfig",
238
+ "DebugEntry",
239
+ "Lazy",
240
+ "lazy",
241
+ "resolve",
242
+ "safe_repr",
243
+ "safe_str",
190
244
  "SimpleInterpolation",
191
245
  "Timer",
192
246
  "lerp",