【汉化】地图图块颜色滤镜
本帖最后由 烁灵 于 2024-12-31 16:11 编辑原贴:Tile Color Filter - Apply tone, blend color, hue, brightness, and opacity to tiles only (Ver.1.2.4) | RPG Maker Forums (rpgmakerweb.com)
仅变更地图颜色、色调、色相、透明度的滤镜
效果:
脚本:保存为 TileColorFilter.js
// TileColorFilter.js Ver.1.2.4
// MIT License (C) 2024 あわやまたな
// http://opensource.org/licenses/mit-license.php
/*:
* @target MZ
* @plugindesc 对地图图块进行多种操作,不影响角色.
* 汉化 by 烁灵 更多脚本请访问 www.hknmtt.com
* @author あわやまたな (Awaya_Matana)
* @url https://awaya3ji.seesaa.net/article/505508535.html
* @help Ver.1.2.4
* [地图、图块备注]
* <tileTone:R,G,B,gray> // 图块色调
* RGB:-255 到 255 gray:0 到 255
* <tileBlend:R,G,B,Opacity> // 图块合成颜色
* RGB:0 到 255 Opacity:0 到 255
* <tileHue:hue> // 图块色相
* hue:-360 到 360
* <tileBrightness:brightness> // 图块明度
* brightness:0 到 255
* <tileOpacity:opacity> // 图块透明度
* <tileOpacity:upperOpacity,lowerOpacity> // 上层、下层不同设定
* opacity:0 到 255
*
* [脚本]
* $gameMap.tone() // 获取地图色调
* $gameMap.blendColor() // 获取地图合成颜色
* $gameMap.brightness() // 获取地图明度
* $gameMap.hue() // 获取地图色相
* $gameMap.upperOpacity() // 获取上层透明度
* $gameMap.lowerOpacity() // 获取下层透明度
*
* [特别说明]
* 当你 "更改地图图块" 后, 图块备注将被重置
* 如果你想保持图块备注,请用 “重置滤镜”
*
* @param bgSyncList
* @text 背景同步列表
* @desc 将背景图与下层图块同步的参数
* @type select[]
* @value Tone
* @value BlendColor
* @value Hue
* @value Brightness
* @value Opacity
* @default ["Tone","BlendColor"]
*
* @param fgSyncList
* @text 前景同步列表
* @desc 将前景图与上层图块同步的参数
* @type select[]
* @value Tone
* @value BlendColor
* @value Hue
* @value Brightness
* @value Opacity
* @default ["Tone","BlendColor"]
*
* @param preconvert
* @text 预转换
* @desc 在启动时生成滤镜效果,避免首次加载时的延迟。
* @type boolean
* @default true
*
* @command setColorTone
* @text 更改颜色色调
* @arg tone
* @text 色调
* @desc R,G,B,gray
* RGB:-255 到 255 gray:0 到 255
* @default 0,0,0,0
* @type combo
* @option 0,0,0,0
* @option -68,-68,-68,0// 黑暗
* @option 34,-34,-68,170 // 墨汁
* @option 68,-34,-34,0 // 日落
* @option -68,-68,0,68 // 夜晚
* @arg duration
* @text 持续时间
* @desc 立即生效则设置为0
* @default 0
* @arg wait
* @text 是否等待完成
* @default false
* @type boolean
*
* @command setBlendColor
* @text 更改合成颜色
* @arg blendColor
* @text 合成颜色
* @desc R,G,B,opacity
* RGB:0 到 255 opacity:0 到 255
* @default 0,0,0,0
* @arg duration
* @text 持续时间
* @desc 立即生效则设置为0
* @default 0
* @arg wait
* @text 是否等待完成
* @default false
* @type boolean
*
* @command setHue
* @text 更改色相
* @arg hue
* @text 色相
* @desc -360 到 360
* @default 0
* @arg duration
* @text 持续时间
* @desc 立即生效则设置为0
* @default 0
* @arg wait
* @text 是否等待完成
* @default false
* @type boolean
*
* @command setBrightness
* @text 更改明度
* @arg brightness
* @text 明度
* @desc 0 到 255
* @default 255
* @arg duration
* @text 持续时间
* @desc 立即生效则设置为0
* @default 0
* @arg wait
* @text 是否等待完成
* @default false
* @type boolean
*
* @command setOpacity
* @text 更改透明度
* @arg layer
* @text 层
* @default All
* @type select
* @value All
* @value Upper
* @value Lower
* @arg opacity
* @text 透明度
* @desc 0 到 255
* @default 255
* @arg duration
* @text 持续时间
* @desc 立即生效则设置为0
* @default 0
* @arg wait
* @text 是否等待完成
* @default false
* @type boolean
*
* @command resetFilter
* @text 重置滤镜
* @arg filter
* @text 种类
* @default All
* @type select
* @option 所有
* @value All
* @option 色调
* @value Tone
* @option 合成颜色
* @value BlendColor
* @option 色相
* @value Hue
* @option 明度
* @value Brightness
* @option 透明度
* @value Opacity
* @arg duration
* @text 持续时间
* @desc 立即生效则设置为0
* @default 0
* @arg wait
* @text 是否等待完成
* @default false
* @type boolean
*
*/
/*:ja
* @target MZ
* @plugindesc マップタイルに対して様々な操作を行えます。
* キャラクターには影響しません。
* @author あわやまたな (Awaya_Matana)
* @url https://awaya3ji.seesaa.net/article/505508535.html
* @help [メモ(マップ及びタイルセット)]
* <tileTone:R,G,B,gray> //タイルの色調
* RGB:-255~255 gray:0~255
* <tileBlend:R,G,B,opacity> //タイルの合成色
* RGB:0~255 opacity:0~255
* <tileHue:hue> //タイルの色相
* hue:-360~360
* <tileBrightness:brightness> //タイルの明度
* brightness:0~255
* <tileOpacity:opacity> //タイルの不透明度
* <tileOpacity:upperOpacity,lowerOpacity> //上層、下層の個別指定
* opacity:0~255
*
* [スクリプト]
* $gameMap.tone() //色調の取得
* $gameMap.blendColor() //合成色の取得
* $gameMap.brightness() //明度の取得
* $gameMap.hue() //色相の取得
* $gameMap.upperOpacity() //上層の不透明度の取得
* $gameMap.lowerOpacity() //下層の不透明度の取得
*
* [仕様]
* 「タイルセットの変更」をするとタイルセットのメモが反映されます。
* マップのメモを優先したい場合は直後に「フィルターのリセット」を
* 実行してください。
*
* [更新履歴]
* 2024/11/03:Ver.1.0.0 公開。
* 2024/11/04:Ver.1.1.0 処理を削減しました。
* 2024/11/06:Ver.1.1.1 スペルミスを修正しました。
* 2024/11/06:Ver.1.2.0 タイルセットのメモを追加しました。
* 2024/11/09:Ver.1.2.1 イベントテスト時のエラーを修正。
* 2024/11/25:Ver.1.2.2 FilterControllerMZ併用時の挙動を修正。
* 2024/11/26:Ver.1.2.3 初回操作時のラグを抑制する処理を追加。
* 2024/12/27:Ver.1.2.4 描画の不具合を修正。
*
* @param bgSyncList
* @text 遠景の同期リスト
* @desc 遠景を下層タイルと同期させます。
* @type select[]
* @option 色調
* @value Tone
* @option 合成色
* @value BlendColor
* @option 色相
* @value Hue
* @option 明度
* @value Brightness
* @option 不透明度
* @value Opacity
* @default ["Tone","BlendColor"]
*
* @param fgSyncList
* @text 近景の同期リスト
* @desc 近景を上層タイルと同期させます。
* @type select[]
* @option 色調
* @value Tone
* @option 合成色
* @value BlendColor
* @option 色相
* @value Hue
* @option 明度
* @value Brightness
* @option 不透明度
* @value Opacity
* @default ["Tone","BlendColor"]
*
* @param preconvert
* @text 事前変換
* @desc ブート時にフィルターを生成して、初回のラグを防ぎます。
* @type boolean
* @default true
*
* @command setColorTone
* @text 色調の変更
* @arg tone
* @text 色調
* @desc R,G,B,グレー
* RGB:-255~255 グレー:0~255
* @default 0,0,0,0
* @type combo
* @option 0,0,0,0
* @option -68,-68,-68,0//ダーク
* @option 34,-34,-68,170 //セピア
* @option 68,-34,-34,0 //夕暮れ
* @option -68,-68,0,68 //夜
* @arg duration
* @text 時間
* @desc 0で瞬間適用
* @default 0
* @arg wait
* @text 完了までウェイト
* @default false
* @type boolean
*
* @command setBlendColor
* @text 色の合成
* @arg blendColor
* @text 合成色
* @desc R,G,B,不透明度
* RGB:0~255 不透明度:0~255
* @default 0,0,0,0
* @arg duration
* @text 時間
* @desc 0で瞬間適用
* @default 0
* @arg wait
* @text 完了までウェイト
* @default false
* @type boolean
*
* @command setHue
* @text 色相の変更
* @arg hue
* @text 色相
* @desc -360~360
* @default 0
* @arg duration
* @text 時間
* @desc 0で瞬間適用
* @default 0
* @arg wait
* @text 完了までウェイト
* @default false
* @type boolean
*
* @command setBrightness
* @text 明度の変更
* @arg brightness
* @text 明度
* @desc 0~255
* @default 255
* @arg duration
* @text 時間
* @desc 0で瞬間適用
* @default 0
* @arg wait
* @text 完了までウェイト
* @default false
* @type boolean
*
* @command setOpacity
* @text 不透明度の変更
* @arg layer
* @text レイヤー
* @default All
* @type select
* @option 全て
* @value All
* @option 上層
* @value Upper
* @option 下層
* @value Lower
* @arg opacity
* @text 不透明度
* @desc 0~255
* @default 255
* @arg duration
* @text 時間
* @desc 0で瞬間適用
* @default 0
* @arg wait
* @text 完了までウェイト
* @default false
* @type boolean
*
* @command resetFilter
* @text フィルターのリセット
* @arg filter
* @text フィルター
* @default All
* @type select
* @option 全て
* @value All
* @option 色調
* @value Tone
* @option 合成色
* @value BlendColor
* @option 色相
* @value Hue
* @option 明度
* @value Brightness
* @option 不透明度
* @value Opacity
* @arg duration
* @text 時間
* @desc 0で瞬間適用
* @default 0
* @arg wait
* @text 完了までウェイト
* @default false
* @type boolean
*
*/
'use strict';
{
//プラグイン名取得。
const pluginName = document.currentScript.src.match(/^.*\/(.*).js$/);
const parameters = PluginManager.parameters(pluginName);
const _PluginManager = window.PluginManagerEx ?? PluginManager;
const script = window.PluginManagerEx ? document.currentScript : pluginName;
const bgSyncMethods = createMethods(parameters.bgSyncList);
const fgSyncMethods = createMethods(parameters.fgSyncList, true);
const preconvert = parameters.preconvert !== "false";
function createMethods(list, upper) {
const methods = [];
for (const name of JSON.parse(list || "[]")) {
switch (name) {
case "Tone":
methods.push(["setColorTone", "tone"]);
break;
case "BlendColor":
methods.push(["setBlendColor", "blendColor"]);
break;
case "Hue":
methods.push(["setHue", "hue"]);
break;
case "Brightness":
methods.push(["setBrightness", "brightness"]);
break;
case "Opacity":
methods.push(["setOpacity", (upper ? "upperOpacity" : "lowerOpacity")]);
break;
}
}
return methods;
}
const _layers = ["Layer"];
const hasFilterControllerMZ = PluginManager._scripts.contains("FilterControllerMZ");
const hasBillboard = ["TF_LayeredMap", "TF_Billboard"].some(name => PluginManager._scripts.contains(name));
if (Utils.checkRMVersion("1.7.0")) {
_layers.push("CombinedLayer");
}
//-----------------------------------------------------------------------------
// PluginManager
_PluginManager.registerCommand(script, "setColorTone", function(args) {
const d = +args.duration;
$gameMap.setTone(args.tone.split(",").map(n=>parseInt(n)), d);
if (d && String(args.wait) === "true") {
this.wait(d);
}
});
_PluginManager.registerCommand(script, "setBlendColor", function(args) {
const d = +args.duration;
$gameMap.setBlendColor(args.blendColor.split(",").map(Number), d);
if (d && String(args.wait) === "true") {
this.wait(d);
}
});
_PluginManager.registerCommand(script, "setHue", function(args) {
const d = +args.duration;
$gameMap.setHue(+args.hue, d);
if (d && String(args.wait) === "true") {
this.wait(d);
}
});
_PluginManager.registerCommand(script, "setBrightness", function(args) {
const d = +args.duration;
$gameMap.setBrightness(+args.brightness, d);
if (d && String(args.wait) === "true") {
this.wait(d);
}
});
_PluginManager.registerCommand(script, "setOpacity", function(args) {
const opacity = +args.opacity;
const d = +args.duration;
switch (args.layer){
case "Upper":
$gameMap.setUpperOpacity(opacity, d);
break;
case "Lower":
$gameMap.setLowerOpacity(opacity, d);
break;
default:
$gameMap.setUpperOpacity(opacity, d);
$gameMap.setLowerOpacity(opacity, d);
break;
}
if (d && String(args.wait) === "true") {
this.wait(d);
}
});
_PluginManager.registerCommand(script, "resetFilter", function(args) {
const d = +args.duration;
switch (args.filter){
case "All":
$gameMap.resetTone(d);
$gameMap.resetBlendColor(d);
$gameMap.resetHue(d);
$gameMap.resetBrightness(d);
$gameMap.resetOpacity(d);
break;
default:
$gameMap["reset" + args.filter](d);
break;
}
if (d && String(args.wait) === "true") {
this.wait(d);
}
});
//-----------------------------------------------------------------------------
// Game_Map
const _Game_Map_initialize = Game_Map.prototype.initialize;
Game_Map.prototype.initialize = function() {
_Game_Map_initialize.call(this);
this.clearTone();
this.clearBlendColor();
this.clearHue();
this.clearBrightness();
this.clearUpperOpacity();
this.clearLowerOpacity();
};
const _Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
_Game_Map_setup.call(this, mapId);
this.setupTone();
this.setupBlendColor();
this.setupHue();
this.setupBrightness();
this.setupOpacity();
};
Game_Map.prototype.tone = function() {
return this._tone;
};
Game_Map.prototype.blendColor = function() {
return this._blendColor;
};
Game_Map.prototype.hue = function() {
return this._hue;
};
Game_Map.prototype.brightness = function() {
return this._brightness;
};
Game_Map.prototype.upperOpacity = function() {
return this._upperOpacity;
};
Game_Map.prototype.lowerOpacity = function() {
return this._lowerOpacity;
};
Game_Map.prototype.clearTone = function() {
this._tone = ;
this._toneTarget = ;
this._toneDuration = 0;
};
Game_Map.prototype.clearBlendColor = function() {
this._blendColor = ;
this._blendTarget = ;
this._blendDuration = 0;
};
Game_Map.prototype.clearHue = function() {
this._hue = 0;
this._hueTarget = 0;
this._hueDuration = 0;
};
Game_Map.prototype.clearBrightness = function() {
this._brightness = 255;
this._brightnessTarget = 0;
this._brightnessDuration = 0;
};
Game_Map.prototype.clearUpperOpacity = function() {
this._upperOpacity = 255;
this._upperOpacityTarget = 0;
this._upperOpacityDuration = 0;
};
Game_Map.prototype.clearLowerOpacity = function() {
this._lowerOpacity = 255;
this._lowerOpacityTarget = 0;
this._lowerOpacityDuration = 0;
};
function getMeta(name, _this) {
const tileset = _this.tileset();
return ($dataMap.meta && $dataMap.meta) || (tileset && tileset.meta && tileset.meta);
};
Game_Map.prototype.setupTone = function() {
this.clearTone();
const meta = getMeta("tileTone", this);
if (meta) {
const tone = meta.split(",").map(Number);
this.setTone(tone);
}
};
Game_Map.prototype.setupBlendColor = function() {
this.clearBlendColor();
const meta = getMeta("tileBlend", this);
if (meta) {
const blendColor = meta.split(",").map(Number);
this.setBlendColor(blendColor);
}
};
Game_Map.prototype.setupHue = function() {
this.clearHue();
const meta = getMeta("tileHue", this);
if (meta) {
const hue = Number(meta || 0);
this.setHue(hue);
}
};
Game_Map.prototype.setupBrightness = function() {
this.clearBrightness();
const meta = getMeta("tileBrightness", this);
if (meta) {
const brightness = Number(meta || 0);
this.setBrightness(brightness);
}
};
Game_Map.prototype.setupOpacity = function() {
this.clearUpperOpacity();
this.clearLowerOpacity();
const meta = getMeta("tileOpacity", this);
if (meta) {
const opacity = meta.split(",").map(Number);
this.setUpperOpacity(opacity);
this.setLowerOpacity(opacity ?? opacity);
}
};
Game_Map.prototype.setTone = function(tone, duration) {
this._toneTarget = tone.clone();
this._toneDuration = duration;
if (!duration) {
this._tone = this._toneTarget.clone();
}
};
Game_Map.prototype.setBlendColor = function(color, duration) {
this._blendTarget = color.clone();
this._blendDuration = duration;
if (!duration) {
this._blendColor = this._blendTarget.clone();
}
};
Game_Map.prototype.setHue = function(hue, duration) {
this._hueTarget = hue;
this._hueDuration = duration;
if (!duration) {
this._hue = this._hueTarget;
}
};
Game_Map.prototype.setBrightness = function(brightness, duration) {
this._brightnessTarget = brightness;
this._brightnessDuration = duration;
if (!duration) {
this._brightness = this._brightnessTarget;
}
};
Game_Map.prototype.setUpperOpacity = function(opacity, duration) {
this._upperOpacityTarget = opacity;
this._upperOpacityDuration = duration;
if (!duration) {
this._upperOpacity = this._upperOpacityTarget;
}
};
Game_Map.prototype.setLowerOpacity = function(opacity, duration) {
this._lowerOpacityTarget = opacity;
this._lowerOpacityDuration = duration;
if (!duration) {
this._lowerOpacity = this._lowerOpacityTarget;
}
};
Game_Map.prototype.resetTone = function(duration) {
const tone = this.tone();
this.setupTone();
const toneTarget = this.tone();
this.setTone(tone);
this.setTone(toneTarget, duration);
};
Game_Map.prototype.resetBlendColor = function(duration) {
const color = this.blendColor();
this.setupBlendColor();
const colorTarget = this.blendColor();
this.setBlendColor(color);
this.setBlendColor(colorTarget, duration);
};
Game_Map.prototype.resetHue = function(duration) {
const hue = this.hue();
this.setupHue();
const hueTarget = this.hue();
this.setHue(hue);
this.setHue(hueTarget, duration);
};
Game_Map.prototype.resetBrightness = function(duration) {
const brightness = this.brightness();
this.setupBrightness();
const brightnessTarget = this.brightness();
this.setBrightness(brightness);
this.setBrightness(brightnessTarget, duration);
};
Game_Map.prototype.resetOpacity = function(duration) {
const upperOpacity = this.upperOpacity();
const lowerOpacity = this.lowerOpacity();
this.setupOpacity();
const upperTarget = this.upperOpacity();
const lowerTarget = this.lowerOpacity();
this.setUpperOpacity(upperOpacity);
this.setLowerOpacity(lowerOpacity);
this.setUpperOpacity(upperTarget, duration);
this.setLowerOpacity(lowerTarget, duration);
};
Game_Map.prototype.updateTone = function() {
if (this._toneDuration > 0) {
const d = this._toneDuration;
for (let i = 0; i < 4; i++) {
this._tone = (this._tone * (d - 1) + this._toneTarget) / d;
}
this._toneDuration--;
}
};
Game_Map.prototype.updateBlendColor = function() {
if (this._blendDuration > 0) {
const d = this._blendDuration;
for (let i = 0; i < 4; i++) {
this._blendColor = (this._blendColor * (d - 1) + this._blendTarget) / d;
}
this._blendDuration--;
}
};
Game_Map.prototype.updateHue = function() {
if (this._hueDuration > 0) {
const d = this._hueDuration;
this._hue = (this._hue * (d - 1) + this._hueTarget) / d;
this._hueDuration--;
}
};
Game_Map.prototype.updateBrightness = function() {
if (this._brightnessDuration > 0) {
const d = this._brightnessDuration;
this._brightness = (this._brightness * (d - 1) + this._brightnessTarget) / d;
this._brightnessDuration--;
}
};
Game_Map.prototype.updateOpacity = function() {
if (this._upperOpacityDuration > 0) {
const d = this._upperOpacityDuration;
this._upperOpacity = (this._upperOpacity * (d - 1) + this._upperOpacityTarget) / d;
this._upperOpacityDuration--;
}
if (this._lowerOpacityDuration > 0) {
const d = this._lowerOpacityDuration;
this._lowerOpacity = (this._lowerOpacity * (d - 1) + this._lowerOpacityTarget) / d;
this._lowerOpacityDuration--;
}
};
const _Game_Map_update = Game_Map.prototype.update;
Game_Map.prototype.update = function(sceneActive) {
_Game_Map_update.call(this, sceneActive);
this.updateTone();
this.updateBlendColor();
this.updateHue();
this.updateBrightness();
this.updateOpacity();
};
const _Game_Map_changeTileset = Game_Map.prototype.changeTileset;
Game_Map.prototype.changeTileset = function(tilesetId) {
_Game_Map_changeTileset.call(this, tilesetId);
const tileset = this.tileset();
const meta = tileset && tileset.meta;
if (!meta) return;
if (meta.tileTone) {
const tone = meta.tileTone.split(",").map(Number);
this.setTone(tone);
}
if (meta.tileBlend) {
const blendColor = meta.tileBlend.split(",").map(Number);
this.setBlendColor(blendColor);
}
if (meta.tileHue) {
const hue = Number(meta.tileHue || 0);
this.setHue(hue);
}
if (meta.tileBrightness) {
const brightness = Number(meta.tileBrightness || 0);
this.setBrightness(brightness);
}
if (meta.tileOpacity) {
const opacity = meta.tileOpacity.split(",").map(Number);
this.setUpperOpacity(opacity);
this.setLowerOpacity(opacity ?? opacity);
}
};
//-----------------------------------------------------------------------------
// Spriteset_Map
const _Spriteset_Map_updateTilemap = Spriteset_Map.prototype.updateTilemap;
Spriteset_Map.prototype.updateTilemap = function() {
_Spriteset_Map_updateTilemap.call(this);
const upperLayer = this._tilemap._upperLayer;
const lowerLayer = this._tilemap._lowerLayer;
upperLayer.setColorTone($gameMap.tone());
lowerLayer.setColorTone($gameMap.tone());
upperLayer.setBlendColor($gameMap.blendColor());
lowerLayer.setBlendColor($gameMap.blendColor());
upperLayer.setHue($gameMap.hue());
lowerLayer.setHue($gameMap.hue());
upperLayer.setBrightness($gameMap.brightness());
lowerLayer.setBrightness($gameMap.brightness());
upperLayer.setOpacity($gameMap.upperOpacity());
lowerLayer.setOpacity($gameMap.lowerOpacity());
};
if (hasBillboard) {
const _Spriteset_Map_updateTilemap = Spriteset_Map.prototype.updateTilemap;
Spriteset_Map.prototype.updateTilemap = function() {
_Spriteset_Map_updateTilemap.call(this);
for (const billboard of this._tilemap._billboards) {
billboard.setColorTone($gameMap.tone());
billboard.setBlendColor($gameMap.blendColor());
billboard.setHue($gameMap.hue());
billboard.setBrightness($gameMap.brightness());
billboard.setOpacity($gameMap.upperOpacity());
}
};
}
if (bgSyncMethods.length) {
const _Spriteset_Map_updateParallax = Spriteset_Map.prototype.updateParallax;
Spriteset_Map.prototype.updateParallax = function() {
_Spriteset_Map_updateParallax.call(this);
if (this._parallax.bitmap) {
for (const methods of bgSyncMethods) {
this._parallax]($gameMap]());
}
}
};
}
if (Spriteset_Map.prototype.updateForeground && fgSyncMethods.length) {
const _Spriteset_Map_updateForeground = Spriteset_Map.prototype.updateForeground;
Spriteset_Map.prototype.updateForeground = function() {
_Spriteset_Map_updateForeground.apply(this, arguments);
if (this._foreground.bitmap) {
for (const methods of fgSyncMethods) {
this._foreground]($gameMap]());
}
}
};
}
//-----------------------------------------------------------------------------
// Sprite_Character
const _Sprite_Character_updateOther = Sprite_Character.prototype.updateOther;
Sprite_Character.prototype.updateOther = function() {
_Sprite_Character_updateOther.call(this);
if (this._tileId > 0) {
this.setHue($gameMap.hue());
} else {
this.setHue(0);
}
};
//-----------------------------------------------------------------------------
// Tilemap.(Combined)Layer
for (const Layer of _layers) {
const _Tilemap_Layer_initialize = Tilemap.prototype.initialize;
Tilemap.prototype.initialize = function() {
_Tilemap_Layer_initialize.apply(this, arguments);
this._opacity = 255;
this._hue = 0;
this._brightness = 255;
this._blendColor = ;
this._colorTone = ;
this._alphaFilter = null;
this._colorFilter = null;
};
Tilemap.prototype.setOpacity = function(opacity) {
if (this._opacity !== Number(opacity)) {
this._opacity = Number(opacity);
this._updateColorFilter();
}
};
Tilemap.prototype.setHue = function(hue) {
if (this._hue !== Number(hue)) {
this._hue = Number(hue);
this._updateColorFilter();
}
};
Tilemap.prototype.setBrightness = function(brightness) {
if (this._brightness !== Number(brightness)) {
this._brightness = Number(brightness);
this._updateColorFilter();
}
};
Tilemap.prototype.getBlendColor = function() {
return this._blendColor.clone();
};
Tilemap.prototype.setBlendColor = function(color) {
if (!(color instanceof Array)) {
throw new Error("Argument must be an array");
}
if (!this._blendColor.equals(color)) {
this._blendColor = color.clone();
this._updateColorFilter();
}
};
Tilemap.prototype.getColorTone = function() {
return this._colorTone.clone();
};
Tilemap.prototype.setColorTone = function(tone) {
if (!(tone instanceof Array)) {
throw new Error("Argument must be an array");
}
if (!this._colorTone.equals(tone)) {
this._colorTone = tone.clone();
this._updateColorFilter();
}
};
Tilemap.prototype._createColorFilter = function() {
this._colorFilter = new TileColorFilter();
if (!this.filters) {
this.filters = [];
}
this.filters.push(this._colorFilter);
if (!this.filterArea) {
this.filterArea = new Rectangle(0, 0, Graphics.width, Graphics.height);
}
};
Tilemap.prototype._updateColorFilter = function() {
if (!this._colorFilter) {
this._createColorFilter();
}
this._colorFilter.setOpacity(this._opacity);
this._colorFilter.setHue(this._hue);
this._colorFilter.setBrightness(this._brightness);
this._colorFilter.setBlendColor(this._blendColor);
this._colorFilter.setColorTone(this._colorTone);
this._colorFilter.enabled = this._opacity < 255 || this._hue > 0 || this._brightness < 255 || !this._blendColor.equals() || !this._colorTone.equals();
};
}
if (!hasFilterControllerMZ && Tilemap.Layer.prototype._render === PIXI.Container.prototype._render) {
Tilemap.Layer.prototype._render = Tilemap.Layer.prototype.render;
Tilemap.Layer.prototype.render = PIXI.Container.prototype.render;
}
//-----------------------------------------------------------------------------
// TileColorFilter
function TileColorFilter() {
this.initialize(...arguments);
}
TileColorFilter.prototype = Object.create(ColorFilter.prototype);
TileColorFilter.prototype.constructor = TileColorFilter;
TileColorFilter.prototype.initialize = function() {
ColorFilter.prototype.initialize.call(this);
this.uniforms.opacity = 255;
};
TileColorFilter.prototype.setOpacity = function(opacity) {
this.uniforms.opacity = Number(opacity);
};
TileColorFilter.prototype._fragmentSrc = function() {
return `varying vec2 vTextureCoord;
uniform sampler2D uSampler;
uniform float hue;
uniform vec4 colorTone;
uniform vec4 blendColor;
uniform float brightness;
uniform float opacity;
vec3 rgbToHsl(vec3 rgb) {
float r = rgb.r;
float g = rgb.g;
float b = rgb.b;
float cmin = min(r, min(g, b));
float cmax = max(r, max(g, b));
float h = 0.0;
float s = 0.0;
float l = (cmin + cmax) / 2.0;
float delta = cmax - cmin;
if (delta > 0.0) {
if (r == cmax) {
h = mod((g - b) / delta + 6.0, 6.0) / 6.0;
} else if (g == cmax) {
h = ((b - r) / delta + 2.0) / 6.0;
} else {
h = ((r - g) / delta + 4.0) / 6.0;
}
if (l < 1.0) {
s = delta / (1.0 - abs(2.0 * l - 1.0));
}
}
return vec3(h, s, l);
}
vec3 hslToRgb(vec3 hsl) {
float h = hsl.x;
float s = hsl.y;
float l = hsl.z;
float c = (1.0 - abs(2.0 * l - 1.0)) * s;
float x = c * (1.0 - abs((mod(h * 6.0, 2.0)) - 1.0));
float m = l - c / 2.0;
float cm = c + m;
float xm = x + m;
if (h < 1.0 / 6.0) {
return vec3(cm, xm, m);
} else if (h < 2.0 / 6.0) {
return vec3(xm, cm, m);
} else if (h < 3.0 / 6.0) {
return vec3(m, cm, xm);
} else if (h < 4.0 / 6.0) {
return vec3(m, xm, cm);
} else if (h < 5.0 / 6.0) {
return vec3(xm, m, cm);
} else {
return vec3(cm, m, xm);
}
}
void main() {
vec4 sample = texture2D(uSampler, vTextureCoord) * opacity / 255.0;
float a = sample.a;
vec3 hsl = rgbToHsl(sample.rgb);
hsl.x = mod(hsl.x + hue / 360.0, 1.0);
hsl.y = hsl.y * (1.0 - colorTone.a / 255.0);
vec3 rgb = hslToRgb(hsl);
float r = rgb.r;
float g = rgb.g;
float b = rgb.b;
float r2 = colorTone.r / 255.0;
float g2 = colorTone.g / 255.0;
float b2 = colorTone.b / 255.0;
float r3 = blendColor.r / 255.0;
float g3 = blendColor.g / 255.0;
float b3 = blendColor.b / 255.0;
float i3 = blendColor.a / 255.0;
float i1 = 1.0 - i3;
r = clamp((r / a + r2) * a, 0.0, 1.0);
g = clamp((g / a + g2) * a, 0.0, 1.0);
b = clamp((b / a + b2) * a, 0.0, 1.0);
r = clamp(r * i1 + r3 * i3 * a, 0.0, 1.0);
g = clamp(g * i1 + g3 * i3 * a, 0.0, 1.0);
b = clamp(b * i1 + b3 * i3 * a, 0.0, 1.0);
r = r * brightness / 255.0;
g = g * brightness / 255.0;
b = b * brightness / 255.0;
gl_FragColor = vec4(r, g, b, a);
}`;
};
//-----------------------------------------------------------------------------
// TilingSprite
if (bgSyncMethods.length) {
const _TilingSprite_initialize = TilingSprite.prototype.initialize;
TilingSprite.prototype.initialize = function(bitmap) {
_TilingSprite_initialize.apply(this, arguments);
this._hue = 0;
this._brightness = 255;
this._blendColor = ;
this._colorTone = ;
this._colorFilter = null;
};
TilingSprite.prototype.setHue = function(hue) {
if (this._hue !== Number(hue)) {
this._hue = Number(hue);
this._updateColorFilter();
}
};
TilingSprite.prototype.setBrightness = function(brightness) {
if (this._brightness !== Number(brightness)) {
this._brightness = Number(brightness);
this._updateColorFilter();
}
};
TilingSprite.prototype.setOpacity = function(opacity) {
this.opacity = opacity;
};
TilingSprite.prototype.getBlendColor = function() {
return this._blendColor.clone();
};
TilingSprite.prototype.setBlendColor = function(color) {
if (!(color instanceof Array)) {
throw new Error("Argument must be an array");
}
if (!this._blendColor.equals(color)) {
this._blendColor = color.clone();
this._updateColorFilter();
}
};
TilingSprite.prototype.getColorTone = function() {
return this._colorTone.clone();
};
TilingSprite.prototype.setColorTone = function(tone) {
if (!(tone instanceof Array)) {
throw new Error("Argument must be an array");
}
if (!this._colorTone.equals(tone)) {
this._colorTone = tone.clone();
this._updateColorFilter();
}
};
TilingSprite.prototype._createColorFilter = function() {
this._colorFilter = new ColorFilter();
if (!this.filters) {
this.filters = [];
}
this.filters.push(this._colorFilter);
};
TilingSprite.prototype._updateColorFilter = function() {
if (!this._colorFilter) {
this._createColorFilter();
}
this._colorFilter.setHue(this._hue);
this._colorFilter.setBrightness(this._brightness);
this._colorFilter.setBlendColor(this._blendColor);
this._colorFilter.setColorTone(this._colorTone);
this._colorFilter.enabled = this._hue > 0 || this._brightness < 255 || !this._blendColor.equals() || !this._colorTone.equals();
};
}
//-----------------------------------------------------------------------------
// Scene_Boot
//事前に変換して初回時を軽量化
if (preconvert && !DataManager.isBattleTest()) {
const _Scene_Boot_create = Scene_Boot.prototype.create;
Scene_Boot.prototype.create = function() {
_Scene_Boot_create.apply(this, arguments);
const sprite = new Sprite();
const filter = new TileColorFilter();
sprite.filters = ;
this.addChild(sprite);
};
}
}
页:
[1]