//-----------------------------------------------------------------------------
// Game_Screen
//
// The game object class for screen effect data, such as changes in color tone
// and flashes.
/**
* The game object class for screen effect data, such as changes in color tone and flashes.
*
* @class
*/
function Game_Screen() {
this.initialize(...arguments);
}
/**
* Initialize the screen
*/
Game_Screen.prototype.initialize = function() {
this.clear();
};
/**
* Clear screen effects
*/
Game_Screen.prototype.clear = function() {
this.clearFade();
this.clearTone();
this.clearFlash();
this.clearShake();
this.clearZoom();
this.clearWeather();
this.clearPictures();
};
/**
* Processing when a battle starts
*/
Game_Screen.prototype.onBattleStart = function() {
this.clearFade();
this.clearFlash();
this.clearShake();
this.clearZoom();
this.eraseBattlePictures();
};
/**
* Get the brightness of the screen
*
* @return {number} The brightness
*/
Game_Screen.prototype.brightness = function() {
return this._brightness;
};
/**
* Get the tone of the screen
*
* @return {number[]} The tone
*/
Game_Screen.prototype.tone = function() {
return this._tone;
};
/**
* Get the flash color of the screen
*
* @return {number[]} The flash color
*/
Game_Screen.prototype.flashColor = function() {
return this._flashColor;
};
/**
* Get the shake effect of the screen
*
* @return {number} The shake effect
*/
Game_Screen.prototype.shake = function() {
return this._shake;
};
/**
* Get the zoom x coordinate
*
* @return {number} The zoom x coordinate
*/
Game_Screen.prototype.zoomX = function() {
return this._zoomX;
};
/**
* Get the zoom y coordinate
*
* @return {number} The zoom y coordinate
*/
Game_Screen.prototype.zoomY = function() {
return this._zoomY;
};
/**
* Get the zoom scale of the screen
*
* @return {number} The zoom scale effect
*/
Game_Screen.prototype.zoomScale = function() {
return this._zoomScale;
};
/**
* Get the weather typeof the screen
*
* @return {string} The weather type
*/
Game_Screen.prototype.weatherType = function() {
return this._weatherType;
};
/**
* Get the weather power of the screen
*
* @return {number} The weather power
*/
Game_Screen.prototype.weatherPower = function() {
return this._weatherPower;
};
/**
* Get a picture by id
*
* @param {number} pictureId - The picture id
* @return {Game_Picture} The picture object
*/
Game_Screen.prototype.picture = function(pictureId) {
const realPictureId = this.realPictureId(pictureId);
return this._pictures[realPictureId];
};
/**
* Get the real picture id of a picture
*
* @param {number} pictureId - The picture id
* @return {number} The real picture id
*/
Game_Screen.prototype.realPictureId = function(pictureId) {
if ($gameParty.inBattle()) {
return pictureId + this.maxPictures();
} else {
return pictureId;
}
};
/**
* Clear fade effect
*/
Game_Screen.prototype.clearFade = function() {
this._brightness = 255;
this._fadeOutDuration = 0;
this._fadeInDuration = 0;
};
/**
* Clear tone effect
*/
Game_Screen.prototype.clearTone = function() {
this._tone = [0, 0, 0, 0];
this._toneTarget = [0, 0, 0, 0];
this._toneDuration = 0;
};
/**
* Clear flash effect
*/
Game_Screen.prototype.clearFlash = function() {
this._flashColor = [0, 0, 0, 0];
this._flashDuration = 0;
};
/**
* Clear shake effect
*/
Game_Screen.prototype.clearShake = function() {
this._shakePower = 0;
this._shakeSpeed = 0;
this._shakeDuration = 0;
this._shakeDirection = 1;
this._shake = 0;
};
/**
* Clear zoom effect
*/
Game_Screen.prototype.clearZoom = function() {
this._zoomX = 0;
this._zoomY = 0;
this._zoomScale = 1;
this._zoomScaleTarget = 1;
this._zoomDuration = 0;
};
/**
*Clear weather effects
*/
Game_Screen.prototype.clearWeather = function() {
this._weatherType = "none";
this._weatherPower = 0;
this._weatherPowerTarget = 0;
this._weatherDuration = 0;
};
/**
* Clear pictures
*/
Game_Screen.prototype.clearPictures = function() {
this._pictures = [];
};
/**
* Erases battle pictures
*/
Game_Screen.prototype.eraseBattlePictures = function() {
this._pictures = this._pictures.slice(0, this.maxPictures() + 1);
};
/**
* Get the max allowed amount of pictures
*
* @return {number} The amount of pictures to allow at maximum
*/
Game_Screen.prototype.maxPictures = function() {
if ("picturesUpperLimit" in $dataSystem.advanced) {
return $dataSystem.advanced.picturesUpperLimit;
} else {
return 100;
}
};
/**
* Starts a fade out effect for a given duration
*
* @param {number} duration - The duration of the fade out
*/
Game_Screen.prototype.startFadeOut = function(duration) {
this._fadeOutDuration = duration;
this._fadeInDuration = 0;
};
/**
* Starts a fade in effect for a given duration
*
* @param {number} duration - The duration of the fade in
*/
Game_Screen.prototype.startFadeIn = function(duration) {
this._fadeInDuration = duration;
this._fadeOutDuration = 0;
};
/**
* Starts a tint effect for a given duration
*
* @param {number[]} tone - The tone
* @param {number} duration - The duration of the tint
*/
Game_Screen.prototype.startTint = function(tone, duration) {
this._toneTarget = tone.clone();
this._toneDuration = duration;
if (this._toneDuration === 0) {
this._tone = this._toneTarget.clone();
}
};
/**
* Starts a flash effect for a given duration
*
* @param {number[]} color - The color
* @param {number} duration - The duration of the flash
*/
Game_Screen.prototype.startFlash = function(color, duration) {
this._flashColor = color.clone();
this._flashDuration = duration;
};
/**
* Starts a shake effect for a given duration
*
* @param {number} power - The power of the shake effect
* @param {number} speed - The speed of the shake effect
* @param {number} duration - The duration of the shake
*/
Game_Screen.prototype.startShake = function(power, speed, duration) {
this._shakePower = power;
this._shakeSpeed = speed;
this._shakeDuration = duration;
};
/**
* Starts a zoom effect for a given duration
*
* @param {number} x - The x coordinate of the zoom
* @param {number} y - The y coordinate of the zoom
* @param {number} scale - The scale of the zoom
* @param {number} duration - The duration of the shake
*/
Game_Screen.prototype.startZoom = function(x, y, scale, duration) {
this._zoomX = x;
this._zoomY = y;
this._zoomScaleTarget = scale;
this._zoomDuration = duration;
};
/**
* Sets the zoom effect
*
* @param {number} x - The x coordinate of the zoom
* @param {number} y - The y coordinate of the zoom
* @param {number} scale - The scale of the zoom
*/
Game_Screen.prototype.setZoom = function(x, y, scale) {
this._zoomX = x;
this._zoomY = y;
this._zoomScale = scale;
};
/**
* Changes the weather effect for the given duration
*
* @param {string} type - The weather type
* @param {number} power - The weather power
* @param {number} duration - The duration of the weather change
*/
Game_Screen.prototype.changeWeather = function(type, power, duration) {
if (type !== "none" || duration === 0) {
this._weatherType = type;
}
this._weatherPowerTarget = type === "none" ? 0 : power;
this._weatherDuration = duration;
if (duration === 0) {
this._weatherPower = this._weatherPowerTarget;
}
};
/**
* Update the screen
*/
Game_Screen.prototype.update = function() {
this.updateFadeOut();
this.updateFadeIn();
this.updateTone();
this.updateFlash();
this.updateShake();
this.updateZoom();
this.updateWeather();
this.updatePictures();
};
/**
* Update the fade out effect
*/
Game_Screen.prototype.updateFadeOut = function() {
if (this._fadeOutDuration > 0) {
const d = this._fadeOutDuration;
this._brightness = (this._brightness * (d - 1)) / d;
this._fadeOutDuration--;
}
};
/**
* Update the fade in effect
*/
Game_Screen.prototype.updateFadeIn = function() {
if (this._fadeInDuration > 0) {
const d = this._fadeInDuration;
this._brightness = (this._brightness * (d - 1) + 255) / d;
this._fadeInDuration--;
}
};
/**
* Update the tone
*/
Game_Screen.prototype.updateTone = function() {
if (this._toneDuration > 0) {
const d = this._toneDuration;
for (let i = 0; i < 4; i++) {
this._tone[i] = (this._tone[i] * (d - 1) + this._toneTarget[i]) / d;
}
this._toneDuration--;
}
};
/**
* Update the flash effect
*/
Game_Screen.prototype.updateFlash = function() {
if (this._flashDuration > 0) {
const d = this._flashDuration;
this._flashColor[3] *= (d - 1) / d;
this._flashDuration--;
}
};
/**
* Update the shake effect
*/
Game_Screen.prototype.updateShake = function() {
if (this._shakeDuration > 0 || this._shake !== 0) {
const delta =
(this._shakePower * this._shakeSpeed * this._shakeDirection) / 10;
if (
this._shakeDuration <= 1 &&
this._shake * (this._shake + delta) < 0
) {
this._shake = 0;
} else {
this._shake += delta;
}
if (this._shake > this._shakePower * 2) {
this._shakeDirection = -1;
}
if (this._shake < -this._shakePower * 2) {
this._shakeDirection = 1;
}
this._shakeDuration--;
}
};
/**
* Update the zoom effect
*/
Game_Screen.prototype.updateZoom = function() {
if (this._zoomDuration > 0) {
const d = this._zoomDuration;
const t = this._zoomScaleTarget;
this._zoomScale = (this._zoomScale * (d - 1) + t) / d;
this._zoomDuration--;
}
};
/**
* Changes the weather effects
*/
Game_Screen.prototype.updateWeather = function() {
if (this._weatherDuration > 0) {
const d = this._weatherDuration;
const t = this._weatherPowerTarget;
this._weatherPower = (this._weatherPower * (d - 1) + t) / d;
this._weatherDuration--;
if (this._weatherDuration === 0 && this._weatherPowerTarget === 0) {
this._weatherType = "none";
}
}
};
/**
* Update the pictures
*/
Game_Screen.prototype.updatePictures = function() {
for (const picture of this._pictures) {
if (picture) {
picture.update();
}
}
};
/**
* Starts a flash effect for damage
*/
Game_Screen.prototype.startFlashForDamage = function() {
this.startFlash([255, 0, 0, 128], 8);
};
// prettier-ignore
/**
* Shows the picture with the given id at the given location with options
*
* @param {number} pictureId - The picture id to show
* @param {string} name - The picture image file name
* @param {number} origin - The picture origin
* @param {number} x - The picture x coordinate
* @param {number} y - The picture y coordinate
* @param {number} scaleX - The x (horizontal) scale of the picture
* @param {number} scaleY - The y (vertical) scale of the picture
* @param {number} opacity - The opacity of the picture
* @param {number} blendMode - The blend mode of the picture
*/
Game_Screen.prototype.showPicture = function(
pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode
) {
const realPictureId = this.realPictureId(pictureId);
const picture = new Game_Picture();
picture.show(name, origin, x, y, scaleX, scaleY, opacity, blendMode);
this._pictures[realPictureId] = picture;
};
// prettier-ignore
/**
* Moves the picture with the given id with options
*
* @param {number} pictureId - The picture id to show
* @param {number} origin - The picture origin
* @param {number} x - The picture x coordinate
* @param {number} y - The picture y coordinate
* @param {number} scaleX - The x (horizontal) scale of the picture
* @param {number} scaleY - The y (vertical) scale of the picture
* @param {number} opacity - The opacity of the picture
* @param {number} blendMode - The blend mode of the picture
* @param {number} duration - The duration of the move
* @param {number} easingType - The easing type of the move
*/
Game_Screen.prototype.movePicture = function(
pictureId, origin, x, y, scaleX, scaleY, opacity, blendMode, duration,
easingType
) {
const picture = this.picture(pictureId);
if (picture) {
// prettier-ignore
picture.move(origin, x, y, scaleX, scaleY, opacity, blendMode,
duration, easingType);
}
};
/**
* Rotates a picture by id at the given speed
*
* @param {number} pictureId - The picture id to rotate
* @param {number} speed - The speed of the rotation
*/
Game_Screen.prototype.rotatePicture = function(pictureId, speed) {
const picture = this.picture(pictureId);
if (picture) {
picture.rotate(speed);
}
};
/**
* Tints a picture by id over a duration of time
*
* @param {number} pictureId - The picture id to tint
* @param {number[]} tone - The new tone of the picture
* @param {number} duration - The duration of the tint
*/
Game_Screen.prototype.tintPicture = function(pictureId, tone, duration) {
const picture = this.picture(pictureId);
if (picture) {
picture.tint(tone, duration);
}
};
/**
* Erases a picture by id
*
* @param {number} pictureId - The picture id
*/
Game_Screen.prototype.erasePicture = function(pictureId) {
const realPictureId = this.realPictureId(pictureId);
this._pictures[realPictureId] = null;
};