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