-
Notifications
You must be signed in to change notification settings - Fork 41
/
OrangeScreenshotSaver.js
62 lines (51 loc) · 1.91 KB
/
OrangeScreenshotSaver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*=============================================================================
* Orange - Screenshot Saver
* By Hudell - www.hudell.com
* OrangeScreenshotSaver.js
* Version: 1.0
* Free for commercial and non commercial use.
*=============================================================================*/
/*:
* @plugindesc This plugin will automatically save screenshots in a "Screenshots" folder inside the game
*
* @author Hudell
*/
var Imported = Imported || {};
var OrangeScreenshotSaver = OrangeScreenshotSaver || {};
(function($) {
"use strict";
$.generateFileName = function(){
var date = new Date();
return '' + date.getFullYear() + '_' + (date.getMonth() + 1) + '_' + date.getDate() + '_' + date.getHours() + '_' + date.getMinutes() + '_' + date.getSeconds() + '_' + date.getMilliseconds() + '_' + Math.floor(Math.random() * 5000) + '.png';
};
$.saveScreenshot = function(){
if (!Utils.isNwjs()) return;
var fs = require('fs');
var path = './Screenshots';
try {
fs.mkdir(path, function(){
var fileName = path + '/' + $.generateFileName();
var snap = SceneManager.snap();
var urlData = snap._canvas.toDataURL();
var base64Data = urlData.replace(/^data:image\/png;base64,/, "");
fs.writeFile(fileName, base64Data, 'base64', function(error){
if (error !== undefined && error !== null) {
console.error('An error occured while saving the screenshot', error);
}
});
});
} catch(error) {
if (error !== undefined && error !== null) {
console.error('An error occured while saving the screenshot:', error);
}
}
};
var oldInput_onKeyUp = Input._onKeyUp;
Input._onKeyUp = function(event) {
oldInput_onKeyUp.call(this, event);
if (event.keyCode == 44) {
$.saveScreenshot();
}
};
})(OrangeScreenshotSaver);
Imported["OrangeScreenshotSaver"] = true;