forked from spacedockapp/spacedock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmconv.rb
More file actions
99 lines (86 loc) · 2.15 KB
/
mconv.rb
File metadata and controls
99 lines (86 loc) · 2.15 KB
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
require "enumerator"
require "nokogiri"
require "pathname"
require_relative "common"
script_path = Pathname.new(File.dirname(__FILE__))
root_path = script_path.parent()
src_path = root_path.join("src")
xml_path = src_path.join("Data.xml").to_s
xml_text = File.read(xml_path)
doc = Nokogiri::XML(xml_text)
ships = doc.xpath("//Data//ShipClassDetails/ShipClassDetail/Id").collect do |node|
node.content
end
v = ships.sort.last.to_i
v+= 1
ship = <<-SHIPTEXT
Nova Class
Front Arc
WHITE 90°
RED WHITE WHITE WHITE RED
WHITE WHITE GREEN WHITE WHITE Rear Arc
GREEN GREEN GREEN 90°
RED
Raptor Class
Front Arc
WHITE 90°
WHITE WHITE WHITE WHITE WHITE RED
WHITE WHITE GREEN WHITE WHITE
GREEN GREEN GREEN
Jem'Hadar Battleship
WHITE Front Arc
WHITE WHITE WHITE 90°
RED WHITE GREEN WHITE RED
WHITE GREEN WHITE
WHITE GREEN WHITE
SHIPTEXT
directions = ["left-turn", "left-bank", "straight", "right-bank", "right-turn", "about"]
shipLines = ship.split "\n"
speed = 6
frontArc = ""
rearArc = ""
externalId = v
shipLines.each do |l|
if speed == 6
parts = l.split "\t"
name = parts[0].chomp
puts %Q(<ShipClassDetail>)
puts %Q(\t<Name>#{name}</Name>)
puts %Q(\t<Id>#{sanitize_title(name).downcase()}</Id>)
externalId += 1
puts %Q(\t<Maneuvers>)
else
parts = l.split "\t"
directions.to_enum.with_index(0) do |direction, i|
if i < parts.length
move = parts[i].chomp
if move.length > 0
puts %Q[\t\t<Maneuver speed="#{speed}" kind="#{direction}" color="#{move.downcase}" />]
# LT Maneuver speed="3" type="tight" color="red" RT
end
end
end
case speed
when 4
if parts[6]
frontArc = parts[6].to_i
end
when 1
if parts[6]
rearArc = parts[6].to_i
end
end
end
speed -= 1
if speed == 0
speed = -1
end
if speed == -3
puts "\t</Maneuvers>"
puts "\t<FrontArc>#{frontArc}</FrontArc>" if frontArc
puts "\t<RearArc>#{rearArc}</RearArc>" if rearArc
puts "</ShipClassDetail>"
speed = 6
frontArc = rearArc = ""
end
end