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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
| //==============================================================================
// 808PrintScreen
//==============================================================================
// File: 808PrintScreen.js
// v1.0
// 7th Sep 2024
//==============================================================================
/*:
* @plugindesc v1.0 Allows taking screenshots by pressing a specified key and saving them to the 'screenshots' folder. Optionally displays a notification on screen.
* @author mugen808
* @param Screenshot Key
* @desc The key to press for taking a screenshot. Default: F7
* @default F7
* @param Screenshot Notification
* @type boolean
* @desc Whether to display a screenshot notification on screen. Default: true
* @default true
* @help
*==============================================================================
* 808PrintScreen
*==============================================================================
*
* This plugin enables taking screenshots of the game by pressing a specified
* key. Screenshots are saved in a 'screenshots' folder in the game directory.
*
* -Available keys:
* F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, A, B, C, D, E, F, G, H,
* I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, 0, 1, 2, 3, 4, 5, 6,
* 7, 8, 9, Shift, Ctrl, Alt, Space, Enter, Escape, Left, Up, Right, Down,
* PrintScreen.
*
*
* By default, a notification will be displayed on the screen when a screenshot
* is taken. This can be deactivate in the plugin parameters.
*
* The screenshot will still be logged in the console regardless of the
* notification setting.
*
* -Parameters:
* Screenshot Key: The key to press for taking a screenshot (default: F7).
*
* Screenshot Notification: Whether to display a notification on the screen
* (default: true).
*
*
*==============================================================================
* Terms
*==============================================================================
*
* Free to use. Redistribution not permitted.
*
*..............................................................................
*/
(function() {
const fs = require('fs');
const path = require('path');
const parameters = PluginManager.parameters('808PrintScreen');
const screenshotKey = parameters['Screenshot Key'] || 'F7';
const screenshotNotification = String(parameters['Screenshot Notification'] || 'false').toLowerCase() === 'true';
function getKeyCode(keyName) {
const keyCodes = {
'F1'span style="color:#7cc4f5;"> : 112, 'F2'span style="color:#7cc4f5;"> : 113, 'F3'span style="color:#7cc4f5;"> : 114, 'F4'span style="color:#7cc4f5;"> : 115, 'F5'span style="color:#7cc4f5;"> : 116, 'F6'span style="color:#7cc4f5;"> : 117, 'F7'span style="color:#7cc4f5;"> : 118, 'F8'span style="color:#7cc4f5;"> : 119, 'F9'span style="color:#7cc4f5;"> : 120, 'F10'span style="color:#7cc4f5;"> : 121, 'F11'span style="color:#7cc4f5;"> : 122, 'F12'span style="color:#7cc4f5;"> : 123,
'A'span style="color:#7cc4f5;"> : 65, 'B'span style="color:#7cc4f5;"> : 66, 'C'span style="color:#7cc4f5;"> : 67, 'D'span style="color:#7cc4f5;"> : 68, 'E'span style="color:#7cc4f5;"> : 69, 'F'span style="color:#7cc4f5;"> : 70, 'G'span style="color:#7cc4f5;"> : 71, 'H'span style="color:#7cc4f5;"> : 72, 'I'span style="color:#7cc4f5;"> : 73, 'J'span style="color:#7cc4f5;"> : 74, 'K'span style="color:#7cc4f5;"> : 75, 'L'span style="color:#7cc4f5;"> : 76, 'M'span style="color:#7cc4f5;"> : 77, 'N'span style="color:#7cc4f5;"> : 78, 'O'span style="color:#7cc4f5;"> : 79, 'P'span style="color:#7cc4f5;"> : 80, 'Q'span style="color:#7cc4f5;"> : 81, 'R'span style="color:#7cc4f5;"> : 82, 'S'span style="color:#7cc4f5;"> : 83, 'T'span style="color:#7cc4f5;"> : 84, 'U'span style="color:#7cc4f5;"> : 85, 'V'span style="color:#7cc4f5;"> : 86, 'W'span style="color:#7cc4f5;"> : 87, 'X'span style="color:#7cc4f5;"> : 88, 'Y'span style="color:#7cc4f5;"> : 89, 'Z'span style="color:#7cc4f5;"> : 90,
'0'span style="color:#7cc4f5;"> : 48, '1'span style="color:#7cc4f5;"> : 49, '2'span style="color:#7cc4f5;"> : 50, '3'span style="color:#7cc4f5;"> : 51, '4'span style="color:#7cc4f5;"> : 52, '5'span style="color:#7cc4f5;"> : 53, '6'span style="color:#7cc4f5;"> : 54, '7'span style="color:#7cc4f5;"> : 55, '8'span style="color:#7cc4f5;"> : 56, '9'span style="color:#7cc4f5;"> : 57,
'Shift'span style="color:#7cc4f5;"> : 16, 'Ctrl'span style="color:#7cc4f5;"> : 17, 'Alt'span style="color:#7cc4f5;"> : 18, 'Space'span style="color:#7cc4f5;"> : 32, 'Enter'span style="color:#7cc4f5;"> : 13, 'Escape'span style="color:#7cc4f5;"> : 27, 'Left'span style="color:#7cc4f5;"> : 37, 'Up'span style="color:#7cc4f5;"> : 38, 'Right'span style="color:#7cc4f5;"> : 39, 'Down'span style="color:#7cc4f5;"> : 40,
'PrintScreen'span style="color:#7cc4f5;"> : 44
};
return keyCodes[keyName] || null;
}
const keyCode = getKeyCode(screenshotKey);
if (keyCode === null) {
throw new Error(`Invalid key: ${screenshotKey}`);
}
Input.keyMapper[keyCode] = 'screenshot';
let screenshotQueue = [];
let screenshotTimeout = null;
function getNextFileName(dirPath) {
for (let i = 1; i <= 999; i++) { // limit of screenshot files in the folder
const fileName = `img${String(i).padStart(3, '0')}.png`;
const filePath = path.join(dirPath, fileName);
if (!fs.existsSync(filePath)) {
return fileName;
}
}
return null; // No available file names
}
function takeScreenshot() {
const dirPath = path.join(process.cwd(), 'screenshots');
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath);
}
const fileName = getNextFileName(dirPath);
if (!fileName) {
console.error('Screenshot limit reached. Please delete some screenshots and try again.');
if (screenshotNotification) {
displayScreenshotText('Screenshot limit reached. Please delete some screenshots and try again.');
}
return;
}
const filePath = path.join(dirPath, fileName);
const bitmap = Graphics._canvas.toDataURL('image/png').replace(/^data:image\/png;base64,/, "");
fs.writeFile(filePath, bitmap, 'base64', function(err) {
if (err) {
console.error('Failed to save screenshot:', err);
} else {
console.log('Screenshot saved as', fileName);
if (screenshotNotification) {
displayScreenshotText(fileName);
}
}
});
}
function displayScreenshotText(message) {
const text = new PIXI.Text(`Screenshot ${message}`, { fontFamily: 'Arial', fontSize: 12, fill: 'white' });
text.x = Graphics.width - text.width - 10;
text.y = 10 + screenshotQueue.length * 20;
SceneManager._scene.addChild(text);
screenshotQueue.push(text);
setTimeout(() => {
SceneManager._scene.removeChild(text);
screenshotQueue.shift();
updateScreenshotQueue();
}, 2150);
}
function updateScreenshotQueue() {
screenshotQueue.forEach((text, index) => {
text.y = 10 + index * 20;
});
}
const alias_SceneManager_update = SceneManager.update;
SceneManager.update = function() {
alias_SceneManager_update.call(this);
if (Input.isTriggered('screenshot')) {
if (!screenshotTimeout) {
takeScreenshot();
screenshotTimeout = setTimeout(() => {
screenshotTimeout = null;
}, 200);
}
}
};
})();
|