-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpgmvp2png.html
180 lines (163 loc) · 5.01 KB
/
rpgmvp2png.html
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>RPG Maker MV 文件转换工具</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
max-width: 500px;
width: 100%;
background-color: #fff;
border-radius: 5px;
padding: 30px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
}
.file-input {
margin-bottom: 20px;
}
.file-input label {
display: block;
font-size: 16px;
margin-bottom: 10px;
}
.file-input input[type="file"] {
display: inline-block;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
padding: 6px 12px;
cursor: pointer;
}
.option-input {
margin-bottom: 20px;
}
.option-input label {
display: inline-flex;
align-items: center;
font-size: 14px;
color: #555;
cursor: pointer;
}
.option-input input[type="checkbox"] {
margin-right: 8px;
}
.footer {
font-size: 12px;
color: #888;
margin-top: 20px;
}
.github-link {
margin-top: 5px;
text-align: center;
font-size: 12px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js"></script>
<script>
// 转换 RPG Maker MV 文件的函数
function decryptRPGMVPFile(file) {
return new Promise((resolve) => {
const reader = new FileReader();
reader.onload = function (e) {
const data = new Uint8Array(e.target.result);
const pngHeader = new Uint8Array([
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00,
0x0d, 0x49, 0x48, 0x44, 0x52,
]);
const pngData = new Uint8Array(pngHeader.length + data.length - 32);
pngData.set(pngHeader);
pngData.set(data.slice(32), pngHeader.length);
resolve(pngData);
};
reader.readAsArrayBuffer(file);
});
}
// 处理文件选择事件的函数
async function handleFileSelect(event) {
const files = event.target.files;
const packFiles = document.getElementById("pack-files").checked;
if (packFiles) {
// 将所有图片打包在一起下载
const zipWriter = new JSZip();
const decryptPromises = [];
for (const file of files) {
if (file.name.endsWith(".rpgmvp")) {
decryptPromises.push(
decryptRPGMVPFile(file).then((pngData) => {
zipWriter.file(file.name.replace(".rpgmvp", ".png"), pngData);
})
);
}
}
await Promise.all(decryptPromises);
const content = await zipWriter.generateAsync({ type: "blob" });
const url = URL.createObjectURL(content);
const link = document.createElement("a");
link.href = url;
link.download = "converted_files.zip";
link.click();
URL.revokeObjectURL(url);
} else {
// 单独下载每个图片
for (const file of files) {
if (file.name.endsWith(".rpgmvp")) {
const pngData = await decryptRPGMVPFile(file);
const blob = new Blob([pngData], { type: "image/png" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = file.name.replace(".rpgmvp", ".png");
link.click();
URL.revokeObjectURL(url);
}
}
}
}
</script>
</head>
<body>
<div class="container">
<h1>RPG Maker MV 文件转换工具</h1>
<div class="file-input">
<label for="file" class="file-label"
>选择一个或多个 .rpgmvp 文件:</label
>
<input
type="file"
id="file"
accept=".rpgmvp"
onchange="handleFileSelect(event)"
multiple
/>
</div>
<div class="option-input">
<label class="checkbox-label">
<input type="checkbox" id="pack-files" />
<span class="checkbox-text">将所有转换后的图片打包下载</span>
</label>
</div>
<div class="github-link">
<p>请访问项目的 GitHub 仓库以获取更多信息和源代码:</p>
<a href="https://github.com/DrRyanHuang/rpgmvp2png" target="_blank"
>https://github.com/DrRyanHuang/rpgmvp2png</a
>
</div>
<div class="footer">© 2024 RPG Maker MV 文件转换工具</div>
</div>
</body>
</html>