Last active
September 11, 2021 14:53
-
-
Save oggy83/194b8fede446244e5992374002c25c41 to your computer and use it in GitHub Desktop.
Oggy_PictureMaskMZ.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*:ja | |
* @target MZ | |
* @plugindesc ピクチャにマスクをかけるプラグイン | |
* @author oggy (http://www.oggy-rpg.com/) | |
* @beforeThan PluginBaseFunction | |
* | |
* @command SET_PICTURE_MASK | |
* @text ピクチャを別のピクチャのマスク画像として適用する | |
* | |
* @arg target | |
* @text マスクを適用するピクチャのID | |
* @type number | |
* @min 1 | |
* @max 100 | |
* @decimals 0 | |
* | |
* @arg mask | |
* @text マスク用のピクチャのID | |
* @type number | |
* @min 1 | |
* @max 100 | |
* @decimals 0 | |
* | |
* @command CLEAR_PICTURE_MASK | |
* @text ピクチャに適用されたマスク画像を戻す | |
* | |
* @arg target | |
* @text マスクを適用するピクチャのID | |
* @type number | |
* @min 1 | |
* @max 100 | |
* @decimals 0 | |
*/ | |
(() => { | |
'use strict'; | |
const script = document.currentScript; | |
const param = PluginManagerEx.createParameter(script); | |
PluginManagerEx.registerCommand(script, 'SET_PICTURE_MASK', function(args) { | |
this.setPictureMask(args); | |
}); | |
PluginManagerEx.registerCommand(script, 'CLEAR_PICTURE_MASK', function(args) { | |
this.clearPictureMask(args); | |
}); | |
Game_Interpreter.prototype.setPictureMask = function(args) { | |
var maskPicture = $gameScreen.picture(args.mask); | |
if (!maskPicture) { | |
console.error("ピクチャIDが不正です(" + args.mask + ")"); | |
return; | |
} | |
var targetPicture = $gameScreen.picture(args.target); | |
if (!targetPicture) { | |
console.error("ピクチャIDが不正です(" + args.target + ")"); | |
return; | |
} | |
targetPicture.maskPictureId = args.mask; | |
}; | |
Game_Interpreter.prototype.clearPictureMask = function(args) { | |
var targetPicture = $gameScreen.picture(args.target); | |
if (!targetPicture) { | |
console.error("ピクチャIDが不正です(" + args.target + ")"); | |
return; | |
} | |
targetPicture.maskPictureId = 0; | |
}; | |
Object.defineProperty(Game_Picture.prototype, 'maskPictureId', { | |
get: function() { | |
return this._maskPictureId || 0; | |
}, | |
set: function(value) { | |
this._maskPictureId = value; | |
}, | |
configurable: true | |
}); | |
var _Oggy_Sprite_Picture_update = Sprite_Picture.prototype.update; | |
Sprite_Picture.prototype.update = function() { | |
_Oggy_Sprite_Picture_update.call(this); | |
this._updateMask(); | |
}; | |
Sprite_Picture.prototype._updateMask = function() { | |
var picture = this.picture(); | |
if (!picture) { | |
return; | |
} | |
if (this.mask != null && picture.maskPictureId === 0) { | |
this.mask = null; | |
} else if (this.mask == null && picture.maskPictureId !== 0) { | |
if ((SceneManager.isCurrentScene(Scene_Map) || SceneManager.isCurrentScene(Scene_Battle)) | |
&& SceneManager._scene._spriteset) { | |
var pictureContainer = SceneManager._scene._spriteset._pictureContainer; | |
var mask = pictureContainer.getChildAt(this.picture().maskPictureId - 1); | |
this.mask = mask; | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment