Jump to content
Sign in to follow this  
Crazyninjaguy

AEE - Data Manager

Recommended Posts

Introduction

 

Just to be clear, this is a Scripter's Tool, and will do nothing by itself.

After attempting to add a game class into a savefile, and not being able to due to not being allowed to alias a module's methods (Unless i've overlooked something), I wrote this.

This allows scripters to add their own Game Classes into savefiles, and load them with the normal savefiles.

Simply alias the create_extra_objects, get_files_to_save and the extract_save_contents methods with your extra classes, and the script will do the rest.

 

Example

 

This is an example of how to use the AEE Data Manager system.

 

class AEEDataManager
alias aee_datamanager_musicplayer_createobjects create_extra_objects
def create_extra_objects
aee_datamanager_musicplayer_createobjects
$game_music = Game_Music.new
end
alias aee_datamanager_musicplayer_getfilestosave get_files_to_save
def get_files_to_save(contents)
aee_datamanager_musicplayer_getfilestosave(contents)
contents[:music] = $game_music
end
alias aee_datamanager_musicplayer_extractfiles extract_save_contents
def extract_save_contents(contents)
aee_datamanager_musicplayer_extractfiles(contents)
$game_music = contents[:music]
end
end

 

Script

 

 

#===============================================================================
# * AEE - Data Manager
# * By Crazyninjaguy
# * http://www.planetdev.co.uk
# * Part of Cng Ace Engine Evolution
# * SCRIPTER'S TOOL
# ---------------------------------------------------------------------------
# * After attempting to add a game class into a savefile, and not being able to
# due to not being allowed to alias a module's methods, I wrote this.
#
# * This allows scripters to add their own Game Classes into savefiles, and load
# them with the normal savefiles.
#
# * Simply alias the create_extra_objects, get_files_to_save and the
# extract_save_contents methods with your extra classes, and the script
# will do the rest. See the post on PlanetDev for an example.
#===============================================================================

$imported = {} if $imported == nil
$imported["AEE-Datamanager"] = true

class AEEDataManager
def initialize
create_extra_database
end
def create_extra_database
end
def create_extra_objects
end
def save_extra_objects(index)
File.open(make_filename(index), "wb") do |file|
$game_system.on_before_save
Marshal.dump(make_save_contents, file)
end
end
def load_extra_objects(index)
File.open(make_filename(index), "rb") do |file|
extract_save_contents(Marshal.load(file))
DataManager.reload_map_if_updated
end
return true
end
def loadfile_extra_objects
end
def make_filename(index)
sprintf("Save%02d_extra.rvdata2", index + 1)
end
def extract_save_contents(contents)
end
def make_save_contents
contents = {}
get_files_to_save(contents)
contents
end
def get_files_to_save(contents)
end
end

class Scene_Title < Scene_Base
alias aee_scenetitle_datamanager_start start
def start
aee_scenetitle_datamanager_start
$game_datamanager = AEEDataManager.new
end
alias aee_scenetitle_datamanager_commandnewgame command_new_game
def command_new_game
$game_datamanager.create_extra_objects
aee_scenetitle_datamanager_commandnewgame
end
end

class Scene_Save < Scene_File
alias aee_scenesave_datamanager_onsaveok on_savefile_ok
def on_savefile_ok
aee_scenesave_datamanager_onsaveok
$game_datamanager.save_extra_objects(@index)
end
end

class Scene_Load < Scene_File
alias aee_sceneload_datamanager_onsaveok on_savefile_ok
def on_savefile_ok
aee_sceneload_datamanager_onsaveok
$game_datamanager.load_extra_objects(@index)
end
end

 

 

Credits

 

Please credit me if you use this.

Available for use in Commercial games, but credit must be given.

Edited by Crazyninjaguy

Share this post


Link to post
Share on other sites

To alias a module method:

module MyModule

 class << self
alias old_method_name my_method
 end

def self.my_method
 ## and put your stuff here and call the old method
end

end

Share this post


Link to post
Share on other sites

or just use

 

class << MyModule
 alias :old_method :method
 def method
#stuff
old_method
 end
end

 

that way you can use your module as a normal class (no need to add def self.method, just use def method)

Edited by Victor Sant

Share this post


Link to post
Share on other sites

I thought you'd probably be able to do it some way or another, silly me for not looking it up first :3

I guess my script is still useful as I can't see a way of aliasing code into the middle of the make_save_contents method.

 

Thanks for the heads up Kread-EX and Victor! :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted