Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- # * Era Module
- # Author: Eshra
- # Compatibility: Rpg Maker VX Ace
- # Released: vUnfinished posted 9 March 2013
- # Dependencies: ** no dependencies **
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Provides helper and utility methods for scripts I've written.
- # Standardizes loading notetags from the db so that it's not iterated
- # through multiple times when getting notes data.
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Update Log:
- # 18 Jan. 2013 - Moved set_revs method from Era to TBM, added core save obj.
- # 10 Jan. 2013 - Rounding and tbs revival settings
- # 30 Dec. 2012 - Notetag Loading standardization
- # 20 Nov. 2012 - added valid_comments
- # 18 Nov. 2012 - added new_event
- #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
- ($imported ||= {})["Era Module"] = 0.1
- module Era
- module LoadDB
- # Turn loading notetags on/off
- # No scripts modify the default off constants as of 18 Jan. 2013
- LOAD_CLASSES = false
- LOAD_SKILLS = true
- LOAD_ITEMS = true
- LOAD_WEAPONS = true
- LOAD_ARMORS = true
- LOAD_ENEMIES = true
- LOAD_TROOPS = false
- LOAD_STATES = true
- LOAD_ANIMATIONS = false
- LOAD_TILESETS = false
- LOAD_COMMON_EVENTS = false
- LOAD_MAPINFOS = false
- LOAD_ACTORS = true
- end # LoadDB
- module RE
- WinNL = /[\r\n]+/
- Num = /\A(?:-|)\d+(?:\.|)(?:\d+|)\Z/ # Regex representing a number
- end # RE
- #============================================================================
- # ** Era::Event
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # API:
- # valid_comments(id) => array of comments for event with id = to param
- # events active page, => nil if no active pages.
- # new_event(spawn_map_id, opts = {}) => spawns an event on the map,
- # requires reproduce events.
- # round(float, power of ten) => rounds the float to arg power of ten
- #
- #============================================================================
- module Event
- #--------------------------------------------------------------------------
- # * New Event
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Places a new event on the map using the "Reproduce Events" Script.
- #--------------------------------------------------------------------------
- def self.new_event(spawn_map_id, opts = {})
- return unless $imported["Ra Event Spawn"] >= 0.2
- player = $game_player
- options = {
- :x => player.x, :y => player.y, :persist => false, :init_dir => -1,
- :opts => {}, :name => nil, :id => 0
- }.merge(opts)
- persist,x,y,id = options[:persist], options[:x], options[:y], options[:id]
- init_dir, opts, name = options[:init_dir], options[:opts], options[:name]
- EventSpawn.spawn_event(spawn_map_id, id, x, y, persist, init_dir,
- opts, name)
- end
- #--------------------------------------------------------------------------
- # * Valid Comments
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Returns the comments for the event with param: id on its active page
- # => nil if no page conditions are met or no comments are found.
- #--------------------------------------------------------------------------
- def self.valid_comments(id)
- return if !(ev = $game_map.events[id]) || !(page = ev.find_proper_page)
- page.list.inject([]){ |a,c| c.code == 108 ? a.push(c.parameters[0]) : a }
- end
- end # Event
- #______________________
- # Convienience methods
- #--------------------------------------------------------------------------
- # * Round a float to the nearest place specified as a power of ten.
- #--------------------------------------------------------------------------
- def self.round(f, pten)
- (f*pten).round.to_f / pten
- end
- end # Era
- #==============================================================================
- # ** DataManager
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Note-tag helper methods. Alias eval_note_era to evaluate notes for
- # the entire database. Determine type by the regex the note matches.
- #==============================================================================
- module DataManager
- class <<self
- alias load_db_era load_database
- alias load_game_era load_game
- end
- def self.load_database
- load_db_era
- if !$BTEST
- load_classes_era if Era::LoadDB::LOAD_CLASSES
- load_actors_era if Era::LoadDB::LOAD_ACTORS
- load_enemies_era if Era::LoadDB::LOAD_ENEMIES
- load_troops_era if Era::LoadDB::LOAD_TROOPS
- load_animations_era if Era::LoadDB::LOAD_ANIMATIONS
- load_tilesets_era if Era::LoadDB::LOAD_TILESETS
- load_common_events_era if Era::LoadDB::LOAD_COMMON_EVENTS
- load_map_infos_era if Era::LoadDB::LOAD_MAPINFOS
- load_skills_era if Era::LoadDB::LOAD_SKILLS
- load_items_era if Era::LoadDB::LOAD_ITEMS
- load_weapons_era if Era::LoadDB::LOAD_WEAPONS
- load_armors_era if Era::LoadDB::LOAD_ARMORS
- load_states_era if Era::LoadDB::LOAD_STATES
- end
- end
- #--------------------------------------------------------------------------
- # * Alias, load_game
- #--------------------------------------------------------------------------
- def self.load_game(index)
- success = load_game_era(index)
- $game_system.init_era if $game_system # init core obj. if just installed
- success
- end
- #----------------------------------------------------------------------------
- # * Load Notetags
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Methods to perform processing on each item in the database. The benefit is
- # that now if two scripts I wrote needed to for example access all of the
- # armors, there would only be one iteration over $data_armors instead of
- # two. The speed up would only be noticable for large databases using several
- # scripts I've written.
- #----------------------------------------------------------------------------
- def self.load_classes_era; $data_classes.each{|c| each_class_era(c)}; end
- #----------------------------------------------------------------------------
- # * Processing for each class in the database
- #----------------------------------------------------------------------------
- def self.each_class_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_actors_era; $data_actors.each{|a| each_actor_era(a)}; end
- #----------------------------------------------------------------------------
- # * Processing for each actor
- #----------------------------------------------------------------------------
- def self.each_actor_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_enemies_era; $data_enemies.each{|e| each_enemy_era(e)}; end
- #----------------------------------------------------------------------------
- # * Processing for each enemy
- #----------------------------------------------------------------------------
- def self.each_enemy_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_troops_era; $data_troops.each{|t| each_troop_era(t)}; end
- #----------------------------------------------------------------------------
- # * Processing for each troop
- #----------------------------------------------------------------------------
- def self.each_troop_era(param)
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_animations_era;$data_animations.each{|a|each_animation_era(a)};end
- #----------------------------------------------------------------------------
- # * Processing for each animation
- #----------------------------------------------------------------------------
- def self.each_animation_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_tilesets_era; $data_tilesets.each{|t|each_tileset_era(t)}; end
- #----------------------------------------------------------------------------
- # * Processing for each tileset
- #----------------------------------------------------------------------------
- def self.each_tileset_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_common_events_era
- $data_common_events.each{|c| each_common_event_era(c) }
- end
- #----------------------------------------------------------------------------
- # * Processing for each common event
- #----------------------------------------------------------------------------
- def self.each_common_event_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_map_infos_era; $data_mapinfos.each{|m| each_map_info_era(m)};end
- #----------------------------------------------------------------------------
- # * Processing for each map info
- #----------------------------------------------------------------------------
- def self.each_map_info_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_skills_era; $data_skills.each{|s| each_skill_era(s)}; end
- #----------------------------------------------------------------------------
- # * Processing for each skill
- #----------------------------------------------------------------------------
- def self.each_skill_era(arg)
- arg.note.split(Era::RE::WinNL).each{ |line| eval_note_era(arg, line)} if arg
- end
- def self.load_items_era; $data_items.each{|i| each_item_era(i)}; end
- #----------------------------------------------------------------------------
- # * Processing for each item
- #----------------------------------------------------------------------------
- def self.each_item_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_weapons_era; $data_weapons.each{|w| each_weapon_era(w)}; end
- #----------------------------------------------------------------------------
- # * Processing for each weapon
- #----------------------------------------------------------------------------
- def self.each_weapon_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_armors_era; $data_armors.each{|a| each_armor_era(a)}; end
- #----------------------------------------------------------------------------
- # * Processing for each armor
- #----------------------------------------------------------------------------
- def self.each_armor_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- def self.load_states_era; $data_states.each{|s| each_state_era(s)}; end
- #----------------------------------------------------------------------------
- # * Processing for each state
- #----------------------------------------------------------------------------
- def self.each_state_era(param)
- return if param.nil?
- param.note.split(Era::RE::WinNL).each{ |line| eval_note_era(param, line)}
- end
- #----------------------------------------------------------------------------
- # * Only one method to evaluate notetags
- # assumes type of data can be inferred based on matching regex
- #----------------------------------------------------------------------------
- def self.eval_note_era(data, line)
- end
- end # DataManager
- #==============================================================================
- # ** Game_System
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- #==============================================================================
- class Game_System
- #--------------------------------------------------------------------------
- # * Alias, initialize
- #--------------------------------------------------------------------------
- alias initialize_cera initialize
- def initialize
- initialize_cera
- init_era(:force => true)
- end
- #--------------------------------------------------------------------------
- # * Init Core Era object
- #--------------------------------------------------------------------------
- def init_era(opts = {})
- options = {:force => false, :opts => {}}.merge(opts)
- opts2 = options[:opts]
- options[:force] ? @era_save = CEra.new(opts2): @era_save ||= CEra.new(opts2)
- end
- #--------------------------------------------------------------------------
- # * Get Core object
- #--------------------------------------------------------------------------
- def era_obj; @era_save; end
- end # Game_System
- #==============================================================================
- # ** CEra
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Allows easier and more organized inclusion in save data. Less namespace
- # pollution etc.
- #==============================================================================
- class CEra
- #--------------------------------------------------------------------------
- # * Init
- #--------------------------------------------------------------------------
- def initialize(opts = {})
- end
- end # CEra
- #==============================================================================
- # ** Game_Event
- # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- # Adds:
- # attr_readers for @event and @list
- #==============================================================================
- class Game_Event < Game_Character; attr_reader :event, :list; end # Game_Event
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement