Skip to content

Commit bc6f004

Browse files
Add support for Steam Achievements (#202)
* Add GodotSteam & GodotSteamC#Bindings These are slightly modified according to the changes outlined in LauraWebdev/GodotSteam_CSharpBindings#43 * Initial Steam achievements! Added achievement for tutorial and boss 1 * Pause on Steam Overlay Open Ignore controller input Open pause menu in necessary scenes * Add support for emptyPockets & vampire achievements * Add Money and Notes Placed support Finishes steam integration for now --------- Co-authored-by: LifeHckr <jarodthereal@gmail.com>
1 parent f40dfeb commit bc6f004

File tree

257 files changed

+14868
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+14868
-8
lines changed

Globals/StageProducer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System;
21
using System.Threading.Tasks;
32
using FunkEngine;
4-
using FunkEngine.Classes.MidiMaestro;
53
using Godot;
4+
using GodotSteam;
65

76
/**
87
* <summary>StageProducer: Handles scene transitions and persistent gameplay data.</summary>
@@ -240,7 +239,7 @@ public override void _Input(InputEvent @event)
240239
{
241240
//Consume controller input, if window out of focus.
242241
//This handles ui_input, other scenes need to consume their own.
243-
if (!GetWindow().HasFocus())
242+
if (ControlSettings.IsOutOfFocus(this))
244243
{
245244
GetViewport().SetInputAsHandled();
246245
return;

Globals/SteamWhisperer.cs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
}

Globals/SteamWhisperer.cs.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bt4f7m5qx106a

Scenes/BattleDirector/Scripts/BattleDirector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ public class NoteHitArgs(BattleDirector bd, Note note, Timing timing) : BattleEv
558558

559559
public void InvokeNotePlaced(ArrowData data)
560560
{
561+
SteamWhisperer.IncrementNoteCount();
561562
NotePlaced?.Invoke(new NoteEventArgs(_curDirector, data));
562563
}
563564

Scenes/Maps/Scripts/Cartographer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ private void WinArea()
174174
return;
175175
}
176176

177+
//Achievement code for emptyPockets
178+
if (StageProducer.PlayerStats.CurRelics.Length == 0)
179+
{
180+
SteamWhisperer.PopAchievement("emptyPockets");
181+
}
182+
177183
EndScreen es = GD.Load<PackedScene>(EndScreen.LoadPath).Instantiate<EndScreen>();
178184
AddChild(es);
179185
es.TopLabel.Text = Tr("BATTLE_ROOM_WIN");

Scenes/Puppets/Enemies/BossBlood/P_BossBlood.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ public override void _Ready()
3131
eff.Owner.Heal(val);
3232
}
3333
),
34+
new EnemyEffect(
35+
this,
36+
BattleEffectTrigger.OnDamageInstance,
37+
1,
38+
(e, eff, val) =>
39+
{
40+
if (e is not BattleDirector.Harbinger.OnDamageInstanceArgs dArgs)
41+
return;
42+
if (
43+
dArgs.Dmg.Target == this
44+
&& dArgs.Dmg.Target.GetCurrentHealth() <= dArgs.Dmg.Damage
45+
)
46+
{
47+
SteamWhisperer.PopAchievement("actOneComp");
48+
}
49+
}
50+
),
3451
};
3552
}
3653
}

Scenes/Puppets/Enemies/Strawman/P_Strawman.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public override void _Ready()
102102
)
103103
{
104104
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.FirstTime, false);
105+
SteamWhisperer.PopAchievement("tutorial");
105106
}
106107
}
107108
),

Scenes/Puppets/Scripts/PlayerStats.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public void AddRelic(RelicTemplate relic)
4444

4545
public void AddNote(Note nSelection)
4646
{
47+
//If the note is vampire, check to see if we already have 2 of them
48+
if (
49+
nSelection.Name == "PlayerVampire"
50+
&& CurNotes.Count(note => note.Name == "PlayerVampire") >= 2
51+
)
52+
{
53+
SteamWhisperer.PopAchievement("vampire");
54+
}
55+
4756
CurNotes = CurNotes.Append(nSelection).ToArray();
4857
}
4958
}

Scenes/UI/Options/Scripts/HowToPlay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void DoTutorial()
5252

5353
public override void _Input(InputEvent @event)
5454
{
55-
if (!GetWindow().HasFocus())
55+
if (ControlSettings.IsOutOfFocus(this))
5656
{
5757
GetViewport().SetInputAsHandled();
5858
return;

Scenes/UI/Options/Scripts/OptionsMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public override void _Ready()
5050

5151
public override void _Input(InputEvent @event)
5252
{
53-
if (!GetWindow().HasFocus())
53+
if (ControlSettings.IsOutOfFocus(this))
5454
{
5555
GetViewport().SetInputAsHandled();
5656
return;

0 commit comments

Comments
 (0)