Last active
January 26, 2022 00:32
-
-
Save fluid-decanter/f5b4d5a100433e1c69070b2f739bfa1f to your computer and use it in GitHub Desktop.
Addon to Galv's Message Busts plugin to support using facesets when no bust can be found.
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
// GALV_MessageBusts_SubEmpty_Addon.js | |
/*: | |
@plugindesc v0.1 Addon to Galv's Message Busts plugin to support using facesets when no bust can be found. | |
@author Decanter | |
@help | |
Place directly after Galv's Message Busts in the plugin order, as this addon directly overrides several methods. Be sure both plugins are somewhere after Yanfly's Message Core, if using that. | |
How it works: If the game tries to load an image - any image - that doesn't exist, it will load an invisible placeholder image instead (overriding the engine's normal behavior, which is to just throw an error message and crash). Then, in the context of deciding whether to show a face or a bust, the game basically asks "is this bust a real image or a 0x0 placeholder image" and if it's placeholder then it will show the face. | |
Full disclosure: I developed this plugin for a particular project I liked - Once Ever After, an adult game by Sierra Lee - and only tested it against that project's use cases. | |
Terms of use: Just give me credit. If you modify the plugin, make a note of that. | |
*/ | |
// OVERRIDE - Will replace errored bitmap with empty bitmap. | |
ImageManager.isReady = function() { | |
for (var key in this._cache) { | |
var bitmap = this._cache[key]; | |
if (bitmap.isError()) { | |
// throw new Error('Failed to load: ' + bitmap.url); | |
this._cache[key] = this.loadEmptyBitmap(); | |
} | |
if (!bitmap.isReady()) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
// OVERRIDE | |
Game_Message.prototype.setFaceImage = function(faceName, faceIndex) { | |
switch (faceName) { | |
case 'PartyLeader': | |
var faceName = $gameParty.leader().faceName(); | |
break; | |
case 'PartyMember': | |
if ($gameParty.members()[faceIndex]) { | |
var faceName = $gameParty.members()[faceIndex].faceName(); | |
var faceIndex = $gameParty.members()[faceIndex].faceIndex(); | |
} else { | |
var faceName = ""; | |
}; | |
break; | |
}; | |
tempName = faceName + "_" + (faceIndex + 1); // using function arguments, be careful | |
Galv.MB.ImageChecker(tempName); | |
Galv.MB.Game_Message_setFaceImage.call(this,faceName,faceIndex); | |
}; | |
// OVERRIDE | |
Window_Message.prototype.drawMessageFace = function() { | |
var name = $gameMessage.faceName() + "_" + ($gameMessage.faceIndex() + 1); | |
Galv.MB.ImageChecker(name); | |
if (!$gameSystem.bustDisableTemp) { | |
// belatedly change x offset since it's normally decided too soon for ImageChecker | |
this._textState.x = this.newLineX(); | |
this._textState.left = this.newLineX(); | |
return; | |
} | |
Galv.MB.Window_Message_drawMessageFace.call(this); | |
}; | |
// NEW | |
Galv.MB.ImageChecker = function(name){ | |
$gameSystem.bustDisableTemp = $gameSystem.bustDisable || false; // renew per-line bust status | |
if ($gameSystem.bustDisableTemp == false) { | |
var img = ImageManager.loadPicture(name + Galv.MB.f); | |
if (img.height <= 1) { | |
$gameSystem.bustDisableTemp = true; | |
} | |
} | |
return; | |
}; | |
// OVERRIDES | |
if (Galv.MB.prio == 0) { | |
// UNDER MESSAGE | |
Window_Message.prototype.newLineX = function() { | |
if ($gameSystem.bustDisableTemp) { | |
return Galv.MB.Window_Message_newLineX.call(this); | |
} else { | |
return 0; | |
}; | |
}; | |
} else { | |
// OVER MESSAGE | |
Window_Message.prototype.newLineX = function() { | |
if ($gameSystem.bustDisableTemp) { | |
return Galv.MB.Window_Message_newLineX.call(this); | |
} else if ($gameMessage.faceName() && Galv.MB.prio == 1 && $gameMessage._positionType == 2 && $gameSystem.bustPos == 0) { | |
return $gameMessage.bustOffset; | |
} else { | |
return 0; | |
}; | |
}; | |
}; | |
// OVERRIDE | |
Sprite_GalvBust.prototype.loadBitmap = function() { | |
var name = $gameMessage.faceName() + "_" + ($gameMessage.faceIndex() + 1); | |
if ($gameSystem.bustDisableTemp) { | |
var img = ImageManager.loadPicture(''); | |
} else { | |
var img = ImageManager.loadPicture(name + Galv.MB.f); | |
}; | |
if (img.isReady()) { | |
if (this.bitmap) { | |
//this._destroyCachedSprite(); | |
this.bitmap = null; | |
}; | |
this.bitmap = img; | |
this.name = name; | |
this.hasBust = true; | |
}; | |
}; | |
// OVERRIDE | |
Sprite_GalvBust.prototype.controlBitmap = function() { | |
// if image changed... | |
if ($gameMessage.faceName() && this.name !== $gameMessage.faceName() + "_" + ($gameMessage.faceIndex() + 1)) { | |
this.loadBitmap(); // reload bitmap | |
}; | |
if (Galv.MB.msgWindow.openness <= 0 || !this.hasBust || $gameSystem.bustDisableTemp) { | |
this.opacity = 0; | |
this.name = ""; | |
this.hasBust = false; | |
return; | |
}; | |
if ($gameSystem.bustMirror) { | |
this.scale.x = -1; | |
var offset = this.bitmap.width; | |
} else { | |
this.scale.x = 1; | |
var offset = 0; | |
}; | |
this.opacity = $gameMessage.faceName() ? Galv.MB.msgWindow._openness : this.opacity - Galv.MB.fadeOutSpeed; | |
// Control image position | |
switch (Galv.MB.msgWindow.tempPosType) { | |
case 0: | |
this.y = this.baseY(); | |
break; | |
case 1: | |
//top and middle | |
this.y = this.baseY() - Galv.MB.msgWindow.y; | |
break; | |
case 2: | |
//bottom | |
if (Galv.MB.prio == 1) { | |
this.y = Galv.MB.msgWindow.height - this.bitmap.height; | |
} else if (Galv.MB.pos === 1) { | |
this.y = this.baseY(); | |
} else { | |
this.y = this.baseY() - Galv.MB.msgWindow.height; | |
}; | |
break; | |
}; | |
if ($gameSystem.bustPos == 1) { | |
// if on the right | |
if (Galv.MB.prio == 1) { | |
this.x = Galv.MB.msgWindow.width - this.bitmap.width + offset; | |
} else { | |
this.x = Galv.MB.msgWindow.x + Galv.MB.msgWindow.width - this.bitmap.width + offset; | |
}; | |
} else { | |
// else on the left | |
if (Galv.MB.prio == 1) { | |
this.x = 0 + offset; | |
} else { | |
this.x = Galv.MB.msgWindow.x + offset; | |
}; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment