var Imported = Imported || {} ;
var TH = TH || {};
Imported.StateChangeAnimations = 1;
TH.StateChangeAnimations = TH.StateChangeAnimations || {};
(function ($) {
$.stateAddRegex = /<state[-_ ]add[-_ ]animation:\s*(\d+)\s*\/>/im
$.stateRemoveRegex = /<state[-_ ]remove[-_ ]animation:\s*(\d+)\s*\/>/im
$.stateAddAnimation = function(state) {
if (state.stateAddAnimation === undefined) {
data = {id: 0, mirror: false, delay: 0};
var res = $.stateAddRegex.exec(state.note);
if (res) {
data.id = Math.floor(res[1]);
}
state.stateAddAnimation = data;
}
return state.stateAddAnimation;
};
$.stateRemoveAnimation = function(state) {
if (state.stateRemoveAnimation === undefined) {
data = {id: 0, mirror: false, delay: 0};
var res = $.stateRemoveRegex.exec(state.note);
if (res) {
data.id = Math.floor(res[1]);
}
state.stateRemoveAnimation = data;
}
return state.stateRemoveAnimation;
};
var TH_GameBattlerBase_addNewState = Game_BattlerBase.prototype.addNewState;
Game_BattlerBase.prototype.addNewState = function(stateId) {
TH_GameBattlerBase_addNewState.call(this, stateId);
this.playStateAddAnimation(stateId);
};
var TH_GameBattlerBase_eraseState = Game_BattlerBase.prototype.eraseState;
Game_BattlerBase.prototype.eraseState = function(stateId) {
if (this.isStateAffected(stateId)) {
this.playEraseStateAnimation(stateId);
}
TH_GameBattlerBase_eraseState.call(this, stateId);
};
Game_BattlerBase.prototype.playStateAddAnimation = function(stateId) {
var state = $dataStates[stateId];
var data = $.stateAddAnimation(state);
if (data.id > 0) {
this.startAnimation(data.id, data.mirror, data.delay);
}
};
Game_BattlerBase.prototype.playEraseStateAnimation = function(stateId) {
var state = $dataStates[stateId];
var data = $.stateRemoveAnimation(state);
if (data.id > 0) {
this.startAnimation(data.id, data.mirror, data.delay);
}
};
})(TH.StateChangeAnimations);