From 68b9aff1ca5eb0827776469344d06f366b1a2311 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Tue, 7 Jan 2025 19:59:35 +0100 Subject: [PATCH] Refactoring --- Program.cs | 15 ++++- Decor.cs => WindowsPhoneSpeedyBlupi/Decor.cs | 0 Def.cs => WindowsPhoneSpeedyBlupi/Def.cs | 16 +---- WindowsPhoneSpeedyBlupi/Env.cs | 25 ++++++++ Game1.cs => WindowsPhoneSpeedyBlupi/Game1.cs | 4 ++ .../GameData.cs | 0 .../InputPad.cs | 10 +-- Jauge.cs => WindowsPhoneSpeedyBlupi/Jauge.cs | 0 Misc.cs => WindowsPhoneSpeedyBlupi/Misc.cs | 0 .../MyResource.cs | 0 .../Pixmap.cs | 8 ++- .../Resource.cs | 3 +- .../Slider.cs | 0 Sound.cs => WindowsPhoneSpeedyBlupi/Sound.cs | 0 .../Tables.cs | 0 Text.cs => WindowsPhoneSpeedyBlupi/Text.cs | 0 .../TinyPoint.cs | 0 .../TinyRect.cs | 0 .../Worlds.cs | 14 ++--- WindowsPhoneSpeedyBlupi/Xna.cs | 61 +++++++++++++++++++ 20 files changed, 123 insertions(+), 33 deletions(-) rename Decor.cs => WindowsPhoneSpeedyBlupi/Decor.cs (100%) rename Def.cs => WindowsPhoneSpeedyBlupi/Def.cs (98%) create mode 100644 WindowsPhoneSpeedyBlupi/Env.cs rename Game1.cs => WindowsPhoneSpeedyBlupi/Game1.cs (99%) rename GameData.cs => WindowsPhoneSpeedyBlupi/GameData.cs (100%) rename InputPad.cs => WindowsPhoneSpeedyBlupi/InputPad.cs (99%) rename Jauge.cs => WindowsPhoneSpeedyBlupi/Jauge.cs (100%) rename Misc.cs => WindowsPhoneSpeedyBlupi/Misc.cs (100%) rename MyResource.cs => WindowsPhoneSpeedyBlupi/MyResource.cs (100%) rename Pixmap.cs => WindowsPhoneSpeedyBlupi/Pixmap.cs (98%) rename Resource.cs => WindowsPhoneSpeedyBlupi/Resource.cs (94%) rename Slider.cs => WindowsPhoneSpeedyBlupi/Slider.cs (100%) rename Sound.cs => WindowsPhoneSpeedyBlupi/Sound.cs (100%) rename Tables.cs => WindowsPhoneSpeedyBlupi/Tables.cs (100%) rename Text.cs => WindowsPhoneSpeedyBlupi/Text.cs (100%) rename TinyPoint.cs => WindowsPhoneSpeedyBlupi/TinyPoint.cs (100%) rename TinyRect.cs => WindowsPhoneSpeedyBlupi/TinyRect.cs (100%) rename Worlds.cs => WindowsPhoneSpeedyBlupi/Worlds.cs (97%) create mode 100644 WindowsPhoneSpeedyBlupi/Xna.cs diff --git a/Program.cs b/Program.cs index 802d40f..1cfff92 100644 --- a/Program.cs +++ b/Program.cs @@ -1,2 +1,13 @@ -using var game = new WindowsPhoneSpeedyBlupi.Game1(); -game.Run(); +using WindowsPhoneSpeedyBlupi; +using static WindowsPhoneSpeedyBlupi.Xna; + +static class Program +{ + static void Main() + { + Env.init(XnaImpl.MonoGame, Platform.Desktop); + var game = new WindowsPhoneSpeedyBlupi.Game1(); + game.Run(); + } +} + diff --git a/Decor.cs b/WindowsPhoneSpeedyBlupi/Decor.cs similarity index 100% rename from Decor.cs rename to WindowsPhoneSpeedyBlupi/Decor.cs diff --git a/Def.cs b/WindowsPhoneSpeedyBlupi/Def.cs similarity index 98% rename from Def.cs rename to WindowsPhoneSpeedyBlupi/Def.cs index 536a4b8..32e02b0 100644 --- a/Def.cs +++ b/WindowsPhoneSpeedyBlupi/Def.cs @@ -1,27 +1,15 @@ // WindowsPhoneSpeedyBlupi, Version=1.0.0.5, Culture=neutral, PublicKeyToken=6db12cd62dbec439 // WindowsPhoneSpeedyBlupi.Def - - using Microsoft.Xna.Framework.Input; +using static WindowsPhoneSpeedyBlupi.Def; namespace WindowsPhoneSpeedyBlupi { public static class Def { - public const bool DETAILED_DEBUGGING = false; - - public const Platform PLATFORM = Platform.Desktop; - - public enum Platform - { - Desktop, - Android, - iOS, - Web - } - + public enum Phase { None, diff --git a/WindowsPhoneSpeedyBlupi/Env.cs b/WindowsPhoneSpeedyBlupi/Env.cs new file mode 100644 index 0000000..1112ff3 --- /dev/null +++ b/WindowsPhoneSpeedyBlupi/Env.cs @@ -0,0 +1,25 @@ +using System; +using static WindowsPhoneSpeedyBlupi.Xna; + +namespace WindowsPhoneSpeedyBlupi +{ + public static class Env + { + public static bool DETAILED_DEBUGGING { get; set; } + + public static Platform PLATFORM { get; private set; } + public static XnaImpl XNA_IMPL { get; private set; } + public static bool INITIALIZED { get; private set; } + + public static void init(XnaImpl xnaImpl, Platform platformIn) + { + if(INITIALIZED) + { + throw new Exception("Env was already initialized. Cannot call the init method again."); + } + XNA_IMPL = xnaImpl; + PLATFORM = platformIn; + INITIALIZED = true; + } + } +} diff --git a/Game1.cs b/WindowsPhoneSpeedyBlupi/Game1.cs similarity index 99% rename from Game1.cs rename to WindowsPhoneSpeedyBlupi/Game1.cs index b9eaef4..f9e854e 100644 --- a/Game1.cs +++ b/WindowsPhoneSpeedyBlupi/Game1.cs @@ -98,6 +98,10 @@ namespace WindowsPhoneSpeedyBlupi public Game1() { + if(!Env.INITIALIZED) + { + throw new Exception("Fatal error: Not initialized. Env.init() was not called."); + } Exiting += OnExiting; if(!TouchPanel.GetCapabilities().IsConnected) { diff --git a/GameData.cs b/WindowsPhoneSpeedyBlupi/GameData.cs similarity index 100% rename from GameData.cs rename to WindowsPhoneSpeedyBlupi/GameData.cs diff --git a/InputPad.cs b/WindowsPhoneSpeedyBlupi/InputPad.cs similarity index 99% rename from InputPad.cs rename to WindowsPhoneSpeedyBlupi/InputPad.cs index e3c11d8..7875435 100644 --- a/InputPad.cs +++ b/WindowsPhoneSpeedyBlupi/InputPad.cs @@ -7,7 +7,7 @@ using System.Linq; using Microsoft.Devices.Sensors; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input.Touch; -using static WindowsPhoneSpeedyBlupi.Def; +using static WindowsPhoneSpeedyBlupi.Xna; namespace WindowsPhoneSpeedyBlupi { @@ -265,7 +265,7 @@ namespace WindowsPhoneSpeedyBlupi float screenHeight = game1.getGraphics().GraphicsDevice.Viewport.Height; float screenRatio = screenWidth / screenHeight; - if (Def.PLATFORM == Platform.Android &&screenRatio > 1.3333333333333333) + if (Env.PLATFORM == Platform.Android &&screenRatio > 1.3333333333333333) { for (int i = 0; i < touchesOrClicks.Count; i++) { @@ -279,7 +279,7 @@ namespace WindowsPhoneSpeedyBlupi float widthHeightRatio = screenWidth / screenHeight; float heightRatio = 480 / screenHeight; float widthRatio = 640 / screenWidth; - if(Def.DETAILED_DEBUGGING) + if(Env.DETAILED_DEBUGGING) { Debug.WriteLine("-----"); Debug.WriteLine("originalX=" + originalX); @@ -294,8 +294,8 @@ namespace WindowsPhoneSpeedyBlupi touchesOrClicks[i] = touchOrClick; } - if(Def.DETAILED_DEBUGGING) Debug.WriteLine("new X" + touchOrClick.X); - if(Def.DETAILED_DEBUGGING) Debug.WriteLine("new Y" + touchOrClick.Y); + if(Env.DETAILED_DEBUGGING) Debug.WriteLine("new X" + touchOrClick.X); + if(Env.DETAILED_DEBUGGING) Debug.WriteLine("new Y" + touchOrClick.Y); } } diff --git a/Jauge.cs b/WindowsPhoneSpeedyBlupi/Jauge.cs similarity index 100% rename from Jauge.cs rename to WindowsPhoneSpeedyBlupi/Jauge.cs diff --git a/Misc.cs b/WindowsPhoneSpeedyBlupi/Misc.cs similarity index 100% rename from Misc.cs rename to WindowsPhoneSpeedyBlupi/Misc.cs diff --git a/MyResource.cs b/WindowsPhoneSpeedyBlupi/MyResource.cs similarity index 100% rename from MyResource.cs rename to WindowsPhoneSpeedyBlupi/MyResource.cs diff --git a/Pixmap.cs b/WindowsPhoneSpeedyBlupi/Pixmap.cs similarity index 98% rename from Pixmap.cs rename to WindowsPhoneSpeedyBlupi/Pixmap.cs index 38b9658..cb3c3ea 100644 --- a/Pixmap.cs +++ b/WindowsPhoneSpeedyBlupi/Pixmap.cs @@ -6,6 +6,8 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using WindowsPhoneSpeedyBlupi; using static System.Net.Mime.MediaTypeNames; +using static WindowsPhoneSpeedyBlupi.Def; +using static WindowsPhoneSpeedyBlupi.Xna; namespace WindowsPhoneSpeedyBlupi { @@ -66,7 +68,7 @@ namespace WindowsPhoneSpeedyBlupi TinyRect result = default(TinyRect); double screenWidth = graphics.GraphicsDevice.Viewport.Width; double screenHeight = graphics.GraphicsDevice.Viewport.Height; - if(Def.PLATFORM == Def.Platform.Android && screenHeight > 480) { + if(Env.PLATFORM == Platform.Android && screenHeight > 480) { screenWidth = screenHeight * (640f / 480f); } if (screenWidth != 0.0 && screenHeight != 0.0) @@ -248,7 +250,7 @@ namespace WindowsPhoneSpeedyBlupi { double screenWidth = graphics.GraphicsDevice.Viewport.Width; double screenHeight = graphics.GraphicsDevice.Viewport.Height; - if (Def.PLATFORM == Def.Platform.Android && screenHeight > 480) + if (Env.PLATFORM == Platform.Android && screenHeight > 480) { screenWidth = screenHeight * (640f / 480f); } @@ -279,7 +281,7 @@ namespace WindowsPhoneSpeedyBlupi { double screenWidth = graphics.GraphicsDevice.Viewport.Width; double screenHeight = graphics.GraphicsDevice.Viewport.Height; - if (Def.PLATFORM == Def.Platform.Android && screenHeight > 480) + if (Env.PLATFORM == Platform.Android && screenHeight > 480) { screenWidth = screenHeight * (640f / 480f); } diff --git a/Resource.cs b/WindowsPhoneSpeedyBlupi/Resource.cs similarity index 94% rename from Resource.cs rename to WindowsPhoneSpeedyBlupi/Resource.cs index e9ff8bd..dccb2ca 100644 --- a/Resource.cs +++ b/WindowsPhoneSpeedyBlupi/Resource.cs @@ -6,7 +6,6 @@ using System.Diagnostics; using System.Globalization; using System.Resources; using System.Runtime.CompilerServices; -using WindowsPhoneSpeedyBlupi; //[DebuggerNonUserCode] //[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] @@ -25,7 +24,7 @@ namespace WindowsPhoneSpeedyBlupi { get { - if (object.ReferenceEquals(resourceMan, null)) + if (ReferenceEquals(resourceMan, null)) { ResourceManager resourceManager = new ResourceManager("WindowsPhoneSpeedyBlupi.Resource", typeof(Resource).Assembly); resourceMan = resourceManager; diff --git a/Slider.cs b/WindowsPhoneSpeedyBlupi/Slider.cs similarity index 100% rename from Slider.cs rename to WindowsPhoneSpeedyBlupi/Slider.cs diff --git a/Sound.cs b/WindowsPhoneSpeedyBlupi/Sound.cs similarity index 100% rename from Sound.cs rename to WindowsPhoneSpeedyBlupi/Sound.cs diff --git a/Tables.cs b/WindowsPhoneSpeedyBlupi/Tables.cs similarity index 100% rename from Tables.cs rename to WindowsPhoneSpeedyBlupi/Tables.cs diff --git a/Text.cs b/WindowsPhoneSpeedyBlupi/Text.cs similarity index 100% rename from Text.cs rename to WindowsPhoneSpeedyBlupi/Text.cs diff --git a/TinyPoint.cs b/WindowsPhoneSpeedyBlupi/TinyPoint.cs similarity index 100% rename from TinyPoint.cs rename to WindowsPhoneSpeedyBlupi/TinyPoint.cs diff --git a/TinyRect.cs b/WindowsPhoneSpeedyBlupi/TinyRect.cs similarity index 100% rename from TinyRect.cs rename to WindowsPhoneSpeedyBlupi/TinyRect.cs diff --git a/Worlds.cs b/WindowsPhoneSpeedyBlupi/Worlds.cs similarity index 97% rename from Worlds.cs rename to WindowsPhoneSpeedyBlupi/Worlds.cs index 09aa315..4b3f57a 100644 --- a/Worlds.cs +++ b/WindowsPhoneSpeedyBlupi/Worlds.cs @@ -275,38 +275,38 @@ namespace WindowsPhoneSpeedyBlupi int num = text.IndexOf(name + "="); if (num == -1) { - return default(TinyPoint); + return default; } num += name.Length + 1; int num2 = text.IndexOf(";", num); if (num2 == -1) { - return default(TinyPoint); + return default; } int num3 = text.IndexOf(" ", num); if (num3 == -1) { - return default(TinyPoint); + return default; } string s = text.Substring(num, num2 - num); string s2 = text.Substring(num2 + 1, num3 - num2 - 1); int result; if (!int.TryParse(s, out result)) { - return default(TinyPoint); + return default; } int result2; if (!int.TryParse(s2, out result2)) { - return default(TinyPoint); + return default; } - TinyPoint result3 = default(TinyPoint); + TinyPoint result3 = default; result3.X = result; result3.Y = result2; return result3; } } - return default(TinyPoint); + return default; } public static int? GetDecorField(string[] lines, string section, int x, int y) diff --git a/WindowsPhoneSpeedyBlupi/Xna.cs b/WindowsPhoneSpeedyBlupi/Xna.cs new file mode 100644 index 0000000..6ca9b97 --- /dev/null +++ b/WindowsPhoneSpeedyBlupi/Xna.cs @@ -0,0 +1,61 @@ +// WindowsPhoneSpeedyBlupi, Version=1.0.0.5, Culture=neutral, PublicKeyToken=6db12cd62dbec439 +// WindowsPhoneSpeedyBlupi.Def + +using static WindowsPhoneSpeedyBlupi.Xna; + +namespace WindowsPhoneSpeedyBlupi +{ + + public static class Xna + { + public enum Platform + { + Desktop, + Android, + iOS, + Web + } + + public enum XnaImpl + { + MonoGame = ProgrammingLanguage.CSharp, + Fna = ProgrammingLanguage.CSharp, + Kni = ProgrammingLanguage.CSharp, + JXNA = ProgrammingLanguage.Java, + JSXN = ProgrammingLanguage.JavaScript + } + + public enum ProgrammingLanguage + { + CSharp, + Java, + JavaScript + } + + + } + + public static class Extensions + { + public static ProgrammingLanguage getProgrammingLanguage(this XnaImpl xnaImpl) + { + return (ProgrammingLanguage)((int)xnaImpl); + } + public static bool isDesktop(this Platform platform) + { + return platform == Platform.Desktop; + } + public static bool isAndroid(this Platform platform) + { + return platform == Platform.Android; + } + public static bool isIOS(this Platform platform) + { + return platform == Platform.iOS; + } + public static bool isWeb(this Platform platform) + { + return platform == Platform.Web; + } + } +} \ No newline at end of file