Skip to content

Commit

Permalink
Run formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaythebusinessgoose committed Dec 17, 2024
1 parent 06afc8a commit f36ca82
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 64 deletions.
4 changes: 3 additions & 1 deletion src/modlunky2/ui/levels/custom_levels/custom_level_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ def add_tilecode(self, tile, percent, alt_tile):
)
return

ref_tile = Tile(new_tile_code, str(usable_code), "", tile_image, tile_image_picker)
ref_tile = Tile(
new_tile_code, str(usable_code), "", tile_image, tile_image_picker
)
self.tile_palette_ref_in_use.append(ref_tile)
self.tile_palette_map[usable_code] = ref_tile

Expand Down
16 changes: 12 additions & 4 deletions src/modlunky2/ui/levels/vanilla_levels/vanilla_level_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ def register_tile_code(tile):
)

# Clear tilecodes from all sister locations so they do not get reused.
sister_locations = LevelDependencies.sister_locations_for_level(lvl, self.lvls_path, self.extracts_path)
sister_locations = LevelDependencies.sister_locations_for_level(
lvl, self.lvls_path, self.extracts_path
)
for sister_location_path in sister_locations:
for level in sister_location_path:
for tilecode in level.level.tile_codes.all():
Expand Down Expand Up @@ -1000,8 +1002,11 @@ def log_codes_left(self):

def use_dependency_tile(self, tile, dependency):
new_tile = tile

def tile_will_conflict():
sister_locations = LevelDependencies.sister_locations_for_level(self.lvl, self.lvls_path, self.extracts_path)
sister_locations = LevelDependencies.sister_locations_for_level(
self.lvl, self.lvls_path, self.extracts_path
)
for sister_location_path in sister_locations:
for level in sister_location_path:
for tilecode in level.level.tile_codes.all():
Expand All @@ -1015,7 +1020,8 @@ def tile_will_conflict():
self.usable_codes.remove(usable_code)
else:
tkMessageBox.showinfo(
"Uh Oh!", "This tile has a conflict, and you've reached the tilecode limit; delete some to add more"
"Uh Oh!",
"This tile has a conflict, and you've reached the tilecode limit; delete some to add more",
)
return
new_tile = Tile(
Expand Down Expand Up @@ -1100,7 +1106,9 @@ def add_tilecode(
)
return

ref_tile = Tile(new_tile_code, str(usable_code), "", tile_image, tile_image_picker)
ref_tile = Tile(
new_tile_code, str(usable_code), "", tile_image, tile_image_picker
)
self.tile_palette_ref_in_use.append(ref_tile)
self.tile_palette_map[usable_code] = ref_tile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
from modlunky2.levels.level_templates import Chunk
from modlunky2.levels.tile_codes import VALID_TILE_CODES, TileCode, TileCodes, ShortCode
from modlunky2.utils import tb_info
from modlunky2.ui.levels.vanilla_levels.variables.level_dependencies import SisterLocation
from modlunky2.ui.levels.vanilla_levels.variables.level_dependencies import (
SisterLocation,
)

logger = logging.getLogger(__name__)


@dataclass
class BrokenTile:
level: SisterLocation
tile: TileCode


class DependenciesTree(ttk.Treeview):
def __init__(self, parent, lvls_path, extracts_path, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
Expand Down Expand Up @@ -50,13 +54,18 @@ def find_broken_tiles(self):

checked_levels.append(other_location.level_name)
for othertilecode in other_location.level.tile_codes.all():
if tilecode.value == othertilecode.value and tilecode.name != othertilecode.name:
if (
tilecode.value == othertilecode.value
and tilecode.name != othertilecode.name
):
if not added_code:
added_code = True
broken_tiles.append(
BrokenTile(self.current_location, tilecode)
)
broken_tiles.append(BrokenTile(other_location, othertilecode))
broken_tiles.append(
BrokenTile(other_location, othertilecode)
)
logger.debug(
"tilecode conflict: %s",
tilecode.value,
Expand Down Expand Up @@ -99,9 +108,7 @@ def resolve_conflicts(self):
usable_codes.remove(new_code)
level.tile_codes.set_obj(
TileCode(
name = old_tile.name,
value = new_code,
comment = old_tile.comment
name=old_tile.name, value=new_code, comment=old_tile.comment
)
) # adds new tile to database with new code
else:
Expand All @@ -111,14 +118,30 @@ def resolve_conflicts(self):
for template in level.level_templates.all():
new_chunks = []
for room in template.chunks:
foreground = [ [ str(new_code) if str(code) == str(old_tile_code) else str(code) for code in row] for row in room.foreground]
background = [ [ str(new_code) if str(code) == str(old_tile_code) else str(code) for code in row] for row in room.background]
foreground = [
[
str(new_code)
if str(code) == str(old_tile_code)
else str(code)
for code in row
]
for row in room.foreground
]
background = [
[
str(new_code)
if str(code) == str(old_tile_code)
else str(code)
for code in row
]
for row in room.background
]
new_chunks.append(
Chunk(
comment = room.comment,
settings = room.settings,
foreground = foreground,
background = background,
comment=room.comment,
settings=room.settings,
foreground=foreground,
background=background,
)
)
template.chunks = new_chunks
Expand Down Expand Up @@ -147,7 +170,10 @@ def update_dependencies(self, level_paths, current_location):
values=(
str(broken_tile.tile.name),
str(broken_tile.tile.value),
str(broken_tile.level.level_name) + " " + str(broken_tile.level.location) + " file",
str(broken_tile.level.level_name)
+ " "
+ str(broken_tile.level.location)
+ " file",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

logger = logging.getLogger(__name__)


@dataclass
class SisterLocation:
level_name: str
level: LevelFile
location: str


class LevelDependencies:
@staticmethod
def dependencies_for_level(lvl):
Expand Down Expand Up @@ -98,7 +100,10 @@ def get_loaded_level(item):
levels.append([get_loaded_level(lvl_name)])

if lvl_name.startswith("generic.lvl"):
return [[get_loaded_level(dep)] for dep in LevelDependencies.generic_dependencies()]
return [
[get_loaded_level(dep)]
for dep in LevelDependencies.generic_dependencies()
]
elif not lvl_name.startswith("basecamp"):
for dependencies in levels:
dependencies.append(get_loaded_level("generic.lvl"))
Expand All @@ -108,48 +113,48 @@ def get_loaded_level(item):
@staticmethod
@lru_cache
def generic_dependencies():
return [
"dwellingarea.lvl",
"cavebossarea.lvl",
"junglearea.lvl",
"blackmarket.lvl",
"beehive.lvl",
"challenge_moon.lvl",
"volcanoarea.lvl",
"vladscastle.lvl",
"challenge_moon.lvl",
"olmecarea.lvl",
"tidepoolarea.lvl",
"lake.lvl",
"lakeoffire.lvl",
"challenge_star.lvl",
"abzu.lvl",
"templearea.lvl",
"beehive.lvl",
"challenge_star.lvl",
"cityofgold.lvl",
"duat.lvl",
"icecavesarea.lvl",
"babylonarea.lvl",
"babylonarea_1-1.lvl",
"hallofushabti.lvl",
"palaceofpleasure.lvl",
"tiamat.lvl",
"sunkencityarea.lvl",
"challenge_sun.lvl",
"eggplantarea.lvl",
"hundun.lvl",
"ending.lvl",
"ending_hard.lvl",
"cosmicocean_babylon.lvl",
"cosmicocean_dwelling.lvl",
"cosmicocean_icecavesarea.lvl",
"cosmicocean_jungle.lvl",
"cosmicocean_sunkencity.lvl",
"cosmicocean_temple.lvl",
"cosmicocean_tidepool.lvl",
"cosmicocean_volcano.lvl",
]
return [
"dwellingarea.lvl",
"cavebossarea.lvl",
"junglearea.lvl",
"blackmarket.lvl",
"beehive.lvl",
"challenge_moon.lvl",
"volcanoarea.lvl",
"vladscastle.lvl",
"challenge_moon.lvl",
"olmecarea.lvl",
"tidepoolarea.lvl",
"lake.lvl",
"lakeoffire.lvl",
"challenge_star.lvl",
"abzu.lvl",
"templearea.lvl",
"beehive.lvl",
"challenge_star.lvl",
"cityofgold.lvl",
"duat.lvl",
"icecavesarea.lvl",
"babylonarea.lvl",
"babylonarea_1-1.lvl",
"hallofushabti.lvl",
"palaceofpleasure.lvl",
"tiamat.lvl",
"sunkencityarea.lvl",
"challenge_sun.lvl",
"eggplantarea.lvl",
"hundun.lvl",
"ending.lvl",
"ending_hard.lvl",
"cosmicocean_babylon.lvl",
"cosmicocean_dwelling.lvl",
"cosmicocean_icecavesarea.lvl",
"cosmicocean_jungle.lvl",
"cosmicocean_sunkencity.lvl",
"cosmicocean_temple.lvl",
"cosmicocean_tidepool.lvl",
"cosmicocean_volcano.lvl",
]

@staticmethod
@lru_cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ def check_dependencies(self):
delimiter = ", "
if len(levels) <= 4:
delimiter = "\n"
self.depend_order_label["text"] = delimiter.join([" -> ".join(
[level.level_name for level in level_path]
) for level_path in levels])
self.depend_order_label["text"] = delimiter.join(
[
" -> ".join([level.level_name for level in level_path])
for level_path in levels
]
)
self.depend_order_label.grid()

def update_lvls_path(self, new_path):
Expand Down

0 comments on commit f36ca82

Please sign in to comment.