Howdy javascript wizards and gurus,
So I know enough to read some and to be able to jerryrig code together.
But I'm asking for some assistance with cleaning up this absolute janky mess of code that I've fused together.
This code here is a combination of 3 of the status menu categories from VisuStella's ElementStatusCore plugin. Specifically the general, parameter, and element categories.
So I know enough to read some and to be able to jerryrig code together.
But I'm asking for some assistance with cleaning up this absolute janky mess of code that I've fused together.
This code here is a combination of 3 of the status menu categories from VisuStella's ElementStatusCore plugin. Specifically the general, parameter, and element categories.
Code:
// Declare Constants
const lineHeight = this.lineHeight();
const gaugeLineHeight = this.gaugeLineHeight();
const basicDataHeight = this.basicDataHeight();
const actor = this._actor;
const padding = this.itemPadding() * 2;
const halfWidth = this.innerWidth / 2;
const thirdWidth = Math.floor(this.innerWidth / 3);
let x = 0;
let y = 0;
let paramWidth = 0;
// Draw Actor Graphic
this.drawActorGraphic(0, this.innerWidth / 2);
// Declare Parameter Rect
let rect = new Rectangle(0, 0, thirdWidth, this.innerHeight);
// Declare Parameters
const params2 = this.getParameterList(2);
const maxLength = Math.max(params2.length);
const nameWidth = rect.width - padding * 2 - this.textWidth('88888');
const topY = y
// Declare Smaller Data Area
let sx = rect.x;
let sy = Math.max(rect.y, rect.y + (rect.height - basicDataHeight));
let sw = rect.width;
let sh = rect.y + rect.height - sy;
// Draw Actor Name
this.drawItemDarkRect(0, sy, sw, lineHeight, 2);
this.drawText(actor.name(), sx, sy, sw, 'center');
// Draw Actor Level
sx = rect.x + Math.round((rect.width - 128) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, lineHeight);
this.drawActorLevel(actor, sx, sy);
// Draw Actor Class
const className = actor.currentClass().name;
sx = rect.x + Math.round((rect.width - this.textSizeEx(className).width) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, lineHeight);
this.drawTextEx(className, sx, sy, sw);
// Draw Actor Icons
sx = rect.x + Math.round((rect.width - 144) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, lineHeight);
this.drawActorIcons(actor, sx, sy);
// Draw Gauges
sx = rect.x + Math.round((rect.width - 128) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, this.innerHeight - sy);
this.placeGauge(actor, "hp", sx, sy);
sy += gaugeLineHeight;
this.placeGauge(actor, "mp", sx, sy);
sy += gaugeLineHeight;
if ($dataSystem.optDisplayTp) {
this.placeGauge(actor, "tp", sx, sy);
}
// Draw Parameters 2
rect.x += rect.width;
x = rect.x + padding;
y = topY;
paramWidth = rect.width - (padding * 2);
if (y !== 0) this.drawItemDarkRect(rect.x, 0, rect.width, y);
for (const paramId of params2) {
this.drawItemDarkRect(thirdWidth * 1, y + padding * 9 + 36, thirdWidth, lineHeight, 2);
this.drawParamName(paramId, x, y + padding * 9 + 36, nameWidth);
this.drawParamValue(paramId, x, y + padding * 9 + 36, paramWidth);
y += lineHeight;
}
this.drawItemDarkRect(thirdWidth * 2, y, thirdWidth, lineHeight, 2);
// Declare Constants
const labelFmt = '\\C[16]%1: \\C[0]%2';
const traitHeight = (this.innerHeight / Math.max(Window_StatusData.traitCol1.length, Window_StatusData.traitCol2.length)) - lineHeight;
let width = this.innerWidth / 2;
// Prepare Elemental Data
const elementCol1 = this.getElementIDsCol1();
const elementCol2 = this.getElementIDsCol2();
let columnData = ['Bonus'];
const dataRows = Math.max(elementCol1.length, elementCol2.length, 1);
const dataCols = columnData.length;
// Draw Elemental Data
this.drawItemDarkRect(thirdWidth * 2, y - 36, thirdWidth, lineHeight, 2);
this.changeTextColor(ColorManager.systemColor());
this.drawText(TextManager.statusMenuDmgDealt, thirdWidth * 2, y - 36, thirdWidth, 'center');
y += lineHeight;
// Draw Elemental Table
for (let i = 0; i < dataRows; i++) {
for (let j = 0; j < dataCols; j++) {
// Draw Dark Rect
const colWidth = this.innerWidth / 2;
this.drawItemDarkRect(thirdWidth * 2, y - 36, thirdWidth, lineHeight);
// Draw Element Name
let elementID = elementCol1[i];
if (dataCols === 4) {
elementID = (j % 2 === 0) ? elementCol1[i] : elementCol2[i];
}
if (!elementID) continue;
const name = $dataSystem.elements[elementID];
this.drawTextEx(name, thirdWidth * 2.5 - 25, y - 36, thirdWidth);
const type = columnData[j];
// Draw Bonus Damage Data
this.resetFontSettings();
let drawText = '';
if (type === 'Bonus') {
const rate = actor.elementRate(elementID);
const flippedRate = (rate - 1) * -1;
this.changeTextColor(ColorManager.paramchangeTextColor(flippedRate));
const dealtPlus = actor.getDealtElementPlus(elementID);
const dealtRate = actor.getDealtElementRate(elementID);
const dealtFlat = actor.getDealtElementFlat(elementID);
const dealt = ((1 + dealtPlus) * dealtRate + dealtFlat) - 1;
this.changeTextColor(ColorManager.paramchangeTextColor(dealt));
drawText = '%1%'.format(Math.round(dealt * 100));
if (dealt >= 0) drawText = '+%1'.format(drawText);
}
// Draw Value
this.contents.drawText(drawText, thirdWidth * 2 - 25, y - 36, (thirdWidth/2) - padding, lineHeight, 'right');
}
y += lineHeight;
}
Code:
// Declare Constants
const maxExp = '-------';
const lineHeight = this.lineHeight();
const gaugeLineHeight = this.gaugeLineHeight();
const basicDataHeight = lineHeight * 6.5;
const actor = this._actor;
const padding = this.itemPadding();
const halfWidth = this.innerWidth / 2;
let rect = new Rectangle(0, 0, halfWidth, this.innerHeight);
let x = 0;
let y = 0;
// Draw Actor Graphic
this.drawActorGraphic(0, this.innerWidth / 2);
// Declare Smaller Data Area
let sx = rect.x;
let sy = Math.max(rect.y, rect.y + (rect.height - basicDataHeight));
let sw = rect.width;
let sh = rect.y + rect.height - sy;
// Draw Actor Name
this.drawItemDarkRect(0, sy, sw, lineHeight, 2);
this.drawText(actor.name(), sx, sy, sw, 'center');
// Draw Actor Level
sx = rect.x + Math.round((rect.width - 128) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, lineHeight);
this.drawActorLevel(actor, sx, sy);
// Draw Actor Class
const className = actor.currentClass().name;
sx = rect.x + Math.round((rect.width - this.textSizeEx(className).width) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, lineHeight);
this.drawTextEx(className, sx, sy, sw);
// Draw Actor Icons
sx = rect.x + Math.round((rect.width - 144) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, lineHeight);
this.drawActorIcons(actor, sx, sy);
// Draw Gauges
sx = rect.x + Math.round((rect.width - 128) / 2);
sy += lineHeight;
this.drawItemDarkRect(0, sy, sw, this.innerHeight - sy);
this.placeGauge(actor, "hp", sx, sy);
sy += gaugeLineHeight;
this.placeGauge(actor, "mp", sx, sy);
sy += gaugeLineHeight;
if ($dataSystem.optDisplayTp) {
this.placeGauge(actor, "tp", sx, sy);
}
// Declare Second Half
rect = new Rectangle(halfWidth, 0, halfWidth, this.innerHeight);
// Draw EXP
this.changeTextColor(ColorManager.systemColor());
this.drawItemDarkRect(rect.x, rect.y, rect.width, lineHeight, 2);
this.drawText(TextManager.exp, rect.x, rect.y, rect.width, 'center');
const expHeight = lineHeight * 5;
this.drawItemDarkRect(rect.x, rect.y + lineHeight * 1, rect.width, lineHeight * 2);
this.drawItemDarkRect(rect.x, rect.y + lineHeight * 3, rect.width, lineHeight * 2);
const expTotal = TextManager.expTotal.format(TextManager.exp);
const expNext = TextManager.expNext.format(TextManager.level);
this.changeTextColor(ColorManager.systemColor());
this.drawText(expTotal, rect.x + padding, rect.y + lineHeight * 1, rect.width - padding * 2);
this.drawText(expNext, rect.x + padding, rect.y + lineHeight * 3, rect.width - padding * 2);
this.resetTextColor();
const expTotalValue = actor.currentExp();
const expNextValue = actor.isMaxLevel() ? maxExp : actor.nextRequiredExp();
this.drawText(expTotalValue, rect.x + padding, rect.y + lineHeight * 1, rect.width - padding * 2, 'right');
this.drawText(expNextValue, rect.x + padding, rect.y + lineHeight * 3, rect.width - padding * 2, 'right');
// Write Actor Biography
y = rect.y + expHeight;
this.changeTextColor(ColorManager.systemColor());
this.drawItemDarkRect(rect.x, y, rect.width, lineHeight, 2);
this.drawText(TextManager.statusMenuBiography, rect.x, y, rect.width, 'center');
this.resetTextColor();
y += lineHeight;
const bioText = actor.getBiography();
this.drawItemDarkRect(rect.x, y, rect.width, this.innerHeight - y);
this.drawTextEx(bioText, rect.x + padding, y, rect.width - padding * 2);
Code:
// Declare Constants
const lineHeight = this.lineHeight();
const gaugeLineHeight = this.gaugeLineHeight();
const basicDataHeight = this.basicDataHeight();
const padding = this.itemPadding() * 2;
const thirdWidth = Math.floor(this.innerWidth / 3);
let x = 0;
let y = 0;
let paramWidth = 0;
// Draw Actor Graphic
this.drawActorGraphic(0, this.innerWidth / 2);
// Declare Parameter Rect
let rect = new Rectangle(0, 0, thirdWidth, this.innerHeight);
// Declare Parameters
const params1 = this.getParameterList(1);
const params2 = this.getParameterList(2);
const params3 = this.getParameterList(3);
const maxLength = Math.max(params1.length, params2.length, params3.length);
const nameWidth = rect.width - padding * 2 - this.textWidth('88888');
const topY = Math.max((this.innerHeight - (maxLength * lineHeight)) / 2, 0);
// Draw Parameters 1
x = rect.x + padding;
y = topY;
paramWidth = rect.width - (padding * 2);
if (y !== 0) this.drawItemDarkRect(rect.x, 0, rect.width, y);
for (const paramId of params1) {
this.drawItemDarkRect(rect.x, y, rect.width, lineHeight);
this.drawParamName(paramId, x, y, nameWidth);
this.drawParamValue(paramId, x, y, paramWidth);
y += lineHeight;
}
this.drawItemDarkRect(rect.x, y, rect.width, this.innerHeight - y);
// Draw Parameters 2
rect.x += rect.width;
x = rect.x + padding;
y = topY;
paramWidth = rect.width - (padding * 2);
if (y !== 0) this.drawItemDarkRect(rect.x, 0, rect.width, y);
for (const paramId of params2) {
this.drawItemDarkRect(rect.x, y, rect.width, lineHeight);
this.drawParamName(paramId, x, y, nameWidth);
this.drawParamValue(paramId, x, y, paramWidth);
y += lineHeight;
}
this.drawItemDarkRect(rect.x, y, rect.width, this.innerHeight - y);
// Draw Parameters 3
rect.x += rect.width;
rect.width = this.innerWidth - rect.x;
x = rect.x + padding;
y = topY;
paramWidth = rect.width - (padding * 2);
if (y !== 0) this.drawItemDarkRect(rect.x, 0, rect.width, y);
for (const paramId of params3) {
this.drawItemDarkRect(rect.x, y, rect.width, lineHeight);
this.drawParamName(paramId, x, y, nameWidth);
this.drawParamValue(paramId, x, y, paramWidth);
y += lineHeight;
}
this.drawItemDarkRect(rect.x, y, rect.width, this.innerHeight - y);
Code:
// Declare Constants
const lineHeight = this.lineHeight();
const actor = this._actor;
const padding = this.itemPadding();
const labelFmt = '\\C[16]%1: \\C[0]%2';
const traitType1 = DataManager.traitSetType('Element');
const traitSet1 = actor.traitSet('Element');
const traitType2 = DataManager.traitSetType('SubElement');
const traitSet2 = actor.traitSet('SubElement');
const traitHeight = (this.innerHeight / Math.max(Window_StatusData.traitCol1.length, Window_StatusData.traitCol2.length)) - lineHeight;
let x = 0;
let y = 0;
let width = this.innerWidth / 2;
// Draw Actor Graphic
this.drawActorGraphic(0, width);
// Draw Element Trait Sets
if (traitType1.Visible || traitType2.Visible) {
this.drawItemDarkRect(x, y, width, lineHeight, 2);
this.drawItemDarkRect(width, y, width, lineHeight, 2);
if (traitType1.Visible) {
this.drawTextEx(labelFmt.format(traitType1.Label, traitSet1.Display), padding, y, width - padding * 2);
}
if (traitType2.Visible) {
this.drawTextEx(labelFmt.format(traitType2.Label, traitSet2.Display), width + padding, y, width - padding * 2);
}
y += lineHeight;
this.setDescriptionFontSizeToTraitSet();
this.drawItemDarkRect(x, y, width, traitHeight);
this.drawItemDarkRect(width, y, width, traitHeight);
if (traitType1.Visible) {
this.drawTextEx(traitSet1.Description, padding, y, width - padding * 2);
}
if (traitType2.Visible) {
this.drawTextEx(traitSet2.Description, width + padding, y, width - padding * 2);
}
this.resetDescriptionFontSize();
this.resetFontSettings();
y += traitHeight;
}
const topY = y;
// Prepare Elemental Data
const elementCol1 = this.getElementIDsCol1();
const elementCol2 = this.getElementIDsCol2();
let columnData;
if (elementCol2.length > 0) {
columnData = ['Resist','Resist','Bonus','Bonus'];
} else {
columnData = ['Resist','Bonus'];
}
const dataRows = Math.max(elementCol1.length, elementCol2.length, 1);
const dataCols = columnData.length;
// Draw Elemental Data
this.drawItemDarkRect(width * 0, y, width, lineHeight, 2);
this.drawItemDarkRect(width * 1, y, width, lineHeight, 2);
this.changeTextColor(ColorManager.systemColor());
this.drawText(TextManager.statusMenuDmgReceive, width * 0, y, width, 'center');
this.drawText(TextManager.statusMenuDmgDealt, width * 1, y, width, 'center');
y += lineHeight;
this.setDescriptionFontSizeToTraitSet();
const smallLineHeight = this.textSizeEx(' ').height;
// Draw Elemental Table
for (let i = 0; i < dataRows; i++) {
for (let j = 0; j < dataCols; j++) {
// Draw Dark Rect
const colWidth = this.innerWidth / dataCols;
this.drawItemDarkRect(colWidth * j, y, colWidth, smallLineHeight);
// Draw Element Name
let elementID = elementCol1[i];
if (dataCols === 4) {
elementID = (j % 2 === 0) ? elementCol1[i] : elementCol2[i];
}
if (!elementID) continue;
const name = $dataSystem.elements[elementID];
this.drawTextEx(name, colWidth * (j + 1/3) + padding, y, colWidth*2/3);
const type = columnData[j];
// Draw Resistance Data
this.resetFontSettings();
let drawText = '';
if (type === 'Resist') {
const rate = actor.elementRate(elementID);
const flippedRate = (rate - 1) * -1;
this.changeTextColor(ColorManager.paramchangeTextColor(flippedRate));
drawText = '%1%'.format(Math.round(flippedRate * 100));
if (actor.getAbsorbedElements().includes(elementID)) {
this.changeTextColor(ColorManager.powerUpColor());
drawText = TextManager.statusMenuDmgAbsorb.format(Math.round(rate * 100));
} else if (rate > 1) {
drawText = '%1'.format(drawText);
} else if (rate <= 1) {
drawText = '+%1'.format(drawText);
}
// Draw Bonus Damage Data
} else if (type === 'Bonus') {
const dealtPlus = actor.getDealtElementPlus(elementID);
const dealtRate = actor.getDealtElementRate(elementID);
const dealtFlat = actor.getDealtElementFlat(elementID);
const dealt = ((1 + dealtPlus) * dealtRate + dealtFlat) - 1;
this.changeTextColor(ColorManager.paramchangeTextColor(dealt));
drawText = '%1%'.format(Math.round(dealt * 100));
if (dealt >= 0) drawText = '+%1'.format(drawText);
}
// Draw Value
this.contents.drawText(drawText, colWidth * j, y, (colWidth/3) - padding, smallLineHeight, 'right');
}
y += smallLineHeight;
}
// Closing the Table
for (let j = 0; j < dataCols; j++) {
const colWidth = this.innerWidth / dataCols;
this.drawItemDarkRect(colWidth * j, y, colWidth, this.innerHeight - y);
}