tf2_line_parser 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3956f69e8630b77980239a86d7e46e554cb30d15bb8b61d69d1780c806283d38
4
- data.tar.gz: 9e6459f1e32cbe9e8d985a86fda96e0ff8b65e3251d0cf0a57baf49c51d2f4cc
3
+ metadata.gz: 6dfafd07fe8d89baabc3e518a825fd42c59c3d6953634e4bc3ea7ff083d7e528
4
+ data.tar.gz: 55d550f7ba62f87a4b5107154792f0a3e83ea74aef0c1df1c6cb05698a515ff6
5
5
  SHA512:
6
- metadata.gz: e57184e1c15bedc3a29e708deb1832ac77297a5d1989ca4e2784002f8b7bdd908cb61b3e9f82d84c2c595d352b16bb9ff75201977ef27e2d9883c1d70d5ffacf
7
- data.tar.gz: 0c553ab92c419369e3a5555ba09be70079502cbc361bd1b74296d3208b53b26f5e3008ec4ac4d76a38595cee3baf3acf2fe9fc6853c1faf360382955f76d460f
6
+ metadata.gz: 1d92cdbcaebb3d8e3eb99b4a7843926558ffd95835f6055141c0483c63b8270abde48a182fdf0814214417a698a10037503b485768ca8841c591357dcf4c5f9e
7
+ data.tar.gz: da48989f45f6b156eb7dfd50c54aaa555db14865e41c5eed2401883c046efa30c743537b61ed3d05fa48a66565bd2b0dc3410791746f48fd59fcfdd1240d732e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tf2_line_parser (0.9.0)
4
+ tf2_line_parser (0.9.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,7 +5,7 @@ module TF2LineParser
5
5
  class Airshot < Damage
6
6
  def self.regex
7
7
  # Airshot can appear after weapon, with optional crit/healing between weapon and airshot
8
- @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_airshot}#{regex_height}/
8
+ @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_airshot}#{regex_height}#{regex_positions}/
9
9
  end
10
10
 
11
11
  def self.regex_airshot
@@ -41,10 +41,11 @@ module TF2LineParser
41
41
  target_team = nil
42
42
  target_name, target_uid, target_steamid, target_team = parse_target_section(target_section) if target_section
43
43
 
44
- [time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot]
44
+ results = [time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot]
45
+ add_positions(results, matched_line)
45
46
  end
46
47
 
47
- def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot)
48
+ def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, airshot, attacker_position = nil, victim_position = nil)
48
49
  @time = parse_time(time)
49
50
  @player = Player.new(player_name, player_uid, player_steamid, player_team)
50
51
  @target = Player.new(target_name, target_uid, target_steamid, target_team) if target_name
@@ -56,6 +57,8 @@ module TF2LineParser
56
57
  @crit = crit
57
58
  @headshot = nil
58
59
  @airshot = (airshot.to_i == 1)
60
+ @attacker_position = attacker_position
61
+ @victim_position = victim_position
59
62
  end
60
63
  end
61
64
  end
@@ -3,10 +3,10 @@
3
3
  module TF2LineParser
4
4
  module Events
5
5
  class Damage < Event
6
- attr_reader :damage, :realdamage, :crit, :headshot, :healing
6
+ attr_reader :damage, :realdamage, :crit, :headshot, :healing, :attacker_position, :victim_position
7
7
 
8
8
  def self.regex
9
- @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_headshot}/
9
+ @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_headshot}#{regex_positions}/
10
10
  end
11
11
 
12
12
  def self.regex_damage_against
@@ -33,6 +33,16 @@ module TF2LineParser
33
33
  @regex_headshot ||= /(?: \(headshot "(?'headshot'\d*)"\))?/
34
34
  end
35
35
 
36
+ # supstats2 3.1.0 and later
37
+ def self.regex_positions
38
+ @regex_positions ||= /(?: \(attacker_position "(?'attacker_position'[^"]*)"\) \(victim_position "(?'victim_position'[^"]*)"\))?/
39
+ end
40
+
41
+ def self.add_positions(results, matched_line)
42
+ results.push(matched_line['attacker_position'], matched_line['victim_position']) if matched_line['attacker_position']
43
+ results
44
+ end
45
+
36
46
  def self.attributes
37
47
  @attributes ||= %i[time player_section target_section value realdamage weapon healing crit headshot]
38
48
  end
@@ -58,10 +68,11 @@ module TF2LineParser
58
68
  target_team = nil
59
69
  target_name, target_uid, target_steamid, target_team = parse_target_section(target_section) if target_section
60
70
 
61
- [time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, headshot]
71
+ results = [time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, headshot]
72
+ add_positions(results, matched_line)
62
73
  end
63
74
 
64
- def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, headshot)
75
+ def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, headshot, attacker_position = nil, victim_position = nil)
65
76
  @time = parse_time(time)
66
77
  @player = Player.new(player_name, player_uid, player_steamid, player_team)
67
78
  @target = Player.new(target_name, target_uid, target_steamid, target_team) if target_name
@@ -72,6 +83,8 @@ module TF2LineParser
72
83
  @healing = healing.to_i if healing
73
84
  @crit = crit
74
85
  @headshot = (headshot == '1') if headshot
86
+ @attacker_position = attacker_position
87
+ @victim_position = victim_position
75
88
  end
76
89
  end
77
90
  end
@@ -4,7 +4,7 @@ module TF2LineParser
4
4
  module Events
5
5
  class HeadshotDamage < Damage
6
6
  def self.regex
7
- @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_airshot} #{regex_headshot}$/
7
+ @regex ||= /#{regex_time} #{regex_player} triggered "damage" #{regex_damage_against}\(damage "(?'value'\d+)"\)#{regex_realdamage}#{regex_weapon}#{regex_healing}#{regex_crit}#{regex_airshot} #{regex_headshot}#{regex_positions}$/
8
8
  end
9
9
 
10
10
  def self.regex_headshot
@@ -42,11 +42,11 @@ module TF2LineParser
42
42
  target_name, target_uid, target_steamid, target_team = parse_target_section(target_section) if target_section
43
43
 
44
44
  results = [time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, headshot]
45
- results << matched_line['airshot'] if matched_line['airshot']
46
- results
45
+ results << matched_line['airshot'] if matched_line['airshot'] || matched_line['attacker_position']
46
+ add_positions(results, matched_line)
47
47
  end
48
48
 
49
- def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, _headshot, airshot = nil)
49
+ def initialize(time, player_name, player_uid, player_steamid, player_team, target_name, target_uid, target_steamid, target_team, value, realdamage, weapon, healing, crit, _headshot, airshot = nil, attacker_position = nil, victim_position = nil)
50
50
  @time = parse_time(time)
51
51
  @player = Player.new(player_name, player_uid, player_steamid, player_team)
52
52
  @target = Player.new(target_name, target_uid, target_steamid, target_team) if target_name
@@ -58,6 +58,8 @@ module TF2LineParser
58
58
  @crit = crit
59
59
  @headshot = true # Always true for HeadshotDamage events
60
60
  @airshot = (airshot.to_i == 1) if airshot
61
+ @attacker_position = attacker_position
62
+ @victim_position = victim_position
61
63
  end
62
64
  end
63
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TF2LineParser
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
  end
@@ -1209,6 +1209,61 @@ module TF2LineParser
1209
1209
  end
1210
1210
  end
1211
1211
 
1212
+ # https://github.com/F2/F2s-sourcemod-plugins/pull/58
1213
+ describe 'damage positions from supstats2 3.1.0' do
1214
+ let(:start) { 'L 12/04/2026 - 20:15:03: "Attacker<3><[U:1:1234]><Red>" triggered "damage" against "Victim<8><[U:1:420]><Blue>" (damage "69") (realdamage "31") (weapon "quake_rl")' }
1215
+ let(:positions) { ' (attacker_position "128 -256 64") (victim_position "224 -192 97")' }
1216
+
1217
+ def expect_positions(event)
1218
+ expect(event.attacker_position).to eq('128 -256 64')
1219
+ expect(event.victim_position).to eq('224 -192 97')
1220
+ end
1221
+
1222
+ it 'reads them from plain damage' do
1223
+ event = Parser.parse(%(#{start} (healing "20") (crit "mini")#{positions}))
1224
+
1225
+ expect(event).to be_an_instance_of(Events::Damage)
1226
+ expect(event.damage).to eq(69)
1227
+ expect(event.healing).to eq(20)
1228
+ expect(event.crit).to eq('mini')
1229
+ expect_positions(event)
1230
+ end
1231
+
1232
+ it 'reads them from a headshot' do
1233
+ event = Parser.parse(%(#{start} (crit "crit") (headshot "1")#{positions}))
1234
+
1235
+ expect(event).to be_an_instance_of(Events::HeadshotDamage)
1236
+ expect(event.headshot).to be true
1237
+ expect(event.crit).to eq('crit')
1238
+ expect_positions(event)
1239
+ end
1240
+
1241
+ it 'reads them from an airshot' do
1242
+ event = Parser.parse(%(#{start} (airshot "1") (height "33")#{positions}))
1243
+
1244
+ expect(event).to be_an_instance_of(Events::Airshot)
1245
+ expect(event.airshot).to be true
1246
+ expect_positions(event)
1247
+ end
1248
+
1249
+ it 'reads them from an airshot headshot' do
1250
+ event = Parser.parse(%(#{start} (airshot "1") (height "33") (headshot "1")#{positions}))
1251
+
1252
+ expect(event).to be_an_instance_of(Events::HeadshotDamage)
1253
+ expect(event.airshot).to be true
1254
+ expect_positions(event)
1255
+ end
1256
+
1257
+ it 'leaves them nil for older logs' do
1258
+ [%(#{start} (crit "mini")), %(#{start} (headshot "1")), %(#{start} (airshot "1") (height "33"))].each do |line|
1259
+ event = Parser.parse(line)
1260
+
1261
+ expect(event.attacker_position).to be_nil
1262
+ expect(event.victim_position).to be_nil
1263
+ end
1264
+ end
1265
+ end
1266
+
1212
1267
  describe 'logs from supstats2 3.0.0' do
1213
1268
  def fixture_events(name)
1214
1269
  File.readlines(File.expand_path("../../fixtures/logs/#{name}", __dir__)).map { |line| Parser.parse(line) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tf2_line_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arie