-
Notifications
You must be signed in to change notification settings - Fork 5
/
Kru_ExtraMovementFramesPatch.js
87 lines (78 loc) · 3.35 KB
/
Kru_ExtraMovementFramesPatch.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
//=============================================================================
// Kru_ExtraMovementFramesPatch.js
//=============================================================================
/*:
* @plugindesc Patches Modern Algebra's Extra Movement Frames to fix web bugs.
* @author Krusynth
*
* @param Pattern
* @desc Pattern to match for the filename
* @default \%[\(\[]([\d\s]*)[\)\]](@[0-9]+)?
*
* @help This plugin extends Modern Algebra's Extra Movement Frames to fix an
* issue with the default filename pattern, which breaks on the web due to the
* use of the % character. Allows users to set their own regex patterns.
*
* The default cycle time can now also be set in the pattern, by using a second
* matching group.
*/
var Kru = Kru || {};
Kru.EMFP = {
};
Kru.EMFP.params = PluginManager.parameters('Kru_ExtraMovementFramesPatch');
Kru.EMFP.params['Pattern'] = new RegExp(Kru.EMFP.params['Pattern']);
ImageManager.isEmfCharacter = function(filename) {
return !!filename.match(Kru.EMFP.params['Pattern']);
};
Game_CharacterBase.prototype.maemfSetupEmfCharacter = function() {
this.maClearEmfCharacterState();
let charName = this.characterName();
if (ImageManager.isEmfCharacter(charName)) {
this._isEmfCharacter = true;
let sign = charName.match(Kru.EMFP.params['Pattern']);
let signArgs = [];
if(sign[1].trim().length) {
signArgs = sign[1].trim().split(' ').map(Number); // array of digit strings
}
this.cycleTime = typeof sign[2] == 'string' ? parseInt(sign[2].match(/[0-9]+/)) : ModernAlgebra.EMF.cycleTime;
// Map arguments in file name to an array of numbers
if(signArgs.length) {
this.emfCharacterState().frameNum = signArgs.shift();
this.emfCharacterState().idleFrame = (signArgs.length > 1) ? signArgs.shift() : ModernAlgebra.EMF.idleFrame;
}
if (signArgs.length > 2) {
this.emfCharacterState().pattern = signArgs;
} else {
let success = false;
// Check for a default match for this number of frames
for (let i = 0; i < ModernAlgebra.EMF.defaultPattern.length; i++) {
if (ModernAlgebra.EMF.defaultPattern[i][0] === this.emfCharacterState().frameNum) {
this.emfCharacterState().idleFrame = ModernAlgebra.EMF.defaultPattern[i][1];
this.emfCharacterState().pattern = ModernAlgebra.EMF.defaultPattern[i].slice(2, (ModernAlgebra.EMF.defaultPattern[i].length));
success = true;
break;
}
}
// If still no pattern specified
if (!success) {
// Populate pattern with a simple cycle starting after idle
this.emfCharacterState().pattern = [];
let idleFramePlus = this.emfCharacterState().idleFrame + 1;
for (let i = 0; i < this.emfCharacterState().frameNum; i++) {
this.emfCharacterState().pattern.push((i + idleFramePlus) % this.emfCharacterState().frameNum);
}
}
}
}
};
Game_CharacterBase.prototype.animationWait = function() {
// If EMF Character
if (this.isEmfCharacter()) {
let realSpeed = this.realMoveSpeed();
let frameNum = this.maxPattern();
return Math.floor((8 - realSpeed)*(this.cycleTime / (4*frameNum))); // CycleTime divided by number of frames in animation
} else {
// Run Default Method - approx. 60 frames at normal speed
return ModernAlgebra.EMF.GameCharacterBase_animationWait.apply(this, arguments) // original method
}
};