From 5ec738ae1b7413d543328dbed5b93f4edb92f4a7 Mon Sep 17 00:00:00 2001 From: Recrown Date: Fri, 14 Dec 2018 14:25:14 -0600 Subject: [PATCH] refactor (moved some files) --- .../ContentResolvers/FontContentResolver.cs | 24 ++++ .../NormalContentResolver.cs | 2 +- .../ResolutionContentResolver.cs | 108 ++++++++++++++++++ RecrownedAthenaeum/RecrownedAthenaeum.csproj | 8 +- RecrownedAthenaeum/packages.config | 2 +- 5 files changed, 139 insertions(+), 5 deletions(-) create mode 100644 RecrownedAthenaeum/ContentSystem/ContentResolvers/FontContentResolver.cs rename RecrownedAthenaeum/ContentSystem/{ => ContentResolvers}/NormalContentResolver.cs (82%) create mode 100644 RecrownedAthenaeum/ContentSystem/ContentResolvers/ResolutionContentResolver.cs diff --git a/RecrownedAthenaeum/ContentSystem/ContentResolvers/FontContentResolver.cs b/RecrownedAthenaeum/ContentSystem/ContentResolvers/FontContentResolver.cs new file mode 100644 index 0000000..b3247cc --- /dev/null +++ b/RecrownedAthenaeum/ContentSystem/ContentResolvers/FontContentResolver.cs @@ -0,0 +1,24 @@ +using RecrownedAthenaeum.ContentSystem; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RecrownedAthenaeum.ContentSystem.ContentResolvers +{ + class FontContentResolver : IContentPathModifier + { + readonly ResolutionContentResolver rcr; + + public FontContentResolver(ResolutionContentResolver rcr) + { + this.rcr = rcr; + } + + public string Modify(string assetName) + { + return rcr.Modify("fonts/" + assetName); + } + } +} diff --git a/RecrownedAthenaeum/ContentSystem/NormalContentResolver.cs b/RecrownedAthenaeum/ContentSystem/ContentResolvers/NormalContentResolver.cs similarity index 82% rename from RecrownedAthenaeum/ContentSystem/NormalContentResolver.cs rename to RecrownedAthenaeum/ContentSystem/ContentResolvers/NormalContentResolver.cs index 3b99332..2adbb00 100644 --- a/RecrownedAthenaeum/ContentSystem/NormalContentResolver.cs +++ b/RecrownedAthenaeum/ContentSystem/ContentResolvers/NormalContentResolver.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace RecrownedAthenaeum.ContentSystem +namespace RecrownedAthenaeum.ContentSystem.ContentResolvers { class NormalContentResolver : IContentPathModifier { diff --git a/RecrownedAthenaeum/ContentSystem/ContentResolvers/ResolutionContentResolver.cs b/RecrownedAthenaeum/ContentSystem/ContentResolvers/ResolutionContentResolver.cs new file mode 100644 index 0000000..1467fa7 --- /dev/null +++ b/RecrownedAthenaeum/ContentSystem/ContentResolvers/ResolutionContentResolver.cs @@ -0,0 +1,108 @@ +using RecrownedAthenaeum.ContentSystem; +using RecrownedAthenaeum.DataTypes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RecrownedAthenaeum.ContentSystem.ContentResolvers +{ + class ResolutionContentResolver : IContentPathModifier + { + 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; + } + } + + Resolution[] resolutions = { + 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; + } + + public string Modify(string path) + { + if (updated) + { + bestResolution = ChooseRounded(); + } + return bestResolution + "/" + path; + } + } +} diff --git a/RecrownedAthenaeum/RecrownedAthenaeum.csproj b/RecrownedAthenaeum/RecrownedAthenaeum.csproj index 4e2707d..6715ff8 100644 --- a/RecrownedAthenaeum/RecrownedAthenaeum.csproj +++ b/RecrownedAthenaeum/RecrownedAthenaeum.csproj @@ -33,8 +33,8 @@ 4 - - ..\packages\MonoGame.Framework.Portable.3.7.0.1708\lib\portable-net45+win8+wpa81\MonoGame.Framework.dll + + ..\packages\MonoGame.Framework.Portable.3.7.1.189\lib\portable-net45+win8+wpa81\MonoGame.Framework.dll ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll @@ -52,8 +52,10 @@ + + - + diff --git a/RecrownedAthenaeum/packages.config b/RecrownedAthenaeum/packages.config index eb66aa2..95d697f 100644 --- a/RecrownedAthenaeum/packages.config +++ b/RecrownedAthenaeum/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file