-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPP_MessageSE.js
367 lines (334 loc) · 10.1 KB
/
MPP_MessageSE.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
//=============================================================================
// MPP_MessageSE.js
//=============================================================================
// Copyright (c) 2021 Mokusei Penguin
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================
/*:
* @target MV MZ
* @plugindesc Add the function to sound SE to [Display text].
* @author Mokusei Penguin
* @url
*
* @help [version 1.1.1]
* This plugin is for RPG Maker MV and MZ.
*
* [Display text] control characters:
* \SE[n] # Change letter SE to n / 0 with no SE
*
* ▼ Plugin command details
* - In MV, the variable N is referred to by writing v [N] in the item for
* inputting a numerical value.
* - In MZ, in the item to enter a numerical value, select the text and
* write v [N] to refer to the variable N.
*
* 〇 MV / MZ
*
* 〇 SetMesCharSe index
* index : Letter SE number
* - Change the letter SE to n.
* - The default value is 1.
* - The control character \SE is temporary, but in the case of a
* plug-in command, it is applied to all text display after execution.
*
* ================================
* Mail : wood_penguin@yahoo.co.jp (@ is half-width)
* Blog : http://woodpenguin.blog.fc2.com/
* License : MIT license
*
* @command messageSe
* @desc
*
* @arg index
* @desc 0: No SE
* @type number
* @min 0
* @default 1
*
*
* @param Character Ses
* @desc
* @type struct<SE>[]
* @default []
*
* @param Se Interval
* @desc
* @type number
* @min 1
* @default 4
*
* @param Stop Se When Skip
* @desc
* @type boolean
* @default false
*
*/
/*~struct~SE:
* @param name
* @desc
* @default
* @require 1
* @dir audio/se
* @type file
*
* @param volume
* @desc
* @type number
* @max 100
* @default 90
*
* @param pitch
* @desc
* @type number
* @min 50
* @max 150
* @default 100
*
* @param pan
* @desc
* @type number
* @min -100
* @max 100
* @default 0
*
*/
/*:ja
* @target MV MZ
* @plugindesc 文章の表示にSEを鳴らす機能を追加します。
* @author 木星ペンギン
* @url
*
* @help [version 1.1.1]
* このプラグインはRPGツクールMVおよびMZ用です。
*
* [文章の表示]の制御文字:
* \SE[n] # 文字SEをn番に変更 / 0でSEなし
*
* ▼ プラグインコマンド詳細
* - MVでは数値を入力する項目で v[N] と記述することで変数N番を参照します。
* - MZでは数値を入力する項目で、テキストを選択して v[N] と記述することで
* 変数N番を参照します。
*
* 〇 MV / MZ
*
* 〇 SetMesCharSe index / メッセージSE変更
* index : 文字SEの番号
* - 文字SEをn番に変更します。
* - デフォルト値は1です。
* - 制御文字\SEは一時的なものですが、プラグインコマンドの場合は実行後全ての
* 文章表示に適用されます。
*
* ================================
* Mail : wood_penguin@yahoo.co.jp (@は半角)
* Blog : http://woodpenguin.blog.fc2.com/
* License : MIT license
*
* @command messageSe
* @text メッセージSE変更
* @desc
*
* @arg index
* @text インデックス
* @desc 0:SEなし
* @type number
* @min 0
* @default 1
*
*
* @param Character Ses
* @text SEの配列
* @desc
* @type struct<SE>[]
* @default []
*
* @param Se Interval
* @text SEの間隔
* @desc
* @type number
* @min 1
* @default 4
*
* @param Stop Se When Skip
* @text スキップでSEを停止
* @desc
* @type boolean
* @default false
*
*/
/*~struct~SE:ja
* @param name
* @text ファイル名
* @desc
* @default
* @require 1
* @dir audio/se
* @type file
*
* @param volume
* @text 音量
* @desc
* @type number
* @max 100
* @default 90
*
* @param pitch
* @text ピッチ
* @desc
* @type number
* @min 50
* @max 150
* @default 100
*
* @param pan
* @text 位相
* @desc
* @type number
* @min -100
* @max 100
* @default 0
*
*/
(() => {
'use strict';
const pluginName = 'MPP_MessageSE';
// Plugin Parameters
const parameters = PluginManager.parameters(pluginName);
const paramReplace = (key, value) => {
try {
return JSON.parse(value);
} catch (e) {
return value;
}
};
const param_CharacterSes = JSON.parse(parameters['Character Ses'] || "[]", paramReplace);
const param_SeInterval = Number(parameters['Se Interval'] || 4);
const param_StopSeWhenSkip = Number(parameters['Stop Se When Skip'] || 4);
// Dealing with other plugins
const __base = (obj, prop) => {
if (obj.hasOwnProperty(prop)) {
return obj[prop];
} else {
const proto = Object.getPrototypeOf(obj);
return function () { return proto[prop].apply(this, arguments); };
}
};
//-------------------------------------------------------------------------
// PluginManager
PluginManager._commands = PluginManager._commands || {};
if (!PluginManager.registerCommand) {
PluginManager.registerCommand = function(pluginName, commandName, func) {
const key = pluginName + ":" + commandName;
this._commands[key] = func;
};
}
if (!PluginManager.callCommand) {
PluginManager.callCommand = function(self, pluginName, commandName, args) {
const key = pluginName + ":" + commandName;
const func = this._commands[key];
if (typeof func === "function") {
func.bind(self)(args);
}
};
}
PluginManager.registerCommand(pluginName, 'messageSe', args => {
$gameMessage.setCharSeIndex(PluginManager.mppValue(args.index));
});
PluginManager.mppValue = function(value) {
const match = /^V\[(\d+)\]$/i.exec(value);
return match ? $gameVariables.value(+match[1]) : +value;
};
//-------------------------------------------------------------------------
// Game_Message
const _Game_Message_initialize = Game_Message.prototype.initialize;
Game_Message.prototype.initialize = function() {
_Game_Message_initialize.apply(this, arguments);
this._charSeIndex = 1;
};
Game_Message.prototype.setCharSeIndex = function(index) {
this._charSeIndex = index;
};
Game_Message.prototype.charSeIndex = function() {
return this._charSeIndex;
};
//-------------------------------------------------------------------------
// Game_Interpreter
const _mzCommands = {
SetMesCharSe: { name:'messageSe', keys:['index'] }
};
Object.assign(_mzCommands, {
'メッセージSE変更': _mzCommands.SetMesCharSe
});
const _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.apply(this, arguments);
const params = _mzCommands[command];
if (params) {
const args2 = Object.assign(...params.keys.map((k,i) => ({[k]:args[i]})));
PluginManager.callCommand(this, pluginName, params.name, args2);
}
};
//-------------------------------------------------------------------------
// Window_Message
const _Window_Message_clearFlags = Window_Message.prototype.clearFlags;
Window_Message.prototype.clearFlags = function() {
_Window_Message_clearFlags.apply(this, arguments);
this._charSeIndex = $gameMessage.charSeIndex();
this._charSeCount = 0;
};
const _Window_Message_processCharacter = Window_Message.prototype.processCharacter;
Window_Message.prototype.processCharacter = function(textState) {
if (Utils.RPGMAKER_NAME = 'MV') {
_Window_Message_processCharacter.apply(this, arguments);
} else {
const length = textState.buffer.length;
_Window_Message_processCharacter.apply(this, arguments);
if (length !== textState.buffer.length) {
this._charSeCount--;
}
}
};
const _Window_Message_updateMessage = Window_Message.prototype.updateMessage;
Window_Message.prototype.updateMessage = function() {
if (_Window_Message_updateMessage.apply(this, arguments)) {
this.updateMessageSe();
return true;
}
return false;
};
Window_Message.prototype.updateMessageSe = function() {
if (this._charSeIndex > 0) {
const se = param_CharacterSes[this._charSeIndex - 1];
if (se && this._charSeCount <= 0) {
AudioManager.playSe(se);
this._charSeCount = param_SeInterval;
}
}
};
const _Window_Message_updateShowFast = Window_Message.prototype.updateShowFast;
Window_Message.prototype.updateShowFast = function() {
const lastShowFast = this._showFast;
_Window_Message_updateShowFast.apply(this, arguments);
if (param_StopSeWhenSkip && !lastShowFast && this._showFast) {
AudioManager.stopSe();
}
};
const _Window_Message_processEscapeCharacter = Window_Message.prototype.processEscapeCharacter;
Window_Message.prototype.processEscapeCharacter = function(code, textState) {
if (code === 'SE') {
this._charSeIndex = this.obtainEscapeParam(textState);
} else {
_Window_Message_processEscapeCharacter.apply(this, arguments);
}
};
const _Window_Message_processNormalCharacter = __base(Window_Message.prototype, 'processNormalCharacter');
Window_Message.prototype.processNormalCharacter = function(textState) {
_Window_Message_processNormalCharacter.apply(this, arguments);
this._charSeCount--;
};
const _Window_Message_startPause = Window_Message.prototype.startPause;
Window_Message.prototype.startPause = function() {
_Window_Message_startPause.apply(this, arguments);
if (param_StopSeWhenSkip) AudioManager.stopSe();
};
})();