Skip to content

Commit

Permalink
Finalized tile map add/remove/rename features
Browse files Browse the repository at this point in the history
  • Loading branch information
cspang1 committed Oct 23, 2023
1 parent 9011dac commit decb20f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/color_palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def remove_color_palette(self, palette_name):

@pyqtSlot(str, str)
def rename_color_palette(self, old_color_palette_name, new_color_palette_name):
index = self.color_palette_name_combo.findText(old_color_palette_name)
self.color_palette_name_combo.setItemText(
self.color_palette_name_combo.findText(old_color_palette_name),
new_color_palette_name
Expand Down
25 changes: 25 additions & 0 deletions src/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,28 @@ def validate(self):
return Validator(False, "At least one tile map is required")

return Validator(True, "")

class cmd_rename_tile_map(QUndoCommand):

def __init__(self, data_source, old_tile_map_name, new_tile_map_name, parent=None):
super().__init__("rename tile map", parent)
self.data_source = data_source
self.old_tile_map_name = old_tile_map_name
self.new_tile_map_name = new_tile_map_name

def redo(self):
self.data_source.rename_tile_map(self.old_tile_map_name, self.new_tile_map_name)

def undo(self):
self.data_source.rename_tile_map(self.new_tile_map_name, self.old_tile_map_name)

def validate(self):
if self.old_tile_map_name == self.new_tile_map_name:
return Validator(False, "")
if not self.new_tile_map_name:
return Validator(False, "Tile map name cannot be blank")
for tile_map in self.data_source.get_tile_maps():
if tile_map.get_name() == self.new_tile_map_name:
return Validator(False, "A tile map with that name already exists")

return Validator(True, "")
15 changes: 13 additions & 2 deletions src/jide.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
cmd_rename_color_palette,
cmd_set_asset_name,
cmd_set_color,
cmd_remove_tile_map
cmd_remove_tile_map,
cmd_rename_tile_map
)

class Jide(QMainWindow, Ui_main_window):
Expand Down Expand Up @@ -260,6 +261,16 @@ def init_models(self):
)
)
)
self.tile_map_picker.tile_map_renamed.connect(
lambda old_tile_map_name, new_tile_map_name:
self.undo_stack.push(
cmd_rename_tile_map(
self.tile_map_data,
old_tile_map_name,
new_tile_map_name
)
)
)

def init_ui(self):
self.sprite_color_palette.set_transparency(True)
Expand Down Expand Up @@ -296,9 +307,9 @@ def init_ui(self):
self.sprite_color_data.color_palette_renamed.connect(self.sprite_color_palette.rename_color_palette)
self.tile_color_data.color_palette_renamed.connect(self.tile_color_palette.rename_color_palette)

# remove, rename, etc. tile map connections here
self.tile_map_data.tile_map_added.connect(self.tile_map_picker.add_tile_map)
self.tile_map_data.tile_map_removed.connect(self.tile_map_picker.remove_tile_map)
self.tile_map_data.tile_map_renamed.connect(self.tile_map_picker.rename_tile_map)

self.sprite_color_data.color_updated.connect(self.sprite_color_palette.update_color)
self.tile_color_data.color_updated.connect(self.tile_color_palette.update_color)
Expand Down
11 changes: 11 additions & 0 deletions src/tile_map_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def remove_tile_map(self, tile_map_name):

return removed_tile_map

@pyqtSlot(str, str)
def rename_tile_map(self, old_tile_map_name, new_tile_map_name):
for tile_map in self.tile_maps:
if tile_map.get_name() == old_tile_map_name:
tile_map.set_name(new_tile_map_name)

self.tile_map_renamed.emit(old_tile_map_name, new_tile_map_name)

def get_tile_maps(self):
return self.tile_maps

Expand All @@ -68,6 +76,9 @@ def get_tile(self, x, y):
def set_tile(self, x, y, color_palette_index, tile_palette_index):
self.data[y][x] = Tile(color_palette_index, tile_palette_index)

def set_name(self, tile_map_name):
self.name = tile_map_name

def get_name(self):
return self.name

Expand Down
3 changes: 1 addition & 2 deletions src/tile_map_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ def remove_tile_map(self, tile_map_name):

@pyqtSlot(str, str)
def rename_tile_map(self, old_tile_map_name, new_tile_map_name):
index = self.tile_map_name_combo.findText(old_tile_map_name)
self.tile_map_name_combo.setItemText(
self.tile_map_name_combo.findText(old_tile_map_name),
new_tile_map_name
)
self.tile_map_name_combo.setCurrentIndex(
self.tile_map_name_combo.findText(old_tile_map_name)
self.tile_map_name_combo.findText(new_tile_map_name)
)

# If the renamed palette has the same index as the current one,
Expand Down

0 comments on commit decb20f

Please sign in to comment.