exp ini generator
This commit is contained in:
parent
a7fbf6ad7d
commit
33010ffe5e
66
Domain/Something/ExpIniFileGenerator.cs
Normal file
66
Domain/Something/ExpIniFileGenerator.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Domain.Somthing;
|
||||||
|
|
||||||
|
public class ExpIniFileGenerator(uint rowCount, uint oddColumnCount, uint evenColumnCount)
|
||||||
|
{
|
||||||
|
private const string _lineEnding = "\r\n";
|
||||||
|
|
||||||
|
public string Generate(IEnumerable<FrameExpInfo> frameInfos)
|
||||||
|
{
|
||||||
|
var groups = frameInfos
|
||||||
|
.DistinctBy(q => new {q.Row, q.Column})
|
||||||
|
.GroupBy(q => q.Row, (row, columns) => new { Row = row, Columns = columns });
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
AppendLine(sb, oddColumnCount.ToString());
|
||||||
|
AppendLine(sb, evenColumnCount.ToString());
|
||||||
|
AppendLine(sb, rowCount.ToString());
|
||||||
|
|
||||||
|
foreach (var row in groups.OrderBy(q => q.Row))
|
||||||
|
{
|
||||||
|
bool? isPreviousContainAnything = null;
|
||||||
|
var stateAccumulator = 0u;
|
||||||
|
foreach (var column in row.Columns)
|
||||||
|
{
|
||||||
|
isPreviousContainAnything ??= column.IsContainAnything;
|
||||||
|
|
||||||
|
if (isPreviousContainAnything == column.IsContainAnything)
|
||||||
|
{
|
||||||
|
stateAccumulator++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.Append(GetExpValue(isPreviousContainAnything.Value, stateAccumulator));
|
||||||
|
stateAccumulator = 0u;
|
||||||
|
isPreviousContainAnything = column.IsContainAnything;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stateAccumulator > 0 && isPreviousContainAnything.HasValue)
|
||||||
|
{
|
||||||
|
sb.Append(GetExpValue(isPreviousContainAnything.Value, stateAccumulator));
|
||||||
|
}
|
||||||
|
sb.Append(_lineEnding);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AppendLine(StringBuilder sb, string text)
|
||||||
|
{
|
||||||
|
sb.Append(text);
|
||||||
|
sb.Append(_lineEnding);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetExpValue(bool isContainAnything, uint accumulator)
|
||||||
|
{
|
||||||
|
return string.Concat(accumulator.ToString(), isContainAnything ? 'e' : 'z');
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FrameExpInfo
|
||||||
|
{
|
||||||
|
public uint Row { get; init; }
|
||||||
|
public uint Column { get; init; }
|
||||||
|
public bool IsContainAnything { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user