2021-03-22 12:09:25 -04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Stats.Client.Abstractions;
|
|
|
|
|
using Stats.Client.Game;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-02-11 22:01:28 -05:00
|
|
|
|
using Data.Models;
|
2021-06-03 11:51:03 -04:00
|
|
|
|
using Stats.Config;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
|
|
|
|
|
|
|
|
|
namespace Stats.Client
|
|
|
|
|
{
|
|
|
|
|
public class WeaponNameParser : IWeaponNameParser
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly StatsConfiguration _config;
|
|
|
|
|
|
2022-01-28 18:28:49 -05:00
|
|
|
|
public WeaponNameParser(ILogger<WeaponNameParser> logger, StatsConfiguration config)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2022-01-28 18:28:49 -05:00
|
|
|
|
_config = config;
|
2021-03-22 12:09:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-11 22:01:28 -05:00
|
|
|
|
public WeaponInfo Parse(string weaponName, Reference.Game gameName)
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
|
|
|
|
var configForGame = _config.WeaponNameParserConfigurations
|
2021-06-03 11:51:03 -04:00
|
|
|
|
?.FirstOrDefault(config => config.Game == gameName) ?? new WeaponNameParserConfiguration()
|
2021-03-22 12:09:25 -04:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
Game = gameName
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-22 12:09:25 -04:00
|
|
|
|
var splitWeaponName = weaponName.Split(configForGame.Delimiters);
|
|
|
|
|
|
|
|
|
|
if (!splitWeaponName.Any())
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
_logger.LogError("Could not parse weapon name {Weapon}", weaponName);
|
2021-03-22 12:09:25 -04:00
|
|
|
|
|
|
|
|
|
return new WeaponInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = "Unknown"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove the _mp suffix
|
2021-03-23 17:01:48 -04:00
|
|
|
|
var filtered = splitWeaponName
|
2021-04-01 14:12:47 -04:00
|
|
|
|
.Where(part => part != configForGame.WeaponSuffix && part != configForGame.WeaponPrefix)
|
|
|
|
|
.ToList();
|
|
|
|
|
var baseName = filtered.First();
|
2021-03-22 12:09:25 -04:00
|
|
|
|
var attachments = new List<string>();
|
|
|
|
|
|
|
|
|
|
if (filtered.Count() > 1)
|
|
|
|
|
{
|
|
|
|
|
attachments.AddRange(filtered.Skip(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var weaponInfo = new WeaponInfo()
|
|
|
|
|
{
|
|
|
|
|
RawName = weaponName,
|
|
|
|
|
Name = baseName,
|
|
|
|
|
Attachments = attachments.Select(attachment => new AttachmentInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = attachment
|
|
|
|
|
}).ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return weaponInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-28 18:28:49 -05:00
|
|
|
|
}
|