Skip to content

Commit

Permalink
feat: add solar panels (#1647)
Browse files Browse the repository at this point in the history
* add solar panels

* address PR comments
  • Loading branch information
evemartin authored Jun 18, 2024
1 parent ff50eaf commit 37a80a5
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 0 deletions.
40 changes: 40 additions & 0 deletions game/decor.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,46 @@ def __init__(self, pk, name, url, xmas_url, width, height, theme, z_index):
theme=get_theme("city"),
pk=32,
),
("solar_panel", "grass"): Decor(
z_index=4,
name="solar_panel",
url="decor/grass/solar_panel.svg",
xmas_url="decor/snow/tree1.svg",
height=100,
width=100,
theme=get_theme("grass"),
pk=33
),
("solar_panel", "farm"): Decor(
z_index=4,
name="solar_panel",
url="decor/farm/solar_panel.svg",
xmas_url="decor/snow/tree1.svg",
height=100,
width=100,
theme=get_theme("farm"),
pk=34
),
("solar_panel", "snow"): Decor(
z_index=4,
name="solar_panel",
url="decor/snow/tree1.svg",
xmas_url="decor/snow/tree1.svg",
height=100,
width=100,
theme=get_theme("snow"),
pk=35
),
("solar_panel", "city"): Decor(
z_index=4,
name="solar_panel",
url="decor/city/school.svg",
xmas_url="decor/snow/school.svg",
height=100,
width=100,
theme=get_theme("city"),
pk=36
)
}


Expand Down
14 changes: 14 additions & 0 deletions game/end_to_end_tests/test_level_editor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

from game.end_to_end_tests.base_game_test import BaseGameTest
from game.views.level_editor import available_blocks
Expand Down Expand Up @@ -129,3 +130,16 @@ def test_draggable_traffic_light(self):
cloned_source_light = self.selenium.find_elements(By.ID, "trafficLightRed")
assert len(scenery_light) == 1
assert len(cloned_source_light) == 1

def test_solar_panels(self):
'''test that the solar panels appear as a scenery option when clicking on the scenery tab
and that they disappear as a scenery option when switching to an incompatible theme, i.e. snow'''
page = self.go_to_level_editor()
page.go_to_scenery_tab()

solar_panel_style = self.selenium.find_element(By.ID, "solar_panel").get_attribute("style")
assert "inline" in solar_panel_style

Select(self.selenium.find_element(By.ID, "theme_select")).select_by_value("snow")
solar_panel_snow_style = self.selenium.find_element(By.ID, "solar_panel").get_attribute("style")
assert "none" in solar_panel_snow_style
86 changes: 86 additions & 0 deletions game/static/game/image/decor/farm/solar_panel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions game/static/game/image/decor/grass/solar_panel.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,13 @@ ocargo.LevelEditor = function(levelId) {

$('.decor_button').each(function(index, element) {
element.src = theme.decor[element.id].url;
if (element.id === "solar_panel") {
if (currentTheme === THEMES.grass || currentTheme === THEMES.farm) {
element.style = "display: inline;"
} else {
element.style = "display: none;"
}
}
});

$('#paper').css({'background-color': theme.background});
Expand Down
Loading

0 comments on commit 37a80a5

Please sign in to comment.