//============================================================================= // EISScreenShots.js //============================================================================= /*: * * @author Kino * @plugindesc This tool allows you to take in game screenshots. * * @param ScreenShot Key * @desc Sets the screenshot key to be this key. * @default P * * @param Map Screenshot Key * @desc Sets the screenshot key for getting non blurred map screenshots. * @default O * * @param Folder Name * @desc Creates/Sets the Folder Name for screenshots in the root directory. * @default ScreenShots * * @help * Version 1.01 * * Function * takeScreenShot(fileName, extension) * - Takes a screenshot of the game window with an extension of your * choice. For example, jpg, jpeg, gif, png. * Example: KR.takeScreenShot("MyFirstScreenShot", "png"); * - This sends a picture called MyFirstScreenShot.png to your screenshot folder, * and creates one if it doesn't exist. * * Contact me via twitter: EISKino, or on the rpg maker forums. * Username on forums: Kino. * Hope this plugin helps, and enjoy! * --Kino */ var KR = KR || {}; KR.Plugins = KR.Plugins || {}; (function($) { var parameters = PluginManager.parameters("EISScreenShots"); var screenshotKey = String(parameters['ScreenShot Key']); var mapScreenShotKey = String(parameters['Map Screenshot Key']); var filePathName = String(parameters['Folder Name']); $.Plugins.ScreenShotTool = function() { function ScreenShotManager() { } ScreenShotManager.gui = require("nw.gui"); ScreenShotManager.system = require("fs"); ScreenShotManager.gameWindow = ScreenShotManager.gui.Window.get(); ScreenShotManager.cachedBitmap = null; ScreenShotManager.setupListener = function() { document.addEventListener('keydown', this.takePicture.bind(this, event)); document.addEventListener('keydown', this.captureCleanScreen.bind(this, event)); }; ScreenShotManager.createPath = function(string) { var path = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, string); if (path.match(/^\/([A-Z]\:)/)) { path = path.slice(1); } path = decodeURIComponent(path); return path; }; ScreenShotManager.createPictureData = function(fileName, extension) { var filePath = this.createPath("/" + filePathName + "/"); var that = this; extension = (typeof extension === 'undefined') ? 'png' : extension; if(!this.system.existsSync(filePath)) { this.system.mkdirSync(filePath); } this.gameWindow.capturePage(function(img) { img = img.replace(/^data:image\/(png|jpg|jpeg);base64,/, ""); that.system.writeFileSync(filePath + fileName + "." + extension, img, 'base64'); }, {format: extension, datatype: 'raw'}); }; ScreenShotManager.takeScreenShot = function(fileName, extension) { this.createPictureData(fileName, extension); }; ScreenShotManager.takeCleanPicture = function() { var bitmap = null; var scene = SceneManager._scene; var image = null; if(scene instanceof Scene_Map) { scene._windowLayer.visible = false; scene._spriteset.hideCharacters(); bitmap = SceneManager.snap(); scene._spriteset.showCharacters(); scene._windowLayer.visible = true; image = this.createImage(bitmap.canvas); bitmap = Bitmap.load(image); this.cachedBitmap = bitmap; } }; ScreenShotManager.replaceBitmap = function(bitmap) { ImageManager.reloadCachedBitmap(this.getCachedBitmapPath(), 0, this.cachedBitmap); }; ScreenShotManager.cacheBitmapPath = function(filePath) { this.cachedPath = filePath; }; ScreenShotManager.getCachedBitmapPath = function() { return this.cachedPath; }; ScreenShotManager.getCachedBitmap = function() { return this.cachedBitmap; }; ScreenShotManager.createImage = function(canvas) { var image = new Image(); image = canvas.toDataURL(); return image; }; ScreenShotManager.captureCleanScreen = function() { var event = arguments[1]; if(event.keyCode === mapScreenShotKey.charCodeAt(0)) { this.takeCleanPicture(); } }; ScreenShotManager.takePicture = function() { this.capture(arguments[1]); }; ScreenShotManager.capture = function(event) { if(event.keyCode === screenshotKey.toUpperCase().charCodeAt(0)) { var date = new Date(); var dateString = (date.getMonth() + 1) + "_" + date.getDate() + "_" + date.getFullYear() + "_" + (date.getHours() % 12) + "_" + date.getMinutes() + "_" + date.getSeconds(); this.takeScreenShot('ScreenShot' + "_" + dateString); } }; ScreenShotManager.setupListener(); //============================================================================= // Spriteset_Map //============================================================================= Spriteset_Map.prototype.showCharacters = function() { for (var i = 0; i < this._characterSprites.length; i++) { var sprite = this._characterSprites[i]; if (!sprite.isTile()) { sprite.show(); } } this.update(); }; //============================================================================= // ImageManager //============================================================================= ImageManager.reloadCachedBitmap = function(filePath, hue, bitmap) { hue = (hue > 0) ? hue : 0; this._cache[filePath + ":" + hue] = bitmap; }; //============================================================================= // Exports //============================================================================= $.takeScreenShot = function(fileName, extension) { ScreenShotManager.takeScreenShot(fileName, extension); }; $.cacheBitmapPath = function(path) { ScreenShotManager.cacheBitmapPath(path); }; $.getCachedBitmapPath = function() { return ScreenShotManager.getCachedBitmapPath(); }; $.getCachedBitmap = function() { return ScreenShotManager.getCachedBitmap(); }; $.takeCleanScreenShot = function() { ScreenShotManager.takeCleanPicture(); }; $.replaceBitmap = function(bitmap) { ScreenShotManager.replaceBitmap(bitmap); }; }; $.Plugins.ScreenShotTool(); })(KR);