Use savefiles in newer builds

♥SOURCE♥

Too sexy for your party.
Veteran
Joined
Mar 14, 2012
Messages
693
Reaction score
411
Primarily Uses
Little update to Save File Doctor to account for Game_Actor changes:

#==============================================================================# ** MakerSystems#------------------------------------------------------------------------------# #==============================================================================module MakerSystems #============================================================================ # ** SaveFileDoctor #---------------------------------------------------------------------------- # #============================================================================ module SaveFileDoctor #---------------------------------------------------------------------- # * Custom Case for Game_Actors. [NEW] #---------------------------------------------------------------------- def self.custom_case_for_game_actors(patient, current) # Get data array that contains each Actor. patient_data = patient.instance_variable_get('@data') # Go through each Actor. patient_data.each do |actor| # Next if actor is nil. Needed because how Game_Actors handles []. next unless actor # Get current actor from current Game_Actors using patient's id. current_actor = current[actor.instance_variable_get('@actor_id')] # Fixes each of patient's Game_Actor objects. fix_object(actor, current_actor) # Healing process for each instance variable of this actor. child_health(object_data(actor), object_data(current_actor)) end end #---------------------------------------------------------------------- # * Heal. [NEW] #---------------------------------------------------------------------- def self.heal(contents) # Will keep track of repaired objects to avoid a stack overflow. @ms_save_file_doctor_ids = [] # Goes through each object in contents hash. contents.each_value do |patient| # Updated version of this Object. current = patient.class.new # Fixes this (loaded) Object with the help of its updated version. fix_object(patient, current) # Starts the healing process for each instance variable. child_health(object_data(patient), object_data(current)) end # No need to keep the objects ids in memory. @ms_save_file_doctor_ids = nil end #---------------------------------------------------------------------- # * Enumerable Child Processing. [NEW] #---------------------------------------------------------------------- def self.enum_child(patient, current) # Iterates loaded version and updated version as a sequence. patient.zip(current).each do |p_value, c_value| # If Enumerable, there might be instanceable Objects inside it. enum_child(p_value.to_a, c_value.to_a) if Enumerable === p_value # Ignore if it can't be instanced. next unless p_value.class.respond_to?:)new) # Stop if this Object was already healed to avoid a stack overflow. return if @ms_save_file_doctor_ids.include?(p_value.__id__) # Saves current Object id. @ms_save_file_doctor_ids << p_value.__id__ # Fixes this Object with the help of its updated version. fix_object(p_value, c_value) # Healing process for each instance variable of this Object. child_health(object_data(p_value), object_data(c_value)) end end #---------------------------------------------------------------------- # * Object Data. [NEW] #---------------------------------------------------------------------- def self.object_data(object) # Returns a hash with each instance variable name and value. Hash[ object.instance_variables.map do |name| [name, object.instance_variable_get(name)] end ] end #---------------------------------------------------------------------- # * Fix Object. [NEW] #---------------------------------------------------------------------- def self.fix_object(patient, current) # Name of the method that should especially handle this object. special = "custom_case_for_#{patient.class.name.downcase}" # Attempts special handling. send(special, patient, current) if respond_to?(special) # Adds new data to loaded Object's data target. data = object_data(current).merge(object_data(patient)) # Uses the correct data target to set each instance variable. data.each { |name, value| patient.instance_variable_set(name, value) } end #---------------------------------------------------------------------- # * Child Health. [NEW] #---------------------------------------------------------------------- def self.child_health(patient, current) # Goes through each instance variable. patient.each do |name, value| # If Enumerable, there might be instanceable Objects inside it. enum_child(value.to_a, current[name].to_a) if Enumerable === value # Ignore if it can't be instanced. next unless value.class.respond_to?:)new) # Stop if this Object was already healed to avoid a stack overflow. return if @ms_save_file_doctor_ids.include?(value.__id__) # Saves current Object id. @ms_save_file_doctor_ids << value.__id__ # Fixes this Object with the help of its updated version. fix_object(value, current[name]) # Healing process for each instance variable of this Object. child_health(object_data(value), object_data(current[name])) end end end end#==============================================================================# ** DataManager#------------------------------------------------------------------------------# This module manages the database and game objects. Almost all of the # global variables used by the game are initialized by this module.#==============================================================================module DataManager class << self #------------------------------------------------------------------------ # * Alias Extract Save Contents. [NEW] #------------------------------------------------------------------------ alias_method:)ms_save_file_doctor_original_extract_save_contents, :extract_save_contents) #------------------------------------------------------------------------ # * Extract Save Contents. [MOD] #------------------------------------------------------------------------ def extract_save_contents(contents) # Healthcare. Object repairing is handled at a local level. MakerSystems::SaveFileDoctor.heal(contents) # Proceeds with the original method, using repaired contents. ms_save_file_doctor_original_extract_save_contents(contents) end end endSave File Doctor is the easiest solution for both scripters and non-scripters alike. Versioning save files is okay, but most people won't be able to do so without help.[/MOD]
 

Zeriab

Huggins!
Veteran
Joined
Mar 20, 2012
Messages
1,268
Reaction score
1,422
First Language
English
Primarily Uses
RMXP
Versioning save files can be done in tandem with your script. You can let the player know when old save files are loaded and still try to load the save file with ♥SOURCE♥'s Save File Doctor.
I do indeed agree that Save File Doctor is the easiest solution. There are even cases where it solves the situation perfectly. In the general case, it does not. It cannot. Be honest about what your script can.
Deliberate specific scripting for migrating data of old save files so they can be used in a newer build is generally a better way. Definitely harder, yes. It requires attention and rigor because you need to know and script exactly what must change.

Regardless of which way you prefer I still highly suggest versioning your save files. The scripting required for loading specific versions is simplified greatly. You also only need to deal with the migration once you get to the next version. For the first build, the actual versioning is simple and straightforward. Moreover, even with versioned saves you can decide to put Save File Doctor in instead.

Implementing versioning only hurts if you already have a live build. You’d need to do silly stuff like trying to load the version in a try-catch clause and go back to the old loading procedure upon failure. Quite ugly.

Btw. good job on the script ♥SOURCE♥. It certainly is technically intriguing :3

*hugs*
 - Zeriab
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,570
Latest member
fgfhdfg
Top