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;
/****
** Game state
****/
/// <summary>Arrays of pressed controller buttons indexed by <see cref="PlayerIndex"/>.</summary>
private readonly Buttons[][] PreviouslyPressedButtons = { new Buttons[0], new Buttons[0], new Buttons[0], new Buttons[0] };
/// <summary>A record of the keyboard state (i.e. the up/down state for each button) as of the latest tick.</summary>
private KeyboardState KStateNow;
/// <summary>A record of the keyboard state (i.e. the up/down state for each button) as of the previous tick.</summary>
private KeyboardState KStatePrior;
/// <summary>A record of the mouse state (i.e. the cursor position, scroll amount, and the up/down state for each button) as of the latest tick.</summary>
private MouseState MStateNow;
/// <summary>A record of the mouse state (i.e. the cursor position, scroll amount, and the up/down state for each button) as of the previous tick.</summary>
private MouseState MStatePrior;
/// <summary>The current mouse position on the screen adjusted for the zoom level.</summary>
private Point MPositionNow;
/// <summary>The previous mouse position on the screen adjusted for the zoom level.</summary>
private Point MPositionPrior;