Skip to content

Commit f09fbc8

Browse files
committed
Merge pull request Pathoschild#40 from Zoryn4163/master
adds first tick update
2 parents 32387c1 + 05e26c5 commit f09fbc8

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

StardewModdingAPI/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class Constants
3535

3636
public const int MinorVersion = 38;
3737

38-
public const int PatchVersion = 1;
38+
public const int PatchVersion = 3;
3939

4040
public const string Build = "Alpha";
4141

StardewModdingAPI/Events/Game.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static class GameEvents
1111
public static event EventHandler GameLoaded = delegate { };
1212
public static event EventHandler Initialize = delegate { };
1313
public static event EventHandler LoadContent = delegate { };
14+
public static event EventHandler FirstUpdateTick = delegate { };
1415
/// <summary>
1516
/// Fires every update (1/60 of a second)
1617
/// </summary>
@@ -110,5 +111,10 @@ public static void InvokeOneSecondTick()
110111
{
111112
OneSecondTick.Invoke(null, EventArgs.Empty);
112113
}
114+
115+
public static void InvokeFirstUpdateTick()
116+
{
117+
FirstUpdateTick.Invoke(null, EventArgs.Empty);
118+
}
113119
}
114120
}

StardewModdingAPI/Extensions.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Reflection;
56
using System.Text;
67
using System.Threading.Tasks;
78
using Microsoft.Xna.Framework;
@@ -59,11 +60,42 @@ public static int GetHash(this IEnumerable enumerable)
5960
hash ^= v.GetHashCode();
6061
}
6162
return hash;
62-
}
63+
}
6364

64-
public static T Cast<T>(this object o) where T : StardewValley.Object
65+
public static T Cast<T>(this object o) where T : class
6566
{
6667
return o as T;
6768
}
69+
70+
public static FieldInfo[] GetPrivateFields(this object o)
71+
{
72+
return o.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
73+
}
74+
75+
public static FieldInfo GetBaseFieldInfo(this Type t, string name)
76+
{
77+
return t.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic);
78+
}
79+
80+
public static T GetBaseFieldValue<T>(this Type t, object o, string name) where T : class
81+
{
82+
return t.GetBaseFieldInfo(name).GetValue(o) as T;
83+
}
84+
85+
/*
86+
public static T GetBaseFieldValue<T>(this object o, string name) where T : class
87+
{
88+
return o.GetType().GetBaseFieldInfo(name).GetValue(o) as T;
89+
}*/
90+
91+
public static object GetBaseFieldValue(this object o, string name)
92+
{
93+
return o.GetType().GetBaseFieldInfo(name).GetValue(o);
94+
}
95+
96+
public static void SetBaseFieldValue (this object o, string name, object newValue)
97+
{
98+
o.GetType().GetBaseFieldInfo(name).SetValue(o, newValue);
99+
}
68100
}
69101
}

StardewModdingAPI/Inheritance/SGame.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ public Buttons[] GetFrameReleasedButtons(PlayerIndex index)
174174
public Farmer PreviousFarmer { get; private set; }
175175

176176
public Int32 CurrentUpdateTick { get; private set; }
177+
public bool FirstUpdate { get; private set; }
178+
179+
public RenderTarget2D Screen
180+
{
181+
get { return typeof (Game1).GetBaseFieldValue<RenderTarget2D>(Program.gamePtr, "screen"); }
182+
set { typeof (Game1).SetBaseFieldValue("screen", value); }
183+
}
177184

178185
private static SGame instance;
179186
public static SGame Instance { get { return instance; } }
@@ -183,6 +190,7 @@ public Buttons[] GetFrameReleasedButtons(PlayerIndex index)
183190
public SGame()
184191
{
185192
instance = this;
193+
FirstUpdate = true;
186194

187195
/*
188196
#if DEBUG
@@ -255,6 +263,11 @@ protected override void Update(GameTime gameTime)
255263
}
256264

257265
Events.GameEvents.InvokeUpdateTick();
266+
if (FirstUpdate)
267+
{
268+
GameEvents.InvokeFirstUpdateTick();
269+
FirstUpdate = false;
270+
}
258271

259272
if (CurrentUpdateTick % 2 == 0)
260273
Events.GameEvents.InvokeSecondUpdateTick();
@@ -278,7 +291,6 @@ protected override void Update(GameTime gameTime)
278291
if (CurrentUpdateTick >= 60)
279292
CurrentUpdateTick = 0;
280293

281-
282294
PreviouslyPressedKeys = CurrentlyPressedKeys;
283295
for(PlayerIndex i = PlayerIndex.One; i <= PlayerIndex.Four; i++)
284296
{

0 commit comments

Comments
 (0)