added basic save/load
This commit is contained in:
@@ -103,6 +103,10 @@ class Editor:
|
||||
self.zoom_out()
|
||||
elif event.key == pygame.K_BACKSPACE:
|
||||
self.deleted_selected_objects()
|
||||
elif event.key == pygame.K_s and event.mod & (pygame.KMOD_CTRL | pygame.KMOD_META):
|
||||
self.graph.save(input("Save as: "))
|
||||
elif event.key == pygame.K_l and event.mod & (pygame.KMOD_CTRL | pygame.KMOD_META):
|
||||
self.graph = Graph.load(input("Load from: "))
|
||||
elif event.key == pygame.K_RETURN:
|
||||
if len(self.selected_nodes) > 0:
|
||||
self.typing_text = "" if len(self.selected_nodes) > 1 else self.graph.nodes[self.selected_nodes[0]].name
|
||||
@@ -319,7 +323,7 @@ class Editor:
|
||||
pygame.draw.line(self.win, (0, 0, 0), self.world_to_screen(node_1.x, node_1.z), self.world_to_screen(node_2.x, node_2.z), self.edge_detect_radius)
|
||||
color = (0, 255, 255) if edge_index in self.selected_edges else (255, 0, 0)
|
||||
pygame.draw.line(self.win, color, self.world_to_screen(node_1.x, node_1.z), self.world_to_screen(node_2.x, node_2.z), self.line_size)
|
||||
|
||||
|
||||
def render_selection_rect(self):
|
||||
rect = self.selection_rectangle
|
||||
if rect != None:
|
||||
@@ -328,7 +332,7 @@ class Editor:
|
||||
width = abs(rect[0][0] - rect[1][0])
|
||||
height = abs(rect[0][1] - rect[1][1])
|
||||
pygame.draw.rect(self.win, (32, 32, 32), pygame.Rect(left, top, width, height), self.line_size)
|
||||
|
||||
|
||||
|
||||
def set_zoom(self, zoom_i: int) -> None:
|
||||
self.zoom_i = max(0, min(len(self.ZOOMS) - 1, zoom_i))
|
||||
@@ -417,7 +421,7 @@ class Editor:
|
||||
self.graph.nodes[node].rename_node(self.typing_text)
|
||||
self.typing_text = ""
|
||||
self.is_renaming_node = False
|
||||
|
||||
|
||||
def create_node(self, pos, typing_text = "") -> None:
|
||||
self.graph.add_node(pos[0], pos[1], typing_text)
|
||||
if len(self.selected_nodes) == 1:
|
||||
@@ -514,17 +518,17 @@ class Editor:
|
||||
if n != 0:
|
||||
self.selected_nodes.append(self.previously_created_nodes[n - 1])
|
||||
self.previously_created_nodes.pop()
|
||||
|
||||
|
||||
def create_selection_rect(self, shifting = False):
|
||||
if not shifting:
|
||||
self.clear_selection()
|
||||
self.previously_created_nodes = []
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
self.selection_rectangle = [mouse_pos, mouse_pos]
|
||||
|
||||
|
||||
def expand_selection_rect(self):
|
||||
self.selection_rectangle[1] = pygame.mouse.get_pos()
|
||||
|
||||
|
||||
def release_selection_rect(self, shifting = False):
|
||||
if not shifting:
|
||||
self.clear_selection()
|
||||
|
||||
Reference in New Issue
Block a user