-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_ResourceUpdate.js
189 lines (163 loc) Β· 4.91 KB
/
RS_ResourceUpdate.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
//================================================================
// RS_ResourceUpdate.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2016 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* RS_ResourceUpdate.js
* @plugindesc This plugin allows you to download adding resource files on PC.
* @author biud436
*
* @param URL_DB
* @desc Please enter the url that has the version text.
* @default https://github.com/biud436/MV/raw/master/Laboratory/DBVersion.json
*
* @param Current Version
* @desc Please enter the currently version.
* @default 0.1.1
*
* @help
* 2016.01.04 (v1.0.0) - First Release.
* 2018.12.01 (v1.0.1) - Fixed the bug that is not loaded files in RPG Maker MV v1.6.1 or more.
*/
/*:ko
* RS_ResourceUpdate.js
* @plugindesc μΈν°λ·μ ν΅ν΄ 리μμ€λ₯Ό λ€μ΄λ‘λ λ°μ μ μλ νλ¬κ·ΈμΈμ
λλ€.
* @author biud436
*
* @param URL_DB
* @desc νμΌ λͺ©λ‘μ΄ μλ νμΌμ μ£Όμλ₯Ό μ μ΄μ£ΌμκΈ° λ°λλλ€.
* @default https://github.com/biud436/MV/raw/master/Laboratory/DBVersion.json
*
* @param Current Version
* @desc νμ¬ λ²μ μ μ
λ ₯νμΈμ.
* @default 0.1.1
*
* @help
* 2016.01.04 (v1.0.0) - First Release.
* 2018.12.01 (v1.0.1) - Fixed the bug that is not loaded files in RPG Maker MV v1.6.1 or more.
*/
var Imported = Imported || {};
Imported.RS_ResourceUpdate = true;
var RS = RS || {};
RS.Net = RS.Net || {};
(function() {
var http, Stream, fs;
var parameters = PluginManager.parameters('RS_ResourceUpdate');
if(!Utils.isMobileDevice()) {
http = require('https');
Stream = require('stream').Transform;
fs = require('fs');
}
var DBV_URL = parameters["URL_DB"] || "https://github.com/biud436/MV/raw/master/Laboratory/DBVersion.json";
RS.Net._dbVersion = '';
RS.Net._currentVersion = parameters["Current Version"] || '0.1.1';
RS.Net._list = [];
/**
* @memberof RS.Net
* @method isInit
*/
RS.Net.isInit = function(stage) {
if(!Utils.isMobileDevice()) {
this._folder = (function() {
var path = require('path');
var targetPath = path.join(process.mainModule.filename, "..");
return decodeURIComponent(targetPath);
})();
this.initDBVersion();
this.initList();
}
}
/**
* @memberof RS.Net
* @method downloadData
* @link http://stackoverflow.com/questions/12740659/downloading-images-with-node-js
*/
RS.Net.downloadData = function(filePath, url, func) {
http.request(url, function(response) {
var data = new Stream();
var ext = url.match(/(\/www|)\/[^\/]*$/);
if(ext && ext instanceof Array) {
ext = ext[0];
}
response.on('data', function(chunk) {
data.push(chunk);
});
response.on('end', function() {
fs.writeFileSync('%1%2'.format(filePath, ext), data.read());
func();
});
}).end();
}
/**
* @memberof RS.Net
* @method allDataDownload
*/
RS.Net.allDataDownload = function(buf) {
try {
var folder = this._folder;
var picPath = folder + buf.src;
var length = buf.list.length;
var req = 1;
buf.list.forEach(function(data, index, arr) {
this.downloadData(picPath, data, function() {
console.log( Math.floor(((req++) / length) * 100));
});
}, this);
} catch(e) {
console.log("λ€μ΄λ‘λ μ€ν¨");
}
this.updateCurrentVersion();
console.log('λ€μ΄λ‘λκ° μλ£λμμ΅λλ€');
}
/**
* @memberof RS.Net
* @method isUpdate
*/
RS.Net.isUpdate = function() {
if(RS.Net._currentVersion !== this.getDBVersion()) {
this.allDataDownload(RS.Net._list);
} else {
console.log("νμ¬ λ²μ μ΄ μ΅μ λ²μ μ
λλ€");
}
}
RS.Net.initDBVersion = function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', DBV_URL);
xhr.onload = function() {
if(xhr.status < 400) {
var json = JsonEx.parse(xhr.responseText);
RS.Net._dbVersion = json['dbVersion'];
console.log(RS.Net._dbVersion);
}
}
xhr.send();
}
RS.Net.initList = function() {
var xhr = new XMLHttpRequest();
var self = this;
xhr.open('GET', DBV_URL);
xhr.onload = function() {
if(xhr.status < 400) {
var json = JsonEx.parse(xhr.responseText);
RS.Net._list = json.data.pictures;
self.isUpdate();
}
}
xhr.send();
}
RS.Net.getDBVersion = function() {
return RS.Net._dbVersion;
}
RS.Net.updateCurrentVersion = function() {
RS.Net._currentVersion = this.getDBVersion();
}
var alias_Scene_Boot_initialize = Scene_Boot.prototype.initialize;
Scene_Boot.prototype.initialize = function() {
alias_Scene_Boot_initialize.call(this);
RS.Net.isInit(this);
};
})();