2019-12-12 19:43:36 +00:00
|
|
|
|
using RecrownedAthenaeum.Assets;
|
|
|
|
|
using RecrownedAthenaeum.Types;
|
2019-01-27 08:01:13 +00:00
|
|
|
|
using System.Diagnostics;
|
2018-09-16 06:37:48 +00:00
|
|
|
|
|
2019-01-27 08:01:13 +00:00
|
|
|
|
namespace RhythmBullet.ContentResolvers
|
2018-09-16 06:37:48 +00:00
|
|
|
|
{
|
2019-12-12 19:43:36 +00:00
|
|
|
|
internal class ResolutionContentResolver : IAssetPathResolver
|
2018-09-16 06:37:48 +00:00
|
|
|
|
{
|
|
|
|
|
int width, height;
|
|
|
|
|
bool updated;
|
|
|
|
|
Resolution bestResolution;
|
|
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
updated = true;
|
|
|
|
|
width = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
updated = true;
|
|
|
|
|
height = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-24 02:46:46 +00:00
|
|
|
|
public Resolution[] resolutions = {
|
2018-09-16 06:37:48 +00:00
|
|
|
|
new Resolution(1920, 1080),
|
|
|
|
|
new Resolution(2560, 1440),
|
|
|
|
|
new Resolution(3840, 2160)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Resolution ChooseRounded()
|
|
|
|
|
{
|
|
|
|
|
updated = false;
|
|
|
|
|
Resolution best = resolutions[0];
|
|
|
|
|
|
|
|
|
|
int leastDifference = -1;
|
|
|
|
|
|
|
|
|
|
int w = Width, h = Height;
|
|
|
|
|
|
|
|
|
|
if (w > h)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < resolutions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int currentDiff = h - resolutions[i].Height;
|
|
|
|
|
|
|
|
|
|
if (currentDiff < 0)
|
|
|
|
|
{
|
|
|
|
|
currentDiff = currentDiff * -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((currentDiff < leastDifference) || leastDifference == -1)
|
|
|
|
|
{
|
|
|
|
|
best = resolutions[i];
|
|
|
|
|
leastDifference = currentDiff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < resolutions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
int currentDiff = w - resolutions[i].Width;
|
|
|
|
|
|
|
|
|
|
if (currentDiff < 0)
|
|
|
|
|
{
|
|
|
|
|
currentDiff = currentDiff * -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentDiff < leastDifference || leastDifference == -1)
|
|
|
|
|
{
|
|
|
|
|
best = resolutions[i];
|
|
|
|
|
leastDifference = currentDiff;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return best;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-30 23:29:54 +00:00
|
|
|
|
public string Modify(string path)
|
2018-09-16 06:37:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (updated)
|
|
|
|
|
{
|
|
|
|
|
bestResolution = ChooseRounded();
|
2019-01-27 08:01:13 +00:00
|
|
|
|
Debug.WriteLine("Selected best resolution set: " + bestResolution);
|
2018-09-16 06:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
return bestResolution + "/" + path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|