Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustdustinthewind committed Nov 30, 2019
2 parents d0bd76a + e0c226e commit a29cac3
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 38 deletions.
18 changes: 18 additions & 0 deletions Pulsarc/Pulsarc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Pulsarc.UI;
using Pulsarc.UI.Screens;
using Pulsarc.UI.Screens.Gameplay;
using Pulsarc.UI.Screens.MainMenu;
using Pulsarc.UI.Screens.SongSelect;
Expand Down Expand Up @@ -107,6 +108,8 @@ internal class PulsarcGame : Game
// Map Converting Flag
private bool converting = false;

private PulsarcScreen lastScreen = null;

public PulsarcGame()
{
// Set up stored Data access
Expand Down Expand Up @@ -219,8 +222,12 @@ protected override void UnloadContent()
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
Thread.Yield();

PulsarcTime.Update();

CheckDiscord();

cursor.SetPos(MouseManager.CurrentState.Position);

// Temporary measure for converting intralism or osu!mania beatmaps
Expand Down Expand Up @@ -255,6 +262,17 @@ protected override void Update(GameTime gameTime)
base.Update(gameTime);
}

private void CheckDiscord()
{
if (ScreenManager.Screens.Peek() != lastScreen)
{
PulsarcScreen currentScreen = (PulsarcScreen)ScreenManager.Screens.Peek();
lastScreen = currentScreen;

currentScreen.UpdateDiscord();
}
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
Expand Down
16 changes: 7 additions & 9 deletions Pulsarc/UI/Screens/Gameplay/GameplayEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ public class GameplayEngine : PulsarcScreen
// Time distance (in ms) from which hitobjects are neither updated not drawn
public int IgnoreTime { get; private set; } = 500;

public override string DiscordDetails => $"Playing Singleplayer";

public override string DiscordState => CurrentBeatmap.Title;

//public override int DiscordTimer => CurrentBeatmap.Arcs[CurrentBeatmap.Arcs.Count -1].Time;
public override bool DiscordTimer => true;

/// <summary>
/// The engine that handles the gameplay of Pulsarc.
/// </summary>
Expand Down Expand Up @@ -313,6 +306,7 @@ private void StartGameplay()
{
AudioManager.StartGamePlayer();


GameplayEngine.Active = true;
Pulsarc.DisplayCursor = false;
}
Expand All @@ -323,8 +317,6 @@ private void StartGameplay()
/// <param name="gameTime">The current GameTime</param>
public override void Update(GameTime gameTime)
{
base.Update(gameTime);

// If not active, don't update.
if (!Active)
return;
Expand Down Expand Up @@ -656,12 +648,18 @@ public void EndGameplay(bool save = false)
ResultScreen next = new ResultScreen(Judgements, errors, scoreDisplay, maxCombo, Rate, 0, CurrentBeatmap, Background, !AutoPlay && save);
Pulsarc.DisplayCursor = true;
Reset();

// Switch to results screen
ScreenManager.RemoveScreen(true);
ScreenManager.AddScreen(next);

// TODO: restart GC when out of gameplay
GC.Collect();
}

public override void UpdateDiscord()
{
PulsarcDiscord.SetStatus("Playing Singleplayer", CurrentBeatmap.Title);
}
}
}
3 changes: 3 additions & 0 deletions Pulsarc/UI/Screens/InProgressScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public InProgressScreen()
{
View = new InProgressScreenView(this);
}

public override void Init()
{
ScreenManager.RemoveScreen();
}

public override void UpdateDiscord() { }
}
}
19 changes: 17 additions & 2 deletions Pulsarc/UI/Screens/MainMenu/Menu.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
using Wobble.Screens;
using Microsoft.Xna.Framework;
using Pulsarc.Utils;
using Wobble.Screens;

namespace Pulsarc.UI.Screens.MainMenu
{
class Menu : PulsarcScreen
{
public override ScreenView View { get; protected set; }

private const string DISCORD_DETAILS = "In the menus";

public Menu()
{
View = new MenuView(this);
DiscordDetails = "In the menus";
PulsarcDiscord.SetStatus("", DISCORD_DETAILS);
}

public override void Update(GameTime gameTime)
{
View?.Update(gameTime);
}

public override void UpdateDiscord()
{
if (PulsarcDiscord.Presence.Details != DISCORD_DETAILS)
PulsarcDiscord.SetStatus("", DISCORD_DETAILS);
}
}
}
12 changes: 1 addition & 11 deletions Pulsarc/UI/Screens/PulsarcScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,11 @@ public abstract class PulsarcScreen : Screen
{
public bool Initialized { get; protected set; } = false;

public virtual string DiscordDetails { get; protected set; } = "";
public virtual string DiscordState { get; protected set; } = "";
public virtual bool DiscordTimer => false;

public virtual void Init()
{
Initialized = true;
}

public override void Update(GameTime gameTime)
{
base.Update(gameTime);

if (PulsarcDiscord.Presence.Details != DiscordDetails || PulsarcDiscord.Presence.State != DiscordState)
PulsarcDiscord.SetStatus(DiscordDetails, DiscordState, DiscordTimer);
}
public abstract void UpdateDiscord();
}
}
2 changes: 2 additions & 0 deletions Pulsarc/UI/Screens/Quit/QuitScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public override void Init()
Pulsarc.Exit();
Environment.Exit(0);
}

public override void UpdateDiscord() { }
}
}
20 changes: 15 additions & 5 deletions Pulsarc/UI/Screens/Result/ResultScreen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Pulsarc.Beatmaps;
using Microsoft.Xna.Framework;
using Pulsarc.Beatmaps;
using Pulsarc.UI.Common;
using Pulsarc.UI.Screens.Gameplay;
using Pulsarc.Utils;
Expand Down Expand Up @@ -34,6 +35,8 @@ class ResultScreen : PulsarcScreen
// Whether or not a full combo was achieved.
public bool FullCombo { get; private set; }

private ScoreData scoreData;

/// <summary>
/// The screen that summarizes the last play.
/// </summary>
Expand Down Expand Up @@ -71,17 +74,24 @@ public ResultScreen(List<JudgementValue> judgements, List<KeyValuePair<double, i
FullCombo = JudgesCount["miss"] == 0;

// Determine the grade achieved.
ScoreData scoreData = new ScoreData(Beatmap.GetHash(), Config.GetString("Profile","Username"), rate, mods, DisplayScore, (float)accuracyTotal, Combo, "D", JudgesCount["max"], JudgesCount["perfect"], JudgesCount["great"], JudgesCount["good"], JudgesCount["bad"], JudgesCount["miss"]);
scoreData = new ScoreData(Beatmap.GetHash(), Config.GetString("Profile","Username"), rate, mods, DisplayScore, (float)accuracyTotal, Combo, "D", JudgesCount["max"], JudgesCount["perfect"], JudgesCount["great"], JudgesCount["good"], JudgesCount["bad"], JudgesCount["miss"]);
scoreData.grade = Scoring.GetGrade(scoreData);

// Save the score locally
if (newScore)
DataManager.ScoreDB.AddScore(scoreData);

DiscordDetails = $"Finished {beatmap.Title}";
DiscordState = $"Grade: {scoreData.grade} | Score: {scoreData.score} | Acc = {Math.Round(accuracyTotal * 100, 2)}%";

View = new ResultScreenView(this, accuracyTotal, scoreData.grade, Beatmap, mapBackground);
}

public override void UpdateDiscord()
{
string details = $"Finished {Beatmap.Title}";
string state = $"Grade: {scoreData.grade} | Score: {scoreData.score} | Acc = {Math.Round(scoreData.accuracy * 100, 2)}%";

Console.WriteLine(details + "\n" + state);

PulsarcDiscord.SetStatus(details, state);
}
}
}
6 changes: 2 additions & 4 deletions Pulsarc/UI/Screens/Settings/SettingsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ public override void Init()
{
base.Init();

DiscordDetails = "In the menus";

View = new SettingsScreenView(this);
}

public override void Update(GameTime gameTime)
{
base.Update(gameTime);

handleMouseInput();

View?.Update(gameTime);
Expand All @@ -50,5 +46,7 @@ private void handleMouseInput()

changeFocus(ms);
}

public override void UpdateDiscord() { }
}
}
5 changes: 4 additions & 1 deletion Pulsarc/UI/Screens/Settings/UI/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public virtual void Save(string category, string key)
Config.SetDouble(category, key,(double) GetSaveValue());
break;
case "bool":
Config.SetBool(category, key,(bool) GetSaveValue());
Config.SetBool(category, key, (bool)GetSaveValue());
break;
case "string":
Config.SetString(category, key, (string)GetSaveValue());
break;
default:
Console.WriteLine("Cannot save type " + Type.ToString() + " in category "+category+" for setting "+key);
Expand Down
10 changes: 6 additions & 4 deletions Pulsarc/UI/Screens/SongSelect/SongSelection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Pulsarc.Beatmaps;
using Pulsarc.UI.Screens.Gameplay;
using Pulsarc.UI.Screens.SongSelect.UI;
using Pulsarc.Utils;
using Pulsarc.Utils.Input;
Expand Down Expand Up @@ -34,8 +35,6 @@ public override void Init()
{
base.Init();

DiscordDetails = "Browsing Maps";

RefreshBeatmaps();
}

Expand Down Expand Up @@ -113,14 +112,17 @@ public List<Beatmap> SortBeatmaps(List<Beatmap> beatmaps, string sort, bool asce

public override void Update(GameTime gameTime)
{
base.Update(gameTime);

HandleKeyboardPresses();
HandleMouseInput();

View?.Update(gameTime);
}

public override void UpdateDiscord()
{
PulsarcDiscord.SetStatus("", "Browsing Maps");
}

private void HandleKeyboardPresses()
{
while (InputManager.KeyboardPresses.Count > 0)
Expand Down
7 changes: 5 additions & 2 deletions Pulsarc/Utils/AssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ public static void Initialize(ContentManager content)

public static Texture2D Load(string path)
{
if (StoredTexture.ContainsKey(path) && StoredTexture[path].Value + textureExpireTimeMs > PulsarcTime.CurrentElapsedTime)
return StoredTexture[path].Key;
if (StoredTexture.ContainsKey(path))
if (StoredTexture[path].Value + textureExpireTimeMs > PulsarcTime.CurrentElapsedTime)
return StoredTexture[path].Key;
else
StoredTexture.Remove(path);

Texture2D newTexture = null;

Expand Down
1 change: 1 addition & 0 deletions Pulsarc/Utils/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static public void InputUpdater()

while (running)
{
Thread.Yield();
if (threadLimiterWatch.ElapsedMilliseconds >= 1)
{
threadLimiterWatch.Restart();
Expand Down

0 comments on commit a29cac3

Please sign in to comment.