forked from razor-x/eve-overview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
138 lines (118 loc) · 3.73 KB
/
Rakefile
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
require 'active_support/core_ext/hash'
require 'active_support/core_ext/string'
require 'yaml'
build = '_build'
task default: :build
task build: [:reset_build_directory, :compile_overviews]
task travis: [:build, :zip]
task :reset_build_directory do
FileUtils.remove_entry_secure build if Dir.exist? build
FileUtils.mkdir_p build
end
task :compile_overviews do
Dir['overviews/*.yml'].each do |path|
overview = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(path))
name = File.basename(path, File.extname(path))
overview[:tabs].each do |tab|
overview[:tab] = tab
compile_overview name, File.join(build, "#{name}-#{tab}.yaml"), overview
end
end
end
task :zip do
system 'zip', '-r', "eve-overview-v#{File.read('VERSION').strip}.zip",
build, 'README.md', 'LICENSE.txt', 'CHANGELOG.md', 'VERSION'
end
def compile_overview(name, path, overview)
overview_hash = {}
overview.each do |k, v|
next if k.to_sym == :tabs
opts = YAML.load_file(File.join(k.pluralize, "#{v}.yml"))
if k.to_sym == :tab
overview_hash.merge! format_tabs(opts)
else
overview_hash.merge! opts
end
end
presets = []
Dir['presets/*.yml'].each do |preset|
presets << format_preset(load_preset(preset))
end
overview_hash.merge! 'presets' => presets
string = "# This EVE overview generated by the EVE Online Overview Generator.\n" \
"# https://github.com/razor-x/eve-overview\n" \
+ overview_hash.to_yaml
File.open(path, 'w') { |f| f.write string }
end
def format_tabs(tabs)
tab_array = []
tabs.each_with_index do |v, i|
v = ActiveSupport::HashWithIndifferentAccess.new v
tab = [i, [
['name', format_tab_name(v)],
['overview', format_preset_name(load_preset_by_name(v[:overview]))],
['bracket', format_preset_name(load_preset_by_name(v[:bracket]))]
]]
tab_array << tab
end
{'tabSetup' => tab_array}
end
def load_preset_by_name(preset)
ActiveSupport::HashWithIndifferentAccess.new(
YAML.load_file File.join('presets', "#{preset}.yml")
)
end
def load_preset(preset)
ActiveSupport::HashWithIndifferentAccess.new(
YAML.load_file preset
)
end
def format_preset(preset)
states = merge_states(preset[:states])
[format_preset_name(preset), [
['alwaysShownStates', states[:show]],
['filteredStates', states[:hide]],
['groups', merge_groups(preset[:groups])]
]]
end
def format_preset_name(preset)
return "#{preset[:symbol]} #{'- ' * 4}" if preset[:level] == 0 && preset[:name].empty?
return "#{preset[:symbol]} #{'- ' * 4}#{preset[:name]}" if preset[:level] == 0
"#{preset[:symbol]}#{' - ' * (4 - preset[:level])}#{preset[:name]}"
end
def format_tab_name(tab)
"<color=0x#{tab[:color]}> #{tab[:name]} </color>"
end
def merge_states(names)
array = []
states = {show: [], hide: []}
names.each do |name|
array << ActiveSupport::HashWithIndifferentAccess.new(
YAML.load_file(File.join('states', "#{name}.yml"))
)
end
array.each do |v|
v.each { |k, v| states[k.to_sym].concat v }
end
states.each { |v| v.flatten.uniq }
end
def merge_groups(names)
hash = ActiveSupport::HashWithIndifferentAccess.new include: [], types: []
names.each do |name|
sub_hash = ActiveSupport::HashWithIndifferentAccess.new YAML.load_file(File.join('groups', "#{name}.yml"))
%i(types include).each do |k|
hash[k].concat sub_hash[k] unless sub_hash[k].nil?
end
end
reduce_group(hash).uniq.sort
end
def reduce_group(group)
types = []
types << group[:types] unless group[:types].nil?
types << group[:include].map do |v|
reduce_group ActiveSupport::HashWithIndifferentAccess.new(
YAML.load_file(File.join('groups', "#{v}.yml"))
)
end unless group[:include].nil?
types.flatten.uniq
end