-
Notifications
You must be signed in to change notification settings - Fork 12
/
ALOE_ItemSkillSortPriority.js
147 lines (134 loc) · 5.44 KB
/
ALOE_ItemSkillSortPriority.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"use strict";
//=============================================================================
// Aloe Guvner - Item & Skill Sort Priority
// ALOE_ItemSkillsortPriority.js
//=============================================================================
var Imported = Imported || {};
Imported.ALOE_ItemSkillSortPriority = true;
var ALOE = ALOE || {};
ALOE.Alias = ALOE.Alias || {};
//=============================================================================
/*:
* @plugindesc Allows items, weapons, armors, and skills to appear in an
* order defined by the developer through notetags.
* @author Aloe Guvner
*
*
* @help
* ============================================================================
* Introduction
* ============================================================================
*
* By default, the items/weapons/armors/skills are sorted by database ID number
* in menu windows, and there is no way to change this order from the editor.
*
* This simple plugin allows the developer to use a notetag in the database
* in order to define a custom order for the items/weapons/armors/skills to
* appear.
*
* ============================================================================
* Instructions
* ============================================================================
*
* The following notetag may be added to the notes on a database entry for
* items/weapons/armors/skills.
*
* <Sort Priority: X>
*
* X --> The sort priority for the item/weapon/armor/skill.
*
* Example:
* <Sort Priority: 2>
*
* If a database entry does not contain this notetag, its sort priority
* is set to the ID# of the entry.
* If a database entry has a defined sort priority that is the same as the
* ID# of an entry without a notetag, the entry with the notetag is
* prioritized.
*
* ============================================================================
* Terms of Use
* ============================================================================
*
* - Free for use in both non-commercial and commercial projects.
* - You are free to edit this plugin as you see fit.
* - Credits are required to: Aloe Guvner
*
*
* ============================================================================
* Changelog
* ============================================================================
*
* Version 1.00:
* - Initial release with support for items, weapons, armors, and skills
*/
//=============================================================================
//=============================================================================
// Notetag Processing
//=============================================================================
// Read the database objects for the <Sort Priority: X> notetag and set a
// sortPriority property.
//=============================================================================
ALOE.notetagsLoaded = false;
ALOE.Alias.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
DataManager.isDatabaseLoaded = function () {
if (!ALOE.Alias.DataManager_isDatabaseLoaded.call(this)) return false;
if (!ALOE.notetagsLoaded) {
this.sortPriorityNotetag($dataSkills);
this.sortPriorityNotetag($dataItems);
this.sortPriorityNotetag($dataWeapons);
this.sortPriorityNotetag($dataArmors);
ALOE.notetagsLoaded = true;
}
return true;
};
DataManager.sortPriorityNotetag = function (data) {
var regExp = /<Sort\s*Priority\s*:\s*(\d+)\s*>/i;
for (var i = 0; i < data.length; i++) {
if (data[i]) {
var match = data[i].note.match(regExp);
data[i].sortPriority = match ? Number(match[1]) : data[i].id + 0.1;
}
}
};
//=============================================================================
// Window_SkillList & Window_ItemList
//=============================================================================
// Alias the makeItemList methods to sort the data it is mined and filtered.
//=============================================================================
ALOE.Alias.Window_SkillList_makeItemList = Window_SkillList.prototype.makeItemList;
Window_SkillList.prototype.makeItemList = function () {
ALOE.Alias.Window_SkillList_makeItemList.call(this);
this.sortPriorityList();
};
ALOE.Alias.Window_ItemList_makeItemList = Window_ItemList.prototype.makeItemList;
Window_ItemList.prototype.makeItemList = function () {
ALOE.Alias.Window_ItemList_makeItemList.call(this);
this.sortPriorityList();
};
//=============================================================================
// Window_Selectable
//=============================================================================
// Method to sort the data objects based on the sortPriority property.
// For an unknown reason, the data used in the equip scene contains a null
// entry at the end of the array, which must be handled separately.
//=============================================================================
Window_Selectable.prototype.sortPriorityList = function () {
if (this._data) {
if (this._data[this._data.length - 1] === null) {
//equip item list
this._data = this._data.filter(function (a) {
return a;
});
this._data.sort(function (a, b) {
return a.sortPriority - b.sortPriority;
});
this._data.push(null);
} else {
//all other item lists
this._data.sort(function (a, b) {
return a.sortPriority - b.sortPriority;
});
}
}
};