-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPartnerLocator.cs
46 lines (37 loc) · 1.91 KB
/
PartnerLocator.cs
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
using System.Collections.Concurrent;
using AndrealImageGenerator.Beans;
using Newtonsoft.Json;
#pragma warning disable CS8618
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable PropertyCanBeMadeInitOnly.Global
namespace AndrealImageGenerator.Common;
internal static class PartnerLocator
{
private static readonly Lazy<ConcurrentDictionary<string, Dictionary<string, PosInfoItem>>> Dict = new(() => new(Init()));
private static readonly ConcurrentDictionary<string, List<PosInfoItem>> Locations
= new(JsonConvert.DeserializeObject<Dictionary<string, List<PosInfoItem>>>(File.ReadAllText(Path.PartnerConfig))!);
private static readonly PosInfoItem ImgV1 = new() { PositionX = 770, PositionY = 58, Size = 950 };
private static readonly PosInfoItem ImgV2 = new() { PositionX = 850, PositionY = 0, Size = 1400 };
private static readonly PosInfoItem ImgV4 = new() { PositionX = 550, PositionY = 50, Size = 1500 };
private static Dictionary<string, Dictionary<string, PosInfoItem>> Init()
{
var ls = new Dictionary<string, Dictionary<string, PosInfoItem>>();
foreach (var (key, value) in Locations) ls.Add(key, value.ToDictionary(i => i.Partner));
return ls;
}
internal static PosInfoItem? Get(string partner, ImgVersion imgVersion)
=> imgVersion switch
{
ImgVersion.ImgV1 => Dict.Value["1"].TryGetValue(partner, out var result) ? result : ImgV1,
ImgVersion.ImgV2 => Dict.Value["2"].TryGetValue(partner, out var result) ? result : ImgV2,
ImgVersion.ImgV4 => Dict.Value["4"].TryGetValue(partner, out var result) ? result : ImgV4,
_ => null
};
public class PosInfoItem
{
public string Partner { get; set; }
public int PositionX { get; set; }
public int PositionY { get; set; }
public int Size { get; set; }
}
}