Setting up module swapping

This commit is contained in:
Maddy Thorson 2021-02-20 21:17:17 -08:00
parent 9a0303781f
commit d7aa6346e8
7 changed files with 26 additions and 24 deletions

View File

@ -30,7 +30,7 @@ namespace Strawberry
static public void LoadAll()
{
Textures = new .();
Load<Texture>("textures", "*.png", Textures, (path) => Game.PlatformLayer.LoadTexture(path));
Load<Texture>("textures", "*.png", Textures, (path) => PlatformLayer.LoadTexture(path));
Sprites = new .();
Load<Sprite>("sprites", "*.ase", Sprites, (path) => { return new Sprite(new String(path)); });

View File

@ -26,31 +26,31 @@ namespace Strawberry
{
for (let i < previousKeyboard.Count)
{
if (!previousKeyboard[i] && Game.PlatformLayer.PollKey((Keys)i))
if (!previousKeyboard[i] && PlatformLayer.PollKey((Keys)i))
lastKeypressTimes[i] = Time.Elapsed;
previousKeyboard[i] = Game.PlatformLayer.PollKey((Keys)i);
previousKeyboard[i] = PlatformLayer.PollKey((Keys)i);
}
}
static public bool Ctrl => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl);
static public bool Alt => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl);
static public bool Shift => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl);
static public bool CapsLock => Game.PlatformLayer.CapsLock;
static public bool NumLock => Game.PlatformLayer.NumLock;
static public bool CapsLock => PlatformLayer.CapsLock;
static public bool NumLock => PlatformLayer.NumLock;
static public bool KeyCheck(Keys key)
{
return Game.PlatformLayer.PollKey(key);
return PlatformLayer.PollKey(key);
}
static public bool KeyPressed(Keys key)
{
return Game.PlatformLayer.PollKey(key) && !previousKeyboard[(int)key];
return PlatformLayer.PollKey(key) && !previousKeyboard[(int)key];
}
static public bool KeyPressed(Keys key, float repeatDelay, float repeatInterval)
{
if (Game.PlatformLayer.PollKey(key))
if (PlatformLayer.PollKey(key))
return !previousKeyboard[(int)key] || Time.OnInterval(repeatInterval, lastKeypressTimes[(int)key] + repeatDelay);
else
return false;
@ -58,7 +58,7 @@ namespace Strawberry
static public bool KeyReleased(Keys key)
{
return !Game.PlatformLayer.PollKey(key) && previousKeyboard[(int)key];
return !PlatformLayer.PollKey(key) && previousKeyboard[(int)key];
}
static public void KeystrokesIntoString(String toString, float keyRepeatDelay, float keyRepeatInterval)
@ -172,12 +172,12 @@ namespace Strawberry
static public bool GamepadButtonCheck(int gamepadID, Buttons button)
{
return Game.PlatformLayer.PollGamepadButton(gamepadID, button);
return PlatformLayer.PollGamepadButton(gamepadID, button);
}
static public float GamepadAxisCheck(int gamepadID, Axes axis)
{
return Game.PlatformLayer.PollGamepadAxis(gamepadID, axis);
return PlatformLayer.PollGamepadAxis(gamepadID, axis);
}
}
}

View File

@ -2,11 +2,6 @@ namespace Strawberry
{
public abstract class Editor : Module
{
public this(PlatformLayer platformLayer)
: base(platformLayer)
{
}
protected override void Update()
{

View File

@ -30,12 +30,11 @@ namespace Strawberry
private int32 updateCounter;
private float msCounter;
public this(PlatformLayer platformLayer)
: base(platformLayer)
public this()
{
Game = this;
Batcher = platformLayer.CreateBatcher();
Batcher = PlatformLayer.CreateBatcher();
VirtualInputs = new List<VirtualInput>();
Assets.LoadAll();
}

View File

@ -1,17 +1,16 @@
using System.Diagnostics;
namespace Strawberry
{
public abstract class Module
{
public enum RunResults { Quit, Swap }
public PlatformLayer PlatformLayer { get; private set; }
private float msCounter;
private uint32 prevTicks;
public this(PlatformLayer platformLayer)
public this()
{
PlatformLayer = platformLayer;
Debug.Assert(PlatformLayer != null, "Must create PlatformLayer before Modules.");
}
private Module Run()

View File

@ -29,7 +29,7 @@ namespace Strawberry
public void ClearMatrix()
{
matrixStack.Clear();
matrixStack.Add(Game.PlatformLayer.ScreenMatrix);
matrixStack.Add(PlatformLayer.ScreenMatrix);
}
public void PushMatrix(Mat4x4 mat)

View File

@ -1,6 +1,12 @@
using System;
using System.Diagnostics;
namespace Strawberry
{
static
{
static public PlatformLayer PlatformLayer = null;
}
public abstract class PlatformLayer
{
public readonly String Title;
@ -12,6 +18,9 @@ namespace Strawberry
public this(String title, int screenWidth, int screenHeight, int windowScale)
{
Debug.Assert(PlatformLayer == null, "Cannot create more than one PlatformLayer");
PlatformLayer = this;
Title = title;
ScreenWidth = screenWidth;
ScreenHeight = screenHeight;