-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteamWhisperer.cs
More file actions
99 lines (82 loc) · 2.44 KB
/
SteamWhisperer.cs
File metadata and controls
99 lines (82 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Godot;
using GodotSteam;
public partial class SteamWhisperer : Node
{
private const uint AppId = 3647600;
public static bool IsOverlayActive = false;
private static int placedNotes = 0;
public override void _EnterTree()
{
OS.SetEnvironment("SteamAppId", AppId.ToString());
OS.SetEnvironment("SteamGameId", AppId.ToString());
}
public override void _ExitTree()
{
if (!Steam.IsSteamRunning())
return;
Steam.StoreStats();
GD.Print("SW: Steam shut down.");
}
public override void _Ready()
{
if (!Steam.SteamInit(AppId, true))
{
GD.PrintErr(
"SW: here was an error initializing Steam. No Steam features will be available."
);
return;
}
GD.Print("SW: Steam initialized successfully.");
Steam.OverlayToggled += (active, _, _) =>
{
IsOverlayActive = active;
};
//Pull in stats
placedNotes = Steam.GetStatInt("NotesPlaced");
GD.Print($"SW: Placed notes: {placedNotes}");
//Uncomment this to reset your achievements/stats. There's no confirmation so...
//ResetAll();
}
//TODO: This might fail sometimes? IDK, need to look into it
public static bool PopAchievement(string id)
{
if (!Steam.IsSteamRunning())
{
return false;
}
if (Steam.SetAchievement(id) && Steam.StoreStats())
{
GD.Print($"SW: Unlocked {id}.");
return true;
}
GD.PrintErr($"SW: Failed to set achievement {id}.");
return false;
}
//Should make this more generic, but we only have one stat
public static bool IncrementNoteCount()
{
if (!Steam.IsSteamRunning())
{
return false;
}
placedNotes++;
if (Steam.SetStatInt("NotesPlaced", placedNotes) && Steam.StoreStats())
{
GD.Print($"SW: Incremented placed notes to {placedNotes}.");
return true;
}
GD.PrintErr($"SW: Failed to increment placed notes to {placedNotes}.");
return false;
}
//For Debugging purposes. Resets all stats/ achievements
private static void ResetAll()
{
if (!Steam.IsSteamRunning())
{
return;
}
Steam.ResetAllStats(true);
Steam.StoreStats();
GD.Print("SW: All stats reset.");
}
}