Highly customizable sorting plugin

Discussion in 'JS Plugin Releases (RMMV)' started by BurningOrca, Apr 23, 2019.

  1. BurningOrca

    BurningOrca Veteran Veteran

    Likes Received:
    First Language:
    Primarily Uses:
    Searching the forum and also google for sorting plugins surely brings up a bunch of results and those I had a look at definitely fulfilled the needs of multiple users, just not mine.

    So what are my needs, and why have I written another sorting plugin?

    I haven't played many RPGs, but most of them I have played offered at least two different pre-defined sort orders for the items.

    So I had 2 different goals while developing this plugin:
    - Offer multiple sort options to the player
    - Offer customizability to the programmer(s) who will use this plugin
    They should be able to decide which sort options are available in there game.

    Credits and Use:
    It's completely open to non-commercial and commercial projects and does not require any credits.

    The plugin itself is very complex, because it has high customizability. So let's go over the plugin parameters:
    Plugin Parameters.PNG

    As you can see, it defines 5 structs for 5 different things that can be sorted by the plugin and a bunch of texts which are for a
    new option in the "Options" menu which I explain later.
    The plugin defines sorting options for Items, Weapons, Armor, Skills and Goods seperately.
    The Goods option let's you define sort orders for the shop buy window, in case you wonder.

    Now let's have a look at one of the structs:
    It has a bunch of sub structs for pre-defined sorting options, each of them consisting of a "Name" you can customize and
    a flag where you can set whether you want to use them in your game.
    Particular Sort Option.PNG
    Changes to the parameters which I have marked yellow won't affect your game once you have already started it with plugin installed before. Why this is the case I'll also explain later.

    Now let's have a look at the custom option:
    It is a list of sub structures, each consisting of the same two parameters 'Name' and 'Use' and a third one where you can define your custom javascript sort value calculation function:
    Custom Methods.PNG

    All these parameters will be converted into arrays by the plugin. The parameter 'Default Sort Method' is the index in this array.
    So for Items this particularly means:
    0: Unsorted (Database Order)
    1: Lexicographically
    2: By Price
    3: By amount in possession
    4: Custom option 1
    5: Custom option 2
    The option which is marked as 'Default' must always have the 'Use' flag set to 'true', otherwise the plugin will throw an error.

    The parameter 'Descending' should be self explanatory.

    The plugin parameters for the equipment have another sub option called parameters.
    Here you can define the stats for which sorting options should be defined.
    In the given example, they will be defined for:
    1 - MaxMP
    2 - Attack
    4 - Magic Attack
    6 - Agility and
    7 - Luck
    Please define only valid numbers here, the plugin doesn't handle invalid numbers not very well
    and please plan those beforehand. Adding or removing parameters after you have started you game once with the
    plugin installed might mess with already defined sorting orders saved with the game.

    What does this plugin lack:
    - Ability to let the player swap items in the sort order (something many RPGs actually offer).
    I found a plugin in the request section of this forum that actually implements such a functionality, but unfortunately
    it won't be compatible with my plugin unless the player always uses the default sorting order. My sorting options will
    definitely overwrite any sorting done by the player manually, so I won't implement such a feature into this plugin.

    How does the plugin affect the game:
    The first thing the plugin does is loading the values of the plugin parameters 'Default Sort Order' and 'Descending' of each individual struct into the ConfigManager, which means they will be saved globally with your game in the config.rpgsave file.
    Unless you delete that file, the defaults from the plugin parameters will be overwritten with the saved configuration the next
    time you start your game, thus any changes to those two plugin parameters won't have any effect.

    The plugin adds a new option 'Sorting Rules' to your games option menu.
    Game Options.PNG

    If you are using YEP_OptionsCore this option won't appear. You have to add it seperately to the plugin parameters of Yanfly's plugin. The important parameter values are as follows:

    Help Description:
    Change default sorting rules for items, weapons,
    armor, skills and shop goods.

    show = Imported.BO_SortingOptions;


    Draw Option Code:
    var rect = this.itemRectForText(index);
    var text = this.commandName(index);
    this.drawText(text, rect.x, rect.y, rect.width, 'left');

    Process OK Code:

    Set every parameter below the Process OK Code parameter to blank strings.
    You also have to install YEP_OptionsCore below my plugin to make it work.

    The new option will pop up a new scene, where you can change the sorting options and orders of the different types
    by pressing the left and right keys:
    Sorting Options Scene.PNG

    If the menu is opened from the title screen any changes will be saved into the Config Manager and will automatically
    taken over to the save files created by the 'New Game' option.

    If the menu is opened from within the game any changes will be saved into a new object which is saved with your save file.
    So there is a global option and individual options per save file.

    Let's sort Armor descending by 'Magic Attack':
    Sort Example.PNG
    You can see, that equipment is sorted differently depending on whether you are in the item scene or in the equip scene.
    In the item scene the equipment items are sorted by their raw stats (Power Ring offering 25, Ring 10 and Lost Ring only 5 Magic Attack)
    In the equip scene they are sorted by the actual effect on the actor (Lost Ring has set a 400% Magic Attack trait, so it comes first).

    Each time one of the windows that can be sorted with this plugin is opened it is sorted by the rules defined in the options,

    Sort Options Items.PNG

    my Item Window is always sorted ascending by name when it is opened.
    I can change the sort order by pression 'O' and the sort method by pressing 'S'.
    These changes are not saved, when the window is closed or switched to 'Weapon'/'Armor'/'Key Item' mode.
    The next time it is opened it is again sorted by the default sorting rule applied in the options.

    The little info window which displayes the keys used for sorting will only show up as long as it's parent window
    is active. Depending on the size of it's parent window it will either by vertical or horizontal:

    Sort Options Shop.PNG

    - Should be compatible with any plugin, that does not sorting on it's own.
    - Should be compatible with any plugin, that does not overwrite the function makeItemList of the following windows
    Window_ItemList, Window_SkillList, Window_ShopBuy without calling an alias.
    - Is in it's current development state at least compatible with the following Yanfly Plugins, as you might have already spotted
    in last screenshot:
    YEP_ItemCore: But won't use it with independend items, as sorting in general seems to mess up with this functionality.
    YEP_X_ItemCategories: Any weapon, armor added to a new category defined by this plugin, will be sorted by the rules
    for normal items.

    This plugin has to be placed under those plugins, but above YEP_OptionsCore to function properly.

    Is not compatible with key board customization or gamepads yet. I would really appreciate suggestions on how I can get compatible with those!!!

    Thanks go to Yanfly. I learned a lot from reading through the code of Yanflys plugins. Without these plugins it might have taken
    a lot longer to develop this plugin.

    The actual plugin:
    As I currently do not have any acount on a content sharing platform, I cannot provide a test project even I really want to.
    Therefore I will upload the plugin directly here. Please grab it if you are interested.
    Any feedback would be appreciated.

    Thanks you,

    Attached Files:

    Last edited: May 10, 2019
    zerobeat032, Lady, Roguedeus and 3 others like this.
  2. Kes

    Kes Global Moderators Global Mod

    Likes Received:
    First Language:
    Primarily Uses:

    Moving this to JS Plugin Releases (MV) now that it is complete.

  3. BurningOrca

    BurningOrca Veteran Veteran

    Likes Received:
    First Language:
    Primarily Uses:
    I found a bug while testing another plugin in the goods sorting options for custom sort.
    I replaced the plugin with version 1.1
    To the 6 people who've already downloaded it you might want to get the new version.
    I also added configuration of the keys for the 'Sort Order' and 'Sort Method' to the plugin parameters.
    Last edited: May 10, 2019
  4. Iqus

    Iqus inVictor Member

    Likes Received:
    First Language:
    Primarily Uses:
    Great plugin!

    It seems to me that it would be easier to access the sorting types from the Item menu instead of having to enter the options menu every time though. Just a thought!

    Great work!
  5. BurningOrca

    BurningOrca Veteran Veteran

    Likes Received:
    First Language:
    Primarily Uses:
    Thank you.

    As I developed the plugin it went through a lot of changes:
    First I added everything to the options menu.
    Then I added keyboard input keys for accessing the sorting options within the appropriate menus and they were saved back to the options.
    But then I thought the options do not make any sense if the sort order selected in the menu is permanently saved back to the options.
    So I made the options the default and the selected sort order in the menu only to be remembered as long as the window is open and in
    case of the item window, it's category is not changed.

    If it is better to keep the last selected sorting within the menu, I could remove the options menu and reintroduce the permasave within the
    item, skill and shop menus.

    Or did I misunderstand your suggestions?
  6. JamesRyan

    JamesRyan Game Designer Veteran

    Likes Received:
    First Language:
    Primarily Uses:
    I have some issues with the "Custom" parameter. I set its "Use" value to false, but it keeps appearing in-game.
  7. BurningOrca

    BurningOrca Veteran Veteran

    Likes Received:
    First Language:
    Primarily Uses:
    @JamesRyan Thank you for your bug report.
    I didn't realized that "Use" was still a string, when I checked it and if( String ) is always true.
    I now replaced it with a newer version, where it will work.
    JamesRyan likes this.
  8. JamesRyan

    JamesRyan Game Designer Veteran

    Likes Received:
    First Language:
    Primarily Uses:
    Thanks! It works like a charm now!

Share This Page