forked from dotabuff/d2vpk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.rb
45 lines (36 loc) · 1.25 KB
/
convert.rb
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
#!/usr/bin/env ruby
require 'rake'
require "json"
require 'fileutils'
require_relative "./vdf"
patches = {
'dota/resource/dota_english.txt' => {
%("Notes:\\n\\nHas a 0.35 seconds transformation time."\r\nYou can dodge projectiles and abilities while transforming.) =>
%("Notes:\\n\\nHas a 0.35 seconds transformation time.\r\nYou can dodge projectiles and abilities while transforming."),
}
}
%w[
dota/resource/{items,dota}_*.txt
dota_pak01/scripts/items/items_game.txt
dota_pak01/scripts/{regions,emoticons}.txt
dota_pak01/scripts/npc/{npc_abilities,npc_heroes,npc_units,items,activelist}.txt
].each do |glob|
Dir.glob glob do |source|
json_name = File.basename(source, '.txt') + ".json"
directory = File.dirname(source)
dest_directory = File.join('json', directory)
dest = File.join(dest_directory, json_name)
FileUtils.mkdir_p dest_directory
puts "Converting #{source} to #{dest}..."
begin
txt = File.read(source)
[*patches[source]].each{|k, v| warn "patch failed: #{k} => #{v}" unless txt.sub!(k, v) }
vdf = VDF.new(txt)
res = JSON.pretty_generate(vdf.kvs)
File.open(dest, "w") {|f| f.write(res) }
rescue => ex
puts "Error: #{ex}"
end
sh 'git', 'add', dest
end
end