forked from silverweed/lifish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boomtolifish.rb
executable file
·99 lines (92 loc) · 2 KB
/
boomtolifish.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
94
95
96
97
98
99
#!/usr/bin/ruby
# Convert BOOM json levels to lifish levels
require 'json'
unless ARGV.length > 0
puts "Usage: #{$0} <boom_levels.json>"
exit 1
end
file = File.read ARGV[0]
boom_levels = JSON.parse(file)['LevelDescription']
# A BOOM level's structure is:
# {
# "FixedBlockID": num,
# "BreakableBlockID": num,
# "BorderID": num,
# "BGPatternID": num,
# "GridDescString: string,
# "Time": num
# }
#
# We need to convert it to lifish format:
# {
# "time": num,
# "music": num,
# "tileIDs": {
# "bg": num,
# "border": num,
# "fixed": num,
# "breakable": num
# },
# "tilemap": string
# }
lifish_hash = {
"name" => "Converted BOOM levels",
"author" => "Federico Filipponi",
"difficulty" => "average",
"tracks" => [
{
"name" => "DMZ beat",
"author" => "Giacomo Parolini",
"loop" => {
"start" => 7.386,
"length" => 44.279
}
},
{
"name" => "Spirit Party",
"author" => "Luca Barazzetta",
"loop" => {
"start" => 3.428,
"length" => 106.3
}
},
{
"name" => "Tick Tock",
"author" => "Luca Barazzetta",
"loop" => {
"start" => 3.428,
"length" => 96.0
}
}
],
"enemies" => [
{ "ai" => 0, "speed" => 1 }, # soldier
{ "ai" => 0, "speed" => 1 }, # sgt. cool
{ "ai" => 1, "speed" => 1 }, # thick lizzy
{ "ai" => 2, "speed" => 2 }, # mean-o-taur
{ "ai" => 1, "speed" => 1 }, # gunner
{ "ai" => 3, "speed" => 1 }, # thing
{ "ai" => 4, "speed" => 1 }, # ghost
{ "ai" => 3, "speed" => 1 }, # smoulder
{ "ai" => 3, "speed" => 1 }, # skully
{ "ai" => 3, "speed" => 2 } # h.r. giggler
],
"levels" => []
}
boom_levels.each_with_index do |level, i|
lv = {
"time" => level["Time"],
"music" => [3, (i / 10).floor + 1].min, # TODO: all tracks
"tileIDs" => {
"bg" => (i / 10).floor + 1,
"border" => (i / 10).floor + 1,
"fixed" => (i / 10).floor + 1,
"breakable" => (i / 10).floor + 1
},
"tilemap" => level["GridDescString"]
}
lifish_hash["levels"] << lv
end
File.open("converted.json", "w") do |f|
f.write lifish_hash.to_json
end