MV Help Centering State Icons In Battle Status Window

Hello,

I am attempting to work out an equation to center the state icon row in the Battle Status window, but am having some trouble coming up with the formula.

Here is the code snippet I have altered from rpg_windows.js:
JavaScript:
Window_Base.prototype.drawActorIcons = function (actor, x, y, width) {
  width = width || 144;
  var icons = actor.allIcons().slice(0, Math.floor(width / Window_Base._iconWidth));
  for (var i = 0; i < icons.length; i++) {
    let newX = (icons.length > 0) ? x - ((Window_Base._iconWidth / 2) * i) : x;
    this.drawIcon(icons[i], newX + Window_Base._iconWidth * i, y + 2);
  }
};

Here is a screenshot of what I am trying to achieve:
Desired Status Window States.png


I'm also using Yanfly's Buffs and States core, but I already figured out that I just need to place the same X offset inside the overloaded functions that draw state icons within that plugin.

Any help is appreciated! Thanks in advance.

UPDATE:
Actually, I was able to correct my equation. I ended up settling on this:

JavaScript:
Window_Base.prototype.drawActorIcons = function (actor, x, y, width) {
  width = width || 144;
  var icons = actor.allIcons().slice(0, Math.floor(width / Window_Base._iconWidth));
  for (var i = 0; i < icons.length; i++) {
    let newX = (icons.length > 0) ? x - ((Window_Base._iconWidth / 2) * icons.length) : x;
    this.drawIcon(icons[i], newX + Window_Base._iconWidth * i, y + 2);
  }
};

I just had to swap out i with icons.length lol I do account for the offset inside a separate plugin to align it to Graphics.boxWidth / 2 (specifically the Victor Engine custom battle status plugin). This thread can be closed. Hopefully this helps anyone in the future trying to do a similar thing with the state icons!

Original thread: https://forums.rpgmakerweb.com/threads/help-centering-state-icons-in-battle-status-window.168993/