Skip to content

Commit

Permalink
finished functionality to set the initial and final screens of each l…
Browse files Browse the repository at this point in the history
…evel
  • Loading branch information
qarlosh committed Oct 7, 2020
1 parent 0bb889a commit 4dc0956
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 74 deletions.
72 changes: 5 additions & 67 deletions heroed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def on_level_layout_changed():
elif keystroke.lower() == "h":
ui.show_help()

elif keystroke.lower() == "d":
ui.show_screen_data = not ui.show_screen_data
ui.draw_screen_data()
#elif keystroke.lower() == "d":
# ui.show_screen_data = not ui.show_screen_data
# ui.draw_screen_data()

elif keystroke.lower() == "n":
# Modify the name of the mod
Expand All @@ -128,70 +128,8 @@ def on_level_layout_changed():
)
ui.draw_mod_name()

elif keystroke.lower() == "t":
print(hero.final_screens())

elif keystroke.lower() == "z":
# define the current screen as the initial screen of the level.
search_screen = editor.selected_screen
while search_screen <= 255:
level, _ = hero.get_levelscr_from_absscr(
search_screen,
editor.level_initial_screens,
editor.level_screen_count,
)
# If the current screen is "lost", then search from
# a posterior screen
if level is None:
search_screen += 1
else:
break

# if found the level, set the initial screen and current length
if level is not None:
final_screen = hero.final_screens(
editor.level_initial_screens, editor.level_screen_count
)[level - 1]

# set level initial screen
level_initial_screens = list(editor.level_initial_screens)
level_initial_screens[level - 1] = editor.selected_screen
editor.level_initial_screens = level_initial_screens

# calculate the new screen count for the level
screen_count = final_screen - editor.selected_screen + 1

# set level length
level_screen_count = list(editor.level_screen_count)
level_screen_count[level - 1] = screen_count
editor.level_screen_count = level_screen_count
editor.define_current_screen_as_initial()

elif keystroke.lower() == "x":
# define the current screen as the final screen of the level.
search_screen = editor.selected_screen
while search_screen >= 0:
level, _ = hero.get_levelscr_from_absscr(
search_screen,
editor.level_initial_screens,
editor.level_screen_count,
)
# If the current screen is "lost", then search from
# a previous screen
if level is None:
search_screen -= 1
else:
break

# if found the level, set the current length
if level is not None:
# calculate the new screen count for the level
screen_count = (
editor.selected_screen
- editor.level_initial_screens[level - 1]
+ 1
)

# set level length
level_screen_count = list(editor.level_screen_count)
level_screen_count[level - 1] = screen_count
editor.level_screen_count = level_screen_count
editor.define_current_screen_as_final()
86 changes: 85 additions & 1 deletion heroed/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,90 @@ def are_there_modified_screens(self):

def is_layout_modified(self):
return self._level_layout_modified

def are_there_modifications(self):
return self.are_there_modified_screens() or self.is_layout_modified()

def define_current_screen_as_initial(self):
"""define the current screen as the initial screen of the level."""
final_screens = hero.final_screens(
self.level_initial_screens, self.level_screen_count
)

# Don't allow setting the same screen as initial and final
if self.selected_screen in final_screens:
return False

search_screen = self.selected_screen
while search_screen <= 255:
level, _ = hero.get_levelscr_from_absscr(
search_screen,
self.level_initial_screens,
self.level_screen_count,
)
# If the current screen is "lost", then search from
# a posterior screen
if level is None:
search_screen += 1
else:
break

# if the level is not found, return
if level is None:
return False

# set the initial screen and current length
# final_screen = final_screens[level - 1]

# set level initial screen
level_initial_screens = list(self.level_initial_screens)
level_initial_screens[level - 1] = self.selected_screen
self.level_initial_screens = tuple(level_initial_screens)

# calculate the new screen count for the level
# screen_count = final_screen - self.selected_screen + 1
screen_count = final_screens[level - 1] - self.selected_screen + 1

# set level length
level_screen_count = list(self.level_screen_count)
level_screen_count[level - 1] = screen_count
self.level_screen_count = tuple(level_screen_count)

return True

def define_current_screen_as_final(self):
"""define the current screen as the final screen of the level."""

# Don't allow setting the same screen as initial and final
if self.selected_screen in self.level_initial_screens:
return False

search_screen = self.selected_screen
while search_screen >= 0:
level, _ = hero.get_levelscr_from_absscr(
search_screen,
self.level_initial_screens,
self.level_screen_count,
)
# If the current screen is "lost", then search from
# a previous screen
if level is None:
search_screen -= 1
else:
break

# if the level is not found, return
if level is None:
return False

# calculate the new screen count for the level
screen_count = (
self.selected_screen - self.level_initial_screens[level - 1] + 1
)

# set level length
level_screen_count = list(self.level_screen_count)
level_screen_count[level - 1] = screen_count
self.level_screen_count = tuple(level_screen_count)

return True
19 changes: 13 additions & 6 deletions heroed/ui/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def draw_help_1(term, **kwargs):
"""\
Use this utility to edit the screens of the video game H.E.R.O. for MSX.
Use this utility to edit the levels of the video game H.E.R.O. for MSX.
The game has 20 levels, each one with a different number of screens, for a
total amount of 256 screens.
Expand All @@ -30,6 +30,10 @@ def draw_help_1(term, **kwargs):
The default screen flow is to enter from above and to exit from below. You can
open a gap to the left or right side of a screen to enable a horizontal flow.
You can also set which is the first screen and which is the final one on each
level, so you can change the length of the levels. But there always have to be
20 levels, and you can use a maximum of 256 screens for all of them.
"""
)

Expand All @@ -43,19 +47,22 @@ def draw_help_2(term, **kwargs):
PAGE UP Previous screen
PAGE DOWN Next screen
HOME First screen (0)
END Las screen (355)
NUMBERS Enter a sequence of 1 or 2 numbers, and optionally end with
ENTER, to go to the first screen of the entered level (1 to
20)
END Last screen (255)
0..9 Enter a sequence of one or two numbers, and optionally end
with ENTER, to go to the first screen of the entered level
(1 to 20)
TAB Switch between TERRAIN or OBJECT editing modes
DIRECTION KEYS move the terrain cursor, the selected object or select an
attribute
SPACE BAR Edit terrain, change the selected enemy type, or change an
attribute value
Z Set the initial screen of the current level (or the next
one, if the current screen does not belong to any level)
X Set the final screen of the current level (or the previous
one, if the current screen does not belong to any level)
S Save (overwrite current ROM file)
N Change the MOD name
H Show this help
D Show/hide the 8 bytes of the current screen definition
Q Quit
"""
)
Expand Down

0 comments on commit 4dc0956

Please sign in to comment.