Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuanglin committed Jun 18, 2024
1 parent cc31ba7 commit cebca2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
20 changes: 13 additions & 7 deletions Fika.Core/Coop/Utils/FikaBackendUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Fika.Core.Networking.Http;
using Fika.Core.Networking.Http.Models;
using System;
using System.Linq;
using System.Reflection;
using Fika.Core.EssentialPatches;

Expand Down Expand Up @@ -79,8 +78,9 @@ public static bool JoinMatch(string profileId, string serverId, out CreateMatch
public static void CreateMatch(string profileId, string hostUsername, RaidSettings raidSettings)
{
long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
var raidCode = GenerateRaidCode(6);
var body = new CreateMatch(raidCode, profileId, hostUsername, timestamp, raidSettings, HostExpectedNumberOfPlayers, raidSettings.Side, raidSettings.SelectedDateTime);
string raidCode = GenerateRaidCode(6);
CreateMatch body = new CreateMatch(raidCode, profileId, hostUsername, timestamp, raidSettings,
HostExpectedNumberOfPlayers, raidSettings.Side, raidSettings.SelectedDateTime);

FikaRequestHandler.RaidCreate(body);

Expand All @@ -92,10 +92,16 @@ public static void CreateMatch(string profileId, string hostUsername, RaidSettin

private static string GenerateRaidCode(int length)
{
var random = new Random();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
Random random = new Random();
char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
string raidCode = "";
for (int i = 0; i < length; i++)
{
int charIndex = random.Next(chars.Length);
raidCode += chars[charIndex];
}

return raidCode;
}
}
}
2 changes: 1 addition & 1 deletion Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private void SetupConfig()
AcceptedTOS = Config.Bind("Hidden", "Accepted TOS", false, new ConfigDescription("Has accepted TOS", tags: new ConfigurationManagerAttributes() { Browsable = false }));

// Advanced
OfficialVersion = Config.Bind("Advanced", "Official Version", false, new ConfigDescription("Show official version instead of fika version.", tags: new ConfigurationManagerAttributes() { IsAdvanced = true }));
OfficialVersion = Config.Bind("Advanced", "Official Version", false, new ConfigDescription("Show official version instead of Fika version.", tags: new ConfigurationManagerAttributes() { IsAdvanced = true }));

// Coop

Expand Down
5 changes: 2 additions & 3 deletions Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class FikaVersionLabel_Patch : ModulePatch
{
private static string versionLabel;

private static Traverse preloaderUiTraverse;

private static Traverse versionNumberTraverse;

private static string fikaVersion;
Expand All @@ -43,7 +41,7 @@ internal static void PatchPostfix(string major, object __result)

fikaVersion = Assembly.GetAssembly(typeof(FikaVersionLabel_Patch)).GetName().Version.ToString();

preloaderUiTraverse = Traverse.Create(MonoBehaviourSingleton<PreloaderUI>.Instance);
Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton<PreloaderUI>.Instance);

preloaderUiTraverse.Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}");

Expand All @@ -56,6 +54,7 @@ internal static void PatchPostfix(string major, object __result)

public static void UpdateVersionLabel()
{
Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton<PreloaderUI>.Instance);
if (FikaPlugin.OfficialVersion.Value)
{
preloaderUiTraverse.Field("string_2").SetValue($"{officalVersion} Beta version");
Expand Down

0 comments on commit cebca2a

Please sign in to comment.