-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
247 lines (217 loc) · 5.33 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
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
require "pathname"
require "fileutils"
require "date"
class Date
# Default inspect is just really stupid
def inspect
"Date.new(#{year}, #{month}, #{day})"
end
def to_s
"%04d.%d.%d" % [year, month, day]
end
end
def trash(*paths)
paths.each do |path|
next unless Pathname(path).exist?
system "trash", path.to_s
ds_store = Pathname(path).parent + ".DS_Store"
ds_store.unlink if ds_store.exist?
end
end
class ModBuilder
attr_reader :category, :name, :archive_name
def initialize(category, name, archive_name)
@category = category
@name = name
@archive_name = archive_name
end
def build_dir
Pathname("output/#{name}")
end
def mod_descriptor
Pathname("output/#{name}.mod")
end
def build!
# Half of this should probably be done by ModBuilder
trash build_dir, mod_descriptor
system "./#{category}/build_#{name}" or raise "Build failed"
Dir.chdir("output") do
system "7za a '../#{archive_name}' '#{name}'/ '#{name}'.mod >/dev/null"
end
end
end
####
# Just make it match base game version (plus maybe a/b/c for hotfixes)
FUN_AND_BALANCE_VERSION = "1.30.1"
desc "Build all packages"
task "all" => ["ck2", "eu4", "hoi4"]
desc "Build all HOI4 packages"
task "hoi4" => [
"a_simple_terrain_map_mode",
"a_simple_terrain_map_mode_kr",
]
desc "Build HOI4 Simple Terrain Map Mode Mod"
task "a_simple_terrain_map_mode" do
ModBuilder.new(
"hoi4",
"a_simple_terrain_map_mode",
"a_simple_terrain_map_mode.7z",
).build!
end
desc "Build HOI4 Simple Terrain Map Mode Mod for Kaiserreich"
task "a_simple_terrain_map_mode_kr" do
ModBuilder.new(
"hoi4",
"a_simple_terrain_map_mode_kr",
"a_simple_terrain_map_mode_kr.7z",
).build!
end
desc "Build all CK2 packages"
task "ck2" => [
"no_localized_ranks",
"suez_canal",
"modern_times",
"modern_times_plus",
]
desc "Build all EU4 packages"
task "eu4" => [
"vanilla",
"extended_timeline",
"1356",
]
desc "Build CK2 No Dynastic Names"
task "no_dynastic_names" do
ModBuilder.new(
"ck2_mods",
"no_dynastic_names",
"ck2_no_dynastic_names.7z",
).build!
end
desc "Build CK2 No Localized Landed Titles"
task "no_localized_landed_titles" do
ModBuilder.new(
"ck2_mods",
"no_localized_landed_titles",
"ck2_no_localized_landed_titles.7z",
).build!
end
desc "Build CK2 No Localized Ranks"
task "no_localized_ranks" do
ModBuilder.new(
"ck2_mods",
"no_localized_ranks",
"ck2_no_localized_ranks.7z",
).build!
end
desc "Build CK2 Suez Canal"
task "suez_canal" do
ModBuilder.new(
"ck2_mods",
"suez_canal",
"ck2_suez_canal.7z",
).build!
end
desc "Build CK2 Modern Times"
task "modern_times" do
ModBuilder.new(
"ck2_mods",
"modern_times",
"ck2_modern_times.7z",
).build!
end
desc "Build CK2 Modern Times Plus"
task "modern_times_plus" do
ModBuilder.new(
"ck2_mods",
"modern_times_plus",
"ck2_modern_times_plus.7z",
).build!
end
desc "Build Fun and Balance for vanilla"
task "vanilla" do
ModBuilder.new(
"fun_and_balance",
"fun_and_balance",
"fun_and_balance_#{FUN_AND_BALANCE_VERSION}_for_eu4_1.28.3.7z",
).build!
end
desc "Build Fun and Balance for 1356"
task "1356" do
ModBuilder.new(
"fun_and_balance",
"fun_and_balance_1356",
"fun_and_balance_#{FUN_AND_BALANCE_VERSION}_for_eu4_1.28.3_and_1356.7z",
).build!
end
desc "Build Fun and Balance for Extended Timeline"
task "extended_timeline" do
ModBuilder.new(
"fun_and_balance",
"fun_and_balance_et",
"fun_and_balance_#{FUN_AND_BALANCE_VERSION}_for_eu4_1.28.3_and_extended_timeline_1.9.3.7z"
).build!
end
desc "Remove build files"
task "clean" do
trash "output"
end
desc "Generate reference for refactoring"
task "reference" do
trash "output", "reference"
system "ck2_mods/build_ck2tweaks"
system "ck2_mods/build_custom_scenario"
system "ck2_mods/build_no_dynastic_names"
system "ck2_mods/build_no_localized_landed_titles"
system "ck2_mods/build_no_localized_ranks"
system "ck2_mods/build_modern_times"
system "ck2_mods/build_modern_times_plus"
system "fun_and_balance/build_fun_and_balance"
system "fun_and_balance/build_fun_and_balance_et"
FileUtils.mv "output", "reference"
end
task "default" => "test"
desc "Run tests"
task "test" do
sh %q[ruby -e 'Dir["test/*.rb"].each{|x| require "./#{x}"}']
Dir.chdir("hoi4_division_designer") do
sh "bundle exec rspec"
end
end
def fix_date(str)
case str
when /\A\d+\.\d+\.\d+\z/, /\A\d+ \S+ \d+\z/, /\A\S+ \d+, \d+\z/
Date.parse(str).to_s
else
str
end
end
desc "Fix code in modern times database"
task "code:cleanup" do
Dir["ck2_mods/**/*.rb"].each do |path|
path = Pathname(path)
orig_content = path.read
content = orig_content.gsub(/"([^"\n]+)"/) do
m = $1
begin
if m =~ /(?:-|\u2013)/
m = m.split(/(\s*(?:-|\u2013)\s*)/, -1).each_slice(2).map{|d,s| [fix_date(d), s]}.join
else
m = fix_date(m)
end
rescue
# keep
end
%Q["#{m}"]
end
if content != orig_content
puts "#{path} changed"
File.write(path, content)
end
end
end
desc "Generate HOI4 maps"
task "hoi4:maps" do
system "visualization_hoi4/draw_blank_state_map source/hoi4-1.6.2"
system "visualization_hoi4/draw_sea_land_map source/hoi4-1.6.2"
system "visualization_hoi4/draw_suppression_maps source/hoi4-1.6.2"
end