Renpy | Save Editor

if var_name in editor.all_variables: editor.all_variables[var_name]['value'] = var_value editor.save_changes() print(f"Updated var_name to var_value") else: print(f"Variable 'var_name' not found in save") if == " main ": import sys

class RenPySaveEditor: def (self, root): self.root = root self.root.title("Ren'Py Save Editor v1.0") self.root.geometry("900x600")

# Navigate to variables if 'variables' in save: save['variables'][variable] = new_value else: save[variable] = new_value renpy save editor

var_name, var_value = var_assignment.split('=', 1)

def update_variable(self): selection = self.variable_listbox.curselection() if not selection: messagebox.showwarning("Warning", "No variable selected") return var_name = self.variable_listbox.get(selection[0]) new_value_str = self.value_entry.get(1.0, tk.END).strip() current_type = self.all_variables[var_name]['type'] try: # Convert value based on type if current_type == 'int': new_value = int(new_value_str) elif current_type == 'float': new_value = float(new_value_str) elif current_type == 'bool': new_value = new_value_str.lower() in ('true', '1', 'yes', 'on') elif current_type == 'list': new_value = json.loads(new_value_str) elif current_type == 'dict': new_value = json.loads(new_value_str) else: new_value = new_value_str # Update variable self.all_variables[var_name]['value'] = new_value self.status_var.set(f"Updated var_name = new_value") except Exception as e: messagebox.showerror("Error", f"Failed to convert value: str(e)") if var_name in editor

self.current_save = None self.save_data = None self.setup_ui() def setup_ui(self): # Menu bar menubar = tk.Menu(self.root) self.root.config(menu=menubar) file_menu = tk.Menu(menubar, tearoff=0) menubar.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Open Save", command=self.open_save) file_menu.add_command(label="Save Changes", command=self.save_changes) file_menu.add_separator() file_menu.add_command(label="Exit", command=self.root.quit) # Main frame main_frame = ttk.Frame(self.root, padding="10") main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S)) # Left panel - variable list left_frame = ttk.LabelFrame(main_frame, text="Variables", width=300) left_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S), padx=5) self.search_var = tk.StringVar() self.search_var.trace('w', self.filter_variables) search_entry = ttk.Entry(left_frame, textvariable=self.search_var) search_entry.grid(row=0, column=0, sticky=(tk.W, tk.E), pady=5, padx=5) search_entry.insert(0, "Search...") self.variable_listbox = tk.Listbox(left_frame, height=25) self.variable_listbox.grid(row=1, column=0, sticky=(tk.W, tk.E, tk.N, tk.S), pady=5, padx=5) self.variable_listbox.bind('<<ListboxSelect>>', self.on_variable_select) scrollbar = ttk.Scrollbar(left_frame, orient="vertical", command=self.variable_listbox.yview) scrollbar.grid(row=1, column=1, sticky=(tk.N, tk.S)) self.variable_listbox.config(yscrollcommand=scrollbar.set) # Right panel - variable editor right_frame = ttk.LabelFrame(main_frame, text="Edit Variable", width=400) right_frame.grid(row=0, column=1, sticky=(tk.W, tk.E, tk.N, tk.S), padx=5) ttk.Label(right_frame, text="Variable Name:").grid(row=0, column=0, sticky=tk.W, pady=5) self.var_name_label = ttk.Label(right_frame, text="") self.var_name_label.grid(row=0, column=1, sticky=tk.W, pady=5) ttk.Label(right_frame, text="Type:").grid(row=1, column=0, sticky=tk.W, pady=5) self.var_type_label = ttk.Label(right_frame, text="") self.var_type_label.grid(row=1, column=1, sticky=tk.W, pady=5) ttk.Label(right_frame, text="Value:").grid(row=2, column=0, sticky=tk.W, pady=5) self.value_entry = tk.Text(right_frame, height=10, width=40) self.value_entry.grid(row=2, column=1, pady=5, padx=5) ttk.Button(right_frame, text="Update Value", command=self.update_variable).grid(row=3, column=1, pady=10) # Status bar self.status_var = tk.StringVar() self.status_var.set("Ready") status_bar = ttk.Label(self.root, textvariable=self.status_var, relief=tk.SUNKEN, anchor=tk.W) status_bar.grid(row=1, column=0, sticky=(tk.W, tk.E)) # Configure grid weights self.root.columnconfigure(0, weight=1) self.root.rowconfigure(0, weight=1) main_frame.columnconfigure(0, weight=1) main_frame.columnconfigure(1, weight=2) main_frame.rowconfigure(0, weight=1) left_frame.columnconfigure(0, weight=1) left_frame.rowconfigure(1, weight=1) self.all_variables = {} def open_save(self): filepath = filedialog.askopenfilename( title="Select Ren'Py Save File", filetypes=[("Ren'Py Saves", "*.save"), ("All Files", "*.*")] ) if not filepath: return try: self.current_save = filepath self.load_save_data() self.display_variables() self.status_var.set(f"Loaded: os.path.basename(filepath)") except Exception as e: messagebox.showerror("Error", f"Failed to load save: str(e)") self.status_var.set("Error loading save")

# Load and edit save editor = RenPySaveEditor(None) editor.current_save = save_file editor.load_save_data() var_value = var_assignment.split('='

def save_changes(self): if not self.current_save: messagebox.showwarning("Warning", "No save file loaded") return try: # Reconstruct save data if isinstance(self.save_data, dict): if 'variables' in self.save_data: # Update variables in original structure for var_name, var_info in self.all_variables.items(): self.save_data['variables'][var_name] = var_info['value'] else: # Direct variable storage for var_name, var_info in self.all_variables.items(): self.save_data[var_name] = var_info['value'] # Save back to file backup_path = self.current_save + ".backup" import shutil shutil.copy2(self.current_save, backup_path) # Write new save file with open(self.current_save, 'wb') as f: # Write header (preserve original if possible) f.write(b'RENPYSAVE') # Compress and write data compressed = zlib.compress(json.dumps(self.save_data).encode()) f.write(compressed) self.status_var.set(f"Saved changes (backup: backup_path)") messagebox.showinfo("Success", "Save file updated successfully!") except Exception as e: messagebox.showerror("Error", f"Failed to save: str(e)") def command_line_editor(): """Command-line version for quick edits""" import sys