Merge pull request #40 from Zoryn4163/master

adds first tick update
This commit is contained in:
Zoryn 2016-03-21 02:29:16 -04:00
commit f09fbc8783
4 changed files with 54 additions and 4 deletions

View File

@ -35,7 +35,7 @@ namespace StardewModdingAPI
public const int MinorVersion = 38;
public const int PatchVersion = 1;
public const int PatchVersion = 3;
public const string Build = "Alpha";

View File

@ -11,6 +11,7 @@ namespace StardewModdingAPI.Events
public static event EventHandler GameLoaded = delegate { };
public static event EventHandler Initialize = delegate { };
public static event EventHandler LoadContent = delegate { };
public static event EventHandler FirstUpdateTick = delegate { };
/// <summary>
/// Fires every update (1/60 of a second)
/// </summary>
@ -110,5 +111,10 @@ namespace StardewModdingAPI.Events
{
OneSecondTick.Invoke(null, EventArgs.Empty);
}
public static void InvokeFirstUpdateTick()
{
FirstUpdateTick.Invoke(null, EventArgs.Empty);
}
}
}

View File

@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
@ -59,11 +60,42 @@ namespace StardewModdingAPI
hash ^= v.GetHashCode();
}
return hash;
}
}
public static T Cast<T>(this object o) where T : StardewValley.Object
public static T Cast<T>(this object o) where T : class
{
return o as T;
}
public static FieldInfo[] GetPrivateFields(this object o)
{
return o.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
}
public static FieldInfo GetBaseFieldInfo(this Type t, string name)
{
return t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
}
public static T GetBaseFieldValue<T>(this Type t, object o, string name) where T : class
{
return t.GetBaseFieldInfo(name).GetValue(o) as T;
}
/*
public static T GetBaseFieldValue<T>(this object o, string name) where T : class
{
return o.GetType().GetBaseFieldInfo(name).GetValue(o) as T;
}*/
public static object GetBaseFieldValue(this object o, string name)
{
return o.GetType().GetBaseFieldInfo(name).GetValue(o);
}
public static void SetBaseFieldValue (this object o, string name, object newValue)
{
o.GetType().GetBaseFieldInfo(name).SetValue(o, newValue);
}
}
}

View File

@ -174,6 +174,13 @@ namespace StardewModdingAPI.Inheritance
public Farmer PreviousFarmer { get; private set; }
public Int32 CurrentUpdateTick { get; private set; }
public bool FirstUpdate { get; private set; }
public RenderTarget2D Screen
{
get { return typeof (Game1).GetBaseFieldValue<RenderTarget2D>(Program.gamePtr, "screen"); }
set { typeof (Game1).SetBaseFieldValue("screen", value); }
}
private static SGame instance;
public static SGame Instance { get { return instance; } }
@ -183,6 +190,7 @@ namespace StardewModdingAPI.Inheritance
public SGame()
{
instance = this;
FirstUpdate = true;
/*
#if DEBUG
@ -255,6 +263,11 @@ namespace StardewModdingAPI.Inheritance
}
Events.GameEvents.InvokeUpdateTick();
if (FirstUpdate)
{
GameEvents.InvokeFirstUpdateTick();
FirstUpdate = false;
}
if (CurrentUpdateTick % 2 == 0)
Events.GameEvents.InvokeSecondUpdateTick();
@ -278,7 +291,6 @@ namespace StardewModdingAPI.Inheritance
if (CurrentUpdateTick >= 60)
CurrentUpdateTick = 0;
PreviouslyPressedKeys = CurrentlyPressedKeys;
for(PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
{