-
Notifications
You must be signed in to change notification settings - Fork 9
Tint rendered lights with light_color #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Osman-Kahraman
merged 2 commits into
Osman-Kahraman:main
from
resolvicomai:fix/light-color-tint
May 21, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # ruff: noqa: E402,I001 | ||
| import os | ||
|
|
||
|
|
||
| os.environ.setdefault("SDL_VIDEODRIVER", "dummy") | ||
|
|
||
| import pygame | ||
|
|
||
| from game_engine.core.light import Light | ||
|
|
||
|
|
||
| def make_surface(size=(8, 8), color=(255, 255, 255, 255)): | ||
| surface = pygame.Surface(size, pygame.SRCALPHA) | ||
| surface.fill(color) | ||
| return surface | ||
|
|
||
|
|
||
| def test_render_tints_light_with_light_color(monkeypatch): | ||
| pygame.display.init() | ||
| pygame.display.set_mode((1, 1)) | ||
| monkeypatch.setattr(pygame.image, "load", lambda path: make_surface()) | ||
|
|
||
| light = Light((8, 8), light_color=(255, 0, 0)) | ||
| light.visibility_polygon = lambda light_pos, segments: [(0, 0), (7, 0), (7, 7), (0, 7)] | ||
|
|
||
| result = light.render((0, 0), [((0, 0), make_surface((1, 1)))]) | ||
|
|
||
| assert result.get_at((4, 4)) == (255, 0, 0, 255) | ||
|
|
||
|
|
||
| def test_template_uses_configured_light_rgb(monkeypatch, tmp_path): | ||
| pygame.display.init() | ||
| pygame.display.set_mode((1, 1)) | ||
| from game_engine.items import template | ||
|
|
||
| items_dir = tmp_path / "items" | ||
| items_dir.mkdir() | ||
| (items_dir / "info.json").write_text( | ||
| """ | ||
| { | ||
| "streetLight": { | ||
| "sizes": [8, 8], | ||
| "coords": [10, 20], | ||
| "health": 100, | ||
| "scale": 1, | ||
| "animations": [], | ||
| "image": "street-light.png", | ||
| "lights": {"coords": [4, 4], "size": 16, "RGB": [150, 30, 10]} | ||
| } | ||
| } | ||
| """, | ||
| encoding="utf-8", | ||
| ) | ||
|
|
||
| created_lights = [] | ||
|
|
||
| class FakeLight: | ||
| def __init__(self, size, light_color=(255, 255, 255)): | ||
| self.light_color = tuple(light_color) | ||
| created_lights.append((size, self.light_color)) | ||
|
|
||
| def render(self, light_pos, items): | ||
| return make_surface((16, 16), (*self.light_color, 255)) | ||
|
|
||
| monkeypatch.chdir(tmp_path) | ||
| monkeypatch.setattr(template.pygame.image, "load", lambda path: make_surface()) | ||
| monkeypatch.setattr(template, "Light", FakeLight) | ||
| monkeypatch.setattr(template, "ITEMS", {}) | ||
|
|
||
| item = template.Temp("streetLight") | ||
| item.decorate(lambda tiles: None)({}) | ||
|
|
||
| assert created_lights == [((16, 16), (150, 30, 10))] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for testing case, I appreciate it...