Source: ColorManager.js

ColorManager.js

//-----------------------------------------------------------------------------
// ColorManager
//
// The static class that handles the window colors.

/**
 * The static class that manages colors in the game
 *
 * @namespace
 */
function ColorManager() {
    throw new Error("This is a static class");
}

/**
 * Loads the game windowskin, important because colors come from the windowskin image file
 *
 * @static
 */
ColorManager.loadWindowskin = function() {
    this._windowskin = ImageManager.loadSystem("Window");
};

/**
 * Returns the color of the pixels at position n (Bottom right of windowskin, the colored squares from top left to bottom right)
 *
 * @static
 * @param {number} n - The index of the colored squares to take a pixel from
 * @return {string} HEX HTML color
 */
ColorManager.textColor = function(n) {
    const px = 96 + (n % 8) * 12 + 6;
    const py = 144 + Math.floor(n / 8) * 12 + 6;
    return this._windowskin.getPixel(px, py);
};

/**
 * Returns the color of the first colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.normalColor = function() {
    return this.textColor(0);
};

/**
 * Returns the color of the 17th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.systemColor = function() {
    return this.textColor(16);
};

/**
 * Returns the color of the 18th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.crisisColor = function() {
    return this.textColor(17);
};

/**
 * Returns the color of the 19th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.deathColor = function() {
    return this.textColor(18);
};

/**
 * Returns the color of the 20th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.gaugeBackColor = function() {
    return this.textColor(19);
};

/**
 * Returns the color of the 21st colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.hpGaugeColor1 = function() {
    return this.textColor(20);
};

/**
 * Returns the color of the 22nd colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.hpGaugeColor2 = function() {
    return this.textColor(21);
};

/**
 * Returns the color of the 23rd colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.mpGaugeColor1 = function() {
    return this.textColor(22);
};

/**
 * Returns the color of the 24th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.mpGaugeColor2 = function() {
    return this.textColor(23);
};

/**
 * Returns the color of the 24th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.mpCostColor = function() {
    return this.textColor(23);
};

/**
 * Returns the color of the 25th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.powerUpColor = function() {
    return this.textColor(24);
};

/**
 * Returns the color of the 26th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.powerDownColor = function() {
    return this.textColor(25);
};

/**
 * Returns the color of the 27th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.ctGaugeColor1 = function() {
    return this.textColor(26);
};

/**
 * Returns the color of the 28th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.ctGaugeColor2 = function() {
    return this.textColor(27);
};

/**
 * Returns the color of the 29th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.tpGaugeColor1 = function() {
    return this.textColor(28);
};

/**
 * Returns the color of the 30th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.tpGaugeColor2 = function() {
    return this.textColor(29);
};

/**
 * Returns the color of the 30th colored square in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.tpCostColor = function() {
    return this.textColor(29);
};

/**
 * Returns the color at position (120, 120) in the windowskin
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.pendingColor = function() {
    return this._windowskin.getPixel(120, 120);
};

/**
 * Returns a color based on actor's health (normal, crisis, dead)
 *
 * @static
 * @param {Game_Actor} actor - Game actor to check status of for text color
 * @return {string} HEX HTML color
 */
ColorManager.hpColor = function(actor) {
    if (!actor) {
        return this.normalColor();
    } else if (actor.isDead()) {
        return this.deathColor();
    } else if (actor.isDying()) {
        return this.crisisColor();
    } else {
        return this.normalColor();
    }
};

/**
 * Returns the normal color
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.mpColor = function(/*actor*/) {
    return this.normalColor();
};

/**
 * Returns the normal color
 *
 * @static
 * @return {string} HEX HTML color
 */
ColorManager.tpColor = function(/*actor*/) {
    return this.normalColor();
};

/**
 * Returns the normal color, power up color, or power down color depending on if change is negative, 0, or positive
 *
 * @static
 * @param {number} change - The amount by which the parameter will change
 * @return {string} HEX HTML color
 */
ColorManager.paramchangeTextColor = function(change) {
    if (change > 0) {
        return this.powerUpColor();
    } else if (change < 0) {
        return this.powerDownColor();
    } else {
        return this.normalColor();
    }
};

/**
 * Returns a color for various types of recover/damage
 *
 * @static
 * @param {number} colorType - Valid types are 0 = HP Damage, 1 = HP Recover, 2 = MP Damage, 3 = MP Recover
 * @return {string} HEX HTML color
 */
ColorManager.damageColor = function(colorType) {
    switch (colorType) {
        case 0: // HP damage
            return "#ffffff";
        case 1: // HP recover
            return "#b9ffb5";
        case 2: // MP damage
            return "#ffff90";
        case 3: // MP recover
            return "#80b0ff";
        default:
            return "#808080";
    }
};

/**
 * Returns the outline color
 *
 * @static
 * @return {string} RGBA HTML color
 */
ColorManager.outlineColor = function() {
    return "rgba(0, 0, 0, 0.6)";
};

/**
 * Returns the dim first color
 *
 * @static
 * @return {string} RGBA HTML color
 */
ColorManager.dimColor1 = function() {
    return "rgba(0, 0, 0, 0.6)";
};

/**
 * Returns the dim second color
 *
 * @static
 * @return {string} RGBA HTML color
 */
ColorManager.dimColor2 = function() {
    return "rgba(0, 0, 0, 0)";
};

/**
 * Returns the item back first color
 *
 * @static
 * @return {string} RGBA HTML color
 */
ColorManager.itemBackColor1 = function() {
    return "rgba(32, 32, 32, 0.5)";
};

/**
 * Returns the item back second color
 *
 * @static
 * @return {string} RGBA HTML color
 */
ColorManager.itemBackColor2 = function() {
    return "rgba(0, 0, 0, 0.5)";
};