mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Setting up module swapping
This commit is contained in:
parent
9a0303781f
commit
d7aa6346e8
|
@ -30,7 +30,7 @@ namespace Strawberry
|
||||||
static public void LoadAll()
|
static public void LoadAll()
|
||||||
{
|
{
|
||||||
Textures = new .();
|
Textures = new .();
|
||||||
Load<Texture>("textures", "*.png", Textures, (path) => Game.PlatformLayer.LoadTexture(path));
|
Load<Texture>("textures", "*.png", Textures, (path) => PlatformLayer.LoadTexture(path));
|
||||||
|
|
||||||
Sprites = new .();
|
Sprites = new .();
|
||||||
Load<Sprite>("sprites", "*.ase", Sprites, (path) => { return new Sprite(new String(path)); });
|
Load<Sprite>("sprites", "*.ase", Sprites, (path) => { return new Sprite(new String(path)); });
|
||||||
|
|
|
@ -26,31 +26,31 @@ namespace Strawberry
|
||||||
{
|
{
|
||||||
for (let i < previousKeyboard.Count)
|
for (let i < previousKeyboard.Count)
|
||||||
{
|
{
|
||||||
if (!previousKeyboard[i] && Game.PlatformLayer.PollKey((Keys)i))
|
if (!previousKeyboard[i] && PlatformLayer.PollKey((Keys)i))
|
||||||
lastKeypressTimes[i] = Time.Elapsed;
|
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 Ctrl => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl);
|
||||||
static public bool Alt => 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 Shift => KeyCheck(Keys.LCtrl) || KeyCheck(Keys.RCtrl);
|
||||||
static public bool CapsLock => Game.PlatformLayer.CapsLock;
|
static public bool CapsLock => PlatformLayer.CapsLock;
|
||||||
static public bool NumLock => Game.PlatformLayer.NumLock;
|
static public bool NumLock => PlatformLayer.NumLock;
|
||||||
|
|
||||||
static public bool KeyCheck(Keys key)
|
static public bool KeyCheck(Keys key)
|
||||||
{
|
{
|
||||||
return Game.PlatformLayer.PollKey(key);
|
return PlatformLayer.PollKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public bool KeyPressed(Keys 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)
|
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);
|
return !previousKeyboard[(int)key] || Time.OnInterval(repeatInterval, lastKeypressTimes[(int)key] + repeatDelay);
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -58,7 +58,7 @@ namespace Strawberry
|
||||||
|
|
||||||
static public bool KeyReleased(Keys key)
|
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)
|
static public void KeystrokesIntoString(String toString, float keyRepeatDelay, float keyRepeatInterval)
|
||||||
|
@ -172,12 +172,12 @@ namespace Strawberry
|
||||||
|
|
||||||
static public bool GamepadButtonCheck(int gamepadID, Buttons button)
|
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)
|
static public float GamepadAxisCheck(int gamepadID, Axes axis)
|
||||||
{
|
{
|
||||||
return Game.PlatformLayer.PollGamepadAxis(gamepadID, axis);
|
return PlatformLayer.PollGamepadAxis(gamepadID, axis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,6 @@ namespace Strawberry
|
||||||
{
|
{
|
||||||
public abstract class Editor : Module
|
public abstract class Editor : Module
|
||||||
{
|
{
|
||||||
public this(PlatformLayer platformLayer)
|
|
||||||
: base(platformLayer)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,12 +30,11 @@ namespace Strawberry
|
||||||
private int32 updateCounter;
|
private int32 updateCounter;
|
||||||
private float msCounter;
|
private float msCounter;
|
||||||
|
|
||||||
public this(PlatformLayer platformLayer)
|
public this()
|
||||||
: base(platformLayer)
|
|
||||||
{
|
{
|
||||||
Game = this;
|
Game = this;
|
||||||
|
|
||||||
Batcher = platformLayer.CreateBatcher();
|
Batcher = PlatformLayer.CreateBatcher();
|
||||||
VirtualInputs = new List<VirtualInput>();
|
VirtualInputs = new List<VirtualInput>();
|
||||||
Assets.LoadAll();
|
Assets.LoadAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
|
using System.Diagnostics;
|
||||||
namespace Strawberry
|
namespace Strawberry
|
||||||
{
|
{
|
||||||
public abstract class Module
|
public abstract class Module
|
||||||
{
|
{
|
||||||
public enum RunResults { Quit, Swap }
|
public enum RunResults { Quit, Swap }
|
||||||
|
|
||||||
public PlatformLayer PlatformLayer { get; private set; }
|
|
||||||
|
|
||||||
private float msCounter;
|
private float msCounter;
|
||||||
private uint32 prevTicks;
|
private uint32 prevTicks;
|
||||||
|
|
||||||
public this(PlatformLayer platformLayer)
|
public this()
|
||||||
{
|
{
|
||||||
PlatformLayer = platformLayer;
|
Debug.Assert(PlatformLayer != null, "Must create PlatformLayer before Modules.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Module Run()
|
private Module Run()
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace Strawberry
|
||||||
public void ClearMatrix()
|
public void ClearMatrix()
|
||||||
{
|
{
|
||||||
matrixStack.Clear();
|
matrixStack.Clear();
|
||||||
matrixStack.Add(Game.PlatformLayer.ScreenMatrix);
|
matrixStack.Add(PlatformLayer.ScreenMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PushMatrix(Mat4x4 mat)
|
public void PushMatrix(Mat4x4 mat)
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
namespace Strawberry
|
namespace Strawberry
|
||||||
{
|
{
|
||||||
|
static
|
||||||
|
{
|
||||||
|
static public PlatformLayer PlatformLayer = null;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract class PlatformLayer
|
public abstract class PlatformLayer
|
||||||
{
|
{
|
||||||
public readonly String Title;
|
public readonly String Title;
|
||||||
|
@ -12,6 +18,9 @@ namespace Strawberry
|
||||||
|
|
||||||
public this(String title, int screenWidth, int screenHeight, int windowScale)
|
public this(String title, int screenWidth, int screenHeight, int windowScale)
|
||||||
{
|
{
|
||||||
|
Debug.Assert(PlatformLayer == null, "Cannot create more than one PlatformLayer");
|
||||||
|
PlatformLayer = this;
|
||||||
|
|
||||||
Title = title;
|
Title = title;
|
||||||
ScreenWidth = screenWidth;
|
ScreenWidth = screenWidth;
|
||||||
ScreenHeight = screenHeight;
|
ScreenHeight = screenHeight;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user