-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_Resize.js
751 lines (597 loc) · 24.7 KB
/
RS_Resize.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
//================================================================
// RS_Resize.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2018 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc This plugin can resize Character and Tileset images for RPG Maker XP. <RS_Resize>
* @author biud436
* @help
* ===================================================================
* Character images
* ===================================================================
* To resize size of the character image for RPG Maker XP,
* You need to execute the following code.
*
* RS.Resize.convertCharacterImage();
*
* The above function creates a new image for RMXP.
* 'convert_img' folder will be going to automatically open after formed a work.
*
* ===================================================================
* Tileset images (Auto-tile floors and normal tiles)
* ===================================================================
* To convert tilesets used for RPG Maker XP, Start up the game and
* execute the following plugin command.
*
* CreateTilesets
*
* There is no arguments in the plugin command and read all tile set images.
* wait for a second after calling above plugin command
* and then it will be opened up the folder called 'convert_img'.
*
* ** Notice that the most of Auto-tiles doesn't be compatible with RMXP. **
*
* In the RPG Maker XP, Internally the one Auto-tile floor is that composited four tiles.
* Each tiles have a size 16 x 16 px, But tiles of RPG Maker MV have a size of 24 x 24px.
* You can understand they are different each other.
* Furthermore, some Auto-tiles couldn't resize the size of it,
* therefore this couldn't create the correct Auto-tile.
*
* The Auto-tile floor consists of two parts!
* First, There are four lines of 12 tiles.
* The first lines that will be resized to 32 x 32px.
* (the middle tile of its line is empty)
*
* Second, the size of other three lines are completely the same as RPG Maker MV,
* so they couldn't resize the size of it and basically doesn't be compatible with RMXP.
*
* - Animated auto-tiles will be supported, but it may contain incorrect pixel.
* - Some Auto-tile walls may contain an incorrect pixel.
* - Auto-tile walls(A4) wouldn't be supported, it contains in the normal tile.
*
* ===================================================================
* Change Log
* ===================================================================
* 2018.11.26 (v1.0.0) - First Release.
*/
/*:ko
* @plugindesc RPG Maker XP용으로 Character와 Tileset 이미지를 Resize합니다. <RS_Resize>
* @author biud436
* @help
* ===================================================================
* 캐릭터 변환
* ===================================================================
* RPG Maker XP용으로 Character 이미지를 Resize 하려면 다음 코드를 호출하세요.
*
* RS.Resize.convertCharacterImage();
*
* 변환이 완료되면 파일이 생성된 변환 폴더가 뜹니다.
*
* ===================================================================
* 타일셋 변환
* ===================================================================
*
* 타일셋을 변환하려면 다음 플러그인 커맨드를 호출하십시오.
*
* CreateTilesets
*
* 오토타일을 만들어내긴 하지만, 오토타일의 경우 거의 호환이 되지 않습니다.
*
* 그 이유는 XP에서는 16 x 16px 크기의 1/4 크기의 타일 4개가 합쳐지지만,
* MV는 주로 24 x 24px 크기의 타일 4개를 조합하기 때문입니다.
*
* 오토타일 부분은 크기가 같습니다.
* 따라서 대부분 오토타일이 16픽셀 밖으로 넘어가는 문제가 있어
* 자연스레 조합이 되지 않습니다.
*
* 호환되는 오토타일은 테두리가 16픽셀 안에 다 들어와있고,
* 빈 공간이 없는 꽉찬 오토타일들이 주로 호환이 됩니다.
*
* 이 부분은 단순 리사이즈로 해결이 불가능합니다.
*
* ===================================================================
* Change Log
* ===================================================================
* 2018.11.26 (v1.0.0) - First Release.
*/
var Imported = Imported || {};
Imported.RS_Resize = true;
var RS = RS || {};
RS.Resize = RS.Resize || {};
(function($) {
var parameters = $plugins.filter(function (i) {
return i.description.contains('<RS_Resize>');
});
parameters = (parameters.length > 0) && parameters[0].parameters;
$.localFilePath = function (filename) {
if(!Utils.isNwjs()) return '';
var path, base;
path = require('path');
base = path.dirname(process.mainModule.filename);
return path.join(base, 'convert_img', filename);
};
/**
* @param {String} filename
* @param {PIXI.Sprite} imageData
*/
$.savePngFile = function(filename, sprite) {
var fs = require('fs');
var path = require('path');
var imageData = Graphics._renderer.extract.base64(sprite);
console.log(imageData);
var data = imageData.replace(/^data:image\/\w+;base64,/, "");
filename = $.localFilePath(filename);
var buf = new Buffer(data, 'base64');
var targetDir = path.join(filename, "..");
if(!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}
fs.writeFile(filename + ".png", buf, function(err) {
if(err) {
console.warn(err);
}
});
};
/**
* https://gist.github.com/kethinov/6658166
* @param {String} dir
* @param {Array} filelist
*/
var walkSync = function(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + file).isDirectory()) {
filelist = walkSync(dir + file + '/', filelist);
}
else {
filelist.push(file);
}
});
return filelist;
};
$.getImageDirPath = function(basedir) {
basedir = basedir || "characters/";
if(!Utils.isNwjs()) return '';
var path, base;
path = require('path');
base = path.dirname(process.mainModule.filename);
return path.join(base, "img", basedir);
};
$.convertCharacterImageImpl = function(filename) {
var bitmap = ImageManager.loadCharacter(filename);
var resizeImage = new Sprite(new Bitmap(128, 192));
var isBigCharacter = ImageManager.isBigCharacter(filename);
var sw, sh;
var dw = 32;
var dh = 48;
if(isBigCharacter) {
sw = Math.floor(bitmap.width / 3);
sh = Math.floor(bitmap.height / 4);
for(var y = 0; y < 4; y++) {
for(var x = 0; x < 3; x++) {
if(x === 1) {
resizeImage.bitmap.blt(bitmap, sw * x, sh * y, sw, sh, dw * 0, y * dh, dw, dh);
resizeImage.bitmap.blt(bitmap, sw * x, sh * y, sw, sh, dw * (x + 1), y * dh, dw, dh);
} else {
resizeImage.bitmap.blt(bitmap, sw * x, sh * y, sw, sh, dw * (x + 1), y * dh, dw, dh);
}
}
}
$.savePngFile(filename, resizeImage);
} else {
sw = Math.floor(bitmap.width / 12);
sh = Math.floor(bitmap.height / 8);
var bx = 0;
var by = 0;
var sx, sy;
for(var index = 0; index < 8; index++) {
resizeImage.bitmap = new Bitmap(128, 192);
for(var y = 0; y < 4; y++) {
for(var x = 0; x < 3; x++) {
sx = (index % 4 * 3 + x) * sw;
sy = (Math.floor(index / 4) * 4 + y) * sh;
if(x === 1) {
resizeImage.bitmap.blt(bitmap, sx, sy, sw, sh, dw * 0, y * dh, dw, dh);
resizeImage.bitmap.blt(bitmap, sx, sy, sw, sh, dw * (x + 1), y * dh, dw, dh);
} else {
resizeImage.bitmap.blt(bitmap, sx, sy, sw, sh, dw * (x + 1), y * dh, dw, dh);
}
}
}
$.savePngFile(filename + "_" + index, resizeImage);
}
}
};
/**
* @return {Array} fileLists
*/
$.getImagefiles = function(dirname) {
var path = $.getImageDirPath(dirname);
var fileLists = [];
walkSync(path, fileLists);
return fileLists;
};
$.convertCharacterImage = function() {
$.getImagefiles().forEach(function(fileName) {
$.convertCharacterImageImpl(fileName.replace(".png", ""));
});
if(process.platform.contains('win')) {
var child_process = require('child_process');
child_process.exec('cmd /K explorer ' + $.localFilePath(""))
}
};
//============================================================================
// TilesetManager
//============================================================================
function TilesetManager() {
this.initialize.apply(this, arguments);
};
TilesetManager.prototype.constructor = TilesetManager;
TilesetManager.prototype.initialize = function(options) {
this._filename = "";
this._options = options;
var size = 0x1400;
if(this._options.contains('E')) {
size = 0x1800;
}
this._offset = 0x000;
this._compositeImage = new Sprite(new Bitmap(256, size));
this._prevLevel = 0;
this._level = 0;
};
TilesetManager.prototype.isNewTileset = function(filename) {
if(this._filename !== "") {
return false;
} else {
return this._filename !== filename;
}
};
TilesetManager.prototype.flush = function(filename) {
if(!filename) return this._filename = "";
var tr = filename.split("_");
this._filename = tr[0];
if(this.isNewTileset(filename)) {
this.flushTileset();
}
};
TilesetManager.prototype.createAutotileFromTilesetA1 = function(filename) {
var bitmap = ImageManager.loadTileset(filename);
// 96 * 128
var resizeImage = new Sprite(new Bitmap((32 * 3) * 4, 32 * 4));
var animationTiles = [0, 1, 2, 1];
for(var index = 0; index < 32; index++) {
var tx = index % 8; // 0 ~ 7
var ty = Math.floor(index / 8); // 0 ~ 3
if((tx % 4) === 0) {
var sw = 48;
var sh = 48;
var dw = 32;
var dh = 32;
var sx = sw * 0;
var sy = sh * 0;
var dx = dw * 0;
var dy = dh * 0;
// 시작 좌표
var bx = tx * 96;
var by = ty * 144;
// 상단 타일 (가운데 타일 제외)
for(var i = 0; i < 2; i++) {
sx = bx + (sw * i);
sy = by + (sh * 0);
dx = (dw * i) * 2;
dy = dh * 0;
for(var j = 0; j < 4; j++) {
resizeImage.bitmap.bltImage(bitmap, sx + (96 * animationTiles[j]), sy, sw, sh, dx + (96 * j), dy, dw, dh);
}
}
// 하단 타일 (그대로)
sx = bx + (sw * 0);
sy = by + (sh * 1);
dx = (dw * 0);
dy = (dh * 1);
for(var i = 0; i < 4; i++) {
resizeImage.bitmap.bltImage(bitmap, sx + (96 * animationTiles[i]), sy, 96, 96, dx + (96 * i), dy, 96, 96);
}
$.savePngFile(filename + "_" + index, resizeImage);
}
}
};
TilesetManager.prototype.createAutotileFromTilesetA2 = function(filename) {
var re = /(?:A2|A3|A4|)/;
if(!re.exec(filename)) {
return false;
}
var bitmap = ImageManager.loadTileset(filename);
var resizeImage = new Sprite(new Bitmap(96, 128));
for(var index = 0; index < 32; index++) {
var tx = index % 8; // 0 ~ 7
var ty = Math.floor(index / 8); // 0 ~ 3
var sw = 48;
var sh = 48;
var dw = 32;
var dh = 32;
var sx = sw * 0;
var sy = sh * 0;
var dx = dw * 0;
var dy = dh * 0;
// 시작 좌표
var bx = tx * 96;
var by = ty * 144;
// 상단 타일 (가운데 타일 제외)
for(var i = 0; i < 2; i++) {
sx = bx + (sw * i);
sy = by + (sh * 0);
dx = (dw * i) * 2;
dy = dh * 0;
resizeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, dy, dw, dh);
}
// 하단 타일 (그대로)
sx = bx + (sw * 0);
sy = by + (sh * 1);
dx = (dw * 0);
dy = (dh * 1);
resizeImage.bitmap.bltImage(bitmap, sx, sy, 96, 96, dx, dy, 96, 96);
$.savePngFile(filename + "_" + index, resizeImage);
resizeImage.bitmap.clear();
};
};
TilesetManager.prototype.flushTileset = function() {
this.exportTilesets();
this._level = 0;
this._prevLevel = 0;
this._offset = 0;
};
TilesetManager.prototype.createAutotileFromTilesetA3 = function(filename) {
// A3 오토타일은 RMMV의 타일맵에서만 사용 가능하므로, 그냥 일반 타일로 넣는다.
var bitmap = ImageManager.loadTileset(filename);
if(bitmap.width <= 0) {
return false;
}
if(this._level !== 0) {
this._prevLevel = this._level;
}
var sw = 48;
var sh = 48;
var dw = 32;
var dh = 32;
var lastSX = 0;
var lastSY = 0;
// 768 x 384
for(var y = 0; y < 8; y++) {
for(var x = 0; x < 8; x++) {
sx = sw * x;
sy = sh * y;
dx = dw * x;
dy = dh * y;
this._compositeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, this._offset + dy, dw, dh);
}
}
this._offset += 0x80;
for(var y = 0; y < 8; y++) {
for(var x = 0; x < 8; x++) {
sx = sw * (x + 8);
sy = sh * (y + 8);
dx = dw * x;
dy = dh * y;
this._compositeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, this._offset + dy, dw, dh);
}
}
this._offset += 0x80;
this._level = 1;
};
TilesetManager.prototype.createAutotileFromTilesetA4 = function(filename) {
var re = /(?:A4|)/g;
if(!re.exec(filename)) {
return false;
}
var bitmap = ImageManager.loadTileset(filename);
var resizeImage = new Sprite(new Bitmap(96, 128));
for(var index = 0; index < 24; index++) {
var tx = index % 8; // 0 ~ 7
var ty = Math.floor(index / 8); // 0 ~ 2
var sw = 48;
var sh = 48;
var dw = 32;
var dh = 32;
var sx = sw * 0;
var sy = sh * 0;
var dx = dw * 0;
var dy = dh * 0;
// 시작 좌표
var bx = tx * 96;
var by = ty * 240;
// 상단 타일 (가운데 타일 제외)
for(var i = 0; i < 2; i++) {
sx = bx + (sw * i);
sy = by + (sh * 0);
dx = (dw * i) * 2;
dy = dh * 0;
resizeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, dy, dw, dh);
}
// 하단 타일 (그대로)
sx = bx + (sw * 0);
sy = by + (sh * 1);
dx = (dw * 0);
dy = (dh * 1);
resizeImage.bitmap.bltImage(bitmap, sx, sy, 96, 192, dx, dy, 96, 96);
$.savePngFile(filename + "_" + index, resizeImage);
resizeImage.bitmap.clear();
};
};
TilesetManager.prototype.createTilesetA5 = function(filename) {
if(this._level !== 0) {
this._prevLevel = this._level;
}
var bitmap = ImageManager.loadTileset(filename);
var sw = 48;
var sh = 48;
var dw = 32;
var dh = 32;
for(var y = 0; y < 32; y++) {
for(var x = 0; x < 8; x++) {
sx = sw * x;
sy = sh * y;
dx = dw * x;
dy = dh * y;
this._compositeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, this._offset + dy, dw, dh);
}
}
this._level = 3;
this._offset += 0x200;
};
TilesetManager.prototype.createTilesetB = function(filename) {
if(this._level !== 0) {
this._prevLevel = this._level;
}
var bitmap = ImageManager.loadTileset(filename);
var sw = 48;
var sh = 48;
var dw = 32;
var dh = 32;
var tx = 0;
var ty = 0;
var id = 0;
this._compositeImage.bitmap.clearRect(0, this._offset, 256, 0x400);
for(var y = 0; y < 16; y++) {
for(var x = 0; x < 8; x++) {
sx = sw * x;
sy = sh * y;
dx = dw * x;
dy = dh * y;
this._compositeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, this._offset + dy, dw, dh);
}
}
this._offset += 0x200;
for(var y = 0; y < 16; y++) {
for(var x = 0; x < 8; x++) {
sx = sw * (x + 8);
sy = sh * y;
dx = dw * x;
dy = dh * y;
this._compositeImage.bitmap.bltImage(bitmap, sx, sy, sw, sh, dx, this._offset + dy, dw, dh);
}
}
this._offset += 0x200;
this._filename = filename.split("_")[0];
this._level++;
};
TilesetManager.prototype.createTilesetC = function(filename, offset) {
this.createTilesetB(filename, offset);
};
TilesetManager.prototype.createTilesetD = function(filename, offset) {
this.createTilesetB(filename, offset);
};
TilesetManager.prototype.createTilesetE = function(filename, offset) {
this.createTilesetB(filename, offset);
};
TilesetManager.prototype.exportTilesets = function() {
var filename = this._filename || new Date().getTime().toString();
$.savePngFile(filename, this._compositeImage);
this._compositeImage.bitmap.clear();
};
//============================================================================
// Scene_Boot
//============================================================================
var _Scene_Boot_loadSystemWindowImage = Scene_Boot.prototype.loadSystemWindowImage;
Scene_Boot.prototype.loadSystemWindowImage = function() {
_Scene_Boot_loadSystemWindowImage.call(this);
$.getImagefiles().forEach(function(fileName) {
ImageManager.reserveCharacter(fileName.replace(".png", ""));
});
};
//============================================================================
// Scene_LoadTilesets
//============================================================================
function Scene_LoadTilesets() {
this.initialize.apply(this, arguments);
};
Scene_LoadTilesets.prototype = Object.create(Scene_Base.prototype);
Scene_LoadTilesets.prototype.constructor = Scene_LoadTilesets;
Scene_LoadTilesets.prototype.initialize = function() {
Scene_Base.prototype.initialize.call(this);
};
Scene_LoadTilesets.prototype.create = function() {
Scene_Base.prototype.create.call(this);
this.createBackground();
this._fileMap = {};
$.getImagefiles("tilesets/").forEach(function(filename) {
var idx = filename.indexOf("_");
var name = filename.slice(0, idx);
if(filename.endsWith(".png")) {
var _name = filename.replace(".png", "");
ImageManager.loadTileset(_name);
if(!this._fileMap[name]) {
this._fileMap[name] = [];
}
this._fileMap[name].push(_name);
}
}, this);
};
Scene_LoadTilesets.prototype.createBackground = function() {
this._backgroundSprite = new Sprite();
this._backgroundSprite.bitmap = SceneManager.backgroundBitmap();
this.addChild(this._backgroundSprite);
};
Scene_LoadTilesets.prototype.isReady = function() {
return Scene_Base.prototype.isReady.call(this);
};
Scene_LoadTilesets.prototype.isValid = function(name, suffix) {
var filename = name + suffix;
return this._fileMap[name].contains(filename);
};
Scene_LoadTilesets.prototype.start = function() {
Scene_Base.prototype.start.call(this);
var keys = Object.keys(this._fileMap);
keys.forEach(function(name) {
var options = [];
if(this._fileMap[name].contains(name + "_E")) {
options.push("E");
}
var tilesets = new TilesetManager(options);
this._fileMap[name].forEach(function(filename) {
var _imagename = filename.replace(".png", "");
if(/(?:_A1)/g.exec(filename)) {
tilesets.createAutotileFromTilesetA1(_imagename);
} else if(/(?:_A2)/g.exec(filename)) {
tilesets.createAutotileFromTilesetA2(_imagename);
} else if(/(?:_A3)/g.exec(filename)) {
tilesets.createAutotileFromTilesetA3(_imagename);
} else if(/(?:_A4)/g.exec(filename)) {
tilesets.createAutotileFromTilesetA4(_imagename);
} else if(/(?:_A5)/g.exec(filename)) {
tilesets.createTilesetA5(_imagename);
} else if(/(?:_B)/g.exec(filename)) {
tilesets.createTilesetB(_imagename);
} else if(/(?:_C)/g.exec(filename)) {
tilesets.createTilesetC(_imagename);
} else if(/(?:_D)/g.exec(filename)) {
tilesets.createTilesetD(_imagename);
} else if(/(?:_E)/g.exec(filename)) {
tilesets.createTilesetE(_imagename);
}
}, this);
tilesets.exportTilesets();
}, this);
if(process.platform.contains('win')) {
var child_process = require('child_process');
child_process.exec('cmd /K explorer ' + $.localFilePath(""))
}
SceneManager.pop();
};
//============================================================================
// Game_Interpreter
//============================================================================
var alias_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === "CreateTilesets") {
SceneManager.push(Scene_LoadTilesets);
}
};
})(RS.Resize);