-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRP_ChangeBackColor.js
416 lines (383 loc) · 13.7 KB
/
NRP_ChangeBackColor.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
//=============================================================================
// NRP_ChangeBackColor.js
//=============================================================================
/*:
* @target MV MZ
* @plugindesc v1.00 Changes the color tone of the battle background.
* @author Takeshi Sunagawa (http://newrpg.seesaa.net/)
* @url https://newrpg.seesaa.net/article/498666610.html
*
* @help Changes the color tone of the battle background.
* Does not affect the battlers or animations, so it is
* This is useful for emphasizing the direction.
*
* Parallaxes created with NRP_ParallaxesPlus.js are also supported.
*
* -------------------------------------------------------------------
* [Usage]
* -------------------------------------------------------------------
* Run the plugin command.
* Both for MZ and MV are valid.
*
* -------------------------------------------------------------------
* [Plugin Command MZ]
* -------------------------------------------------------------------
* ◆ChangeColorBattle
* Changes the color tone of the battle background
* to the specified value.
* See the description in the plug-in commands for details.
*
* -------------------------------------------------------------------
* [Plugin Command MV]
* -------------------------------------------------------------------
* ◆NRP.ChangeBackColor 255 255 255 60
* Change the color tone to 255,255,255 (red, green, blue)
* over 60 frames (1/60 second).
* If time is omitted, the change is instantaneous.
*
* Enter each color in the range of 0~255.
* "0 0 0" makes it completely dark.
* With "255 255 255", it returns to the original state.
*
* -------------------------------------------------------------------
* [Sample for DynamicMotion]
* -------------------------------------------------------------------
* When calling from DynamicAnimation or DynamicMotion,
* the MV format is also convenient in MZ.
*
* -------------------------------------------------------------------
* // Darken it.
* <D-Motion>
* plugin = NRP.ChangeBackColor 128 128 128 15
* </D-Motion>
*
* <D-Animation/>
*
* // Return to original.
* <D-Motion>
* plugin = NRP.ChangeBackColor 255 255 255 15
* </D-Motion>
*
* -------------------------------------------------------------------
* [Terms]
* -------------------------------------------------------------------
* There are no restrictions.
* Modification, redistribution freedom, commercial availability,
* and rights indication are also optional.
* The author is not responsible,
* but will deal with defects to the extent possible.
*
* @-----------------------------------------------------
* @ [Plugin Commands]
* @-----------------------------------------------------
*
* @command ChangeColorBattle
* @desc Changes the color tone of the battle background.
*
* @arg Color
* @type string
* @default 255,255,255
* @desc Input the background color tone in RGB format.
* 255 is the maximum value for each.
*
* @arg Duration
* @type number
* @desc The execution time (1/60 sec.) to change the color tone.
*
* @-----------------------------------------------------
* @ [Plugin Parameters]
* @-----------------------------------------------------
*
*/
/*:ja
* @target MV MZ
* @plugindesc v1.00 戦闘背景の色調を変更する。
* @author 砂川赳(http://newrpg.seesaa.net/)
* @url https://newrpg.seesaa.net/article/498666610.html
*
* @help 戦闘背景の色調を変更します。
* バトラーやアニメーションには影響を与えないため、
* 演出の強調に便利です。
*
* NRP_ParallaxesPlus.jsで作成した遠景にも対応しています。
*
* -------------------------------------------------------------------
* ■使用方法
* -------------------------------------------------------------------
* プラグインコマンドを実行してください。
* MZ用、MV用の双方が有効です。
*
* -------------------------------------------------------------------
* ■プラグインコマンド(MZ)
* -------------------------------------------------------------------
* ◆色調を変更
* 戦闘背景の色調を指定した値へと変更します。
* 詳細はプラグインコマンド内の説明をご覧ください。
*
* -------------------------------------------------------------------
* ■プラグインコマンド(MV)
* -------------------------------------------------------------------
* ◆NRP.ChangeBackColor 255 255 255 60
* 色調を255,255,255(赤、緑、青)に60フレーム(1/60秒)かけて変更します。
* 時間を省略すると瞬時に変更します。
*
* 各色は0~255の範囲で入力してください。
* 「0 0 0」で真っ暗に。「255 255 255」で元に戻ります。
*
* -------------------------------------------------------------------
* ■DynamicMotion用のサンプル
* -------------------------------------------------------------------
* DynamicAnimationおよびDynamicMotionから呼び出す場合は、
* MZにおいてもMV形式を使う方法が便利です。
*
* -------------------------------------------------------------------
* // 暗くする。
* <D-Motion>
* plugin = NRP.ChangeBackColor 128 128 128 15
* </D-Motion>
*
* <D-Animation/>
*
* // 元に戻す。
* <D-Motion>
* plugin = NRP.ChangeBackColor 255 255 255 15
* </D-Motion>
*
* -------------------------------------------------------------------
* ■利用規約
* -------------------------------------------------------------------
* 特に制約はありません。
* 改変、再配布自由、商用可、権利表示も任意です。
* 作者は責任を負いませんが、不具合については可能な範囲で対応します。
*
* @-----------------------------------------------------
* @ プラグインコマンド
* @-----------------------------------------------------
*
* @command ChangeColorBattle
* @text 色調を変更
* @desc 戦闘背景の色調を変更します。
*
* @arg Color
* @text 色調
* @type string
* @default 255,255,255
* @desc 背景の色調をRGB(赤緑青)の順番で入力。
* 255が各最大値となります。
*
* @arg Duration
* @text 時間(1/60秒)
* @type number
* @desc 色調変更にかける実行時間です。
*
* @-----------------------------------------------------
* @ プラグインパラメータ
* @-----------------------------------------------------
*
*/
(function() {
"use strict";
function toNumber(str, def) {
if (str == undefined || str == "") {
return def;
}
return isNaN(str) ? def : +(str || def);
}
function toBoolean(str, def) {
if (str === true || str === "true") {
return true;
} else if (str === false || str === "false") {
return false;
}
return def;
}
const PLUGIN_NAME = "NRP_ChangeBackColor";
const parameters = PluginManager.parameters(PLUGIN_NAME);
//-----------------------------------------------------------------------------
// MZ用プラグインコマンド
//-----------------------------------------------------------------------------
// MVには存在しないため、空で定義しておかないとエラーになる。
if (!PluginManager.registerCommand) {
PluginManager.registerCommand = function() {}
}
/**
* ●色調の変更(戦闘)
*/
PluginManager.registerCommand(PLUGIN_NAME, "ChangeColorBattle", function(args) {
const colorArray = textToArray(args.Color);
const duration = textToArray(args.Duration);
changeColorBattle(colorArray, duration);
});
/**
* ●戦闘時の色調変更
*/
function changeColorBattle(colorArray, duration) {
const spriteset = getSpriteset();
// 背景の色調変更
spriteset._back1Sprite.startTint(colorArray, duration);
spriteset._back2Sprite.startTint(colorArray, duration);
// NRP_ParallaxesPlus.jsが存在すれば対応
if (spriteset._parallaxPlus) {
for (const parallaxPlus of spriteset._parallaxPlus) {
parallaxPlus.startTint(colorArray, duration);
}
}
}
//-----------------------------------------------------------------------------
// MV用プラグインコマンド
//-----------------------------------------------------------------------------
/**
* ●MV用のプラグインコマンド
*/
const _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
// 小文字化してから判定
const lowerCommand = command.toLowerCase();
// 色調を変更
if (lowerCommand === "nrp.changebackcolor") {
const colorArray = [args[0], args[1], args[2]];
const duration = args[3];
changeColorBattle(colorArray, duration);
}
};
// ----------------------------------------------------------------------------
// TilingSprite
// ----------------------------------------------------------------------------
/**
* 【独自】色調の変更開始
*/
TilingSprite.prototype.startTint = function(tintArray, duration) {
// 時間指定がない場合は即時反映
if (!duration) {
// 配列を数値に変換してから反映
this.tint = arrayToTint(tintArray);
// 値を初期化
this._tintDuration = null;
this._tintCount = null;
this._tintTarget = null;
this._tintTargetOriginal = null;
return;
}
// 最終的な色調(配列)
this._tintTarget = tintArray;
// 当初の色調(配列)
this._tintTargetOriginal = tintToArray(this.tint);
this._tintDuration = duration;
this._tintCount = 0;
};
/**
* ●更新
*/
const _TilingSprite_update = TilingSprite.prototype.update;
TilingSprite.prototype.update = function() {
_TilingSprite_update.apply(this, arguments);
// 色調を更新
this.updateChangeBackColor();
};
/**
* 【独自】色調を更新
*/
TilingSprite.prototype.updateChangeBackColor = function() {
_TilingSprite_update.apply(this, arguments);
// 実行時間が存在する場合、色調変更
if (this._tintDuration > 0) {
let colorArray = [];
// RGBを一つずつ抜き出して処理
for (let i = 0; i < 3; i++) {
// 現在の値
const oldColor = this._tintTargetOriginal[i];
// 現在の値と最終値との差分を計算し、現在時間での値を求める。
let newColor = oldColor + (this._tintTarget[i] - oldColor) * this._tintCount / this._tintDuration;
// 0~255に制限
newColor = newColor.clamp(0, 255);
colorArray.push(newColor);
}
// 配列を数値に変換してから反映
this.tint = arrayToTint(colorArray);
// 時間経過
this._tintCount++;
// 終了処理
if (this._tintCount > this._tintDuration) {
this._tintDuration = null;
this._tintCount = null;
this._tintTarget = null;
this._tintTargetOriginal = null;
}
}
};
// ----------------------------------------------------------------------------
// 共通関数
// ----------------------------------------------------------------------------
/**
* ●色調を配列に変換します。
* ※色調は数値でビット管理されているため、
* そのままでは操作が難しいため配列に変換する。
*/
function tintToArray(tint) {
// 数値を配列に分解
const r = (tint >> 16) & 255;
const g = (tint >> 8) & 255;
const b = tint & 255;
return [r, g, b];
}
/**
* ●配列を色調に変換します。
*/
function arrayToTint(array) {
const r = array[0];
const g = array[1];
const b = array[2];
return (r << 16) | (g << 8) | b;
}
/**
* ●文字列を分解して配列に変換する。
* ※例1:"1,2,3" -> [1,2,3]
* ※例2:"1~3" -> [1,2,3]
*/
function textToArray(textArr) {
const array = [];
// 無効なら処理しない。
if (textArr === undefined || textArr === null || textArr === "") {
return array;
}
// カンマ区切りでループ
for (let text of textArr.split(",")) {
// 空白除去
text = text.trim();
// 1~5というように範囲指定の場合
// ※~が存在する。
if (text.indexOf("~") >= 0) {
const rangeVal = text.split("~");
const rangeStart = eval(rangeVal[0]);
const rangeEnd = eval(rangeVal[1]);
// IDの指定範囲で実行
// 開始のほうが終了より大きい場合は反対に実行
if (rangeEnd < rangeStart) {
for (let i = rangeStart; i >= rangeEnd; i--) {
array.push(eval(i));
}
} else {
for (let i = rangeStart; i <= rangeEnd; i++) {
array.push(eval(i));
}
}
// 通常時
} else {
try {
array.push(eval(text));
// 数式評価できない場合はそのままpush
} catch (e) {
array.push(text);
}
}
}
return array;
}
/**
* ●現在の画面のSpritesetを取得する。
*/
function getSpriteset() {
return SceneManager._scene._spriteset;
}
})();