-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathFileMapDataSender.cs
76 lines (67 loc) · 2.62 KB
/
FileMapDataSender.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
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
using StreamCompanionTypes.DataTypes;
using StreamCompanionTypes.Interfaces;
using System;
using System.Collections.Generic;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using StreamCompanionTypes.Attributes;
using StreamCompanionTypes.Interfaces.Consumers;
using StreamCompanionTypes.Interfaces.Services;
using StreamCompanion.Common;
namespace FileMapDataSender
{
[SupportedOSPlatform("windows")]
[SCPlugin("MMF sender", "Sends data using memory mapped files", Consts.SCPLUGIN_AUTHOR, Consts.SCPLUGIN_BASEURL)]
public class FileMapDataSender : IPlugin, IMapDataConsumer, IDisposable, IHighFrequencyDataConsumer
{
private readonly FileMapManager _fileMapManager;
public FileMapDataSender(ILogger logger)
{
_fileMapManager = new FileMapManager(logger);
}
public void Save(string fileName, string content)
{
_fileMapManager.Write(fileName, content);
}
public Task SetNewMapAsync(IMapSearchResult map, CancellationToken cancellationToken)
{
var ingamePatterns = new List<string>();
foreach (var s in map.OutputPatterns)
{
//TODO: export ingameOverlay(showInOsu) stuff out of there
var name = s.Name;
if (s.ShowInOsu)
{
ingamePatterns.Add(name);
}
string valueToWrite = (s.SaveEvent & map.Action) != 0 ? s.GetFormatedPattern() : " ";
if (s.ShowInOsu)
{
var configName = "conf-" + name;
var valueName = "value-" + name;
var config = $"{s.XPosition} {s.YPosition} {s.Color.R} {s.Color.G} {s.Color.B} {s.Color.A} {s.FontName.Replace(' ', '/')} {s.FontSize} {s.Aligment}";
_fileMapManager.Write(configName, config);
if (!s.IsMemoryFormat)
_fileMapManager.Write(valueName, valueToWrite.Replace("\r", ""));
}
if (!s.IsMemoryFormat)
_fileMapManager.Write(name, valueToWrite);
}
_fileMapManager.Write("Sc-ingamePatterns", string.Join(" ", ingamePatterns) + " ");
return Task.CompletedTask;
}
public void Dispose()
{
_fileMapManager.Write("Sc-ingamePatterns", " ");
}
public void Handle(string content)
{
//ignored
}
public void Handle(string name, string content)
{
_fileMapManager.Write(name, content);
}
}
}