List Sort by Rank

Normally the default listing of things like items and skills when presented in a window are in order of ID.

I was wondering if anyone would be willing to tackle a quick sorting mechanism so its easier to keep related members of a list together regardless of how far appeart their entries are in the database. This way if Strong Attack I is (ID:9) and Strong Attack II is (ID:33) they can both appear side by side in the list and not several button presses apart.

The simplest way I can think of, is to allow for a 'rank' to be assigned to any listable object.

Example:

<rank:#>This way all melee abilities can be rank 1XX, all white magic rank 2XX, etc...

In the above example, Strong Attack I could be rank:109 and Strong Attack II could be rank:108, thus when listed they would always appear side by side and (more > less) powerful.

Objects with the same rank would still be sorted by ID. Or a secondary rank can be assigned... If a secondary exists its always sorted in front of non-secondary ranked objects.

Example:

<rank:main,secondary>With a secondary rank included the above example could be rank:100,9 & rank:100,8 instead.

Hopefully with something like this, it won't be so damned painful to have such scattered database entries. 😀

Thanks for your time!
Would this just be for the skill window? 
Would this just be for the skill window? 
And Item Window. 😉

Thanks for the attention BTW!

edit:

Essentially any time the player needs to select an action (skill or item) it would trigger this sorting.

Also it might be better if the note tag was less easily used by other plugins... say something like:

Code:
<sort_rank:#,#>
Try this  😀

By the way, would you mind changing my regexp on reference event to the one similiar like this?

I notice a big mistake on my regex when checking this snippet, lol

Spoiler
Code:
//=============================================================================// SSG_ItemSort.js// Version 1.0.0//=============================================================================/*: * @plugindesc Item sort * @author Heartbreak61 *  * @param Default Sort Value 1 * @desc Default value for items, skills, and equipments * @default 100 * * @param Default Sort Value 2 * @desc Default value for items, skills, and equipments * @default 100 * * @param Sort Mode * @desc Ascending or descending for item that 'sort value'.  Sort by ID will still be ascending. * @default descending *  * @help * ============================================================================ * [Simple Stupid Gaming] Item Sort * <sort_value: Number, Number> */var Imported = Imported || {};Imported['SSG Item Sort'] = '1.0.0';(function() { // don't touch this!'use strict';var parameters = PluginManager.parameters('SSG_ItemSort');var sV = Number(parameters['Default Sort Value 1'] || 100);var sVV = Number(parameters['Default Sort Value 2'] || 100);var sM = String(parameters['Sort Mode'] || 'descending');var regexp = /(\d+)\s*[,;]?\s*(\d*)/;var _DataManager_onLoad = DataManager.onLoad;DataManager.onLoad = function(object) {	_DataManager_onLoad.call(this, object);	if ([$dataSkills, $dataItems, $dataWeapons, $dataArmors].contains(object)) {		for (var i = 0; i < object.length; i++) {			if (!object[i]) { continue; }			var str = object[i].meta.sort_value;			if (!str) {				object[i].sortValue = [sV, sVV];				continue;			}			var one = Number(str.match(regexp)[1]);			var two = Number(str.match(regexp)[2] || sVV);			object[i].sortValue = [one, two];		}	}};var _Window_SkillList_makeItemList = Window_SkillList.prototype.makeItemList;Window_SkillList.prototype.makeItemList = function() {	_Window_SkillList_makeItemList.call(this);	if (this._data.length > 0) {		this._data.sort(function(a,  {			var result;			if (sM.toLowerCase() === 'ascending') {				result = a.sortValue[0] - b.sortValue[0];				if (result === 0) {					result = a.sortValue[1] - b.sortValue[1];				}			} else {				result = b.sortValue[0] - a.sortValue[0];				if (result === 0) {					result = b.sortValue[1] - a.sortValue[1];				}			}			if (result === 0) {				result = a.id - b.id;			}			return result;		})	}};var _Window_ItemList_makeItemList = Window_ItemList.prototype.makeItemList;Window_ItemList.prototype.makeItemList = function() {	_Window_ItemList_makeItemList.call(this);	if (this._data.length > 0) {		var arr = this._data.slice(0);		if (arr.contains(null)) {			arr.pop();		}		arr.sort(function(a,  {			var result;			if (sM.toLowerCase() === 'ascending') {				result = a.sortValue[0] - b.sortValue[0];				if (result === 0) {					result = a.sortValue[1] - b.sortValue[1];					if (result === 0) {							result = a.id - b.id;					}				}			} else {				result = b.sortValue[0] - a.sortValue[0];				if (result === 0) {					result = b.sortValue[1] - a.sortValue[1];					if (result === 0) {							result = a.id - b.id;					}				}			}			console.log(result);			return result;		})		if (this._data.contains(null)) { arr.push(null); }		this._data = arr.slice(0);	}}})(); // Don't touch this!
That works exactly as I had hoped Heartbreak61!
Heartbreak61, I have been running into this error occasionally.

file:///X:/SkyDrive/_RMMV%20Projects/Projects/Prequel%20Project/js/plugins/SSG_ItemSort.js 47/X:/SkyDrive/_RMMV%20Projects/Projects/Prequel%20Project/js/plugins/SSG_ItemSort.js:47 Uncaught TypeError: Cannot read property 'sort_value' of undefinedIt only happens when I start the game. Before it runs. It happens once and then everything fine.

It seems intermittent.
Try changing 

var _DataManager_onLoad = DataManager.onLoad;DataManager.onLoad = function(object) {    _DataManager_onLoad.call(this, object);    if ([$dataSkills, $dataItems, $dataWeapons, $dataArmors].contains(object)) {        for (var i = 0; i < object.length; i++) {            if (!object) { continue; }            var str = object.meta.sort_value;            if (!str) {                object.sortValue = [sV, sVV];                continue;            }            var one = Number(str.match(regexp)[1]);            var two = Number(str.match(regexp)[2] || sVV);            object.sortValue = [one, two];        }    }};To this:

var _DataManager_onLoad = DataManager.onLoad;DataManager.onLoad = function(object) {    _DataManager_onLoad.call(this, object);    if ([$dataSkills, $dataItems, $dataWeapons, $dataArmors].contains(object)) {        for (var i = 1; i < object.length; i++) {            if (!object) { continue; }            var str = object.meta.sort_value;            if (!str) {                object.sortValue = [sV, sVV];                continue;            }            var one = Number(str.match(regexp)[1]);            var two = Number(str.match(regexp)[2] || sVV);            object.sortValue = [one, two];        }    }};It looks like he was checking if object in $dataSomething (Actors,items,etc) had the notetag starting with object 0, but since RMMV doesn't have an object 0 (its null/undefined, because for whatever reason they didn't keep to consistent 0 based indexing or not). I've changed it to start checking with IDs 1 or higher.
@roguedeus

maybe it's caused by empty actor on actor list database, for example you have actor 1-5 then you have "empty actor" on 6-7, and you have actor 8-10.

I could fix this but I can't promise it will be fast. My daytime job is kinda like hell these weeks lol.

Sorry for this bug.

@liquidize

it could be. member with id 0 from RMMV's $dataSomething is always null.

but i'm sure that i've checked if any object exist using if (!object){continue;}. then, it should skip that member 0 and any member that has falsy value (i.e. undefined, NaN, null, 0, "", false)
@roguedeus

maybe it's caused by empty actor on actor list database, for example you have actor 1-5 then you have "empty actor" on 6-7, and you have actor 8-10.

I could fix this but I can't promise it will be fast. My daytime job is kinda like hell these weeks lol.

Sorry for this bug.

@liquidize

it could be. member with id 0 from RMMV's $dataSomething is always null.

but i'm sure that i've checked if any object exist using if (!object){continue;}. then, it should skip that member 0 and any member that has falsy value (i.e. undefined, NaN, null, 0, "", false)
 

I have empty actors. But the issue doesn't always happen very time I start. It is really intermittent.

 

No rush!
I can verify now that its not caused by empty actors... I filled all my actor slots.

Trying this:

Code:
var _DataManager_onLoad = DataManager.onLoad;DataManager.onLoad = function(object) {    _DataManager_onLoad.call(this, object);    if ([$dataSkills, $dataItems, $dataWeapons, $dataArmors].contains(object)) {        for (var i = 1; i < object.length; i++) {            if (!object[i]) { continue; }            var str = object[i].meta.sort_value;            if (!str) {                object[i].sortValue = [sV, sVV];                continue;            }            var one = Number(str.match(regexp)[1]);            var two = Number(str.match(regexp)[2] || sVV);            object[i].sortValue = [one, two];        }    }};
This is pretty useful, good request.  Nice script also guys!
It just happened again... Even with the change to the code.

It doesn't seem to happen as often though.

Original thread: https://forums.rpgmakerweb.com/threads/list-sort-by-rank.50556/