-
Notifications
You must be signed in to change notification settings - Fork 1
/
FaceAnimetion.js
266 lines (245 loc) · 9.83 KB
/
FaceAnimetion.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
//=============================================================================
// FaceAnimetion.js
//=============================================================================
/*:ja
* v0.1.0
* @plugindesc
* 顔グラのアニメーションを行う
*
* @author オオホタルサイコ
*
* @param FaceIndex
* @default 0
* @desc 表示する顔グラのインデックス番号
*
* @param EyeAnmCnt
* @default 4
* @desc 目のアニメーション数
*
* @param MouthAnmCnt
* @default 2
* @desc 口のアニメーション数
*
* @param FaceWidth
* @default 144
* @desc 顔グラの横幅
*
* @param FaceHeight
* @default 144
* @desc 顔グラの縦幅
*
* @param OffsetX
* @default 18
* @desc 顔グラの調整X座標
*
* @param OffsetY
* @default 0
* @desc 顔グラの調整Y座標
*
* @param DispFace
* @default 0
* @desc 顔グラの表示場所
*
* @help
* ■概要
* FaceAnimetionプラグインを利用するにはプラグインコマンドから実行します。
* プラグインコマンドを実行すると会話中の顔グラの表示を変更することが可能です。
* [FaceWidth] [FaceHeight] [offsetX] [offsetY]は省略可能
*
* ■プラグインコマンド
* FaceAnimetion set [FaceIndex] [EyeAnmCnt] [MouthAnmCnt] # 顔グラを設定します
* FaceAnimetion set [FaceIndex] [EyeAnmCnt] [MouthAnmCnt] [FaceWidth] # 顔グラを設定します
* FaceAnimetion set [FaceIndex] [EyeAnmCnt] [MouthAnmCnt] [FaceWidth] [FaceHeight] # 顔グラを設定します
* FaceAnimetion set [FaceIndex] [EyeAnmCnt] [MouthAnmCnt] [FaceWidth] [FaceHeight] [OffsetX] # 顔グラを設定します
* FaceAnimetion set [FaceIndex] [EyeAnmCnt] [MouthAnmCnt] [FaceWidth] [FaceHeight] [OffsetX] [OffsetY] # 顔グラを設定します
* FaceAnimetion set [FaceIndex] [EyeAnmCnt] [MouthAnmCnt] [FaceWidth] [FaceHeight] [OffsetX] [OffsetY] [DispFace] # 顔グラを設定します
* FaceAnimetion clear # 初期設定状態に戻します
*/
//name space
var fcanm = fcanm || (fcanm = {});
(function(fcanm){
var FaceAnimetion = (function(){
//constructor
function FaceAnimetion(){
this.initialize();
};
//member methods
FaceAnimetion.prototype.initialize = function(){
var parameters = PluginManager.parameters("FaceAnimetion");
this.faceIndex = Number(parameters["FaceIndex"] || 0);
this.eyeAnmCnt = Number(parameters["EyeAnmCnt"] || 0);
this.mouthAnmCnt = Number(parameters["MouthAnmCnt"] || 0);
this.faceWidth = Number(parameters["FaceWidth"] || Window_Base._faceWidth);
this.faceHeight = Number(parameters["FaceHeight"] || Window_Base._faceHeight);
this.offsetX = Number(parameters["OffsetX"] || this.standardPadding());
this.offsetY = Number(parameters["OffsetY"] || 0);
this.dispFace = Number(parameters["DispFace"] || 0);
};
FaceAnimetion.prototype.setParameter = function(args){
//parse
if(args.length < 4){
this._tr("setParameter: args is invalid.");
return false;
}
var parameters = PluginManager.parameters('FaceAnimetion');
this.faceIndex = Number(args[1]);
this.eyeAnmCnt = Number(args[2]);
this.mouthAnmCnt = Number(args[3]);
this.faceWidth = Number(args[4] || this.faceWidth);
this.faceHeight = Number(args[5] || this.faceHeight);
this.offsetX = Number(args[6] || this.offsetX);
this.offsetY = Number(args[7] || this.offsetY);
this.dispFace = Number(args[8] || this.dispFace);
return true;
};
return FaceAnimetion;
}
)();
FaceAnimetion.prototype.clearParameter = function(){
this.initialize();
};
fcanm.FaceAnimetion = new FaceAnimetion();
}(fcanm || (fcanm = { }) ));
(function(){
//-----------------------------------------------------------------------------
// parse and dispatch plugin command
//-----------------------------------------------------------------------------
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args){
_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === 'FaceAnimetion'){
switch(args[0]){
case 'set':
fcanm.FaceAnimetion.setParameter(args);
break;
case 'clear':
fcanm.FaceAnimetion.clearParameter();
break;
default:
break;
}
}
};
var msgInit = Window_Message.prototype.initialize;
Window_Message.prototype.initialize = function(){
msgInit.call(this);
fcanm.FaceAnimetion.initialize();
this._eyeAnimetionFlg = false;
this._faceSprite = new Sprite_Base();
this._eyeSprite = new Sprite_Base();
this._eyeCnt = 0;
this._mouthSprite = new Sprite_Base();
this.addChild(this._faceSprite);
this.addChild(this._eyeSprite);
this.addChild(this._mouthSprite);
}
Window_Message.prototype.newLineX = function() {
return (fcanm.FaceAnimetion.dispFace > 0 || $gameMessage.faceName() == "") ? 0 : fcanm.FaceAnimetion.faceWidth;
};
Window_Message.prototype.drawMessageFace = function() {
this.drawFace($gameMessage.faceName(), fcanm.FaceAnimetion.faceIndex, 0, 0, fcanm.FaceAnimetion.faceWidth, fcanm.FaceAnimetion.faceHeight);
};
Window_Message.prototype.drawFace = function(faceName, faceIndex, x, y, width, height) {
this._eyeCnt = 0;
this.procCnt = 0;
this.cnt = 0;
this._eyeAnimetionFlg = false;
this.eyeIndex = 0;
this.mouthIndex = 1;
if(faceName != ""){
var bitmap = ImageManager.loadFace(faceName);
width = (width > 0) ? width : Window_Base._faceWidth;
height = (height > 0) ? height : Window_Base._faceHeight;
var bitmap = ImageManager.loadFace(faceName);
var sw = width;
var sh = height;
var dx = Math.floor(x);
var dy = Math.floor(y);
var sx = 0;
var sy = Math.floor(faceIndex) * sh;
// // EyeSprite
var sx2 = sw;
var sy2 = Math.floor(faceIndex) * sh;
// // MouthSprite
var sx3 = (fcanm.FaceAnimetion.eyeAnmCnt + 1) * sw;
var sy3 = Math.floor(faceIndex) * sh;
this._faceSprite.bitmap = bitmap;
this._faceSprite.setFrame(sx, sy, sw, sh);
this._faceSprite.x = 0 + fcanm.FaceAnimetion.offsetX;
this._faceSprite.y = (Window_Base._faceHeight + this.lineHeight()/2) - height + fcanm.FaceAnimetion.offsetY;
this._eyeSprite.bitmap = bitmap;
this._eyeSprite.setFrame(sx2, sy2, sw, sh);
this._eyeSprite.x = 0 + fcanm.FaceAnimetion.offsetX;
this._eyeSprite.y = (Window_Base._faceHeight + this.lineHeight()/2) - height + fcanm.FaceAnimetion.offsetY;
this._mouthSprite.bitmap = bitmap;
this._mouthSprite.setFrame(sx3, sy3, sw, sh);
this._mouthSprite.x = 0 + fcanm.FaceAnimetion.offsetX;
this._mouthSprite.y = (Window_Base._faceHeight + this.lineHeight()/2) - height + fcanm.FaceAnimetion.offsetY;
}
}
Window_Message.prototype.drawFaceEye = function(faceName, faceIndex, eyeIndex, x, y, width, height) {
if(this._eyeSprite.bitmap != null){
width = (width > 0) ? width : Window_Base._faceWidth;
height = (height > 0) ? height : Window_Base._faceHeight;
var sw = width;
var sh = height;
var dx = Math.floor(x);
var dy = Math.floor(y);
var sx = (eyeIndex + 1) * sw;
var sy = Math.floor(faceIndex) * sh;
this._eyeSprite.setFrame(sx, sy, sw, sh);
}
};
Window_Message.prototype.drawFaceMouth = function(faceName, faceIndex, mouthIndex, x, y, width, height) {
if(this._mouthSprite.bitmap != null){
width = (width > 0) ? width : Window_Base._faceWidth;
height = (height > 0) ? height : Window_Base._faceHeight;
var sw = width;
var sh = height;
var dx = Math.floor(x);
var dy = Math.floor(y);
var sx = (fcanm.FaceAnimetion.eyeAnmCnt + mouthIndex + 1) * sw;
var sy = Math.floor(faceIndex) * sh;
this._mouthSprite.setFrame(sx, sy, sw, sh);
}
};
var msgUpd = Window_Message.prototype.update;
Window_Message.prototype.update = function() {
this.cnt = this.cnt + 1;
if(!this._eyeAnimetionFlg && Math.floor(Math.random() * (120 - 1 + 1) + 1) == 3){
this._eyeAnimetionFlg = true;
}
if(this._eyeAnimetionFlg && this.cnt%10 == 0){
if(this._eyeSprite.bitmap != null){
this.eyeIndex = this.eyeIndex % fcanm.FaceAnimetion.eyeAnmCnt;
this.drawFaceEye($gameMessage.faceName(), fcanm.FaceAnimetion.faceIndex, this.eyeIndex, this._faceSprite.x, this._faceSprite.y, this._faceSprite.width, this._faceSprite.height);
this.eyeIndex = this.eyeIndex + 1;
this._eyeCnt = this._eyeCnt + 1;
if(this._eyeCnt == fcanm.FaceAnimetion.eyeAnmCnt + 1){
this._eyeAnimetionFlg = false;
this._eyeCnt = 0;
this.eyeIndex = 0;
}
}
}
msgUpd.call(this);
};
var msgProcChara = Window_Message.prototype.processCharacter
Window_Message.prototype.processCharacter = function(textState){
msgProcChara.call(this, this._textState);
this.procCnt = this.procCnt + 1;
if(this.procCnt%5 == 0){
if(this._mouthSprite.bitmap != null){
this.mouthIndex = (this.mouthIndex + 1) % fcanm.FaceAnimetion.mouthAnmCnt;
this.drawFaceMouth($gameMessage.faceName(), fcanm.FaceAnimetion.faceIndex, this.mouthIndex, this._faceSprite.x, this._faceSprite.y, this._faceSprite.width, this._faceSprite.height);
}
}
};
var msgClose = Window_Message.prototype.terminateMessage;
Window_Message.prototype.terminateMessage = function() {
this._faceSprite.bitmap = null;
this._mouthSprite.bitmap = null;
this._eyeSprite.bitmap = null;
msgClose.call(this);
};
})();