Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #~ Dumps certain variables into a global save file. In order to them to be
- #~ dumped, tag their name (the name in the editor) with an * (asterisk).
- #~ ~Kread
- GLOBAL_SAVEFILE_NAME = 'Global_Data.rvdata2'
- #==============================================================================
- # ** DataManager
- #==============================================================================
- module DataManager
- #--------------------------------------------------------------------------
- # * Create the game objects
- #--------------------------------------------------------------------------
- class << self; alias_method(:krx_gsf_dl_cgo, :create_game_objects); end
- def self.create_game_objects
- krx_gsf_dl_cgo
- $game_system.read_global_savefile(GLOBAL_SAVEFILE_NAME)
- end
- end
- #==============================================================================
- # ** Game_System
- #==============================================================================
- class Game_System
- #--------------------------------------------------------------------------
- # * Write the global savefile
- #--------------------------------------------------------------------------
- def write_global_savefile(filename)
- contents = []
- (1..$game_variables.size).each do |i|
- next unless $data_system.variables[i].include?('*')
- contents.push([i, $game_variables[i]])
- end
- File.open(filename, 'wb') do |file|
- Marshal.dump(contents, file)
- end
- true
- end
- #--------------------------------------------------------------------------
- # * Read the global savefile
- #--------------------------------------------------------------------------
- def read_global_savefile(filename)
- contents = nil
- if FileTest.exist?(filename)
- File.open(filename, 'rb') {|file| contents = Marshal.load(file)}
- end
- return false unless contents
- contents.each {|array| $game_variables[array[0]] = array[1]}
- true
- end
- end
- #==============================================================================
- # ** Game_Variables
- #==============================================================================
- class Game_Variables
- #--------------------------------------------------------------------------
- # * Returns the data size
- #--------------------------------------------------------------------------
- def size
- @data.size
- end
- #--------------------------------------------------------------------------
- # * Assigns a value
- #--------------------------------------------------------------------------
- alias_method(:krx_gsf_gv_ass, :[]=)
- def []=(variable_id, value)
- krx_gsf_gv_ass(variable_id, value)
- if $data_system.variables[variable_id].include?('*')
- $game_system.write_global_savefile(GLOBAL_SAVEFILE_NAME)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement