- 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]
#==============================================================================# ** 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?

SOURCE