Browse Source

Improve popup and add lobby list command

tags/v1.1.0
NGnius (Graham) 4 years ago
parent
commit
c292f4e4a8
3 changed files with 60 additions and 20 deletions
  1. +1
    -0
      GameSDKcraft/CallbackUtility.cs
  2. +1
    -5
      GameSDKcraft/GameSDKcraft.csproj
  3. +58
    -15
      GameSDKcraft/Plugin.cs

+ 1
- 0
GameSDKcraft/CallbackUtility.cs View File

@@ -96,6 +96,7 @@ namespace GamecraftRPC
Discord.LobbyManager lm = Plugin.DiscordRPC.GetLobbyManager();
Discord.LobbyTransaction lt = lm.GetLobbyCreateTransaction();
lt.SetMetadata("steamid", PresenceUtility.SteamId.ToString());
lt.SetMetadata("name", Steamworks.SteamClient.Name);
lt.SetType(Discord.LobbyType.Public);
lt.SetCapacity(2);
lm.CreateLobby(lt, SyncActivityLobby);


+ 1
- 5
GameSDKcraft/GameSDKcraft.csproj View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.0.1</Version>
<Version>1.1.0</Version>
<Authors>Me</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/???/???</PackageProjectUrl>
@@ -72,10 +72,6 @@
<HintPath>..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\Blocks.HUDFeedbackBlocks.dll</HintPath>
</Reference>
<Reference Include="ClusterToWireConversion.Mock">
<HintPath>..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\ClusterToWireConversion.Mock.dll</HintPath>
</Reference>
<Reference Include="CommandLine">
<HintPath>..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath>
<HintPath>..\..\ref\Gamecraft_Data\Managed\CommandLine.dll</HintPath>


+ 58
- 15
GameSDKcraft/Plugin.cs View File

@@ -1,5 +1,7 @@
using System;
using System.IO;
using System.Reflection;
using System.Text;
//using Microsoft.Win32;

using IllusionPlugin;
@@ -94,6 +96,8 @@ namespace GamecraftRPC
Client.EnterMenu += CallbackUtility.MenuEnter;

GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Engines.PlayerCountEngine());
Client client = new Client();

CommandBuilder.Builder()
.Name("JoinDiscord")
@@ -136,7 +140,6 @@ namespace GamecraftRPC
if (DiscordRPC != null)
{
Game game = Game.CurrentGame();
Client client = new Client();
GamecraftModdingAPI.Utility.Logging.CommandLog($"Gamecraft {client.Version}\nUnity {client.UnityVersion}\n{PluginInfo()}\nSDK {DiscordRPC.ToString()}\nGame {game.Name}");
}
else
@@ -174,25 +177,65 @@ namespace GamecraftRPC
}
})
.Build();
#if !RELEASE
bool alreadyWarned = false;

CommandBuilder.Builder()
.Name("ListDiscordLobbies")
.Description($"View a list of public multiplayer lobbies available through {Name}")
.Action(() =>
{
LobbySearchQuery query = lm.GetSearchQuery();
query.Sort("slots", LobbySearchCast.Number, "999");
query.Limit(100);
lm.Search(query, result =>
{
if (result == Result.Ok)
{
StringBuilder sb = new StringBuilder("~ Lobby List [ID | Username (players/max)] ~\n");
int lobbyCount = lm.LobbyCount();
for (int i = 0; i < lobbyCount; i++)
{
long id = lm.GetLobbyId(i);
Lobby lobby = lm.GetLobby(id);
sb.AppendFormat("{3} | {0} ({1}/{2})\n", lm.GetLobbyMetadataValue(id, "name"),
lm.MemberCount(id), lobby.Capacity.ToString(), lm.GetLobbyMetadataValue(id, "steamid"));
}
GamecraftModdingAPI.Utility.Logging.CommandLog(sb.ToString().TrimEnd());
}
});
})
.Build();

string popupFileName = "." + Name + "_startuppopup";
bool alreadyWarned = File.Exists(popupFileName);
Client.EnterMenu += (_, args) =>
{
if (alreadyWarned) return;
//GamecraftModdingAPI.Utility.Logging.LogDebug($"Displaying {Name} {Version} DEBUG warning");
/*
RobocraftX.Services.ErrorBuilder.DisplayCustomError(
$"THIS IS NOT ACTUALLY AN ERROR! {Name} v{Version} is a pre-release. If you encounter a bug or other issue, please report it to NGnius or Exmods on Discord.",
"Discord", () => { UnityEngine.Application.OpenURL("https://discord.exmods.org"); },
"Ok!", () => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Dismissed {Name} {Version} DEBUG warning"); }
);
*/
RobocraftX.Services.ErrorBuilder.DisplayWarning($"{Name} v{Version} is a pre-release. If you encounter a bug or other issue, please report it to NGnius or Exmods on Discord.");
alreadyWarned = true;
};
client.PromptUser(new DualChoicePrompt(
#if !RELEASE
$"Version {Version} of {Name} is a pre-release. If you encounter a bug or other issue, please report it on the Exmods Discord.",
#else
$"Congrats, you've installed the {Name} mod! If you encounter a bug or other issue, please report it on the Exmods Discord.",
#endif

GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up");
Name,
"Discord",
() =>
{
if (DiscordRPC == null)
{
UnityEngine.Application.OpenURL("https://discord.exmods.org");
}
else
{
DiscordRPC.GetOverlayManager().OpenGuildInvite("2CtWzZT", result => { GamecraftModdingAPI.Utility.Logging.MetaLog($"Open Discord server invite through GameSDK {result}"); });
}
File.WriteAllText(popupFileName, Version);
},
"Ok",
() => { File.WriteAllText(popupFileName, Version); }));
};

GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up");
}

public void OnFixedUpdate() { } // called once per physics update


Loading…
Cancel
Save