Adding Steam Rich Presence support. (#1453)

* Steam Rich Presence support. I opted to put this code inside of
DesktopLauncher.java instead of SNet.java because it heavily overlaps
with the work the DiscordRPC code was already doing.

Testing wasn't easy because I had to figure out how the Steam version
actually runs normally, but it was straightforward once I figured out
what version information to slam into the JAR and fixed 'desktop:steamtest' to work locally with my paths.

Because of how Steam currently expects SetRichPresence to be used, I had
to upload to the Steam partner site a trivial Rich Presence loc token
called 'steam_status_raw' that just gets entirely substituted for the
'steam_status' RP token string. I didn't expect that I'd need to do
anything for localization support (and instead just let it use English
for everyone like Discord) but apparently Steam isn't happy if you
directly set 'steam_display' to a raw string (but I'm going to look at
that when I'm back at work because I don't know that we need that
requirement.)

* Whoops, left this in there from debugging the Steam connection.

* Fixing coding style, and also triggering another CI build
This commit is contained in:
Daniel Jennings 2020-01-27 09:17:52 -08:00 committed by Anuken
parent 5ebc04ab29
commit d849a3a87f

View File

@ -243,36 +243,65 @@ public class DesktopLauncher extends ClientLauncher{
@Override
public void updateRPC(){
if(!useDiscord) return;
//if we're using neither discord nor steam, do no work
if(!useDiscord && !steam) return;
DiscordRichPresence presence = new DiscordRichPresence();
//common elements they each share
boolean inGame = !state.is(State.menu);
String gameMapWithWave = "Unknown Map";
String gameMode = "";
String gamePlayersSuffix = "";
String uiState = "";
if(!state.is(State.menu)){
String map = world.getMap() == null ? "Unknown Map" : world.isZone() ? world.getZone().localizedName : Strings.capitalize(world.getMap().name());
String mode = state.rules.pvp ? "PvP" : state.rules.attackMode ? "Attack" : "Survival";
String players = net.active() && playerGroup.size() > 1 ? " | " + playerGroup.size() + " Players" : "";
presence.state = mode + players;
if(!state.rules.waves){
presence.details = map;
}else{
presence.details = map + " | Wave " + state.wave;
presence.largeImageText = "Wave " + state.wave;
if(inGame){
if(world.getMap() != null){
gameMapWithWave = world.isZone() ? world.getZone().localizedName : Strings.capitalize(world.getMap().name());
}
if(state.rules.waves){
gameMapWithWave += " | Wave " + state.wave;
}
gameMode = state.rules.pvp ? "PvP" : state.rules.attackMode ? "Attack" : "Survival";
if(net.active() && playerGroup.size() > 1){
gamePlayersSuffix = " | " + playerGroup.size() + " Players";
}
}else{
if(ui.editor != null && ui.editor.isShown()){
presence.state = "In Editor";
uiState = "In Editor";
}else if(ui.deploy != null && ui.deploy.isShown()){
presence.state = "In Launch Selection";
uiState = "In Launch Selection";
}else{
presence.state = "In Menu";
uiState = "In Menu";
}
}
presence.largeImageKey = "logo";
if(useDiscord){
DiscordRichPresence presence = new DiscordRichPresence();
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
if(inGame){
presence.state = gameMode + gamePlayersSuffix;
presence.details = gameMapWithWave;
if(state.rules.waves){
presence.largeImageText = "Wave " + state.wave;
}
}else{
presence.state = uiState;
}
presence.largeImageKey = "logo";
DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
}
if(steam){
//Steam mostly just expects us to give it a nice string, but it apparently expects "steam_display" to always be a loc token, so I've uploaded this one which just passes through 'steam_status' raw.
SVars.net.friends.setRichPresence("steam_display", "#steam_status_raw");
if(inGame){
SVars.net.friends.setRichPresence("steam_status", gameMapWithWave);
}else{
SVars.net.friends.setRichPresence("steam_status", uiState);
}
}
}
@Override