View difference between Paste ID: jdbKXs2s and DFHK5f5R
SHOW: | | - or go back to the newest paste.
1
module DEGICA
2
  module CONVERT
3
    FOLDER = 'mv-data/'
4
    
5
    LOGGING = true # only useful for debugging this script
6
    LOGSCRIPTS = true # lists any damage formulae, and event commands using scripts
7
    LOGCOMMENTS = true # only turn this on if you have scripts that look for certain comments and want to re-implement them
8
    
9
    def self.run
10
      DataManager.load_normal_database
11
      dest = FOLDER.gsub(/\\/){''}
12
      Dir.mkdir dest unless File.exists?(dest)
13
      
14
      #*************************************************************************
15
      @log = File.open(FOLDER + "_log.txt", "w") if LOGGING
16
      @scriptlog = File.open(FOLDER + "_scripts.txt", "w") if LOGSCRIPTS
17
      @commentlog = File.open(FOLDER + "_comments.txt", "w") if LOGCOMMENTS
18
      #*************************************************************************
19
      
20
      convert_actors
21
      convert_classes
22
      convert_skills
23
      convert_items
24
      convert_weapons
25
      convert_armors
26
      convert_enemies
27
      convert_troops
28
      convert_states
29
      convert_animations
30
      convert_tilesets
31
      convert_common_events
32
      convert_system
33
      convert_mapinfos
34
      
35
      Dir.glob('Data/Map???.rvdata2').each {|filename| convert_map(filename)}
36
      
37
      #*************************************************************************
38
      @log.close if LOGGING
39
      @scriptlog.close if LOGSCRIPTS
40
      @commentlog.close if LOGCOMMENTS
41
      #*************************************************************************
42
    end
43
    
44
    #===========================================================================
45
    #
46
    # DATABASE CONVERSION
47
    #
48
    #===========================================================================
49
    
50
    #===========================================================================
51
    # ACTORS
52
    #===========================================================================
53
    def self.convert_actors
54
      f = File.open(FOLDER + "Actors.json", "w")
55
      f.puts('[')
56
      f.puts('null,')
57
      for x in 1 ... $data_actors.size
58
        actor = $data_actors[x]
59
        actor = RPG::Actor.new if !actor
60
        actor_data = '{'
61
        
62
        actor_data += '"id":' + x.to_s + ','
63
        actor_data += '"battlerName":"",'
64
        actor_data += '"characterIndex":' + actor.character_index.to_s + ','
65
        actor_data += '"characterName":"' + actor.character_name + '",'
66
        actor_data += '"classId":' + actor.class_id.to_s + ','
67
        actor_data += '"equips":' + actor.equips.to_s.gsub(/ /){''} + ','
68
        actor_data += '"faceIndex":' + actor.face_index.to_s + ','
69
        actor_data += '"faceName":"' + actor.face_name + '",'
70
        actor_data += '"traits":' + get_traits(actor) + ','
71
        actor_data += '"initialLevel":' + actor.initial_level.to_s + ','
72
        actor_data += '"maxLevel":' + actor.max_level.to_s + ','
73
        actor_data += '"name":' + get_text(actor.name) + ','
74
        actor_data += '"nickname":' + get_text(actor.nickname) + ','
75
        actor_data += '"note":' + get_text(actor.note) + ','
76
        actor_data += '"profile":' + get_text(actor.description)
77
        
78
        actor_data += '}'
79
        actor_data += ',' if x < $data_actors.size - 1
80
        f.puts(actor_data)
81
      end
82
      f.puts(']')
83
      f.close
84
    end
85
    
86
    #===========================================================================
87
    # CLASSES
88
    #===========================================================================
89
    def self.convert_classes
90
      f = File.open(FOLDER + "Classes.json", "w")
91
      f.puts('[')
92
      f.puts('null,')
93
      for x in 1 ... $data_classes.size
94
        cls = $data_classes[x]
95
        cls = RPG::Class.new if !cls
96
        cls_data = '{'
97
        
98
        cls_data += '"id":' + x.to_s + ','
99
        cls_data += '"expParams":' + cls.exp_params.to_s.gsub(/ /){''} + ','
100
        cls_data += '"traits":' + get_traits(cls) + ','
101
        cls_data += '"learnings":' + get_learnings(cls) + ','
102
        cls_data += '"name":' + get_text(cls.name) + ','
103
        cls_data += '"note":' + get_text(cls.note) + ','
104
        cls_data += '"params":' + get_params(cls) 
105
        
106
        cls_data += '}'
107
        cls_data += ',' if x < $data_classes.size - 1
108
        f.puts(cls_data)
109
      end
110
      f.puts(']')
111
      f.close
112
    end
113
    def self.get_learnings(obj)
114
      res = '['
115
      count = 1
116
      max_count = obj.learnings.size
117
      obj.learnings.each do |lrn|
118
        res += '{"level":' + lrn.level.to_s + ','
119
        res += '"note":' + get_text(lrn.note) + ','
120
        res += '"skillId":' + lrn.skill_id.to_s + '}'
121
        res += ',' if count < max_count
122
        count += 1
123
      end      
124
      res += ']'
125
      res
126
    end
127
    
128
    def self.get_params(cls)
129
      res = '['
130
      for p in 0..7
131
        res += '['
132
        for l in 0..99
133
          res += cls.params[p,l].to_s
134
          res += ',' if l < 99
135
        end
136
        res += ']'
137
        res += ',' if p < 7
138
      end
139
      res += ']'
140
      res
141
    end
142
    
143
    #===========================================================================
144
    # SKILLS
145
    #===========================================================================
146
    def self.convert_skills
147
      f = File.open(FOLDER + "Skills.json", "w")
148
      f.puts('[')
149
      f.puts('null,')
150
      for x in 1 ... $data_skills.size
151
        skill = $data_skills[x]
152
        skill = RPG::Skill.new if !skill
153
        skl_data = '{'
154
        
155
        skl_data += '"id":' + x.to_s + ','
156
        skl_data += '"animationId":' + skill.animation_id.to_s + ','
157
        skl_data += '"damage":' + get_damage(skill) + ','
158
        skl_data += '"description":' + get_text(skill.description) + ','
159
        skl_data += '"effects":' + get_effects(skill) + ','
160
        skl_data += '"hitType":' + skill.hit_type.to_s + ','
161
        skl_data += '"iconIndex":' + skill.icon_index.to_s + ','
162
        skl_data += '"message1":' + get_text(skill.message1) + ','
163
        skl_data += '"message2":' + get_text(skill.message2) + ','
164
        skl_data += '"mpCost":' + skill.mp_cost.to_s + ','
165
        skl_data += '"name":' + get_text(skill.name) + ','
166
        skl_data += '"note":' + get_text(skill.note) + ','
167
        skl_data += '"occasion":' + skill.occasion.to_s + ','
168
        skl_data += '"repeats":' + skill.repeats.to_s + ','
169
        skl_data += '"requiredWtypeId1":' + skill.required_wtype_id1.to_s + ','
170
        skl_data += '"requiredWtypeId2":' + skill.required_wtype_id2.to_s + ','
171
        skl_data += '"scope":' + skill.scope.to_s + ','
172
        skl_data += '"speed":' + skill.speed.to_s + ','
173
        skl_data += '"stypeId":' + skill.stype_id.to_s + ','
174
        skl_data += '"successRate":' + skill.success_rate.to_s + ','
175
        skl_data += '"tpCost":' + skill.tp_cost.to_s + ','
176
        skl_data += '"tpGain":' + skill.tp_gain.to_s
177
        
178
        skl_data += '}'
179
        skl_data += ',' if x < $data_skills.size - 1
180
        f.puts(skl_data)
181
      end
182
      f.puts(']')
183
      f.close
184
    end
185
    
186
    #===========================================================================
187
    # ITEMS
188
    #===========================================================================
189
    def self.convert_items
190
      f = File.open(FOLDER + "Items.json", "w")
191
      f.puts('[')
192
      f.puts('null,')
193
      for x in 1 ... $data_items.size
194
        item = $data_items[x]
195
        item = RPG::Item.new if !item
196
        itm_data = '{'
197
        
198
        itm_data += '"id":' + x.to_s + ','
199
        itm_data += '"animationId":' + item.animation_id.to_s + ','
200
        itm_data += '"consumable":' + item.consumable.to_s + ','
201
        itm_data += '"damage":' + get_damage(item) + ','
202
        itm_data += '"description":' + get_text(item.description) + ','
203
        itm_data += '"effects":' + get_effects(item) + ','
204
        itm_data += '"hitType":' + item.hit_type.to_s + ','
205
        itm_data += '"iconIndex":' + item.icon_index.to_s + ','
206
        itm_data += '"itypeId":' + item.itype_id.to_s + ','
207
        itm_data += '"name":' + get_text(item.name) + ','
208
        itm_data += '"note":' + get_text(item.note) + ','
209
        itm_data += '"occasion":' + item.occasion.to_s + ','
210
        itm_data += '"price":' + item.price.to_s + ','
211
        itm_data += '"repeats":' + item.repeats.to_s + ','
212
        itm_data += '"scope":' + item.scope.to_s + ','
213
        itm_data += '"speed":' + item.speed.to_s + ','
214
        itm_data += '"successRate":' + item.success_rate.to_s + ','
215
        itm_data += '"tpGain":' + item.tp_gain.to_s
216
        
217
        itm_data += '}'
218
        itm_data += ',' if x < $data_items.size - 1
219
        f.puts(itm_data)
220
      end
221
      f.puts(']')
222
      f.close
223
    end
224
    
225
    #===========================================================================
226
    # WEAPONS
227
    #===========================================================================
228
    def self.convert_weapons
229
      f = File.open(FOLDER + "Weapons.json", "w")
230
      f.puts('[')
231
      f.puts('null,')
232
      for x in 1 ... $data_weapons.size
233
        wpn = $data_weapons[x]
234
        wpn = RPG::Weapon.new if !wpn
235
        wpn_data = '{'
236
        
237
        wpn_data += '"id":' + x.to_s + ','
238
        wpn_data += '"animationId":' + wpn.animation_id.to_s + ','
239
        wpn_data += '"description":' + get_text(wpn.description) + ','
240
        wpn_data += '"etypeId":1,' # weapons are 0 in Ace, but 1 in MV
241
        wpn_data += '"traits":' + get_traits(wpn) + ','
242
        wpn_data += '"iconIndex":' + wpn.icon_index.to_s + ','
243
        wpn_data += '"name":' + get_text(wpn.name) + ','
244
        wpn_data += '"note":' + get_text(wpn.note) + ','
245
        wpn_data += '"params":' + wpn.params.to_s.gsub(/ /){''} + ','
246
        wpn_data += '"price":' + wpn.price.to_s + ','
247
        wpn_data += '"wtypeId":' + wpn.wtype_id.to_s
248
        
249
        wpn_data += '}'
250
        wpn_data += ',' if x < $data_weapons.size - 1
251
        f.puts(wpn_data)
252
      end
253
      f.puts(']')
254
      f.close
255
    end
256
    
257
    #===========================================================================
258
    # ARMORS
259
    #===========================================================================
260
    def self.convert_armors
261
      f = File.open(FOLDER + "Armors.json", "w")
262
      f.puts('[')
263
      f.puts('null,')
264
      for x in 1 ... $data_armors.size
265
        amr = $data_armors[x]
266
        amr = RPG::Armor.new if !amr
267
        amr_data = '{'
268
        
269
        amr_data += '"id":' + x.to_s + ','
270
        amr_data += '"atypeId":' + amr.atype_id.to_s + ','
271
        amr_data += '"description":' + get_text(amr.description) + ','
272
        amr_data += '"etypeId":' + amr.etype_id.to_s + ','
273
        amr_data += '"traits":' + get_traits(amr) + ','
274
        amr_data += '"iconIndex":' + amr.icon_index.to_s + ','
275
        amr_data += '"name":' + get_text(amr.name) + ','
276
        amr_data += '"note":' + get_text(amr.note) + ','
277
        amr_data += '"params":' + amr.params.to_s.gsub(/ /){''} + ','
278
        amr_data += '"price":' + amr.price.to_s
279
        
280
        amr_data += '}'
281
        amr_data += ',' if x < $data_armors.size - 1
282
        f.puts(amr_data)
283
      end
284
      f.puts(']')
285
      f.close
286
    end
287
    
288
    #===========================================================================
289
    # ENEMIES
290
    #===========================================================================
291
    def self.convert_enemies
292
      f = File.open(FOLDER + "Enemies.json", "w")
293
      f.puts('[')
294
      f.puts('null,')
295
      for x in 1 ... $data_enemies.size
296
        foe = $data_enemies[x]
297
        foe = RPG::Enemy.new if !foe
298
        foe_data = '{'
299
        
300
        foe_data += '"id":' + x.to_s + ','
301
        foe_data += '"actions":' + get_actions(foe) + ','
302
        foe_data += '"battlerHue":' + foe.battler_hue.to_s + ','
303
        foe_data += '"battlerName":"' + foe.battler_name + '",'
304
        foe_data += '"dropItems":' + get_drop_items(foe) + ','
305
        foe_data += '"exp":' + foe.exp.to_s + ','
306
        foe_data += '"traits":' + get_traits(foe) + ','
307
        foe_data += '"gold":' + foe.gold.to_s + ','
308
        foe_data += '"name":' + get_text(foe.name) + ','
309
        foe_data += '"note":' + get_text(foe.note) + ','
310
        foe_data += '"params":' + foe.params.to_s.gsub(/ /){''}
311
        
312
        foe_data += '}'
313
        foe_data += ',' if x < $data_enemies.size - 1
314
        f.puts(foe_data)
315
      end
316
      f.puts(']')
317
      f.close
318
    end
319
    
320
    def self.get_actions(foe)
321
      res = '['
322
      count = 1
323
      max_count = foe.actions.size
324
      foe.actions.each do |action|
325
        res += '{"conditionParam1":' + action.condition_param1.to_s + ','
326
        res += '"conditionParam2":' + action.condition_param2.to_s + ','
327
        res += '"conditionType":' + action.condition_type.to_s + ','
328
        res += '"rating":' + action.rating.to_s + ','
329
        res += '"skillId":' + action.skill_id.to_s + '}'
330
        res += ',' if count < max_count
331
        count += 1
332
      end
333
      res += ']'
334
      res
335
    end
336
    
337
    def self.get_drop_items(foe)
338
      res = '['
339
      count = 1
340
      max_count = foe.drop_items.size
341
      foe.drop_items.each do |item|
342
        res += '{"dataId":' + item.data_id.to_s + ','
343
        res += '"denominator":' + item.denominator.to_s + ','
344
        res += '"kind":' + item.kind.to_s + '}'
345
        res += ',' if count < max_count
346
        count += 1
347
      end
348
      res += ']'
349
      res
350
    end
351
    
352
    #===========================================================================
353
    # TROOPS
354
    #===========================================================================
355
    def self.convert_troops
356
      f = File.open(FOLDER + "Troops.json", "w")
357
      f.puts('[')
358
      f.puts('null,')
359
      for x in 1 ... $data_troops.size
360
        troop = $data_troops[x]
361
        troop = RPG::Troop.new if !troop
362
        troop_data = '{'
363
        
364
        #***********************************************************************
365
        log("Troop " + x.to_s + " (" + get_text(troop.name) + ")")
366
        @logtroop = sprintf('Troop %d %s ', x, troop.name)
367
        #***********************************************************************
368
      
369
        troop_data += '"id":' + x.to_s + ','
370
        troop_data += '"members":' + get_troop_members(troop) + ','
371
        troop_data += '"name":' + get_text(troop.name) + ','
372
        troop_data += '"pages":' + get_troop_pages(troop) 
373
        
374
        troop_data += '}'
375
        troop_data += ',' if x < $data_troops.size - 1
376
        f.puts(troop_data)
377
      end
378
      f.puts(']')
379
      f.close
380
    end
381
    
382
    def self.get_troop_members(troop)
383
      res = '['
384
      count = 1
385
      max_count = troop.members.size
386
      troop.members.each do |enemy|
387
        res += '{"enemyId":' + enemy.enemy_id.to_s + ','
388
        res += '"x":' + enemy.x.to_s + ','
389
        res += '"y":' + enemy.y.to_s + ','
390
        res += '"hidden":' + enemy.hidden.to_s + '}'
391
        res += ',' if count < max_count
392
        count += 1
393
      end
394
      res += ']'
395
      res
396
    end
397
    
398
    def self.get_troop_pages(troop)
399
      res = '['
400
      count = 1
401
      max_count = troop.pages.size
402
      troop.pages.each do |page|
403
        #***********************************************************************
404
        log("  Page " + count.to_s)
405
        @logkey = sprintf('%s Page %d', @logtroop, count)
406
        #***********************************************************************
407
        cond = page.condition
408
        res += '{"conditions":{"actorHp":' + cond.actor_hp.to_s + ','
409
        res += '"actorId":' + cond.actor_id.to_s + ','
410
        res += '"actorValid":' + cond.actor_valid.to_s + ','
411
        res += '"enemyHp":' + cond.enemy_hp.to_s + ','
412
        res += '"enemyIndex":' + cond.enemy_index.to_s + ','
413
        res += '"enemyValid":' + cond.enemy_valid.to_s + ','
414
        res += '"switchId":' + cond.switch_id.to_s + ','
415
        res += '"switchValid":' + cond.switch_valid.to_s + ','
416
        res += '"turnA":' + cond.turn_a.to_s + ','
417
        res += '"turnB":' + cond.turn_b.to_s + ','
418
        res += '"turnEnding":' + cond.turn_ending.to_s + ','
419
        res += '"turnValid":' + cond.turn_valid.to_s + '},'
420
        
421
        res += '"list":' + get_command_list(page.list) + ','
422
        res += '"span":' + page.span.to_s + '}'
423
        
424
        res += ',' if count < max_count
425
        count += 1
426
      end
427
      res += ']'
428
      res
429
    end
430
    
431
    #===========================================================================
432
    # STATES
433
    #===========================================================================
434
    def self.convert_states
435
      f = File.open(FOLDER + "States.json", "w")
436
      f.puts('[')
437
      f.puts('null,')
438
      for x in 1 ... $data_states.size
439
        state = $data_states[x]
440
        state = RPG::State.new if !state
441
        state_data = '{'
442
        
443
        state_data += '"id":' + x.to_s + ','
444
        state_data += '"autoRemovalTiming":' + state.auto_removal_timing.to_s + ','
445
        state_data += '"chanceByDamage":' + state.chance_by_damage.to_s + ','
446
        state_data += '"iconIndex":' + state.icon_index.to_s + ','
447
        state_data += '"maxTurns":' + state.max_turns.to_s + ','
448
        state_data += '"message1":' + get_text(state.message1) + ','
449
        state_data += '"message2":' + get_text(state.message2) + ','
450
        state_data += '"message3":' + get_text(state.message3) + ','
451
        state_data += '"message4":' + get_text(state.message4) + ','
452
        state_data += '"minTurns":' + state.min_turns.to_s + ','
453
        state_data += '"motion":0,'
454
        state_data += '"overlay":0,'
455
        state_data += '"name":' + get_text(state.name) + ','
456
        state_data += '"note":' + get_text(state.note) + ','
457
        state_data += '"priority":' + state.priority.to_s + ','
458
        state_data += '"removeAtBattleEnd":' + state.remove_at_battle_end.to_s + ','
459
        state_data += '"removeByDamage":' + state.remove_by_damage.to_s + ','
460
        state_data += '"removeByRestriction":' + state.remove_by_restriction.to_s + ','
461
        state_data += '"removeByWalking":' + state.remove_by_walking.to_s + ','
462
        state_data += '"restriction":' + state.restriction.to_s + ','
463
        state_data += '"stepsToRemove":' + state.steps_to_remove.to_s + ','
464
        state_data += '"traits":' + get_traits(state)        
465
        
466
        state_data += '}'
467
        state_data += ',' if x < $data_states.size - 1
468
        f.puts(state_data)
469
      end
470
      f.puts(']')
471
      f.close
472
    end
473
    
474
    #===========================================================================
475
    # ANIMATIONS
476
    #===========================================================================
477
    def self.convert_animations
478
      f = File.open(FOLDER + "Animations.json", "w")
479
      f.puts('[')
480
      f.puts('null,')
481
      for x in 1 ... $data_animations.size
482
        anim = $data_animations[x]
483
        anim = RPG::Animation.new if !anim
484
        anim_data = '{'
485
        
486
        anim_data += '"id":' + x.to_s + ','
487
        anim_data += '"animation1Hue":' + anim.animation1_hue.to_s + ','
488
        anim_data += '"animation1Name":"' + anim.animation1_name + '",'
489
        anim_data += '"animation2Hue":' + anim.animation2_hue.to_s + ','
490
        anim_data += '"animation2Name":"' + anim.animation2_name + '",'
491
        anim_data += '"frames":' + get_anim_frames(anim) + ','
492
        anim_data += '"name":' + get_text(anim.name) + ','
493
        anim_data += '"position":' + anim.position.to_s + ','
494
        anim_data += '"timings":' + get_anim_timings(anim) 
495
        
496
        anim_data += '}'
497
        anim_data += ',' if x < $data_animations.size - 1
498
        f.puts(anim_data)
499
      end
500
      f.puts(']')
501
      f.close
502
    end
503
    
504
    def self.get_anim_frames(anim)
505
      res = '['
506
      for f in 0 ... anim.frame_max
507
        res += '['
508
        frame = anim.frames[f]
509
        if frame
510
          for c in 0 ... frame.cell_max
511
            res += '['
512
            frame.cell_data[c,4] = 360 - frame.cell_data[c,4] if frame.cell_data[c,4] != 0
513
            for i in 0..7
514
              res += frame.cell_data[c,i].to_s
515
              res += ',' if i < 7
516
            end
517
            res += ']'
518
            res += ',' if c < frame.cell_max - 1
519
          end
520
        else
521
          res += '[]'
522
        end
523
        res += ']'
524
        res += ',' if f < anim.frame_max - 1
525
      end
526
      res += ']'
527
      res
528
    end
529
    
530
    def self.get_anim_timings(anim)
531
      res = '['
532
      for t in 0 ... anim.timings.size
533
        timing = anim.timings[t]
534
        res += '{"flashColor":' + get_color(timing.flash_color) + ','
535
        res += '"flashDuration":' + timing.flash_duration.to_s + ','
536
        res += '"flashScope":' + timing.flash_scope.to_s + ','
537
        res += '"frame":' + timing.frame.to_s + ','
538
        res += '"se":'
539
        if timing.se.name == ''
540
          res += 'null'
541
        else
542
          res += get_audio(timing.se)
543
        end
544
        res += '}'
545
        res += ',' if t < anim.timings.size - 1
546
      end
547
      res += ']'
548
      res
549
    end
550
    
551
    #===========================================================================
552
    # TILESETS
553
    #===========================================================================
554
    def self.convert_tilesets
555
      f = File.open(FOLDER + "Tilesets.json", "w")
556
      f.puts('[')
557
      f.puts('null,')
558
      for x in 1 ... $data_tilesets.size
559
        tileset = $data_tilesets[x]
560
        tileset = RPG::Tileset.new if !tileset
561
        ts_data = '{'
562
        
563
        ts_data += '"id":' + x.to_s + ','
564
        ts_data += '"flags":'
565
        flags = []
566
        for t in 0 .. 8191
567
          flags[t] = tileset.flags[t]
568
        end
569
        ts_data += flags.to_s.gsub(/ /){''} + ','
570
        ts_data += '"mode":' + tileset.mode.to_s + ','
571
        ts_data += '"name":' + get_text(tileset.name) + ','
572
        ts_data += '"note":' + get_text(tileset.note) + ','
573
        ts_data += '"tilesetNames":' + tileset.tileset_names.to_s.gsub(/, /){','}
574
        
575
        ts_data += '}'
576
        ts_data += ',' if x < $data_tilesets.size - 1
577
        f.puts(ts_data)
578
      end
579
      f.puts(']')
580
      f.close
581
    end
582
    
583
    #===========================================================================
584
    # COMMON EVENTS
585
    #===========================================================================
586
    def self.convert_common_events
587
      f = File.open(FOLDER + "CommonEvents.json", "w")
588
      f.puts('[')
589
      f.puts('null,')
590
      for x in 1 ... $data_common_events.size
591
        event = $data_common_events[x]
592
        event = RPG::CommonEvent.new if !event
593
        
594
        #***********************************************************************
595
        log("Common Event " + x.to_s + " (" + get_text(event.name) + ")")
596
        @logkey = sprintf('Common Event %d %s', x, event.name)
597
        #***********************************************************************
598
        
599
        ev_data = '{'
600
        
601
        ev_data += '"id":' + x.to_s + ','
602
        ev_data += '"list":' + get_command_list(event.list) + ','
603
        ev_data += '"name":' + get_text(event.name) + ','
604
        ev_data += '"switchId":' + event.switch_id.to_s + ','
605
        ev_data += '"trigger":' + event.trigger.to_s
606
        
607
        ev_data += '}'
608
        ev_data += ',' if x < $data_common_events.size - 1
609
        f.puts(ev_data)
610
      end
611
      f.puts(']')
612
      f.close
613
    end
614
    
615
    #===========================================================================
616
    # SYSTEM
617
    #===========================================================================
618
    def self.convert_system
619
      f = File.open(FOLDER + "System.json", "w")
620
      system = $data_system
621
      sys_data = '{'
622
      
623
      sys_data += '"airship":' + get_vehicle(system.airship) + ','
624
      sys_data += '"armorTypes":' + system.armor_types.to_s.gsub(/nil/){'""'}.gsub(/, /){','} + ','
625
      sys_data += '"attackMotions":' + get_attack_motions + ','
626
      sys_data += '"battleBgm":' + get_audio(system.battle_bgm) + ','
627
      sys_data += '"battleBack1Name":"' + system.battleback1_name + '",'
628
      sys_data += '"battleBack2Name":"' + system.battleback2_name + '",'
629
      sys_data += '"battlerHue":' + system.battler_hue.to_s + ','
630
      sys_data += '"battlerName":"' + system.battler_name + '",'
631
      sys_data += '"boat":' + get_vehicle(system.boat) + ','
632
      sys_data += '"currencyUnit":"' + system.currency_unit + '",'
633
      sys_data += '"defeatMe":{"name":"Defeat1","pan":0,"pitch":100,"volume":90},'
634
      sys_data += '"editMapId":' + system.edit_map_id.to_s + ','
635
      sys_data += '"elements":' + system.elements.to_s.gsub(/nil/){'""'}.gsub(/, /){','} + ','
636
      sys_data += '"equipTypes":' + system.terms.etypes.unshift('').to_s.gsub(/, /){','} + ','
637
      sys_data += '"gameTitle":' + get_text(system.game_title) + ','
638
      sys_data += '"gameoverMe":' + get_audio(system.gameover_me) + ','
639
      sys_data += '"locale":"en_US",'
640
      sys_data += '"magicSkills":[1],'
641
      sys_data += '"menuCommands":[true,true,true,true,true,true],'
642
      sys_data += '"optDisplayTp":' + system.opt_display_tp.to_s + ','
643
      sys_data += '"optDrawTitle":' + system.opt_draw_title.to_s + ','
644
      sys_data += '"optExtraExp":' + system.opt_extra_exp.to_s + ','
645
      sys_data += '"optFloorDeath":' + system.opt_floor_death.to_s + ','
646
      sys_data += '"optFollowers":' + system.opt_followers.to_s + ','
647
      sys_data += '"optSideView":false,'
648
      sys_data += '"optSlipDeath":' + system.opt_slip_death.to_s + ','
649
      sys_data += '"optTransparent":' + system.opt_transparent.to_s + ','
650
      sys_data += '"partyMembers":' + system.party_members.to_s.gsub(/ /){''} + ','
651
      sys_data += '"ship":' + get_vehicle(system.ship) + ','
652
      sys_data += '"skillTypes":' + system.skill_types.to_s.gsub(/nil/){'""'}.gsub(/, /){','} + ','
653
      sys_data += '"sounds":' + get_system_sounds(system) + ','
654
      sys_data += '"startMapId":' + system.start_map_id.to_s + ','
655
      sys_data += '"startX":' + system.start_x.to_s + ','
656
      sys_data += '"startY":' + system.start_y.to_s + ','
657
      system.switches[0] = ''
658
      sys_data += '"switches":' + system.switches.to_s.gsub(/nil/){'""'}.gsub(/, /){','} + ','
659
      sys_data += '"terms":{"basic":' + (system.terms.basic + ['EXP','EXP']).to_s.gsub(/, /){','} + ','
660
      system.terms.commands[11] = 'Options'
661
      sys_data += '"commands":' + (system.terms.commands + ['Buy','Sell']).to_s.gsub(/, /){','} + ','
662
      sys_data += '"params":' + (system.terms.params + ['Hit','Evasion']).to_s.gsub(/, /){','} + ','
663
      sys_data += '"messages":' + get_system_messages + '},'
664
      sys_data += '"testBattlers":' + get_test_battlers(system.test_battlers) + ','
665
      sys_data += '"testTroopId":' + system.test_troop_id.to_s + ','
666
      sys_data += '"title1Name":"' + system.title1_name + '",'
667
      sys_data += '"title2Name":"' + system.title2_name + '",'
668
      sys_data += '"titleBgm":' + get_audio(system.title_bgm) + ','
669
      system.variables[0] = ''
670
      sys_data += '"variables":' + system.variables.to_s.gsub(/nil/){'""'}.gsub(/, /){','} + ','
671
      sys_data += '"versionId":' + system.version_id.to_s + ','
672
      sys_data += '"victoryMe":' + get_audio(system.battle_end_me) + ','
673
      sys_data += '"weaponTypes":' + system.weapon_types.to_s.gsub(/nil/){'""'}.gsub(/, /){','} + ','
674
      sys_data += '"windowTone":' + get_tone(system.window_tone)
675
      
676
      sys_data += '}'
677
      f.puts(sys_data)
678
      f.close
679
    end
680
    
681
    def self.get_attack_motions
682
      res = '['
683
      res += '{"type":0,"weaponImageId":0},'
684
      res += '{"type":1,"weaponImageId":1},'
685
      res += '{"type":1,"weaponImageId":2},'
686
      res += '{"type":1,"weaponImageId":3},'
687
      res += '{"type":1,"weaponImageId":4},'
688
      res += '{"type":1,"weaponImageId":5},'
689
      res += '{"type":1,"weaponImageId":6},'
690
      res += '{"type":2,"weaponImageId":7},'
691
      res += '{"type":2,"weaponImageId":8},'
692
      res += '{"type":2,"weaponImageId":9},'
693
      res += '{"type":0,"weaponImageId":10},'
694
      res += '{"type":0,"weaponImageId":11},'
695
      res += '{"type":0,"weaponImageId":12}'
696
      res += ']'
697
      res
698
    end
699
      
700
    def self.get_vehicle(vehicle)
701
      res = '{"bgm":' + get_audio(vehicle.bgm) + ','
702
      res += '"characterIndex":' + vehicle.character_index.to_s + ','
703
      res += '"characterName":"' + vehicle.character_name + '",'
704
      res += '"startMapId":' + vehicle.start_map_id.to_s + ','
705
      res += '"startX":' + vehicle.start_x.to_s + ','
706
      res += '"startY":' + vehicle.start_y.to_s + '}'
707
      res
708
    end
709
    
710
    def self.get_system_sounds(system)
711
      res = '['
712
      for x in 0 ... system.sounds.size
713
        res += get_audio(system.sounds[x])
714
        res += ',' if x < system.sounds.size - 1
715
      end
716
      
717
      res += ']'
718
      res
719
    end
720
    
721
    def self.get_system_messages
722
      res = '{'
723
      res += '"actionFailure":"There was no effect on %1!",'
724
      res += '"actorDamage":"%1 took %2 damage!",'
725
      res += '"actorDrain":"%1 was drained of %2 %3!",'
726
      res += '"actorGain":"%1 gained %2 %3!",'
727
      res += '"actorLoss":"%1 lost %2 %3!",'
728
      res += '"actorNoDamage":"%1 took no damage!",'
729
      res += '"actorNoHit":"Miss! %1 took no damage!",'
730
      res += '"actorRecovery":"%1 recovered %2 %3!",'
731
      res += '"alwaysDash":"Always Dash",'
732
      res += '"bgmVolume":"BGM Volume",'
733
      res += '"bgsVolume":"BGS Volume",'
734
      res += '"buffAdd":"%1\'s %2 went up!",'
735
      res += '"buffRemove":"%1''s %2 returned to normal!",'
736
      res += '"commandRemember":"Command Remember",'
737
      res += '"counterAttack":"%1 counterattacked!",'
738
      res += '"criticalToActor":"A painful blow!!",'
739
      res += '"criticalToEnemy":"An excellent hit!!",'
740
      res += '"debuffAdd":"%1\'s %2 went down!",'
741
      res += '"defeat":"%1 was defeated.",'
742
      res += '"emerge":"%1 emerged!",'
743
      res += '"enemyDamage":"%1 took %2 damage!",'
744
      res += '"enemyDrain":"%1 was drained of %2 %3!",'
745
      res += '"enemyGain":"%1 gained %2 %3!",'
746
      res += '"enemyLoss":"%1 lost %2 %3!",'
747
      res += '"enemyNoDamage":"%1 took no damage!",'
748
      res += '"enemyNoHit":"Miss! %1 took no damage!",'
749
      res += '"enemyRecovery":"%1 recovered %2 %3!",'
750
      res += '"escapeFailure":"However, it was unable to escape!",'
751
      res += '"escapeStart":"%1 has started to escape!",'
752
      res += '"evasion":"%1 evaded the attack!",'
753
      res += '"expNext":"To Next %1",'
754
      res += '"expTotal":"Current %1",'
755
      res += '"file":"File",'
756
      res += '"levelUp":"%1 is now %2 %3!",'
757
      res += '"loadMessage":"Load which file?",'
758
      res += '"magicEvasion":"%1 nullified the magic!",'
759
      res += '"magicReflection":"%1 reflected the magic!",'
760
      res += '"meVolume":"ME Volume",'
761
      res += '"obtainExp":"%1 %2 received!",'
762
      res += '"obtainGold":"%1\\\\G found!",'
763
      res += '"obtainItem":"%1 found!",'
764
      res += '"obtainSkill":"%1 learned!",'
765
      res += '"partyName":"%1\'s Party",'
766
      res += '"possession":"Possession",'
767
      res += '"preemptive":"%1 got the upper hand!",'
768
      res += '"saveMessage":"Save to which file?",'
769
      res += '"seVolume":"SE Volume",'
770
      res += '"substitute":"%1 protected %2!",'
771
      res += '"surprise":"%1 was surprised!",'
772
      res += '"useItem":"%1 uses %2!",'
773
      res += '"victory":"%1 was victorious!"'
774
      res += '}'
775
      res
776
    end
777
    
778
    def self.get_test_battlers(battlers)
779
      res = '['
780
      for x in 0 ... battlers.size
781
        battler = battlers[x]
782
        res += '{'
783
        res += '"actorId":' + battler.actor_id.to_s + ','
784
        res += '"equips":' + battler.equips.to_s.gsub(/ /){''} + ','
785
        res += '"level":' + battler.level.to_s
786
        res += '}'
787
        res += ',' if x < battlers.size - 1
788
      end
789
      res += ']'
790
      res
791
    end
792
    
793
    #===========================================================================
794
    # MAPINFOS
795
    #===========================================================================
796
    def self.convert_mapinfos
797
      f = File.open(FOLDER + "MapInfos.json", "w")
798
      f.puts('[')
799
      f.puts('null,')
800
      max_key = $data_mapinfos.keys.max
801
      for x in 1 .. max_key
802
        map = $data_mapinfos[x]
803
        if map
804
          map_data = '{'
805
          map_data += '"id":' + x.to_s + ','
806
          map_data += '"expanded":' + map.expanded.to_s + ','
807
          map_data += '"name":' + get_text(map.name) + ','
808
          map_data += '"order":' + map.order.to_s + ','
809
          map_data += '"parentId":' + map.parent_id.to_s + ','
810
          map_data += '"scrollX":' + map.scroll_x.to_s + ','
811
          map_data += '"scrollY":' + map.scroll_y.to_s
812
          map_data += '}'
813
        else
814
          map_data = 'null'
815
        end
816
        
817
        map_data += ',' if x < max_key
818
        f.puts(map_data)
819
      end      
820
      f.puts(']')
821
      f.close
822
    end
823
    
824
825
    #===========================================================================
826
    # MAPS
827
    #===========================================================================
828
    def self.convert_map(filename)
829
      map = load_data(filename)
830
      f = File.open(FOLDER + filename.gsub(/Data\//){''}.gsub(/rvdata2/){'json'}, "w")
831
      f.puts('{')
832
      
833
      #*************************************************************************
834
      log("Map " + filename + " (" + map.display_name + ")")
835
      filename.gsub!(/Map(\d+)\.rvdata2/) do
836
        @logmap = sprintf('Map %d %s', $1.to_i, (
837
          $data_mapinfos[$1.to_i] ? $data_mapinfos[$1.to_i].name : '???'))
838
      end
839
      #*************************************************************************
840
      
841
      map.autoplay_bgm ||= false
842
      map.autoplay_bgs ||= false
843
      map.battleback1_name ||= ''
844
      map.battleback2_name ||= ''
845
      
846
      map_data = '"autoplayBgm":' + map.autoplay_bgm.to_s + ','
847
      map_data += '"autoplayBgs":' + map.autoplay_bgs.to_s + ','
848
      map_data += '"battleback1Name":"' + map.battleback1_name + '",'
849
      map_data += '"battleback2Name":"' + map.battleback2_name + '",'
850
      map_data += '"bgm":' + get_audio(map.bgm) + ','
851
      map_data += '"bgs":' + get_audio(map.bgs) + ','
852
      map_data += '"disableDashing":' + map.disable_dashing.to_s + ','
853
      map_data += '"displayName":' + get_text(map.display_name) + ','
854
      map_data += '"encounterList":' + get_encounter_list(map.encounter_list) + ','
855
      map_data += '"encounterStep":' + map.encounter_step.to_s + ','
856
      map_data += '"height":' + map.height.to_s + ','
857
      map_data += '"note":' + get_text(map.note) + ','
858
      map_data += '"parallaxLoopX":' + map.parallax_loop_x.to_s + ','
859
      map_data += '"parallaxLoopY":' + map.parallax_loop_y.to_s + ','
860
      map_data += '"parallaxName":"' + map.parallax_name + '",'
861
      map_data += '"parallaxShow":' + map.parallax_show.to_s + ','
862
      map_data += '"parallaxSx":' + map.parallax_sx.to_s + ','
863
      map_data += '"parallaxSy":' + map.parallax_sy.to_s + ','
864
      map_data += '"scrollType":' + map.scroll_type.to_s + ','
865
      map_data += '"specifyBattleback":' + map.specify_battleback.to_s + ','
866
      map_data += '"tilesetId":' + map.tileset_id.to_s + ','
867
      map_data += '"width":' + map.width.to_s + ','
868
      map_data += '"data":' + get_map_data(map.data).to_s.gsub(/ /){''} + ','
869
      map_data += '"events":' + get_map_events(map.events)
870
      f.puts(map_data)
871
      
872
      f.puts('}')
873
      f.close
874
    end
875
    
876
    def self.get_encounter_list(list)
877
      res = '['
878
      for x in 0 ... list.size
879
        encounter = list[x]
880
        encounter = RPG::Map::Encounter.new if !encounter
881
        res += '{"regionSet":' + encounter.region_set.to_s.gsub(/ /){''} + ','
882
        res += '"troopId":' + encounter.troop_id.to_s + ','
883
        res += '"weight":' + encounter.weight.to_s
884
        res += '}'
885
        res += ',' if x < list.size - 1
886
      end
887
      res += ']'
888
      res
889
    end
890
    
891
    def self.get_map_data(data)
892
      res = []
893
      for z in 0 ... data.zsize - 1 # 3 map layers
894
        for y in 0 ... data.ysize
895
          for x in 0 ... data.xsize
896
            res.push(data[x,y,z])
897
          end
898
        end
899
      end
900
      for y in 0 ... data.ysize # new 4th map layer?
901
        for x in 0 ... data.xsize
902
          res.push(0)
903
        end
904
      end
905
      z = data.zsize - 1 # original 4th layer (regions + ???)
906
      for y in 0 ... data.ysize
907
        for x in 0 ... data.xsize
908
          res.push(data[x,y,z])
909
        end
910
      end
911
      for y in 0 ... data.ysize # regions
912
        for x in 0 ... data.xsize
913
          res.push(data[x,y,3] >> 8)
914
        end
915
      end
916
      res
917
    end
918
    
919
    def self.get_map_events(events)
920
      res = '['
921
      max_key = events.keys.max
922
      if max_key
923
        for x in 0 .. max_key
924
          if events.has_key?(x)
925
            event = events[x]
926
            res += get_event(event)
927
          else
928
            res += 'null'
929
          end
930
          res += ',' if x < max_key
931
        end
932
      end
933
      res += ']'
934
      res
935
    end
936
    
937
    def self.get_event(event)
938
      #*************************************************************************
939
      log("  Event " + event.id.to_s + " (" + get_text(event.name) + " @ " + event.x.to_s + "," + event.y.to_s + ")")
940
      @logevent = sprintf('%s - Event %d %s (%d,%d)', @logmap, event.id, event.name, event.x, event.y)
941
      #*************************************************************************
942
      res = '{"id":' + event.id.to_s + ','
943
      res += '"name":' + get_text(event.name) + ','
944
      res += '"note":"",'
945
      res += '"pages":' + get_event_pages(event.pages) + ','
946
      res += '"x":' + event.x.to_s + ','
947
      res += '"y":' + event.y.to_s      
948
      res += '}'
949
      res
950
    end
951
    
952
    def self.get_event_pages(pages)
953
      res = '['
954
      for x in 0 ... pages.size
955
        #***********************************************************************
956
        log("    Page " + (x+1).to_s)
957
        @logkey = sprintf('%s - Page %d', @logevent, x+1)
958
        #***********************************************************************
959
        page = pages[x]
960
        page = RPG::Event::Page.new if !page
961
        res += get_page(page)
962
        res += ',' if x < pages.size - 1
963
      end
964
      res += ']'
965
      res
966
    end
967
        
968
    def self.get_page(page)
969
      condition = page.condition
970
      res = '{"conditions":' 
971
      res += '{"actorId":' + condition.actor_id.to_s + ','
972
      res += '"actorValid":' + condition.actor_valid.to_s + ','
973
      res += '"itemId":' + condition.item_id.to_s + ','
974
      res += '"itemValid":' + condition.item_valid.to_s + ','
975
      res += '"selfSwitchCh":"' + condition.self_switch_ch + '",'
976
      res += '"selfSwitchValid":' + condition.self_switch_valid.to_s + ','
977
      res += '"switch1Id":' + condition.switch1_id.to_s + ','
978
      res += '"switch1Valid":' + condition.switch1_valid.to_s + ','
979
      res += '"switch2Id":' + condition.switch2_id.to_s + ','
980
      res += '"switch2Valid":' + condition.switch2_valid.to_s + ','
981
      res += '"variableId":' + condition.variable_id.to_s + ','
982
      res += '"variableValid":' + condition.variable_valid.to_s + ','
983
      res += '"variableValue":' + condition.variable_value.to_s + '},'
984
      
985
      res += '"directionFix":' + page.direction_fix.to_s + ','
986
      
987
      graphic = page.graphic
988
      res += '"image":'
989
      res += '{"tileId":' + graphic.tile_id.to_s + ','
990
      res += '"characterName":"' + graphic.character_name + '",'
991
      res += '"direction":' + graphic.direction.to_s + ','
992
      res += '"pattern":' + graphic.pattern.to_s + ','
993
      res += '"characterIndex":' + graphic.character_index.to_s + '},'
994
      
995
      res += '"moveFrequency":' + page.move_frequency.to_s + ','
996
      res += '"moveRoute":' + get_move_route(page.move_route) + ','
997
      res += '"moveSpeed":' + page.move_speed.to_s + ','
998
      res += '"moveType":' + page.move_type.to_s + ','
999
      res += '"priorityType":' + page.priority_type.to_s + ','
1000
      res += '"stepAnime":' + page.step_anime.to_s + ','
1001
      res += '"through":' + page.through.to_s + ','
1002
      res += '"trigger":' + page.trigger.to_s + ','
1003
      res += '"walkAnime":' + page.walk_anime.to_s + ','
1004
      res += '"list":' + get_command_list(page.list) + '}'
1005
      
1006
      res
1007
    end
1008
    
1009
    #===========================================================================
1010
    # SUPPORT OBJECTS FOR DATABASE
1011
    #===========================================================================
1012
    
1013
    def self.get_traits(obj)
1014
      res = '['
1015
      count = 1
1016
      max_count = obj.features.size
1017
      obj.features.each do |feat|
1018
        res += '{"code":' + feat.code.to_s + ','
1019
        res += '"dataId":' + feat.data_id.to_s + ','
1020
        res += '"value":' + feat.value.to_s + '}'
1021
        res += ',' if count < max_count
1022
        count += 1
1023
      end      
1024
      res += ']'
1025
      res
1026
    end
1027
    
1028
    def self.get_effects(obj)
1029
      res = '['
1030
      count = 1
1031
      max_count = obj.effects.size
1032
      obj.effects.each do |effct|
1033
        res += '{"code":' + effct.code.to_s + ','
1034
        res += '"dataId":' + effct.data_id.to_s + ','
1035
        res += '"value1":' + effct.value1.to_s + ','
1036
        res += '"value2":' + effct.value2.to_s + '}'
1037
        res += ',' if count < max_count
1038
        count += 1
1039
      end      
1040
      res += ']'
1041
      res
1042
    end
1043
    
1044
    def self.get_damage(obj)
1045
      dmg = obj.damage
1046
      
1047
      if LOGSCRIPTS && obj.damage.formula.to_i.to_s != obj.damage.formula
1048
        sl_data = sprintf('%s %d %s: Damage Formula: %s', 
1049
          (obj.is_a?(RPG::Skill) ? 'Skill' : 'Item'), obj.id, obj.name, dmg.formula)
1050
        @scriptlog.puts(sl_data)
1051
      end
1052
      
1053
      res = '{"critical":' + dmg.critical.to_s + ','
1054
      res += '"elementId":' + dmg.element_id.to_s + ','
1055
      res += '"formula":"' + dmg.formula + '",'
1056
      res += '"type":' + dmg.type.to_s + ','
1057
      res += '"variance":' + dmg.variance.to_s + '}'
1058
      res
1059
    end
1060
    
1061
    
1062
    #===========================================================================
1063
    #
1064
    # EVENT COMMANDS
1065
    #
1066
    #===========================================================================
1067
    
1068
    #===========================================================================
1069
    # COMMAND LISTS
1070
    #===========================================================================
1071
    
1072
    def self.get_command_list(list)
1073
      res = '['
1074
      count = 1
1075
      max_count = list.size
1076
      list.each do |cmd|
1077
        @loginfo = sprintf('%s Line %d: ', @logkey, count)
1078
        
1079
        case cmd.code
1080
        when 102 # show choices
1081
          cmd.parameters[1] -= 1 # disallow cancel
1082
          cmd.parameters[1] = -2 if cmd.parameters[1] == 4 # branch on cancel
1083
          cmd.parameters[2] = 0 # default 
1084
          cmd.parameters[3] = 2 # window position 
1085
          cmd.parameters[4] = 0 # window background
1086
        when 104
1087
          cmd.parameters[1] = 2 # key item
1088
        when 108, 408 # comment
1089
          log_comment(cmd.parameters[0])
1090
        when 111
1091
          if cmd.parameters[0] == 11 # Key Pressed
1092
            # ASD buttons are not catered for in MV.  To use these, you will
1093
            # have to add 41 (A), 43 (S) and 44 (D) to the Input.keyMapper hash
1094
            # in rpg_core.js:
1095
            # Input.keyMapper[41] = 'A'
1096
            # Input.keyMapper[53] = 'S'
1097
            # Input.keyMapper[44] = 'D'
1098
            case cmd.parameters[1]
1099
            when 14
1100
              cmd.parameters = [12, "Input.isTriggered('A')"]
1101
            when 15
1102
              cmd.parameters = [12, "Input.isTriggered('S')"]
1103
            when 16
1104
              cmd.parameters = [12, "Input.isTriggered('D')"]
1105
            else
1106
              cmd.parameters[1] = ['', '', 'down', '', 'left', '', 'right', '', 'up',
1107
                '', '', 'shift', 'cancel', 'ok', '', '', '', 'pageup', 'pagedown'][
1108
                cmd.parameters[1]]
1109
            end
1110
          elsif cmd.parameters[0] == 12 # Script
1111
            log_script('Conditional Branch script call', cmd.parameters[1])
1112
          end
1113
        when 122 # Control Variables
1114
          if cmd.parameters[3] == 4 # Script
1115
            log_script('Control Variables script call', cmd.parameters[4])
1116
          end
1117
        when 231 # show picture
1118
          if cmd.parameters[9] == 2 # subtract
1119
            params = cmd.parameters
1120
            cmd.code = 355
1121
            cmd.parameters = [sprintf('$gameScreen.showPicture(%d, "%s", %d, %s, %s, %d, %d, %d, %d)',
1122
              params[0], params[1], params[2], (params[3] == 0 ? params[4].to_s : '$gameVariables.value(' + params[4].to_s + ')'),
1123
              (params[3] == 0 ? params[5].to_s : '$gameVariables.value(' + params[5].to_s + ')'),
1124
              params[6], params[7], params[8], params[9])]
1125
          end
1126
        when 232 # move picture
1127
          cmd.parameters[1] = 0 # not used, but can't be blank in MV
1128
          if cmd.parameters[9] == 2 # subtract
1129
            params = cmd.parameters
1130
            cmd.code = 355
1131
            cmd.parameters = [sprintf('$gameScreen.movePicture(%d, %d, %s, %s, %d, %d, %d, %d, %d)%s',
1132
              params[0], params[2], (params[3] == 0 ? params[4].to_s : '$gameVariables.value(' + params[4].to_s + ')'),
1133
              (params[3] == 0 ? params[5].to_s : '$gameVariables.value(' + params[5].to_s + ')'),
1134
              params[6], params[7], params[8], params[9], params[10], params[11] ? '; this.wait(' + params[10].to_s + ')' : '')]
1135
          end
1136
        when 285 # get location info
1137
          cmd.parameters[1] = 6 if cmd.parameters[1] == 5 # region id now +1
1138
        when 319 # change equipment
1139
          cmd.parameters[1] += 1
1140
        when 302 # shop processing
1141
          cmd.parameters[3] = 0 if cmd.parameters[3].nil?
1142
        when 322 # change actor graphic
1143
          cmd.parameters[4] = 0 # SV graphic
1144
          cmd.parameters[5] = ''
1145
        when 355, 655 # Script call
1146
          log_script('Script call', cmd.parameters[0])
1147
        when 505 # Move route 
1148
          mvrcmd = cmd.parameters[0]
1149
          if mvrcmd.code == 45 # script
1150
            log_script('Move Route Script call', mvrcmd.parameters[0])
1151
          end
1152
        end
1153
        
1154
        evt_cmd = '{"code":' + cmd.code.to_s + ','
1155
        evt_cmd += '"indent":' + cmd.indent.to_s + ','
1156
        evt_cmd += '"parameters":' + convert_parameters(cmd.parameters) + '}'
1157
        
1158
        #***********************************************************************
1159
        log("      " + evt_cmd)
1160
        #***********************************************************************
1161
        
1162
        res += evt_cmd
1163
        res += ',' if count < max_count
1164
        count += 1
1165
      end
1166
      res += ']'
1167
      res
1168
    end
1169
    
1170
    def self.get_move_route(mr)
1171
      res = '{"list":['
1172
      list = mr.list
1173
      for x in 0 ... list.size
1174
        cmd = list[x]
1175
        
1176
        case cmd.code
1177
        when 43
1178
          if cmd.parameters[0] == 2 then
1179
            cmd.code = 45
1180
            cmd.parameters = ["this.setBlendMode(2);"]
1181
          end
1182
        end
1183
        
1184
        mvr = '{"code":' + cmd.code.to_s + ','
1185
        mvr += '"indent":null,'
1186
        mvr += '"parameters":' + convert_parameters(cmd.parameters) + '}'
1187
        
1188
        #***********************************************************************
1189
        log("        " + mvr)
1190
        #***********************************************************************
1191
        
1192
        res += mvr
1193
        res += ',' if x < list.size - 1
1194
      end
1195
      res += '],"repeat":' + mr.repeat.to_s + ','
1196
      res += '"skippable":' + mr.skippable.to_s + ','
1197
      res += '"wait":' + mr.wait.to_s + '}'
1198
      res
1199
    end
1200
    
1201
    def self.convert_parameters(params)
1202
      res = '['
1203
      for x in 0 ... params.size
1204
        param = params[x]
1205
        case param
1206
        when RPG::MoveRoute
1207
          param = get_move_route(param)
1208
        when RPG::MoveCommand
1209
          param = get_move_command(param)
1210
        when RPG::AudioFile
1211
          param = get_audio(param)
1212
        when String
1213
          param = get_text(param)
1214
        when Symbol
1215
          param = get_text(param.to_s)
1216
        when Tone
1217
          param = get_tone(param)
1218
        when Color
1219
          param = get_color(param)
1220
        end
1221
        
1222
        res += param.to_s
1223
        res += ',' if x < params.size - 1
1224
      end
1225
      res += ']'
1226
      res
1227
    end
1228
          
1229
    
1230
    #===========================================================================
1231
    # COMMANDS
1232
    #===========================================================================
1233
    
1234
    def self.get_move_command(param)
1235
      res = '{"code":' + param.code.to_s + ','
1236
      res += '"indent":null,'
1237
      res += '"parameters":' + convert_parameters(param.parameters).to_s + '}'
1238
      res
1239
    end
1240
    
1241
    #===========================================================================
1242
    # COMMON OBJECTS
1243
    #===========================================================================
1244
    
1245
    def self.get_text(text)
1246
      '"' + text.gsub(/\\/){'\\\\'}.gsub(/[\r\n]+/){'\\n'}.gsub(/"/){'\\"'} + '"'
1247
    end
1248
    
1249
    def self.get_audio(a)
1250
      a = RPG::AudioFile.new if !a
1251
      res = '{"name":"' + a.name + '",'
1252
      res += '"pan":0,'
1253
      res += '"pitch":' + a.pitch.to_s + ','
1254
      res += '"volume":' + a.volume.to_s + '}'
1255
      res
1256
    end      
1257
    
1258
    def self.get_color(color)
1259
      res = '['
1260
      res += color.red.to_s + ',' 
1261
      res += color.green.to_s + ',' 
1262
      res += color.blue.to_s + ',' 
1263
      res += color.alpha.to_s 
1264
      res += ']'
1265
      res
1266
    end
1267
    
1268
    def self.get_tone(tone)
1269
      res = '['
1270
      res += tone.red.to_s + ','
1271
      res += tone.green.to_s + ','
1272
      res += tone.blue.to_s + ','
1273
      res += tone.gray.to_s
1274
      res += ']'
1275
      res
1276
    end
1277
    
1278
    def self.log(details)
1279
      @log.puts(details) if LOGGING
1280
    end
1281
    
1282
    def self.log_script(title, cmd)
1283
      @scriptlog.puts(sprintf('%s - %s: %s', @loginfo, title, cmd)) if LOGSCRIPTS
1284
    end
1285
    
1286
    def self.log_comment(comment)
1287
      @commentlog.puts(sprintf('%s - Comment: %s', @loginfo, comment)) if LOGCOMMENTS
1288
    end
1289
  end
1290
end
1291
DEGICA::CONVERT::run