diff --git a/main.py b/main.py index 92fda92..c863701 100644 --- a/main.py +++ b/main.py @@ -3204,7 +3204,7 @@ class PuzzleBlock(QGraphicsPathItem): self.container = QWidget() self.container.setObjectName("blockContainer") self.container.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) - if self.b_type == "logic": + if self.b_type == "logic" or self.b_type == "created_event" or self.b_type == "created_joint": self.container.setFixedSize(130, 20) self.container.setStyleSheet("background: transparent; border: none;") else: @@ -3273,14 +3273,14 @@ class PuzzleBlock(QGraphicsPathItem): # Color Coding self.update_path() - colors = {"begin": "#2e7d32", "middle": "#1565c0", "end": "#c62828", "logic": "#ef6c00"} + colors = {"begin": "#2e7d32", "middle": "#1565c0", "end": "#c62828", "logic": "#ef6c00", "created_event": "#6a1b9a", "created_joint": "#00695c"} self.setBrush(QBrush(QColor(colors.get(b_type, "#555")))) self.setPen(QPen(QColor("#ffffff"), 1)) self.label_item = QGraphicsSimpleTextItem(self.label_text, self) self.label_item.setBrush(QColor("white")) - if self.b_type == "logic": + if self.b_type == "logic" or self.b_type == "created_event" or self.b_type == "created_joint": self.label_item.setPos(2, 1) else: self.label_item.setPos(25, 15) @@ -3290,7 +3290,7 @@ class PuzzleBlock(QGraphicsPathItem): """This changes how they visually appear. Likely no logic broken here.""" self.prepareGeometryChange() - if self.b_type == "logic": + if self.b_type == "logic" or self.b_type == "created_event" or self.b_type == "created_joint": display_width = 130 # Slimmer profile display_height = 20 # Shorter default height else: @@ -3550,19 +3550,25 @@ class BlockLibrary(QTreeWidget): # This will now be 'created_joint' or 'created_event' instead of just 'begin' s_type = getattr(block_item, 'sub_type', 'standard') label = block_item.label_text + + print(f"[DEBUG - DROP] Captured dropped block. Label: '{label}' | Sub-type: '{s_type}'") # 2. Route to the correct sidebar category if s_type == "created_joint": target_category = "created_joint" # Teal + print(f"[DEBUG - DROP] Routing '{label}' to CALCULATED JOINTS shelf.") elif s_type == "created_event": - target_category = "created_event" # Orange (Individual Variables) + print(f"[DEBUG - DROP] Blocked: '{label}' is a created_event. Aborting sidebar injection for Individual view.") + return # Orange (Individual Variables) else: + print(f"[DEBUG - DROP] Ignored: '{label}' is sub-type '{s_type}' (Standard block). Skipping.") return # Don't add standard 'begin' blocks to the logic list # 3. Prevent Duplicate Sidebar Entries category_item = self.get_or_create_category(target_category) for i in range(category_item.childCount()): if category_item.child(i).text(0) == label: + print(f"[DEBUG - DROP] Duplicate blocked: '{label}' already exists in '{target_category}' tree.") return # 4. Update the Sidebar UI immediately @@ -3572,16 +3578,27 @@ class BlockLibrary(QTreeWidget): def update_item_name(self, old_name, new_name): """Rename logic blocks in the VARIABLES dropdown.""" + print(f"[DEBUG - RENAME] Signal intercepted. Attempting to update rename from '{old_name}' -> '{new_name}'") cat = self.get_or_create_category("created_joint") + + found = False for i in range(cat.childCount()): item = cat.child(i) if item.text(0) == old_name: item.setText(0, new_name) + print(f"[DEBUG - RENAME] Success! Updated sidebar node label from '{old_name}' to '{new_name}'") + found = True + break + + if not found: + print(f"[DEBUG - RENAME] Warning: Could not find any active sidebar item matching matching text '{old_name}' to execute rename operation.") def discover_saved_blocks(self, save_file, target_subtype): """Scans save file and populates categories using the helper function.""" + print(f"[DEBUG - LOADPASS] Executing JSON block discovery pass against file: '{save_file}' | Looking for: '{target_subtype}'") if not os.path.exists(save_file): + print(f"[DEBUG - LOADPASS] Aborted pass: Targets tracking file '{save_file}' does not exist on disk.") return try: @@ -3592,9 +3609,10 @@ class BlockLibrary(QTreeWidget): target_cat = self.get_or_create_category(target_subtype) if not target_cat: - print(f"[ERROR] Could not resolve category for: {target_subtype}") + print(f"[ERROR - LOADPASS] Dynamic category allocation crash! Could not resolve folder configuration for: '{target_subtype}'") return + print(f"[DEBUG - LOADPASS] Connected to target sidebar category folder: '{target_cat.text(0)}'. Parsing elements...") for block_data in data: if block_data.get('sub_type') == target_subtype: # Resolve name (LineEdit input or generic label) @@ -3606,6 +3624,7 @@ class BlockLibrary(QTreeWidget): for i in range(target_cat.childCount()): if target_cat.child(i).text(0) == name: is_duplicate = True + print(f"[DEBUG - LOADPASS] Match detected: Skipping loop pass for element '{name}'. Reason: Already present in category view.") break if not is_duplicate: @@ -3644,39 +3663,7 @@ class BlockLibrary(QTreeWidget): print(f"[DEBUG] Sidebar: Removed '{label}' from {cat_key}") return # Exit once the spawn is deleted - # def add_dynamic_logic_item(self, block_item): - # """ - # Triggered when a 'begin' block is dropped on the canvas. - # Adds a corresponding 'logic' block to this library. - # """ - # # 1. Check for duplicates - # # We don't want to add "Joint 1" five times if they drag five 'begin' blocks - # label = block_item.label_text - - # items = self.findItems(label, Qt.MatchExactly) - # for item in items: - # if item.data(Qt.UserRole) == "logic": - # print(f"DEBUG: {label} (logic) already exists in library. Skipping.") - # return - - # # 2. Add the item as a 'logic' type - # # In your system, logic blocks have no fields (they are just variables) - # print(f"DEBUG: Dynamically adding '{label}' as a logic block.") - # self.add_item(label, "logic", fields=[]) - - # def update_item_name(self, old_name, new_name): - # print(f"[DEBUG - Library] Searching for items matching: '{old_name}'") - # items = self.findItems(old_name, Qt.MatchExactly) - - # if not items: - # print(f"[DEBUG - Library] No items found matching '{old_name}'") - - # for item in items: - # # Ensure we only rename the logic-type items - # if item.data(Qt.UserRole) == "logic": - # item.setText(new_name) - # print(f"[DEBUG - Library] Successfully updated sidebar item to '{new_name}'") from PySide6.QtWidgets import QGraphicsLineItem, QGraphicsRectItem, QGraphicsSimpleTextItem @@ -3797,9 +3784,9 @@ class TopologyCanvas(QGraphicsView): # 3. Determine the visual class of the block # (Same logic as before, but cleaner) if b_type == "created_event": - visual_type = "begin" + visual_type = "created_event" elif b_type == "created_joint": - visual_type = "logic" + visual_type = "created_joint" else: visual_type = b_type @@ -4214,10 +4201,17 @@ class TopologyCanvas(QGraphicsView): # Re-running embed_logic_block will fix the internal Z-value and position self.embed_logic_block(curr, host, slot_key) + # --- FIXED BLOCK DISCOVERY ROUTING --- if hasattr(self, 'block_library_ref') and self.block_library_ref: - # Determine what we are looking for based on current editor mode - target = "created_joint" if self.block_library_ref.mode == "individual" else "created_event" - self.block_library_ref.discover_saved_blocks(file_path, target) + if self.block_library_ref.mode == "individual": + # Individual mode reads its own file for joints + self.block_library_ref.discover_saved_blocks(file_path, "created_joint") + else: + # Group mode forces a look into the individual file to find the events, + # but we map it to "logic" so it drops into the VARIABLES shelf! + individual_file = "config_individual.json" + print(f"[DEBUG - LOAD] Group view pulling events from: {individual_file}") + self.block_library_ref.discover_saved_blocks(individual_file, "created_event") # 3. Final visual refresh self.scene.update()