openra 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openra/cli/commands/replay_data.rb +68 -24
- data/lib/openra/replays.rb +1 -0
- data/lib/openra/replays/replay.rb +2 -2
- data/lib/openra/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62b93a256a360d12ed36a4b50207648cb78f0db6
|
4
|
+
data.tar.gz: 2cd510fb3f3bb34916f1ecc278f3dea352ed31a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d378e1942e96d258d4d96228812435a9404aab7301f7b40e0426167745acb2755c04b6a3c4e09474f04fbec7f8abc2c1fd9d05107995472776ff87ab9137c88
|
7
|
+
data.tar.gz: b62c614956326db37a276fdd845264d2bd30ed8babd4c126442a6afd187409f2e54845007c2691af1c0bbfb1c7f907d5f28bc343341e357e90d544e7f552895c
|
@@ -12,49 +12,87 @@ module Openra
|
|
12
12
|
def call(replay:, **options)
|
13
13
|
replay = Openra::Replays::Replay.new(replay)
|
14
14
|
|
15
|
-
client_index_mapping = {}
|
16
15
|
players = replay.metadata.each_with_object([]) do |(key, value), arr|
|
17
16
|
next unless key.start_with?('Player')
|
18
|
-
arr << value
|
17
|
+
arr << value
|
18
|
+
end
|
19
|
+
player_indices = players.map { |player| player['ClientIndex'] }
|
20
|
+
player_teams = players.map { |player| player['Team'] }
|
21
|
+
team_alignment = player_teams.each_with_object({}) do |team, hash|
|
22
|
+
if team == 0
|
23
|
+
hash[SecureRandom.uuid] = 1
|
24
|
+
else
|
25
|
+
hash[team] ||= 0
|
26
|
+
hash[team] += 1
|
27
|
+
end
|
19
28
|
end
|
20
29
|
|
21
30
|
replay_data = {
|
22
31
|
mod: replay.mod,
|
23
32
|
version: replay.version,
|
33
|
+
server_name: nil,
|
24
34
|
map: {
|
25
|
-
name: replay.map_title,
|
35
|
+
name: utf8(replay.map_title),
|
26
36
|
hash: replay.map_id
|
27
37
|
},
|
28
38
|
game: {
|
39
|
+
type: team_alignment.values.join('v'),
|
29
40
|
start_time: replay.start_time,
|
30
41
|
end_time: replay.end_time,
|
31
|
-
duration: replay.duration
|
42
|
+
duration: replay.duration,
|
43
|
+
options: {}
|
32
44
|
},
|
33
45
|
clients: [],
|
34
46
|
chat: []
|
35
47
|
}
|
36
48
|
|
37
|
-
|
38
|
-
replay.orders.select
|
39
|
-
|
40
|
-
|
41
|
-
|
49
|
+
timestep = nil
|
50
|
+
sync_info_orders = replay.orders.select do |order|
|
51
|
+
order.command == 'SyncInfo'
|
52
|
+
end
|
53
|
+
num_sync_info_orders = sync_info_orders.length
|
54
|
+
|
55
|
+
sync_info_orders.each.with_index do |sync_info_order, index|
|
56
|
+
sync_info = Openra::YAML.load(sync_info_order.target)
|
42
57
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
58
|
+
# Get all clients
|
59
|
+
sync_info.each_pair do |key, data|
|
60
|
+
case key
|
61
|
+
when /^Client@/
|
62
|
+
replay_data[:clients] << {
|
63
|
+
index: data['Index'],
|
64
|
+
name: utf8(data['Name']),
|
65
|
+
preferred_color: data['PreferredColor'],
|
66
|
+
color: data['Color'],
|
67
|
+
faction: data['Faction'],
|
68
|
+
ip: data['IpAddress'],
|
69
|
+
team: data['Team'] == 0 ? nil : data['Team'],
|
70
|
+
is_bot: data['Bot'].nil? ? false : true,
|
71
|
+
is_admin: data['IsAdmin'] == 'True',
|
72
|
+
is_player: player_indices.include?(data['Index']),
|
73
|
+
build: []
|
74
|
+
}
|
75
|
+
when 'GlobalSettings'
|
76
|
+
next unless index.next == num_sync_info_orders
|
56
77
|
|
57
|
-
|
78
|
+
timestep = data['Timestep']
|
79
|
+
replay_data[:server_name] = data['ServerName']
|
80
|
+
replay_data[:game][:options] = {
|
81
|
+
explored_map: data['Options']['explored']['Value'] == 'True',
|
82
|
+
speed: data['Options']['gamespeed']['Value'],
|
83
|
+
starting_cash: data['Options']['startingcash']['Value'],
|
84
|
+
starting_units: data['Options']['startingunits']['Value'],
|
85
|
+
fog_enabled: data['Options']['fog']['Value'] == 'True',
|
86
|
+
cheats_enabled: data['Options']['cheats']['Value'] == 'True',
|
87
|
+
kill_bounty_enabled: data['Options']['bounty']['Value'] == 'True',
|
88
|
+
allow_undeploy: data['Options']['factundeploy']['Value'] == 'True',
|
89
|
+
crated_enabled: data['Options']['crates']['Value'] == 'True',
|
90
|
+
build_off_allies: data['Options']['allybuild']['Value'] == 'True',
|
91
|
+
restrict_build_radius: data['Options']['buildradius']['Value'] == 'True',
|
92
|
+
short_game: data['Options']['shortgame']['Value'] == 'True',
|
93
|
+
techlevel: data['Options']['techlevel']['Value']
|
94
|
+
}
|
95
|
+
end
|
58
96
|
end
|
59
97
|
end
|
60
98
|
|
@@ -79,7 +117,7 @@ module Openra
|
|
79
117
|
|
80
118
|
replay_data[:chat] << {
|
81
119
|
name: client[:name],
|
82
|
-
message: order.target
|
120
|
+
message: utf8(order.target)
|
83
121
|
}
|
84
122
|
end
|
85
123
|
end
|
@@ -91,6 +129,12 @@ module Openra
|
|
91
129
|
puts JSON.pretty_generate(replay_data)
|
92
130
|
end
|
93
131
|
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def utf8(string)
|
136
|
+
string.force_encoding('UTF-8')
|
137
|
+
end
|
94
138
|
end
|
95
139
|
end
|
96
140
|
end
|
data/lib/openra/replays.rb
CHANGED
@@ -32,14 +32,14 @@ module Openra
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def start_time
|
35
|
-
@start_time ||= DateTime.strptime(
|
35
|
+
@start_time ||= ::DateTime.strptime(
|
36
36
|
metadata['Root']['StartTimeUtc'],
|
37
37
|
'%Y-%m-%d %H-%M-%S'
|
38
38
|
).to_time
|
39
39
|
end
|
40
40
|
|
41
41
|
def end_time
|
42
|
-
@end_time ||= DateTime.strptime(
|
42
|
+
@end_time ||= ::DateTime.strptime(
|
43
43
|
metadata['Root']['EndTimeUtc'],
|
44
44
|
'%Y-%m-%d %H-%M-%S'
|
45
45
|
).to_time
|
data/lib/openra/version.rb
CHANGED