216 lines
6.4 KiB
JavaScript
216 lines
6.4 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc 画像を合成します
|
||
* @author
|
||
*
|
||
* @help 画像合成プラグイン
|
||
* オルタカスタマイズ
|
||
* 変数 914を利用
|
||
*
|
||
*
|
||
*/
|
||
|
||
var CBR = CBR || {};
|
||
CBR.imgFusion = {};
|
||
|
||
var _CBRimgFusion_Game_System_initialize = Game_System.prototype.initialize;
|
||
Game_System.prototype.initialize = function () {
|
||
_CBRimgFusion_Game_System_initialize.call(this);
|
||
|
||
this._CBR_imgFusion = {};
|
||
this._CBR_imgFusion._fusionList = [];
|
||
this._CBR_imgFusion._fusionList._start = -1;
|
||
};
|
||
|
||
if (typeof CBR_Game_Interpreter_command355 === "undefined") {
|
||
const CBR_Game_Interpreter_command355 = Game_Interpreter.prototype.command355;
|
||
Game_Interpreter.prototype.command355 = function () {
|
||
//CBR-xxxの場合CBR.xxxにobjを渡す
|
||
let key = this.currentCommand().parameters[0];
|
||
if (key.match(/^CBR\-/)) {
|
||
let obj = [];
|
||
//下に続いてるスクリプトの取得
|
||
while (this.nextEventCode() === 655) {
|
||
this._index++;
|
||
obj[obj.length] = this.currentCommand().parameters[0];
|
||
}
|
||
const temp = key.split("-");
|
||
//CBR-×××があったら
|
||
if (CBR[temp[1]]) {
|
||
//下に続くデータを入れる
|
||
CBR[temp[1]](obj);
|
||
}
|
||
//普通にスクリプト実行
|
||
} else {
|
||
CBR_Game_Interpreter_command355.call(this);
|
||
}
|
||
return true;
|
||
};
|
||
}
|
||
|
||
// 同じ画像名があるなら無い場合lengthを返す、findIndex使った方がよくね? こっちの方が見易いか
|
||
CBR.imgFusion.getKey = function (name, make) {
|
||
//後に何があるかわからないから.pngは残す
|
||
const ary = $gameSystem._CBR_imgFusion._fusionList;
|
||
let key = -1;
|
||
for (var i = 0, len = ary.length; i < len; i++) {
|
||
if (ary[i].base == name) {
|
||
key = i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (key === -1 && make) {
|
||
//存在しなくてmakeがtrueの時は最後尾に作るようにする
|
||
return ary.length;
|
||
} else {
|
||
return key;
|
||
}
|
||
};
|
||
|
||
//合成するぞー
|
||
CBR["画像合成"] = function (aryOri) {
|
||
var ary = [];
|
||
|
||
aryOri.forEach((e) => {
|
||
if (e.charAt(0) === "@") {
|
||
var data = e.split("/");
|
||
var type = data[0].slice(1);
|
||
|
||
//汁データが入ってる変数
|
||
var numberEki = 0;
|
||
var numberFuku = 0;
|
||
if (data[1] == "sir") {
|
||
numberEki = 901;
|
||
numberFuku = 204;
|
||
} else if (data[1] == "yoz") {
|
||
numberEki = 902;
|
||
numberFuku = 205;
|
||
} else if (data[1] == "rei") {
|
||
numberEki = 903;
|
||
numberFuku = 206;
|
||
} else if (data[1] == "kao") {
|
||
numberEki = 904;
|
||
numberFuku = 207;
|
||
} else if (data[1] == "kur") {
|
||
numberEki = 905;
|
||
numberFuku = 208;
|
||
} else if (data[1] == "chi") {
|
||
numberEki = 906;
|
||
numberFuku = 209;
|
||
} else if (data[1] == "mir") {
|
||
numberEki = 907;
|
||
numberFuku = 210;
|
||
} else if (data[1] == "aki") {
|
||
numberEki = 908;
|
||
numberFuku = 211;
|
||
} else if (data[1] == "nar") {
|
||
numberEki = 909;
|
||
numberFuku = 212;
|
||
} else if (data[1] == "kag") {
|
||
numberEki = 910;
|
||
numberFuku = 213;
|
||
}
|
||
// 部位名 キャラ名 ポーズ番号 服番号
|
||
if ($gameVariables.value(numberEki)[type]) {
|
||
ary.push(`cha_${type}_${data[1]}_${data[2]}_${$gameVariables.value(numberFuku)}.png`);
|
||
}
|
||
} else {
|
||
ary.push(e);
|
||
}
|
||
});
|
||
|
||
// [ベース,画像,画像,,,,,]
|
||
$gameVariables.setValue(914, ary.slice(0, ary.length + 1));
|
||
|
||
//ベースと要素の変数を実行
|
||
for (let i = 0, len = ary.length; i < len; i++) {
|
||
ary[i] = ary[i].replace(/\\V\[(\d+)\]/g, function (a, b) {
|
||
// 変数を入れる
|
||
return $gameVariables.value(b);
|
||
});
|
||
}
|
||
|
||
const base = ary.shift().slice(1, -1);
|
||
const key = CBR.imgFusion.getKey(base, true); // あったら上書き、無かったら新しく作るのでtrue
|
||
$gameSystem._CBR_imgFusion._fusionList[key] = {
|
||
//上書きしました
|
||
base: base,
|
||
add_ary: ary
|
||
};
|
||
|
||
//もし指定した画像がロード済み・表示中だったら・アップデートでimgfusionするように
|
||
for (let i = 0, len = $gameScreen.maxPictures(); i < len; i++) {
|
||
const pic = SceneManager._scene._spriteset._pictureContainer.children[i];
|
||
if (pic._pictureName + ".png" == base) {
|
||
if (pic.bitmap._loadingState === "loaded") {
|
||
pic.CBR_ImgFusion(pic.bitmap, pic._pictureName);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
};
|
||
|
||
//画像合成 → _onBitmapLoad →imgfusion→updateで毎回確認
|
||
//startの時画像が読み込まれてたらコレを実行する
|
||
Sprite_Picture.prototype.CBR_ImgFusion = function (bitmap, name) {
|
||
const key = CBR.imgFusion.getKey(name + ".png");
|
||
const ary = $gameSystem._CBR_imgFusion._fusionList[key];
|
||
if (ary) {
|
||
const ary2 = [];
|
||
bitmap.CBR_reLoad = false;
|
||
ary.add_ary.forEach((val, index) => {
|
||
ary2.push(ImageManager.loadBitmap("img/pictures/", val.slice(0, -4), undefined, true));
|
||
//要素が読み込まれてなかったら非表示、要素ロード後にまたココを実行
|
||
if (ary2[index]._loadingState != "loaded") {
|
||
bitmap.CBR_reLoad = true;
|
||
}
|
||
});
|
||
|
||
if (!bitmap.CBR_reLoad) {
|
||
// 問題なければそのまま描写
|
||
bitmap.clear();
|
||
bitmap.context.globalCompositeOperation = "normal";
|
||
bitmap.context.drawImage(bitmap._image, 0, 0);
|
||
ary2.forEach((val, index) => {
|
||
//ONEONE1用
|
||
bitmap.context.globalCompositeOperation = "normal";
|
||
// if (val._url.match(/cha_/)) {
|
||
// bitmap.context.globalCompositeOperation = "multiply";
|
||
// }
|
||
//ONEONE1用
|
||
bitmap.context.drawImage(val._image, 0, 0);
|
||
});
|
||
} else {
|
||
// 未ロードの要素があったら消す
|
||
// 何故かclearRectすると色々とフレッシュする
|
||
bitmap.context.clearRect(0, 0, bitmap.width, bitmap.height);
|
||
}
|
||
}
|
||
};
|
||
|
||
//もし今とベースが同じでパーツが未ロードだったらクリアしない
|
||
var Sprite_Picture_update = Sprite_Picture.prototype.update;
|
||
Sprite_Picture.prototype.update = function () {
|
||
Sprite_Picture_update.call(this);
|
||
|
||
if (this.picture() && this.bitmap) {
|
||
if (this.bitmap.CBR_reLoad) {
|
||
this.CBR_ImgFusion(this.bitmap, this._pictureName);
|
||
}
|
||
}
|
||
};
|
||
|
||
//これから画像読みこんだので表示しますってヤツ
|
||
Sprite_Picture.prototype._onBitmapLoad = function (bitmapLoaded) {
|
||
if (bitmapLoaded === this._bitmap) {
|
||
if (this._refreshFrame && this._bitmap) {
|
||
this._refreshFrame = false;
|
||
this._frame.width = this._bitmap.width;
|
||
this._frame.height = this._bitmap.height;
|
||
|
||
this.CBR_ImgFusion(this.bitmap, this._pictureName);
|
||
}
|
||
}
|
||
this._refresh();
|
||
};
|