SMAPI/StardewModdingAPI/Inheritance/SGame.cs

75 lines
2.0 KiB
C#
Raw Normal View History

2016-02-29 09:26:36 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
2016-02-29 11:16:32 +08:00
using System.Reflection;
2016-02-29 09:26:36 +08:00
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using StardewValley;
2016-02-29 11:16:32 +08:00
using StardewValley.Minigames;
2016-02-29 09:26:36 +08:00
2016-02-29 11:16:32 +08:00
namespace StardewModdingAPI.Inheritance
2016-02-29 09:26:36 +08:00
{
public class SGame : Game1
{
2016-02-29 11:16:32 +08:00
public static FieldInfo[] StaticFields { get { return Thing(); } }
public static FieldInfo[] Thing()
{
return typeof(Game1).GetFields();
}
2016-02-29 09:26:36 +08:00
public KeyboardState KStateNow { get; private set; }
public KeyboardState KStatePrior { get; private set; }
public Keys[] CurrentlyPressedKeys { get; private set; }
public Keys[] PreviouslyPressedKeys { get; private set; }
public Keys[] FramePressedKeys
{
get { return CurrentlyPressedKeys.Where(x => !PreviouslyPressedKeys.Contains(x)).ToArray(); }
}
protected override void Initialize()
{
Program.Log("XNA Initialize");
Events.InvokeInitialize();
base.Initialize();
}
protected override void LoadContent()
{
Program.Log("XNA LoadContent");
Events.InvokeLoadContent();
base.LoadContent();
}
protected override void Update(GameTime gameTime)
{
KStateNow = Keyboard.GetState();
CurrentlyPressedKeys = KStateNow.GetPressedKeys();
foreach (Keys k in FramePressedKeys)
Events.InvokeKeyPressed(k);
if (KStateNow != KStatePrior)
{
Events.InvokeKeyboardChanged(KStateNow);
}
Events.InvokeUpdateTick();
base.Update(gameTime);
KStatePrior = KStateNow;
PreviouslyPressedKeys = CurrentlyPressedKeys;
}
protected override void Draw(GameTime gameTime)
{
Events.InvokeDrawTick();
base.Draw(gameTime);
}
}
}