time for a crusade against dialogs
This commit is contained in:
@@ -19,6 +19,7 @@ import io.anuke.mindustry.core.GameState.*;
|
||||
import io.anuke.mindustry.desktop.steam.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.maps.Map;
|
||||
import io.anuke.mindustry.net.*;
|
||||
import io.anuke.mindustry.net.Net.*;
|
||||
|
||||
@@ -29,10 +30,9 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
|
||||
public class DesktopLauncher extends ClientLauncher{
|
||||
private final static String applicationId = "610508934456934412";
|
||||
public final static String discordID = "610508934456934412";
|
||||
|
||||
boolean useDiscord = OS.is64Bit, showConsole = true;
|
||||
SteamCoreNetImpl steamCore;
|
||||
|
||||
public static void main(String[] arg){
|
||||
try{
|
||||
@@ -58,7 +58,7 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
if(useDiscord){
|
||||
try{
|
||||
DiscordEventHandlers handlers = new DiscordEventHandlers();
|
||||
DiscordRPC.INSTANCE.Discord_Initialize(applicationId, handlers, true, "1127400");
|
||||
DiscordRPC.INSTANCE.Discord_Initialize(discordID, handlers, true, "1127400");
|
||||
Log.info("Initialized Discord rich presence.");
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DiscordRPC.INSTANCE::Discord_Shutdown));
|
||||
@@ -111,21 +111,8 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
Log.err("Steam client not running.");
|
||||
}else{
|
||||
Vars.steam = true;
|
||||
steamCore = new SteamCoreNetImpl(new ArcNetImpl());
|
||||
Events.on(ClientLoadEvent.class, event -> {
|
||||
Core.settings.defaults("name", steamCore.friends.getPersonaName());
|
||||
//update callbacks
|
||||
Core.app.addListener(new ApplicationListener(){
|
||||
@Override
|
||||
public void update(){
|
||||
if(SteamAPI.isSteamRunning()){
|
||||
SteamAPI.runCallbacks();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
//steam shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(SteamAPI::shutdown));
|
||||
initSteam();
|
||||
|
||||
}
|
||||
}catch(Exception e){
|
||||
Log.err("Failed to load Steam native libraries.");
|
||||
@@ -134,6 +121,27 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
}
|
||||
}
|
||||
|
||||
void initSteam(){
|
||||
SVars.net = new SNet(new ArcNetImpl());
|
||||
SVars.stats = new SStats();
|
||||
SVars.workshop = new SWorkshop();
|
||||
|
||||
Events.on(ClientLoadEvent.class, event -> {
|
||||
Core.settings.defaults("name", SVars.net.friends.getPersonaName());
|
||||
//update callbacks
|
||||
Core.app.addListener(new ApplicationListener(){
|
||||
@Override
|
||||
public void update(){
|
||||
if(SteamAPI.isSteamRunning()){
|
||||
SteamAPI.runCallbacks();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
//steam shutdown hook
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(SteamAPI::shutdown));
|
||||
}
|
||||
|
||||
static void handleCrash(Throwable e){
|
||||
Consumer<Runnable> dialog = Runnable::run;
|
||||
boolean badGPU = false;
|
||||
@@ -159,12 +167,22 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
|
||||
@Override
|
||||
public NetProvider getNet(){
|
||||
return steam ? steamCore : new ArcNetImpl();
|
||||
return steam ? SVars.net : new ArcNetImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishMap(Map map){
|
||||
SVars.workshop.publishMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inviteFriends(){
|
||||
SVars.net.showFriendInvites();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLobby(){
|
||||
steamCore.updateLobby();
|
||||
SVars.net.updateLobby();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.anuke.mindustry.desktop.steam;
|
||||
|
||||
import io.anuke.arc.function.*;
|
||||
|
||||
public enum SAchievement{
|
||||
;
|
||||
|
||||
private final BooleanProvider completed;
|
||||
|
||||
public static final SAchievement[] all = values();
|
||||
|
||||
SAchievement(BooleanProvider completed){
|
||||
this.completed = completed;
|
||||
}
|
||||
|
||||
/** Creates an achievement that is triggered when this stat reaches a number.*/
|
||||
SAchievement(SStat stat, int required){
|
||||
this(() -> stat.get() >= required);
|
||||
}
|
||||
|
||||
public void checkCompletion(){
|
||||
if(!achieved() && conditionsMet()){
|
||||
SVars.stats.stats.setAchievement(name());
|
||||
SVars.stats.stats.storeStats();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean achieved(){
|
||||
return SVars.stats.stats.isAchieved(name(), false);
|
||||
}
|
||||
|
||||
public boolean conditionsMet(){
|
||||
return completed.get();
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import java.util.concurrent.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class SteamCoreNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, NetProvider{
|
||||
public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, NetProvider{
|
||||
public final SteamNetworking snet = new SteamNetworking(this);
|
||||
public final SteamMatchmaking smat = new SteamMatchmaking(this);
|
||||
public final SteamFriends friends = new SteamFriends(this);
|
||||
@@ -43,7 +43,7 @@ public class SteamCoreNetImpl implements SteamNetworkingCallback, SteamMatchmaki
|
||||
Consumer<Host> lobbyCallback;
|
||||
Runnable lobbyDoneCallback, joinCallback;
|
||||
|
||||
public SteamCoreNetImpl(NetProvider provider){
|
||||
public SNet(NetProvider provider){
|
||||
this.provider = provider;
|
||||
|
||||
Events.on(ClientLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){
|
||||
@@ -324,7 +324,11 @@ public class SteamCoreNetImpl implements SteamNetworkingCallback, SteamMatchmaki
|
||||
smat.setLobbyData(steamID, "versionType", Version.type);
|
||||
smat.setLobbyData(steamID, "wave", state.wave + "");
|
||||
smat.setLobbyData(steamID, "gamemode", Gamemode.bestFit(state.rules) + "");
|
||||
}
|
||||
}
|
||||
|
||||
public void showFriendInvites(){
|
||||
if(currentLobby != null){
|
||||
friends.activateGameOverlayInviteDialog(currentLobby);
|
||||
Log.info("Activating overlay dialog");
|
||||
}
|
||||
22
desktop/src/io/anuke/mindustry/desktop/steam/SStat.java
Normal file
22
desktop/src/io/anuke/mindustry/desktop/steam/SStat.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package io.anuke.mindustry.desktop.steam;
|
||||
|
||||
public enum SStat{
|
||||
unitsDestroyed;
|
||||
|
||||
public int get(){
|
||||
return SVars.stats.stats.getStatI(name(), 0);
|
||||
}
|
||||
|
||||
public void add(int amount){
|
||||
SVars.stats.stats.setStatI(name(), get() + amount);
|
||||
SVars.stats.onUpdate();
|
||||
|
||||
for(SAchievement a : SAchievement.all){
|
||||
a.checkCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(){
|
||||
add(1);
|
||||
}
|
||||
}
|
||||
67
desktop/src/io/anuke/mindustry/desktop/steam/SStats.java
Normal file
67
desktop/src/io/anuke/mindustry/desktop/steam/SStats.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package io.anuke.mindustry.desktop.steam;
|
||||
|
||||
import com.codedisaster.steamworks.*;
|
||||
import io.anuke.arc.util.*;
|
||||
|
||||
public class SStats implements SteamUserStatsCallback{
|
||||
public final SteamUserStats stats = new SteamUserStats(this);
|
||||
|
||||
//todo store stats periodically
|
||||
private boolean updated = false;
|
||||
|
||||
public SStats(){
|
||||
stats.requestCurrentStats();
|
||||
}
|
||||
|
||||
public void onUpdate(){
|
||||
this.updated = true;
|
||||
}
|
||||
|
||||
private void registerEvents(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserStatsReceived(long gameID, SteamID steamID, SteamResult result){
|
||||
if(result == SteamResult.OK){
|
||||
registerEvents();
|
||||
}else{
|
||||
Log.err("Failed to recieve steam stats: {0}", result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserStatsStored(long l, SteamResult steamResult){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserStatsUnloaded(SteamID steamID){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserAchievementStored(long l, boolean b, String s, int i, int i1){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeaderboardFindResult(SteamLeaderboardHandle steamLeaderboardHandle, boolean b){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeaderboardScoresDownloaded(SteamLeaderboardHandle steamLeaderboardHandle, SteamLeaderboardEntriesHandle steamLeaderboardEntriesHandle, int i){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeaderboardScoreUploaded(boolean b, SteamLeaderboardHandle steamLeaderboardHandle, int i, boolean b1, int i1, int i2){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGlobalStatsReceived(long l, SteamResult steamResult){
|
||||
|
||||
}
|
||||
}
|
||||
9
desktop/src/io/anuke/mindustry/desktop/steam/SVars.java
Normal file
9
desktop/src/io/anuke/mindustry/desktop/steam/SVars.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package io.anuke.mindustry.desktop.steam;
|
||||
|
||||
public class SVars{
|
||||
public final static int steamID = 1127400;
|
||||
|
||||
public static SNet net;
|
||||
public static SStats stats;
|
||||
public static SWorkshop workshop;
|
||||
}
|
||||
@@ -4,16 +4,15 @@ import com.codedisaster.steamworks.*;
|
||||
import com.codedisaster.steamworks.SteamRemoteStorage.*;
|
||||
import io.anuke.mindustry.maps.*;
|
||||
|
||||
public class WorkshopImpl implements SteamUGCCallback{
|
||||
private SteamUGC ugc = new SteamUGC(this);
|
||||
public class SWorkshop implements SteamUGCCallback{
|
||||
public final SteamUGC ugc = new SteamUGC(this);
|
||||
|
||||
public void publishMap(Map map){
|
||||
ugc.createItem(1127400, WorkshopFileType.GameManagedItem);
|
||||
ugc.createItem(SVars.steamID, WorkshopFileType.GameManagedItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUGCQueryCompleted(SteamUGCQuery query, int numResultsReturned, int totalMatchingResults, boolean isCachedData, SteamResult result){
|
||||
//ugc.submitItemUpdate()
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +34,12 @@ public class WorkshopImpl implements SteamUGCCallback{
|
||||
@Override
|
||||
public void onCreateItem(SteamPublishedFileID publishedFileID, boolean needsToAcceptWLA, SteamResult result){
|
||||
//TODO
|
||||
if(result == SteamResult.OK){
|
||||
|
||||
}else{
|
||||
//TODO show "failed to create" dialog
|
||||
//ui.showError("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user