Holy87

Homepath saving

Sep 27th, 2013 (edited)
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $imported = {} if $imported == nil
  2. $imported["H87_Homesave"] = 2.0
  3. #===============================================================================
  4. # MYDOCUMENTS SAVING
  5. #===============================================================================
  6. # Author: Holy87
  7. # Version: 2.0
  8. # User difficulty: ★
  9. #-------------------------------------------------------------------------------
  10. # This script changes the savegames path: not in the game root anymore, but
  11. # in C:\Users\Username\MyDocuments\GameTitle\Saves or
  12. # in C:\Users\Username\MyDocuments\My Games\GameTitle\Saves or
  13. # in C:\Users\Username\Saved Games\GameTitle\Saves
  14. # Not only this script will make your game more professional, but will allow
  15. # you to install the game in different paths having the saves in the same
  16. # folder. You could also share the project in a CD disk and can play to your
  17. # frients without installing anithyng on the PC.
  18. #-------------------------------------------------------------------------------
  19. # Instructions:
  20. # Install this script under Materials and above the Main.
  21. # IMPORTANT: REQUIRES HOLY87 UNIVERSAL MODULE.
  22. #-------------------------------------------------------------------------------
  23. # Compatibility:
  24. # DataManager: alias methos
  25. #   settings_path
  26. #   save_file_exists?
  27. #   make_filename
  28. #-------------------------------------------------------------------------------
  29.  
  30. #==============================================================================
  31. # ** SETTINGS
  32. #==============================================================================
  33. module Homesave
  34.   # choose where the game saves location is
  35.   # saved_games: C:\Users\user\Saved Games\Project Name\Saves
  36.   # my_documents: C:\Users\user\Documents\Project Name\Saves
  37.   # my_games: C:\Users\user\Documents\My Games\Project Name\Saves
  38.   SAVES_HOME = :saved_games
  39.  
  40.   # the saves folder name
  41.   SAVES_FOLDER = "Salvataggi" #change this string for saves folder
  42. end
  43.  
  44. #==============================================================================
  45. # ** Homesave
  46. #------------------------------------------------------------------------------
  47. #  This is the core of the script.
  48. #==============================================================================
  49. module Homesave
  50.   # returns the complete path for save files
  51.   # ex. C:/Users/user/Documents/Game/Saves
  52.   # @return [String]
  53.   def self.saves_path
  54.     path = project_data_directory + '/' + saves_directory
  55.     Dir.mkdir(path) unless File.directory?(path)
  56.     path
  57.   end
  58.  
  59.   # Returns the game folder name
  60.   # @return [String]
  61.   def self.game_directory_name
  62.     load_data("Data/System.rvdata2").game_title
  63.   end
  64.  
  65.   # returns the main project data directory (if you want to
  66.   # add more directories it should be useful to call this
  67.   # instead of the save, for ex. mods)
  68.   # @return [String]
  69.   def self.project_data_directory
  70.     case SAVES_HOME
  71.     when :my_documents
  72.       fpath = Win.get_folder_path(:docs)
  73.     when :saved_games
  74.       fpath = Win.saved_games_folder
  75.     when :my_games
  76.       fpath = Win.get_folder_path(:docs) + '/My Games'
  77.     else
  78.       fpath = '.'
  79.     end
  80.     Dir.mkdir(fpath) unless File.directory?(fpath)
  81.     fpath << '/' + game_directory_name
  82.     Dir.mkdir(fpath) unless File.directory?(fpath)
  83.     fpath
  84.   end
  85.  
  86.   # Returns the Saves folder name
  87.   # @return [String]
  88.   def self.saves_directory
  89.     SAVES_FOLDER
  90.   end
  91.  
  92.   # @return [String]
  93.   # @deprecated use saves_path
  94.   def self.folder_path
  95.     saves_path
  96.   end
  97. end #homesave
  98.  
  99. #==============================================================================
  100. # ** DataManager
  101. #------------------------------------------------------------------------------
  102. #  Path editing
  103. #==============================================================================
  104. module DataManager
  105.   class << self
  106.     alias sett_filename settings_path #alias method settings_path (supp)
  107.     alias exst_filename save_file_exists? #alias method save_file_exists?
  108.     alias save_filename make_filename #alias method make_filename
  109.   end
  110.  
  111.   # Changes the game_settings path (universal module)
  112.   def self.settings_path
  113.     Homesave.saves_path + "/" + sett_filename
  114.   end
  115.  
  116.   # Changes the path where saves are checked
  117.   def self.save_file_exists?
  118.     temp = Dir.pwd
  119.     Dir.chdir(Homesave.saves_path)
  120.     exist = exst_filename
  121.     Dir.chdir(temp)
  122.     return exist
  123.   end
  124.  
  125.   # changes the saves path
  126.   def self.make_filename(index)
  127.     Homesave.saves_path + "/" + save_filename(index)
  128.   end
  129. end #DataManager
RAW Paste Data