-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathContinuousAnimation.js
236 lines (203 loc) · 8.7 KB
/
ContinuousAnimation.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
/*:
@target MZ
@plugindesc continuous animation v1.0.0
@author unagiootoro
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/ContinuousAnimation.js
@help
The animation displayed on the map can be used for menus, battle scenes, etc.
It is a plug-in that continues to display even if it is sandwiched.
【How to use】
This plugin can be used just by installing it.
※Important point
Animation when resuming with the save data after saving
Continuous display is not supported.
【License】
This plugin is available under the terms of the MIT license.
*/
/*:ja
@target MZ
@plugindesc 継続アニメーション v1.0.0
@author うなぎおおとろ
@url https://raw.githubusercontent.com/unagiootoro/RPGMZ/master/ContinuousAnimation.js
@help
マップで表示中のアニメーションをメニューや戦闘などのシーンを
挟んでも継続して表示するプラグインです。
【使用方法】
このプラグインは導入するだけで使用可能です。
※注意点
セーブした後にそのセーブデータで再開した場合のアニメーションの
継続表示については非対応です。
【ライセンス】
このプラグインは、MITライセンスの条件の下で利用可能です。
*/
"use strict";
const ContinuousAnimation = {};
{
class BaseAnimationBackupInfo {
constructor(animationId, targets, mirror) {
this._animationId = animationId;
this._targets = targets;
this._mirror = mirror;
}
get animationId() { return this._animationId; }
get targets() { return this._targets; }
get mirror() { return this._mirror; }
}
class MZAnimationBackupInfo extends BaseAnimationBackupInfo {
constructor(animationId, targets, mirror, frameIndex, delay) {
super(animationId, targets, mirror);
this._frameIndex = frameIndex;
this._delay = delay;
}
get frameIndex() { return this._frameIndex; }
get delay() { return this._delay; }
}
class MVAnimationBackupInfo extends BaseAnimationBackupInfo {
constructor(animationId, targets, mirror, duration) {
super(animationId, targets, mirror);
this._duration = duration;
}
get duration() { return this._duration; }
}
class AnimationBackupManager {
static initialize() {
this._backupInfos = [];
}
static backup(animationSprites) {
for (const sprite of animationSprites) {
const backupInfo = sprite.makeBackupInfo();
if (backupInfo) this._backupInfos.push(backupInfo);
}
}
static restore() {
for (const backupInfo of this._backupInfos) {
$gameTemp.requestContinueAnimation(backupInfo);
}
this._backupInfos = [];
}
}
{
const _initialize = Spriteset_Base.prototype.initialize;
Spriteset_Base.prototype.initialize = function() {
_initialize.call(this);
this._lastAnimationRequest = {};
};
const _createAnimation = Spriteset_Base.prototype.createAnimation;
Spriteset_Base.prototype.createAnimation = function(request) {
this._lastAnimationRequest = request;
_createAnimation.call(this, request);
};
const _createAnimationSprite = Spriteset_Base.prototype.createAnimationSprite;
Spriteset_Base.prototype.createAnimationSprite = function(
targets, animation, mirror, delay
) {
_createAnimationSprite.call(this, targets, animation, mirror, delay);
const backupInfo = this._lastAnimationRequest.backupInfo;
if (!backupInfo) return;
// createAnimationSpriteによって生成されたアニメーションSpriteを取得する。
const sprite = this._animationSprites[this._animationSprites.length - 1];
sprite.restoreBackupInfo(this._lastAnimationRequest.backupInfo);
};
}
{
const _initMembers = Sprite_Animation.prototype.initMembers;
Sprite_Animation.prototype.initMembers = function() {
_initMembers.call(this);
this._restoreFrameIndex = 0;
};
Sprite_Animation.prototype.makeBackupInfo = function() {
if (!this._playing) return null;
return new MZAnimationBackupInfo(this._animation.id, this.targetObjects, this._mirror, this._frameIndex, this._delay);
};
Sprite_Animation.prototype.restoreBackupInfo = function(backupInfo) {
this._restoreFrameIndex = backupInfo.frameIndex;
this._delay = backupInfo.delay;
};
const _update = Sprite_Animation.prototype.update;
Sprite_Animation.prototype.update = function() {
if (this._restoreFrameIndex === 0) {
_update.call(this);
} else {
Sprite.prototype.update.call(this);
if (this._delay > 0) {
this._delay--;
} else if (this._playing) {
if (!this._started && this.canStart()) {
if (this._effect) {
if (this._effect.isLoaded) {
this._handle = Graphics.effekseer.play(this._effect);
this._started = true;
} else {
EffectManager.checkErrors();
}
} else {
this._started = true;
}
}
if (this._started) {
for (let i = 0; i < this._restoreFrameIndex; i++) {
this.updateEffectGeometry();
SceneManager.updateEffekseer();
}
this._frameIndex = this._restoreFrameIndex;
this._restoreFrameIndex = 0;
this.updateEffectGeometry();
this.updateMain();
this.updateFlash();
}
}
}
};
}
{
Sprite_AnimationMV.prototype.makeBackupInfo = function() {
return new MVAnimationBackupInfo(this._animation.id, this.targetObjects, this._mirror, this._duration);
};
Sprite_AnimationMV.prototype.restoreBackupInfo = function(backupInfo) {
this._duration = backupInfo.duration;
};
}
{
// createSpritesetによってSpriteset_Mapの生成とupdateが行われるため、
// それよりも前に継続アニメーションのリクエストを行う。
const _createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
Scene_Map.prototype.createDisplayObjects = function() {
AnimationBackupManager.restore();
_createDisplayObjects.call(this);
};
// シーンの終了を行う前にアニメーションのバックアップを行う。
const _terminate = Scene_Map.prototype.terminate;
Scene_Map.prototype.terminate = function() {
this.backupAnimations();
_terminate.call(this);
};
Scene_Map.prototype.backupAnimations = function() {
const effectsContainer = this._spriteset._effectsContainer;
const animationSprites = effectsContainer.children.filter(sprite => {
return (sprite instanceof Sprite_Animation || sprite instanceof Sprite_AnimationMV);
})
AnimationBackupManager.backup(animationSprites);
};
}
{
Game_Temp.prototype.requestContinueAnimation = function(backupInfo) {
const targets = backupInfo.targets;
const animationId = backupInfo.animationId;
const mirror = backupInfo.mirror;
if ($dataAnimations[animationId]) {
const request = { targets, animationId, mirror, backupInfo };
this._animationQueue.push(request);
for (const target of targets) {
if (target.startAnimation) {
target.startAnimation();
}
}
}
};
}
AnimationBackupManager.initialize();
ContinuousAnimation.BaseAnimationBackupInfo;
ContinuousAnimation.MZAnimationBackupInfo;
ContinuousAnimation.MVAnimationBackupInfo;
ContinuousAnimation.AnimationBackupManager;
}