-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.rb
93 lines (78 loc) · 2.28 KB
/
main.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
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
require 'fileutils'
require_relative "utils"
require_relative "scene"
require_relative "scripts"
require_relative "conversion"
FILE_EXTENSIONS = [".tscn", ".tres", ".gd", ".shader"]
def fetch_files(dir, list)
for file in Dir.entries(dir) - [".", ".."]
if dir == "."
name = file
else
name = dir + "/" + file
end
if Dir.exists?(name)
if not $NO_RECURSION
fetch_files(name, list)
end
else
if FILE_EXTENSIONS.include?(File.extname(name))
list << name
end
end
end
end
def save_file(file, data)
if $DEBUG
File.new(File.dirname(file) + "/DEBUG#" + File.basename(file), "w").puts(data.to_s)
else
File.new(file, "w").puts(data.to_s)
end
end
def rename_file(file, new_name)
if $DEBUG
FileUtils.cp(file, File.dirname(file) + "/DEBUG#" + File.basename(new_name))
else
File.rename(file, new_name)
end
end
$DEBUG = true if ARGV.delete("--debug")
$NO_RECURSION = true if ARGV.delete("--no-recursion")
root = "."
if i = ARGV.index("--path")
root = ARGV[i + 1]
ARGV.delete_at(i)
ARGV.delete_at(i)
end
file_list = []
if not Dir.exists?(root) and File.exists?(root)
file_list = [root]
else
fetch_files(root, file_list)
end
file_list.reject! {|file| file.include?("DEBUG#")}
i = 1
all = file_list.length
file_list.select{|f| File.extname(f) == ".shader"}.each do |shader|
puts "Renaming file: #{shader} (#{i}/#{all})"
rename_file(shader, shader.chomp("shader") + "gdshader")
i += 1
end
file_list.select{|f| File.extname(f) == ".tscn"}.each do |scene|
puts "Converting file: #{scene} (#{i}/#{all})"
file = Scene.new(scene)
save_file(scene, file)
i += 1
end
file_list.select{|f| File.extname(f) == ".gd"}.each do |script|
puts "Converting file: #{script} (#{i}/#{all})"
file = Script.new(File.readlines(script))
save_file(script, file)
i += 1
end
file_list.select{|f| File.extname(f) == ".tres"}.each do |resource|
puts "Converting file: #{resource} (#{i}/#{all})"
file = Resource.new(File.readlines(resource))
save_file(resource, file)
i += 1
end