Math is hard
This commit is contained in:
+25
-10
@@ -1,25 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SixLabors.ImageSharp;
|
||||
using Configuration = fxl.codes.kisekae.Entities.Configuration;
|
||||
using fxl.codes.kisekae.Entities;
|
||||
|
||||
namespace fxl.codes.kisekae.Models
|
||||
{
|
||||
public class PlaysetModel
|
||||
{
|
||||
public readonly int Height;
|
||||
public readonly string Name;
|
||||
public readonly int Width;
|
||||
public readonly CelModel[] Cels;
|
||||
|
||||
[JsonIgnore] public Color BorderColor = Color.Black;
|
||||
[JsonIgnore] public readonly string BorderColor;
|
||||
|
||||
internal PlaysetModel(Configuration configuration)
|
||||
{
|
||||
BorderColor = configuration.BackgroundColorHex;
|
||||
|
||||
Name = configuration.Name;
|
||||
Height = configuration.Height;
|
||||
Width = configuration.Width;
|
||||
Cels = new CelModel[0];
|
||||
var totalCels = configuration.Cels.Count;
|
||||
Cels = configuration.Cels.Select((x, index) => new CelModel(x, (totalCels - index) * 10)).ToArray();
|
||||
|
||||
var summation = configuration.Cels.Aggregate(Set.None, (current, cel) => current | cel.Sets);
|
||||
if (summation == Set.None)
|
||||
{
|
||||
Array.Fill(Sets, true);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var value in Enum.GetValues<Set>().Where(x => (x & summation) == x && x != Set.None))
|
||||
if (value == Set.Zero) Sets[0] = true;
|
||||
else Sets[(int)Math.Log2((double)value)] = true;
|
||||
}
|
||||
|
||||
public CelModel[] Cels { get; set; }
|
||||
public int Height { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool[] Sets { get; set; } = new bool[10];
|
||||
public int Width { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user