From d0b2089583ef446bacf2ec11bb048b07a573f8a6 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Mon, 8 Aug 2016 10:17:58 -0700 Subject: [PATCH] Added confirmation when saving Jumpman level with error conditions * added bad location check in JumpmanLevelBuilder --- omnivore/tasks/jumpman/jumpman_editor.py | 10 +++++++++- omnivore/utils/jumpman.py | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/omnivore/tasks/jumpman/jumpman_editor.py b/omnivore/tasks/jumpman/jumpman_editor.py index 89fcbf28..0eb9519b 100644 --- a/omnivore/tasks/jumpman/jumpman_editor.py +++ b/omnivore/tasks/jumpman/jumpman_editor.py @@ -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 @@ -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() diff --git a/omnivore/utils/jumpman.py b/omnivore/utils/jumpman.py index 094da0f8..e5965254 100644 --- a/omnivore/utils/jumpman.py +++ b/omnivore/utils/jumpman.py @@ -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: @@ -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)