// AdjustAniPos.js
// Created on 9/24/2018
// Last modified on 11/13/2018 by Yethwhinger
var objYeth = objYeth || {};
/*:
* @plugindesc This plugin is meant to adjust the position
* of animations on battlers.
* @author Yethwhinger
*
* @help This plugin adjusts the position of animations
* over a battler by moving it using <offsetAniX:number1>
* and <offsetAniY:number2> entries in the note fields of the Enemies
* and Actors sections of the database. number1 and number2
* represent pixel adjustments in the x and y directions.
*
* Specific animations can be adjusted for a battler by using
* the note format <offsetAniXSp:id1 numberX1,id2 numberX2,...> and
* <offsetAniYSp:id1 numberY1,id2 numberY2,...>. For example,
* animation 3 could be moved 20 pixels down for a specific
* actor by adding <offsetAniYSp:3 20>. All such special
* adjustments should go into the same note. For example, if
* adjusting the position for animation 7 down by 10 pixels on
* the same actor, the previous note would be modified to look
* like <offsetAniYSp:3 20,7 10>.
*
* If using this plugin with YEP_X_ActSeqPack2, place this
* plugin just above that one in the plugin list.
*/
//----------------------------
// Changes to Game_Enemy
//----------------------------
objYeth.Game_Enemy_setup_OffsetAni = Game_Enemy.prototype.setup;
Game_Enemy.prototype.setup = function (enemyId, x, y) {
var osAniX = $dataEnemies[enemyId].meta.offsetAniX;
var osAniY = $dataEnemies[enemyId].meta.offsetAniY;
var osAniXSp = $dataEnemies[enemyId].meta.offsetAniXSp;
var osAniYSp = $dataEnemies[enemyId].meta.offsetAniYSp;
var noteFormat = /(\d+)\s+(-?\d+),?/g;
var tempMatch;
objYeth.Game_Enemy_setup_OffsetAni.call(this, enemyId, x, y);
this._offsetAniX = 0;
this._offsetAniY = 0;
this._offsetAniXSp = [];
this._offsetAniYSp = [];
if (osAniX) {
this._offsetAniX = Number(osAniX);
}
if (osAniY) {
this._offsetAniY = Number(osAniY);
}
if (osAniXSp) {
tempMatch = noteFormat.exec(osAniXSp);
while (tempMatch) {
this._offsetAniXSp[tempMatch[1]] = Number(tempMatch[2]);
tempMatch = noteFormat.exec(osAniXSp);
}
noteFormat.lastIndex = 0;
}
if (osAniYSp) {
tempMatch = noteFormat.exec(osAniYSp);
while (tempMatch) {
this._offsetAniYSp[tempMatch[1]] = Number(tempMatch[2]);
tempMatch = noteFormat.exec(osAniYSp);
}
noteFormat.lastIndex = 0;
}
};
//----------------------------
// Changes to Game_Actor
//----------------------------
objYeth.Game_Actor_setup_OffsetAni = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function (actorId) {
var osAniX = $dataActors[actorId].meta.offsetAniX;
var osAniY = $dataActors[actorId].meta.offsetAniY;
var osAniXSp = $dataActors[actorId].meta.offsetAniXSp;
var osAniYSp = $dataActors[actorId].meta.offsetAniYSp;
var noteFormat = /(\d+)\s+(-?\d+),?/g;
var tempMatch;
objYeth.Game_Actor_setup_OffsetAni.call(this, actorId);
this._offsetAniX = 0;
this._offsetAniY = 0;
this._offsetAniXSp = [];
this._offsetAniYSp = [];
if (osAniX) {
this._offsetAniX = Number(osAniX);
}
if (osAniY) {
this._offsetAniY = Number(osAniY);
}
if (osAniXSp) {
tempMatch = noteFormat.exec(osAniXSp);
while (tempMatch) {
this._offsetAniXSp[tempMatch[1]] = Number(tempMatch[2]);
tempMatch = noteFormat.exec(osAniXSp);
}
noteFormat.lastIndex = 0;
}
if (osAniYSp) {
tempMatch = noteFormat.exec(osAniYSp);
while (tempMatch) {
this._offsetAniYSp[tempMatch[1]] = Number(tempMatch[2]);
tempMatch = noteFormat.exec(osAniYSp);
}
noteFormat.lastIndex = 0;
}
};
//----------------------------
// Changes to Sprite_Animation
//----------------------------
Sprite_Animation.prototype.updatePosition = function () {
if (this._animation.position === 3) {
this.x = this.parent.width / 2;
this.y = this.parent.height / 2;
} else {
var parent = this._target.parent;
var grandparent = parent ? parent.parent : null;
this.x = this._target.x;
this.y = this._target.y;
if (this.parent === grandparent) {
this.x += parent.x;
this.y += parent.y;
}
if (this._animation.position === 0) {
this.y -= this._target.height;
} else if (this._animation.position === 1) {
this.y -= this._target.height / 2;
}
var battler = this._target._battler;
if (!battler) {
battler = this._target.parent._battler;
}
if (battler) {
var xSp = battler._offsetAniXSp[this._animation.id] || 0;
var ySp = battler._offsetAniYSp[this._animation.id] || 0;
this.x += battler._offsetAniX + xSp;
this.y += battler._offsetAniY + ySp;
}
}
};