-
Notifications
You must be signed in to change notification settings - Fork 41
/
OrangeNoteTagToVariable.js
141 lines (124 loc) · 4.72 KB
/
OrangeNoteTagToVariable.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
/*=============================================================================
* Orange - Notetag to Variable
* By Hudell - www.hudell.com
* OrangeNoteTagToVariable.js
* Version: 1.2
* Free for commercial and non commercial use.
*=============================================================================*/
/*:
* @plugindesc Allow you to automatically change a Variable value everytime a notetag is found on a map or event - <OrangeNoteTagToVariable>
* @author Hudell
*
* @param VariableId
* @desc The number of the Variable to store the value of the notetag
* @default 0
*
* @param notetag
* @desc The name of the notetag to look for on the maps and event notes
* @default 0
*
* @param noteList
* @desc Configure several notes with a single plugin using this param
* @default
*
* @help
* Add the <notetag:value> on the notes of the maps and events that you want to tag.
*
* This plugin can be added multiple times to the same project
* (just make a copy of the file and add it)
*
* ============================================================================
* Latest Version
* ============================================================================
*
* Get the latest version of this script on
* http://hudell.com
*
*=============================================================================*/
var Imported = Imported || {};
if (Imported["OrangeNoteTagToVariable"] === undefined) {
(function() {
"use strict";
var getProp = undefined;
if (Imported["MVCommons"] !== undefined) {
getProp = MVC.getProp;
} else {
getProp = function (meta, propName){ if (meta === undefined) return undefined; if (meta[propName] !== undefined) return meta[propName]; for (var key in meta) { if (key.toLowerCase() == propName.toLowerCase()) { return meta[key]; } } return undefined; };
}
var paramList = [];
function updateParamList(){
for (var i = 0; i < $plugins.length; i++) {
if ($plugins[i].description.indexOf('<OrangeNoteTagToVariable>') >= 0) {
var variableId = Number($plugins[i].parameters['VariableId'] || 0);
var notetagName = $plugins[i].parameters['notetag'] || '';
if (variableId > 0 && notetagName.trim().length > 0) {
paramList.push({
variableId : variableId,
notetagName : notetagName
});
}
var list = $plugins[i].parameters['noteList'];
if (list !== undefined) {
var re = /<([^<>:]+):([^>]*)>/g;
while(true) {
var match = re.exec(list);
if (match) {
notetagName = match[1];
variableId = Number(match[2] || 0);
if (variableId > 0 && notetagName.trim().length > 0) {
paramList.push({
variableId : variableId,
notetagName : notetagName
});
}
} else {
break;
}
}
}
}
}
}
updateParamList();
if (paramList.length > 0) {
var updateVariableList = function() {
if (SceneManager._scene instanceof Scene_Map) {
for (var i = 0; i < paramList.length; i++) {
var value = undefined;
if ($gameMap._interpreter.isRunning() && $gameMap._interpreter._eventId > 0) {
var eventData = $dataMap.events[$gameMap._interpreter._eventId];
if (eventData) {
value = getProp(eventData.meta, paramList[i].notetagName);
}
}
if (value === undefined) {
value = $gameMap.getNoteTagValue(paramList[i].notetagName);
}
if (value !== undefined) {
$gameVariables.setValue(paramList[i].variableId, value);
}
}
}
};
var oldGameInterpreter_setup = Game_Interpreter.prototype.setup;
Game_Interpreter.prototype.setup = function(list, eventId) {
oldGameInterpreter_setup.call(this, list, eventId);
updateVariableList();
};
var oldGameInterpreter_terminate = Game_Interpreter.prototype.terminate;
Game_Interpreter.prototype.terminate = function(list, eventId) {
oldGameInterpreter_terminate.call(this, list, eventId);
updateVariableList();
};
Game_Map.prototype.getNoteTagValue = function(notetagName) {
return getProp($dataMap.meta, notetagName);
};
var oldGamePlayer_performTransfer = Game_Player.prototype.performTransfer;
Game_Player.prototype.performTransfer = function() {
oldGamePlayer_performTransfer.call(this);
updateVariableList();
};
}
})();
Imported["OrangeNoteTagToVariable"] = 1.2;
}