Refactoring

This commit is contained in:
Robert Vokac 2025-01-07 19:59:35 +01:00
parent ce693bd9af
commit 68b9aff1ca
20 changed files with 123 additions and 33 deletions

@ -1,2 +1,13 @@
using var game = new WindowsPhoneSpeedyBlupi.Game1();
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();
}
}

@ -1,26 +1,14 @@
// 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
{

@ -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;
}
}
}

@ -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)
{

@ -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);
}
}

@ -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);
}

@ -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;

@ -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)

@ -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;
}
}
}