-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRP_AutoTileAnimationConfigMZ.js
303 lines (271 loc) · 10.1 KB
/
NRP_AutoTileAnimationConfigMZ.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
//=============================================================================
// NRP_AutoTileAnimationConfigMZ.js
//=============================================================================
/*:
* @target MZ
* @plugindesc v1.02 Changes the animation speed of auto tiles (water, falls, etc.).
* @author Takeshi Sunagawa (http://newrpg.seesaa.net/)
* @url http://newrpg.seesaa.net/article/480713311.html
*
* @help Changes the animation speed of auto tiles (water, falls, etc.).
* This plugin is for MZ only.
*
* [Usage]
* First, please change the BaseWait of the animation.
* This is the display time for one pattern of auto tiles (A1).
* The default value of 30 corresponds to 0.5 seconds.
* The smaller the value, the faster the animation will be.
*
* However, this value affects all auto tile animations,
* including water/falls.
*
* For example, if you want only the water to maintain its original speed,
* adjust the individual magnification settings by increasing them.
*
* [Note on Tilesets]
* It is possible to change the magnification
* for each tileset by writing the following.
*
* <WaterMagnification:X>: Change the magnification of the water animation to X.
* <FallsMagnification:X> : Change the magnification of the falls animation to X.
*
* [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.
*
* @param BaseWait
* @type number
* @default 30
* @desc This is the basic time to display one pattern of animation. The default is 30 (0.5 seconds).
*
* @param WaterMagnification
* @type number
* @default 1
* @desc The magnification of the water animation display time.
* The base wait time multiplied by this value will be used.
*
* @param FallsMagnification
* @type number
* @default 1
* @desc The magnification of the falls animation display time.
* The base wait time multiplied by this value will be used.
*/
/*:ja
* @target MZ
* @plugindesc v1.02 オートタイル(水、滝など)のアニメーション速度を変更します。
* @author 砂川赳(http://newrpg.seesaa.net/)
* @url http://newrpg.seesaa.net/article/480713311.html
*
* @help 水、滝などオートタイル(A1)のアニメーション速度を変更します。
* このプラグインはMZ専用です。
*
* ■使い方
* まずはアニメーションの基本ウェイト時間を変更してください。
* これがオートタイル(A1)の1パターンの表示時間です。
* 標準の30は0.5秒に相当します。
* 値を小さくするほどアニメーションが高速化します。
*
* ただし、この値は水/滝など、
* オートタイルのアニメーション全てに影響します。
*
* 例えば、水だけは元の速さを維持したいという場合は、
* 個別の倍率設定を大きくして調整してください。
*
* ■タイルセットのメモ欄
* 以下を記述すれば、タイルセット毎に倍率の変更が可能です。
*
* <WaterMagnification:X> : 水アニメーションの倍率をXに変更
* <FallsMagnification:X> : 滝アニメーションの倍率をXに変更
*
* ■利用規約
* 特に制約はありません。
* 改変、再配布自由、商用可、権利表示も任意です。
* 作者は責任を負いませんが、不具合については可能な範囲で対応します。
*
* @param BaseWait
* @text 基本ウェイト時間
* @type number
* @default 30
* @desc アニメーションの1パターンを表示する基本時間です。
* 標準は30(0.5秒)です。
*
* @param WaterMagnification
* @text 水の倍率
* @type number
* @default 1
* @desc 水アニメーションの表示時間に対する倍率です。
* 基本ウェイト時間にこれをかけた値が使用されます。
*
* @param FallsMagnification
* @text 滝の倍率
* @type number
* @default 1
* @desc 滝アニメーションの表示時間に対する倍率です。
* 基本ウェイト時間にこれをかけた値が使用されます。
*/
(function() {
"use strict";
function toNumber(str, def) {
if (str == "") {
return def;
}
return isFinite(str) ? str : def;
}
const PLUGIN_NAME = "NRP_AutoTileAnimationConfigMZ";
const parameters = PluginManager.parameters(PLUGIN_NAME);
const pBaseWait = toNumber(parameters["BaseWait"]);
const pWaterMagnification = toNumber(parameters["WaterMagnification"]);
const pFallsMagnification = toNumber(parameters["FallsMagnification"]);
/**
* 【上書】オートタイルアニメーションの更新
*/
Tilemap.prototype.update = function() {
this.animationCount++;
// this.animationFrame = Math.floor(this.animationCount / 30);
this.animationFrame = Math.floor(this.animationCount / pBaseWait);
for (const child of this.children) {
if (child.update) {
child.update();
}
}
};
/**
* ●オートタイルの追加
* ※アニメーションパターンの制御
*/
const _Tilemap__addAutotile = Tilemap.prototype._addAutotile;
Tilemap.prototype._addAutotile = function(layer, tileId, dx, dy) {
if (Tilemap.isTileA1(tileId)) {
const kind = Tilemap.getAutotileKind(tileId);
const shape = Tilemap.getAutotileShape(tileId);
const tx = kind % 8;
const ty = Math.floor(kind / 8);
let setNumber = 0;
let bx = 0;
let by = 0;
let autotileTable = Tilemap.FLOOR_AUTOTILE_TABLE;
let isTable = false;
// 現在のタイルセットを取得
const tileset = $gameMap.tileset();
// 水タイルの速度調整
// const waterSurfaceIndex = [0, 1, 2, 1][this.animationFrame % 4];
const waterSurfaceIndex = [0, 1, 2, 1][Math.floor(this.animationFrame / tileset.waterMagnification) % 4];
setNumber = 0;
let editFlg = false;
if (kind === 0) {
bx = waterSurfaceIndex * 2;
by = 0;
editFlg = true;
} else if (kind === 1) {
bx = waterSurfaceIndex * 2;
by = 3;
editFlg = true;
} else if (kind > 3) {
bx = Math.floor(tx / 4) * 8;
by = ty * 6 + (Math.floor(tx / 2) % 2) * 3;
if (kind % 2 === 0) {
bx += waterSurfaceIndex * 2;
} else {
bx += 6;
autotileTable = Tilemap.WATERFALL_AUTOTILE_TABLE;
// 滝タイルの速度調整
// by += this.animationFrame % 3;
by += Math.floor(this.animationFrame / tileset.fallsMagnification) % 3;
}
editFlg = true;
}
if (editFlg) {
const table = autotileTable[shape];
const w1 = (this.tileWidth || this._tileWidth) / 2;
const h1 = (this.tileHeight || this._tileHeight) / 2;
for (let i = 0; i < 4; i++) {
const qsx = table[i][0];
const qsy = table[i][1];
const sx1 = (bx * 2 + qsx) * w1;
const sy1 = (by * 2 + qsy) * h1;
const dx1 = dx + (i % 2) * w1;
const dy1 = dy + Math.floor(i / 2) * h1;
if (isTable && (qsy === 1 || qsy === 5)) {
const qsx2 = qsy === 1 ? (4 - qsx) % 4 : qsx;
const qsy2 = 3;
const sx2 = (bx * 2 + qsx2) * w1;
const sy2 = (by * 2 + qsy2) * h1;
layer.addRect(setNumber, sx2, sy2, dx1, dy1, w1, h1);
layer.addRect(setNumber, sx1, sy1, dx1, dy1 + h1 / 2, w1, h1 / 2);
} else {
layer.addRect(setNumber, sx1, sy1, dx1, dy1, w1, h1);
}
}
// 対象の場合は終了
return;
}
}
// それ以外は元の処理を呼出
_Tilemap__addAutotile.apply(this, arguments);
};
/**
* ●マップ情報の設定
*/
const _Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
_Game_Map_setup.apply(this, arguments);
setTilesetInfo();
};
/**
* ●タイルセットの変更
*/
const _Game_Map_changeTileset = Game_Map.prototype.changeTileset;
Game_Map.prototype.changeTileset = function(tilesetId) {
_Game_Map_changeTileset.apply(this, arguments);
setTilesetInfo();
};
/**
* ●タイルセットに情報を設定
*/
function setTilesetInfo() {
// 読み込まれていない場合は処理しない。
if (!$gameMap || !$gameMap.tileset()) {
return;
}
// 個別倍率を設定
// ※常駐処理は避けて、極力処理はこちらでやっておく。
const tileset = $gameMap.tileset();
tileset.waterMagnification = getWaterMagnification(tileset);
tileset.fallsMagnification = getFallsMagnification(tileset);
}
/**
* ●水の倍率を設定
*/
function getWaterMagnification(tileset) {
const waterMagnification = tileset.meta.WaterMagnification;
// 個別の指定があれば優先
if (waterMagnification) {
return waterMagnification;
}
// 指定がなければ設定値
return pWaterMagnification;
}
/**
* ●滝の倍率を設定
*/
function getFallsMagnification(tileset) {
const fallsMagnification = tileset.meta.FallsMagnification;
// 個別の指定があれば優先
if (fallsMagnification) {
return fallsMagnification;
}
// 指定がなければ設定値
return pFallsMagnification;
}
/**
* ●マップデータのロード完了時にタイルイベントのリンク先を復元
*/
const _DataManager_onLoad = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad.apply(this, arguments);
setTilesetInfo();
};
})();