This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
/
_ModelSettingJson.js
388 lines (348 loc) · 9.52 KB
/
_ModelSettingJson.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
// Modified by xiazeyu.
/**
* @desc To get the model settings from given json file
*/
import { Live2DFramework } from "../lib/Live2DFramework"
/**
* @name ModelSettingJson
* @desc return the struct of ModelSettingJson
* @param null
* @returns {Structure} ModelSettingJson
*/
export default function ModelSettingJson()
{ // Define the index in the json file.
this.NAME = "name";
this.ID = "id";
this.MODEL = "model";
this.TEXTURES = "textures";
this.HIT_AREAS = "hit_areas";
this.PHYSICS = "physics";
this.POSE = "pose";
this.EXPRESSIONS = "expressions";
this.MOTION_GROUPS = "motions";
this.SOUND = "sound";
this.FADE_IN = "fade_in";
this.FADE_OUT = "fade_out";
this.LAYOUT = "layout";
this.INIT_PARAM = "init_param";
this.INIT_PARTS_VISIBLE = "init_parts_visible";
this.VALUE = "val";
this.FILE = "file";
this.json = {};
}
/**
* @name loadModelSetting
* @desc load model settings from json
* @param {string} jsonPath, {function} callback
* @returns null
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.loadModelSetting = function(path, callback)
{
var thisRef = this;
var pm = Live2DFramework.getPlatformManager();
pm.loadBytes(path, function(buf) {
var str = String.fromCharCode.apply(null,new Uint8Array(buf));
thisRef.json = JSON.parse(str);
callback();
});
};
/**
* @name getTextureFile
* @desc get texture file from json
* @param {int} order number of texture
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getTextureFile = function(n)
{
if (this.json[this.TEXTURES] == null || this.json[this.TEXTURES][n] == null)
return null;
return this.json[this.TEXTURES][n];
}
/**
* @name getModelFile
* @desc get model file from json
* @param null
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getModelFile = function()
{
return this.json[this.MODEL];
};
/**
* @name getTextureNum
* @desc get the amount of textures from json
* @param null
* @returns {int} amout
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getTextureNum = function()
{
if (this.json[this.TEXTURES] == null) return 0;
return this.json[this.TEXTURES].length;
}
/**
* @name getHitAreaNum
* @desc get the amount of hit area from json
* @param null
* @returns {int} amout
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getHitAreaNum = function()
{
if (this.json[this.HIT_AREAS] == null)
return 0;
return this.json[this.HIT_AREAS].length;
}
/**
* @name getHitAreaID
* @desc get the hit area ID of given index from json
* @param {int} index
* @returns {int} ID
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getHitAreaID = function(n)
{
if (this.json[this.HIT_AREAS] == null ||
this.json[this.HIT_AREAS][n] == null)
return null;
return this.json[this.HIT_AREAS][n][this.ID];
}
/**
* @name getHitAreaName
* @desc get the hit area name of given index from json
* @param {int} index
* @returns {string} name
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getHitAreaName = function(n)
{
if (this.json[this.HIT_AREAS] == null ||
this.json[this.HIT_AREAS][n] == null)
return null;
return this.json[this.HIT_AREAS][n][this.NAME];
}
/**
* @name getPhysicsFile
* @desc get physics file from json
* @param null
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getPhysicsFile = function()
{
return this.json[this.PHYSICS];
}
/**
* @name getPoseFile
* @desc get pose file from json
* @param null
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getPoseFile = function()
{
return this.json[this.POSE];
}
/**
* @name getExpressionNum
* @desc get the amount of expressions from json
* @param null
* @returns {int} amout
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getExpressionNum = function()
{
return (this.json[this.EXPRESSIONS] == null) ? 0 : this.json[this.EXPRESSIONS].length;
}
/**
* @name getExpressionFile
* @desc get expression file from json
* @param null
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getExpressionFile = function(n)
{
if (this.json[this.EXPRESSIONS] == null)
return null;
return this.json[this.EXPRESSIONS][n][this.FILE];
}
/**
* @name getExpressionName
* @desc get the hit expression name of given index from json
* @param {int} index
* @returns {string} name
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getExpressionName = function(n)
{
if (this.json[this.EXPRESSIONS] == null)
return null;
return this.json[this.EXPRESSIONS][n][this.NAME];
}
/**
* @name getLayout
* @desc get the layout from json
* @param null
* @returns {string} layout
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getLayout = function()
{
return this.json[this.LAYOUT];
}
/**
* @name getInitParamNum
* @desc get the amount of init parameter from json
* @param null
* @returns {int} amount
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getInitParamNum = function()
{
return (this.json[this.INIT_PARAM] == null) ? 0 : this.json[this.INIT_PARAM].length;
}
/**
* @name getMotionNum
* @desc get the amount of motions from json
* @param null
* @returns {int} amout
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getMotionNum = function(name)
{
if (this.json[this.MOTION_GROUPS] == null ||
this.json[this.MOTION_GROUPS][name] == null)
return 0;
return this.json[this.MOTION_GROUPS][name].length;
}
/**
* @name getMotionFile
* @desc get motion file from json
* @param null
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getMotionFile = function(name, n)
{
if (this.json[this.MOTION_GROUPS] == null ||
this.json[this.MOTION_GROUPS][name] == null ||
this.json[this.MOTION_GROUPS][name][n] == null)
return null;
return this.json[this.MOTION_GROUPS][name][n][this.FILE];
}
/**
* @name getMotionSound
* @desc get motion's sound file from json
* @param null
* @returns {string} file path
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getMotionSound = function(name, n)
{
if (this.json[this.MOTION_GROUPS] == null ||
this.json[this.MOTION_GROUPS][name] == null ||
this.json[this.MOTION_GROUPS][name][n] == null ||
this.json[this.MOTION_GROUPS][name][n][this.SOUND] == null)
return null;
return this.json[this.MOTION_GROUPS][name][n][this.SOUND];
}
/**
* @name getMotionFadeIn
* @desc get the motion's fade in setting from json
* @param {string} name, {int} index
* @returns {int} time (1000 if not found)
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getMotionFadeIn = function(name, n)
{
if (this.json[this.MOTION_GROUPS] == null ||
this.json[this.MOTION_GROUPS][name] == null ||
this.json[this.MOTION_GROUPS][name][n] == null ||
this.json[this.MOTION_GROUPS][name][n][this.FADE_IN] == null)
return 1000;
return this.json[this.MOTION_GROUPS][name][n][this.FADE_IN];
}
/**
* @name getMotionFadeOut
* @desc get the motion's fade out setting from json
* @param {string} name, {int} index
* @returns {int} time (1000 if not found)
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getMotionFadeOut = function(name, n)
{
if (this.json[this.MOTION_GROUPS] == null ||
this.json[this.MOTION_GROUPS][name] == null ||
this.json[this.MOTION_GROUPS][name][n] == null ||
this.json[this.MOTION_GROUPS][name][n][this.FADE_OUT] == null)
return 1000;
return this.json[this.MOTION_GROUPS][name][n][this.FADE_OUT];
}
/**
* @name getInitParamID
* @desc get the visible ID of init parameter from json
* @param {(int)} index
* @returns {int} ID
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getInitParamID = function(n)
{
if (this.json[this.INIT_PARAM] == null ||
this.json[this.INIT_PARAM][n] == null)
return null;
return this.json[this.INIT_PARAM][n][this.ID];
}
/**
* @name getInitParamValue
* @desc get the visible value of init parameter from json
* @param {(int)} index
* @returns {int} value
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getInitParamValue = function(n)
{
if (this.json[this.INIT_PARAM] == null || this.json[this.INIT_PARAM][n] == null)
return NaN;
return this.json[this.INIT_PARAM][n][this.VALUE];
}
/**
* @name getInitPartsVisibleNum
* @desc get the amount of init parts visible from json
* @param null
* @returns {int} amout
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getInitPartsVisibleNum = function()
{
return (this.json[this.INIT_PARTS_VISIBLE] == null) ? 0 : this.json[this.INIT_PARTS_VISIBLE].length;
}
/**
* @name getInitPartsVisibleID
* @desc get the visible ID of init parts from json
* @param {(int)} index
* @returns {int} ID
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getInitPartsVisibleID = function(n)
{
if (this.json[this.INIT_PARTS_VISIBLE] == null || this.json[this.INIT_PARTS_VISIBLE][n] == null)
return null;
return this.json[this.INIT_PARTS_VISIBLE][n][this.ID];
}
/**
* @name getInitPartsVisibleValue
* @desc get the visible value of init parts from json
* @param {(int)} index
* @returns {int} value
* @memberOf ModelSettingJson
*/
ModelSettingJson.prototype.getInitPartsVisibleValue = function(n)
{
if (this.json[this.INIT_PARTS_VISIBLE] == null || this.json[this.INIT_PARTS_VISIBLE][n] == null)
return NaN;
return this.json[this.INIT_PARTS_VISIBLE][n][this.VALUE];
}