Skip to content
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

fix: forbid cows from origin and house spaces #1625

Merged
merged 27 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions game/end_to_end_tests/test_level_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@


class TestLevelEditor(BaseGameTest):
def set_up_basic_map(self):
self.test_level_editor_displays()

add_road_button = self.selenium.find_element(By.ID, "add_road")
add_road_button.click()

road_start = self.selenium.find_element(By.CSS_SELECTOR, "rect[x='130'][y='530']")
road_end = self.selenium.find_element(By.CSS_SELECTOR, "rect[x='330'][y='530']")
ActionChains(self.selenium).drag_and_drop(road_start, road_end).perform()

mark_start_button = self.selenium.find_element(By.ID, "start")
mark_start_button.click()
ActionChains(self.selenium).move_to_element(road_start).click().perform()

add_house_button = self.selenium.find_element(By.ID, "add_house")
add_house_button.click()
ActionChains(self.selenium).move_to_element(road_end).click().perform()

return [road_start, road_end]

def set_up_draggable_cow(self):
scenery_tab = self.selenium.find_element(By.ID, "scenery_tab")
scenery_tab.click()

cow = self.selenium.find_element(By.CSS_SELECTOR, "img[id='cow']")
cow.click()

draggable_cow = self.selenium.find_element(By.CSS_SELECTOR, "image[x='0'][y='0']")

return draggable_cow

def test_level_editor_displays(self):
page = self.go_to_level_editor()

Expand All @@ -22,25 +53,44 @@ def test_code_tab_blocks_load(self):
assert page.element_exists_by_id(f"{block_type}_image")

def test_multiple_houses(self):
add_road_button = self.selenium.find_element(By.ID, "add_road")
add_road_button.click()
[road_start, road_end] = self.set_up_basic_map()

road_start = self.selenium.find_element(By.CSS_SELECTOR, "rect[x='130'][y='530']")
road_end = self.selenium.find_element(By.CSS_SELECTOR, "rect[x='330'][y='530']")
ActionChains(self.selenium).drag_and_drop(road_start, road_end).perform()
road_middle = self.selenium.find_element(By.CSS_SELECTOR, "rect[x='230'][y='530']")

add_house_button = self.selenium.find_element(By.ID, "add_house")
add_house_button.click()
ActionChains(self.selenium).move_to_element(road_start).click().perform()
ActionChains(self.selenium).move_to_element(road_end).click().perform()
ActionChains(self.selenium).move_to_element(road_middle).click().perform()

added_houses = self.selenium.find_elements(By.CSS_SELECTOR, "rect[fill='#0000ff']")
assert len(added_houses) == 2

delete_house_button = self.selenium.find_element(By.ID, "delete_house")
delete_house_button.click()
ActionChains(self.selenium).move_to_element(road_end).click().perform()
ActionChains(self.selenium).move_to_element(road_middle).click().perform()
ActionChains(self.selenium).move_to_element(road_start).perform()

houses_after_delete = self.selenium.find_elements(By.CSS_SELECTOR, "rect[fill='#0000ff']")
assert len(houses_after_delete) == 1

def test_cow_on_origin(self):
[road_start, road_end] = self.set_up_basic_map()

origin_space = self.selenium.find_elements(By.CSS_SELECTOR, "rect[fill='#ff0000']")
assert len(origin_space) == 1

draggable_cow = self.set_up_draggable_cow()
ActionChains(self.selenium).click_and_hold(draggable_cow).move_to_element(road_start).perform()
start_space_warning = self.selenium.find_elements(By.CSS_SELECTOR, "rect[fill='#e35f4d'][fill-opacity='0.7'][x='130'][y='530']")
assert len(start_space_warning) == 1

def test_cow_on_house(self):
[road_start, road_end] = self.set_up_basic_map()

house_space = self.selenium.find_elements(By.CSS_SELECTOR, "rect[fill='#0000ff']")
assert len(house_space) == 1
assert road_end == house_space[0]

draggable_cow = self.set_up_draggable_cow()
ActionChains(self.selenium).click_and_hold(draggable_cow).move_to_element(road_end).perform()
allowed_space = self.selenium.find_elements(By.CSS_SELECTOR, "rect[fill='#87e34d']")
assert len(allowed_space) == 0
2 changes: 1 addition & 1 deletion game/static/game/js/level_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ ocargo.LevelEditor = function(levelId) {

function isValidPlacement(controlledCoord){
var controlledNode = ocargo.Node.findNodeByCoordinate(controlledCoord, nodes);
if (!controlledNode)
if (!controlledNode || isOriginCoordinate(controlledCoord) || isHouseCoordinate(controlledCoord))
return false;
for (var i=0; i < cows.length; i++) {
var otherCow = cows[i];
Expand Down
Loading