Skip to content

Commit

Permalink
Added confirmation when saving Jumpman level with error conditions
Browse files Browse the repository at this point in the history
* added bad location check in JumpmanLevelBuilder
  • Loading branch information
robmcmullen committed Aug 8, 2016
1 parent abb2747 commit d0b2089
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion omnivore/tasks/jumpman/jumpman_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# Enthought library imports.
from traits.api import on_trait_change, Any, Bool, Int, Str, List, Event, Enum, Instance, File, Unicode, Property, provides
from pyface.key_pressed_event import KeyPressedEvent
from pyface.api import YES, NO

# Local imports.
from omnivore import get_image_path
Expand Down Expand Up @@ -852,6 +852,14 @@ def _mouse_mode_default(self):
export_data_name = "Jumpman Level Tester ATR"
export_extensions = [".atr"]

def is_valid_for_save(self):
all_ok = True
if not self.bitmap.level_builder.harvest_ok:
reason = self.bitmap.level_builder.harvest_reason()
answer = self.task.confirm("%s\n\nSave Anyway?" % reason, "Bad Peanut Grid")
all_ok = (answer == YES)
return all_ok

def made_current_active_editor(self):
self.update_mouse_mode(AnticDSelectMode)
self.refresh_toolbar_state()
Expand Down
14 changes: 14 additions & 0 deletions omnivore/utils/jumpman.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,28 @@ def __init__(self, segments):
self.harvest_offset = (0, 0)
self.harvest_offset_seen = set()
self.harvest_offset_dups = set()
self.harvest_bad_locations = 0
self.harvest_ok = True

def set_harvest_offset(self, offset):
self.harvest_offset = tuple(offset)
self.harvest_offset_seen = set()
self.harvest_offset_dups = set()
self.harvest_bad_locations = 0
self.check_harvest()

def check_harvest(self):
self.check_invalid_harvest(self.objects)
self.check_peanut_grid(self.objects)
self.harvest_ok = not bool(self.harvest_offset_dups) and not bool(self.harvest_bad_locations)

def harvest_reason(self):
reasons = []
if self.harvest_offset_dups:
reasons.append("* Multiple peanuts in same grid square!\nJumpman will not collect those peanuts properly.")
if self.harvest_bad_locations:
reasons.append("* Peanuts in border area between grid squares!\nGame will crash when collecting those peanuts.")
return "\n\n".join(reasons)

def check_invalid_harvest(self, objs):
for obj in objs:
Expand All @@ -603,6 +615,8 @@ def check_invalid_harvest(self, objs):
self.harvest_offset_dups.add(grid)
else:
self.harvest_offset_seen.add(grid)
if obj.is_bad_location(*self.harvest_offset):
self.harvest_bad_locations += 1
if obj.trigger_painting:
self.check_invalid_harvest(obj.trigger_painting)

Expand Down

0 comments on commit d0b2089

Please sign in to comment.