//=============================================================================
// * Dragon Refuge - RPG Maker Plugins by Jorge *
//=============================================================================
var
Dragon = Dragon || {};
Dragon.CommunityBoot = Dragon.CommunityBoot || { VERSION: [1, 0, 0] };
/*:@pluginname Dragon_CommunityBoot
* @plugindesc [MZ] [V1.0.0]
* @url http://dragonrefuge.net
* @target MZ
* @author The Dragon
*/
(($) => {
//-----------------------------------------------------------------------------
// Graphics
//
// The static class that carries out graphics processing.
const alias_Graphics_initialize = Graphics.initialize;
const alias_Graphics__switchFullScreen = Graphics._switchFullScreen;
const alias_Graphics__cancelFullScreen = Graphics._cancelFullScreen;
const alias_Graphics__requestFullScreen = Graphics._requestFullScreen;
const alias_Graphics__onKeyDown = Graphics._onKeyDown;
Object.assign(Graphics, {
initialize() {
const flag = alias_Graphics_initialize.apply(this, arguments);
this._setStretchMode(false);
this._canvas.style.imageRendering = 'pixelated';
document.body.style.overflow = 'hidden';
nw.Window.get().setResizable(false);
return flag;
},
_switchFullScreen() {
const win = nw.Window.get();
win.setResizable(true);
alias_Graphics__switchFullScreen.apply(this, arguments);
win.setResizable(false);
},
_cancelFullScreen() {
if (this._scaleBeforeFullscreen) {
this.defaultScale = this._scaleBeforeFullscreen
} else {
this.defaultScale = this._getSystemScreenScale();
}
alias_Graphics__cancelFullScreen.apply(this, arguments);
},
_requestFullScreen() {
this._scaleBeforeFullscreen = this.defaultScale;
this.defaultScale = this._getMaxIntegerScale();
alias_Graphics__requestFullScreen.apply(this, arguments);
},
_getSystemScreenScale() {
if ($dataSystem && "screenScale" in $dataSystem.advanced) {
return $dataSystem.advanced.screenScale;
} else {
return 1;
}
},
_setStretchMode(flag) {
const last = this._stretchEnabled;
this._stretchEnabled = !!flag;
if (this._stretchEnabled !== last) {
this._updateAllElements();
}
},
_getMaxIntegerScale(screenWidth = window.screen.width, screenHeight = window.screen.height) {
const
game = [Graphics.width, Graphics.height],
client = [screenWidth, screenHeight],
min = Math.min(...client),
i = client.indexOf(min);
return Math.max(1, Math.floor(min / game[i]));
},
_onKeyDown(event) {
if (!event.ctrlKey && !event.altKey) {
switch (event.keyCode) {
case 112: // F1
event.preventDefault();
if (this._isFullScreen()) {
this.defaultScale = Math.max(1, (this.defaultScale + 1) % (this._getMaxIntegerScale() + 1));
} else {
this.defaultScale = Math.max(1, (this.defaultScale + 1) % (this._getMaxIntegerScale(window.screen.availWidth, window.screen.availHeight) + 1));
this._updateWindow(0.5, 0.5);
}
break;
default:
console.log(alias_Graphics__onKeyDown);
return alias_Graphics__onKeyDown.apply(this, arguments);
}
}
},
_updateWindow(ox = 0, oy = 0) {
if (Utils.isNwjs()) {
const win = nw.Window.get();
console.log(win)
win.setResizable(true);
const xDelta = (this.width * this.defaultScale) - window.innerWidth;
const yDelta = (this.height * this.defaultScale) - window.innerHeight;
window.moveBy(-xDelta * ox, -yDelta * oy);
win.resizeBy(xDelta, yDelta);
win.setResizable(false);
}
}
});
//-----------------------------------------------------------------------------
// Scene_Boot
//
// The scene class for initializing the entire game.
Object.assign(Scene_Boot.prototype, {
adjustWindow() {
Graphics.defaultScale = Graphics._getSystemScreenScale();
Graphics._updateWindow(0.5, 0.5);
}
});
})(Dragon.CommunityBoot);