Notetag autoloader

https://github.com/Garryl/RGSS3-Scripts/tree/master/RGSS3-Scripts/Loader

This is a script I've been working on to make it easier to set up note tags to be loaded. The goal is that instead of having to alias the data manager load_database in all of my scripts, plus a whole lot of very similar setup to apply regexes to the note tags of all the objects, I can just pop this script in and describe the loading process in a couple of lines. It would look something like...

module Garryl  module Loader    register(LoadFeature.new(RegexConfig.new(/<feature element rate:\s*([1-9][0-9]*)[,]?\s*([\+]?[0-9]+(\.[0-9]+)?)\s*>/i, RegexConfig::CAPTURE_INT, RegexConfig::CAPTURE_FLOAT), Game_BattlerBase::FEATURE_ELEMENT_RATE))  endend... instead of...
Spoiler
Code:
module DataManager  # *************************************************************************  # * Aliases                                                               *  # *************************************************************************  class << self    alias garryl_example_alias_datamanager_load_database    load_database  end    # *************************************************************************  # * Aliased Functions                                                     *  # *************************************************************************  #--------------------------------------------------------------------------  # * Load Database  #--------------------------------------------------------------------------  def self.load_database    garryl_example_alias_datamanager_load_database        groups = [$data_actors, $data_classes, $data_weapons, $data_armors, $data_enemies, $data_states]    for group in groups      for obj in group        next if obj.nil?        next if obj.note.empty?        obj.note.scan(/<feature element rate:\s*([1-9][0-9]*)[,]?\s*([\+]?[0-9]+(\.[0-9]+)?)\s*>/i) {|id, value|          obj.features.push(RPG::BaseItem::Feature.new(Game_BattlerBase::FEATURE_ELEMENT_RATE, id.to_i, value.to_f))        }      end    end  endend
... and suddenly any feature-bearing object will add element rate features defined in their notes. (Obviously element rate is just an example, not something I'd actually need to do with standard scripts since the editor lets you just assign features directly in the features table, but it's a good illustration of how it works.)

It's partially tested (an earlier version was working, but I've changed it since then). It's designed primarily for loading new features (for actors, equipment, states, etc.) and effects (for skills and items), but it also includes (untested) support for something else entirely using a method call to a method in the object whose note tag is being loaded.

This should be compatible with everything, since it only deals with two methods, DataManager.LoadDatabase and Game_Map.setup, and it just aliases them.

Edit: Changed to load the note tags of maps when they're loaded, which is different from when normal database elements are loaded.

Edit: Did some actual testing and bug fixing and getting it to actually run right in the basic cases.

Edit: Also, optionally, a script to have it load, from note tags, all of the standard features and effects that you can assign through the GUI.

Edit: Now on GitHub instead of pasted here. First completed version, yay!
Looks really interesting, Garryl! Though I find myself wondering if remembering the correct syntax for a call to register will be worth the time you save by just having a template with the database alias and regex setup already done for you. I don't know if I'd use it myself, but if it helps you to make better scripts, I'm all for it! 🙂 Well done.
One of the other benefits is that it becomes a lot easier to change what things get loaded for. When I put my Passive Skill and Items script in (once I change things to use the Autoloader), I can have all my other scripts that define and create new features apply them to skills and items as well with only a couple of lines of code instead of having to manually change each and every one.

Garryl::Loader::LoadGroup::LOAD_FEATURES.push(Garryl::Loader::LoadGroup::SKILLS)Garryl::Loader::LoadGroup::LOAD_FEATURES.push(Garryl::Loader::LoadGroup::ITEMS)Much better than having to change the loading method in every script to account for whether or not the passive skills script is present. And to do even more of that if I were to do something else like that, such as, say, a map field effect script (grant features to all battlers based on the map or the region or the tile that the player is standing on). I have about a half-dozen scripts already that create new features or effects, so this should be a lot more convenient.Edit: Editing my post to avoid double posting. That's the preferred course of action around here, right?

I've done some testing and a) made it work for features and effects, and 😎 created a script to load the huge list of default features and effects from note tags instead of through the GUI. Now I just need to test custom method loading and map note tag loading.

Edit: Tested custom method loading, works like a charm. Ditto map note loading. I've got the custom method form set up so that it'll call the specified method of the object whose note tags are being loaded once for each set of captures (line-by-line via String.scan), passing an array containing all capture blocks of that capture set. Alternatively, you can set it to not try to regex (by passing nil in the constructor instead of a NoteRegexConfig object), in which case it'll just call the method once per object, passing the entire note as the parameter (not an array) and letting you work with it to extract whatever is relevant from there in that method.

Original thread: https://forums.rpgmakerweb.com/threads/notetag-autoloader.40464/