Changes
This commit is contained in:
parent
ea5dabf84b
commit
99910d425d
8
Env.cs
8
Env.cs
@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using static WindowsPhoneSpeedyBlupi.Xna;
|
||||
using static WindowsPhoneSpeedyBlupi.EnvClasses;
|
||||
|
||||
namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
@ -8,16 +8,16 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
public static bool DETAILED_DEBUGGING { get; set; }
|
||||
|
||||
public static Platform PLATFORM { get; private set; }
|
||||
public static XnaImpl XNA_IMPL { get; private set; }
|
||||
public static Impl IMPL { get; private set; }
|
||||
public static bool INITIALIZED { get; private set; }
|
||||
|
||||
public static void init(XnaImpl xnaImpl, Platform platformIn)
|
||||
public static void init(Impl impl, Platform platformIn)
|
||||
{
|
||||
if(INITIALIZED)
|
||||
{
|
||||
throw new Exception("Env was already initialized. Cannot call the init method again.");
|
||||
}
|
||||
XNA_IMPL = xnaImpl;
|
||||
IMPL = impl;
|
||||
PLATFORM = platformIn;
|
||||
INITIALIZED = true;
|
||||
}
|
||||
|
124
EnvClasses.cs
Normal file
124
EnvClasses.cs
Normal file
@ -0,0 +1,124 @@
|
||||
// WindowsPhoneSpeedyBlupi, Version=1.0.0.5, Culture=neutral, PublicKeyToken=6db12cd62dbec439
|
||||
// WindowsPhoneSpeedyBlupi.Def
|
||||
|
||||
using static WindowsPhoneSpeedyBlupi.EnvClasses;
|
||||
|
||||
namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
|
||||
public static class EnvClasses
|
||||
{
|
||||
public enum Platform
|
||||
{
|
||||
Desktop,
|
||||
Android,
|
||||
iOS,
|
||||
Web
|
||||
}
|
||||
|
||||
public enum Impl
|
||||
{
|
||||
MonoGame = ProgrammingLanguage.CSharp,
|
||||
FNA = ProgrammingLanguage.CSharp,
|
||||
KNI = ProgrammingLanguage.CSharp,
|
||||
JXNA = ProgrammingLanguage.Java,
|
||||
JSXNA = ProgrammingLanguage.JavaScript
|
||||
}
|
||||
|
||||
public enum ProgrammingLanguage
|
||||
{
|
||||
CSharp,
|
||||
Java,
|
||||
JavaScript
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static ProgrammingLanguage getProgrammingLanguage(this Impl xnaImpl)
|
||||
{
|
||||
return (ProgrammingLanguage)((int)xnaImpl);
|
||||
}
|
||||
public static bool isMonoGame(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl == Impl.MonoGame;
|
||||
}
|
||||
public static bool isFNA(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl == Impl.FNA;
|
||||
}
|
||||
|
||||
public static bool isKNI(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl == Impl.KNI;
|
||||
}
|
||||
|
||||
public static bool isJXNA(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl == Impl.JXNA;
|
||||
}
|
||||
|
||||
public static bool isJSXNA(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl == Impl.JSXNA;
|
||||
}
|
||||
public static bool isNotMonoGame(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl != Impl.MonoGame;
|
||||
}
|
||||
public static bool isNotFNA(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl != Impl.FNA;
|
||||
}
|
||||
|
||||
public static bool isNotKNI(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl != Impl.KNI;
|
||||
}
|
||||
|
||||
public static bool isNotJXNA(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl != Impl.JXNA;
|
||||
}
|
||||
|
||||
public static bool isNotJSXNA(this Impl xnaImpl)
|
||||
{
|
||||
return xnaImpl != Impl.JSXNA;
|
||||
}
|
||||
//
|
||||
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;
|
||||
}
|
||||
public static bool isNotDesktop(this Platform platform)
|
||||
{
|
||||
return platform != Platform.Desktop;
|
||||
}
|
||||
public static bool isNotAndroid(this Platform platform)
|
||||
{
|
||||
return platform != Platform.Android;
|
||||
}
|
||||
public static bool isNotIOS(this Platform platform)
|
||||
{
|
||||
return platform != Platform.iOS;
|
||||
}
|
||||
public static bool isNotWeb(this Platform platform)
|
||||
{
|
||||
return platform != Platform.Web;
|
||||
}
|
||||
}
|
||||
}
|
21
Game1.cs
21
Game1.cs
@ -103,11 +103,18 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
throw new Exception("Fatal error: Not initialized. Env.init() was not called.");
|
||||
}
|
||||
Exiting += OnExiting;
|
||||
if(!TouchPanel.GetCapabilities().IsConnected)
|
||||
|
||||
#if KNI
|
||||
Deactivated += OnDeactivated;
|
||||
Activated += OnActivated;
|
||||
#endif
|
||||
|
||||
if (Env.IMPL.isNotKNI() && !TouchPanel.GetCapabilities().IsConnected)
|
||||
{
|
||||
this.IsMouseVisible = true;
|
||||
Mouse.SetCursor(MouseCursor.Arrow);
|
||||
}
|
||||
|
||||
graphics = new GraphicsDeviceManager(this);
|
||||
graphics.IsFullScreen = false;
|
||||
base.Content.RootDirectory = "Content";
|
||||
@ -149,7 +156,11 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
}
|
||||
|
||||
#if !KNI
|
||||
protected override void OnDeactivated(object sender, EventArgs args)
|
||||
#else
|
||||
protected void OnDeactivated(object sender, EventArgs args)
|
||||
#endif
|
||||
{
|
||||
if (phase == Def.Phase.Play)
|
||||
{
|
||||
@ -159,13 +170,21 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
decor.CurrentDelete();
|
||||
}
|
||||
#if !KNI
|
||||
base.OnDeactivated(sender, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !KNI
|
||||
protected override void OnActivated(object sender, EventArgs args)
|
||||
#else
|
||||
protected void OnActivated(object sender, EventArgs args)
|
||||
#endif
|
||||
{
|
||||
continueMission = 1;
|
||||
#if !KNI
|
||||
base.OnActivated(sender, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected void OnExiting(object sender, EventArgs args)
|
||||
|
21
InputPad.cs
21
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.Xna;
|
||||
using static WindowsPhoneSpeedyBlupi.EnvClasses;
|
||||
|
||||
namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
@ -241,10 +241,18 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
int keyPress = 0;
|
||||
padPressed = false;
|
||||
Def.ButtonGlyph buttonGlyph = Def.ButtonGlyph.None;
|
||||
TouchCollection touches = TouchPanel.GetState();
|
||||
touchCount = touches.Count;
|
||||
List<TinyPoint> touchesOrClicks = new List<TinyPoint>();
|
||||
foreach (TouchLocation item in touches)
|
||||
|
||||
TouchCollection touches = default;
|
||||
if (Env.IMPL.isNotKNI())
|
||||
{
|
||||
touches = TouchPanel.GetState();
|
||||
touchCount = touches.Count;
|
||||
}
|
||||
|
||||
List <TinyPoint> touchesOrClicks = new List<TinyPoint>();
|
||||
|
||||
|
||||
if(Env.IMPL.isNotKNI()) foreach (TouchLocation item in touches)
|
||||
{
|
||||
if (item.State == TouchLocationState.Pressed || item.State == TouchLocationState.Moved)
|
||||
{
|
||||
@ -253,6 +261,7 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MouseState mouseState = Mouse.GetState();
|
||||
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||
{
|
||||
@ -265,7 +274,7 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
float screenHeight = game1.getGraphics().GraphicsDevice.Viewport.Height;
|
||||
float screenRatio = screenWidth / screenHeight;
|
||||
|
||||
if (Env.PLATFORM == Platform.Android &&screenRatio > 1.3333333333333333)
|
||||
if ((Env.PLATFORM.isAndroid() && screenRatio > 1.3333333333333333) || (Env.IMPL.isKNI()))
|
||||
{
|
||||
for (int i = 0; i < touchesOrClicks.Count; i++)
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using WindowsPhoneSpeedyBlupi;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using static WindowsPhoneSpeedyBlupi.Def;
|
||||
using static WindowsPhoneSpeedyBlupi.Xna;
|
||||
using static WindowsPhoneSpeedyBlupi.EnvClasses;
|
||||
|
||||
namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
|
104
Worlds.cs
104
Worlds.cs
@ -6,8 +6,12 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.IsolatedStorage;
|
||||
using System.Text;
|
||||
using Microsoft.JSInterop;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using WindowsPhoneSpeedyBlupi;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
@ -33,20 +37,29 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
|
||||
public static string[] ReadWorld(int gamer, int rank)
|
||||
{
|
||||
|
||||
string worldFilename = GetWorldFilename(gamer, rank);
|
||||
|
||||
string text = null;
|
||||
try
|
||||
if (Env.IMPL.isNotKNI() && Env.PLATFORM.isNotWeb())
|
||||
{
|
||||
Stream stream = TitleContainer.OpenStream(worldFilename);
|
||||
StreamReader streamReader = new StreamReader(stream);
|
||||
text = streamReader.ReadToEnd();
|
||||
stream.Close();
|
||||
try
|
||||
{
|
||||
Stream stream = TitleContainer.OpenStream(worldFilename);
|
||||
StreamReader streamReader = new StreamReader(stream);
|
||||
text = streamReader.ReadToEnd();
|
||||
stream.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Write(e.Message);
|
||||
Debug.Write("Fatal error. Loading world failed: " + worldFilename + "\n");
|
||||
//Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
else
|
||||
{
|
||||
Debug.Write(e.Message);
|
||||
Debug.Write("Fatal error. Loading world failed: " + worldFilename + "\n");
|
||||
//Environment.Exit(1);
|
||||
text = WorldTxt.getWorld(rank);
|
||||
}
|
||||
if (text == null)
|
||||
{
|
||||
@ -62,6 +75,9 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
|
||||
public static bool ReadGameData(byte[] data)
|
||||
{
|
||||
Debug.WriteLine("ReadGameData");
|
||||
|
||||
#if !(KNI && WEB)
|
||||
IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
if (userStoreForApplication.FileExists(GameDataFilename))
|
||||
{
|
||||
@ -83,10 +99,26 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
if (true) return false;
|
||||
string result = LocalStorageHelperHolder.LocalStorageHelper.ReadFromLocalStorageAsync(GameDataFilename).Result;
|
||||
if (result == null || result.Length == 0) { return false; }
|
||||
else
|
||||
{
|
||||
byte[] resultAsByteArray = Encoding.UTF8.GetBytes(result);
|
||||
Array.Copy(resultAsByteArray, data, resultAsByteArray.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void WriteGameData(byte[] data)
|
||||
{
|
||||
Debug.WriteLine("WriteGameData");
|
||||
|
||||
#if !(KNI && WEB)
|
||||
|
||||
IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
IsolatedStorageFileStream isolatedStorageFileStream = userStoreForApplication.OpenFile(GameDataFilename, FileMode.Create);
|
||||
if (isolatedStorageFileStream != null)
|
||||
@ -94,10 +126,17 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
isolatedStorageFileStream.Write(data, 0, data.Length);
|
||||
isolatedStorageFileStream.Close();
|
||||
}
|
||||
#else
|
||||
//LocalStorageHelperHolder.LocalStorageHelper.SaveToLocalStorageAsync(GameDataFilename, Encoding.UTF8.GetString(data));
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void DeleteCurrentGame()
|
||||
{
|
||||
Debug.WriteLine("DeleteCurrentGame");
|
||||
|
||||
#if !KNI
|
||||
|
||||
IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
try
|
||||
{
|
||||
@ -106,10 +145,17 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
catch
|
||||
{
|
||||
}
|
||||
#else
|
||||
//LocalStorageHelperHolder.LocalStorageHelper.DeleteFromLocalStorageAsync(GameDataFilename);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public static string ReadCurrentGame()
|
||||
{
|
||||
Debug.WriteLine("ReadCurrentGame");
|
||||
#if !(KNI && WEB)
|
||||
IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
if (userStoreForApplication.FileExists(CurrentGameFilename))
|
||||
{
|
||||
@ -131,10 +177,16 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
}
|
||||
}
|
||||
return null;
|
||||
#else
|
||||
if (true) return null;
|
||||
return LocalStorageHelperHolder.LocalStorageHelper.ReadFromLocalStorageAsync(CurrentGameFilename).Result;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void WriteCurrentGame(string data)
|
||||
{
|
||||
Debug.WriteLine("WriteCurrentGame");
|
||||
#if !(KNI && WEB)
|
||||
IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
|
||||
IsolatedStorageFileStream isolatedStorageFileStream = userStoreForApplication.OpenFile(CurrentGameFilename, FileMode.Create);
|
||||
if (isolatedStorageFileStream != null)
|
||||
@ -142,6 +194,9 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
isolatedStorageFileStream.Write(Encoding.UTF8.GetBytes(data), 0, data.Length);
|
||||
isolatedStorageFileStream.Close();
|
||||
}
|
||||
#else
|
||||
//LocalStorageHelperHolder.LocalStorageHelper.SaveToLocalStorageAsync(CurrentGameFilename, data);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void GetIntArrayField(string[] lines, string section, int rank, string name, int[] array)
|
||||
@ -461,5 +516,36 @@ namespace WindowsPhoneSpeedyBlupi
|
||||
{
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if KNI && WEB
|
||||
public class LocalStorageHelper
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
|
||||
// Constructor to inject IJSRuntime
|
||||
public LocalStorageHelper(IJSRuntime jsRuntime)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
public async Task SaveToLocalStorageAsync(string key, string data)
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, data);
|
||||
}
|
||||
|
||||
public async Task<string> ReadFromLocalStorageAsync(string key)
|
||||
{
|
||||
return await _jsRuntime.InvokeAsync<string>("localStorage.getItem", key);
|
||||
}
|
||||
|
||||
public async Task DeleteFromLocalStorageAsync(string key)
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", key);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
61
Xna.cs
61
Xna.cs
@ -1,61 +0,0 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user