using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework.Reflection;
using StardewValley;
using StardewValley.BellsAndWhistles;
using StardewValley.Locations;
using StardewValley.Menus;
using StardewValley.Tools;
using xTile.Dimensions;
using xTile.Layers;
using SFarmer = StardewValley.Farmer;
namespace StardewModdingAPI.Framework
{
/// <summary>SMAPI's extension of the game's core <see cref="Game1"/>, used to inject events.</summary>
internal class SGame : Game1
{
/*********
** Properties
*********/
/****
** SMAPI state
****/
/// <summary>The number of ticks until SMAPI should notify mods that the game has loaded.</summary>
/// <remarks>Skipping a few frames ensures the game finishes initialising the world before mods try to change it.</remarks>
private int AfterLoadTimer = 5;
/// <summary>Whether the player has loaded a save and the world has finished initialising.</summary>
private bool IsWorldReady => this.AfterLoadTimer < 0;
/// <summary>Whether the game is returning to the menu.</summary>
private bool IsExiting;
/// <summary>Whether the game's zoom level is at 100% (i.e. nothing should be scaled).</summary>
public bool ZoomLevelIsOne => Game1.options.zoomLevel.Equals(1.0f);
/// <summary>Encapsulates monitoring and logging.</summary>
private readonly IMonitor Monitor;
/****
** Private wrappers
****/
// ReSharper disable ArrangeStaticMemberQualifier, ArrangeThisQualifier, InconsistentNaming
/// <summary>Used to access private fields and methods.</summary>
private static readonly IReflectionHelper Reflection = new ReflectionHelper();
private static List<float> _fpsList => SGame.Reflection.GetPrivateField<List<float>>(typeof(Game1), nameof(_fpsList)).GetValue();
private static Stopwatch _fpsStopwatch => SGame.Reflection.GetPrivateField<Stopwatch>(typeof(Game1), nameof(SGame._fpsStopwatch)).GetValue();
private static float _fps
{
set { SGame.Reflection.GetPrivateField<float>(typeof(Game1), nameof(_fps)).SetValue(