public override void Init() { ConsoleSys = Sys.Ref.ConsoleSys; try { Client = new Discord.Discord(670224014903345182, (ulong)CreateFlags.NoRequireDiscord); var activity = new Activity { State = "Playing", Details = "Playing the game", Timestamps = { Start = 0 }, Assets = { LargeImage = "logo" }, Instance = true, }; Client.GetActivityManager().UpdateActivity(activity, (result) => { if (result == Result.Ok) { ConsoleSys.Message("Updated Discord presence."); } else { ConsoleSys.Message("Could not update Discord presence."); } }); } catch (Exception Exception) { ConsoleSys.Error("Failed to init Discord"); ConsoleSys.Error(Exception.Message); } }
public override void Init() { ConsoleSys = Sys.Ref.ConsoleSys; if (!FilesystemUtil.GD.FileExists("res://Unary.Common/Locales/Locales.json")) { ConsoleSys.Error("Failed to find Locales.json, LocaleSys will likely crash everything"); return; } string LocalesManifest = FilesystemUtil.GD.FileRead("res://Unary.Common/Locales/Locales.json"); if (LocalesManifest == null) { ConsoleSys.Error("Failed to read Locales.json, LocaleSys will likely crash everything"); return; } try { LocaleList = JsonConvert.DeserializeObject <Dictionary <string, string> >(LocalesManifest); } catch (Exception Exception) { ConsoleSys.Error("Failed to parse Locales.json, LocaleSys will likely crash everything"); ConsoleSys.Error(Exception.Message); return; } SelectedLocaleEntries = new Dictionary <string, string>(); FallbackLocaleEntries = new Dictionary <string, string>(); SelectedLocale = Sys.Ref.Shared.GetObject <ConfigSys>().Shared.Get <string>("Unary.Common.Locale"); FallbackLocale = Sys.Ref.Shared.GetObject <ConfigSys>().Shared.Get <string>("Unary.Common.Locale.Fallback"); if (SelectedLocale == FallbackLocale) { SelectedIsFallback = true; } if (!LocaleList.ContainsKey(SelectedLocale)) { SelectedLocale = "en"; } if (!LocaleList.ContainsKey(FallbackLocale)) { FallbackLocale = "en"; } LoadLocale("Unary.Common", SelectedLocale, true); if (!SelectedIsFallback) { LoadLocale("Unary.Common", FallbackLocale, false); } }
private void LoadLocale(string ModID, string LocaleIndex, bool Selected) { string LocaleDir = "res://" + ModID + "/Locales/" + LocaleIndex; if (!FilesystemUtil.GD.DirExists(LocaleDir)) { ConsoleSys.Error("Failed to load locale at " + LocaleDir + " because folder does not exist"); return; } List <string> LocaleFiles = FilesystemUtil.GD.DirGetFiles(LocaleDir); for (int i = LocaleFiles.Count - 1; i >= 0; --i) { if (!LocaleFiles[i].EndsWith(".json")) { LocaleFiles.RemoveAt(i); } } for (int i = LocaleFiles.Count - 1; i >= 0; --i) { string LocaleManifest = FilesystemUtil.GD.FileRead(LocaleFiles[i]); try { Dictionary <string, string> LocaleEntries = JsonConvert.DeserializeObject <Dictionary <string, string> >(LocaleManifest); foreach (var Entry in LocaleEntries) { if (!ModIDUtil.Validate(Entry.Key)) { ConsoleSys.Error("Locale entry " + Entry.Key + " is not a valid ModIDEntry"); continue; } if (Selected) { SelectedLocaleEntries[Entry.Key] = Entry.Value; } else { FallbackLocaleEntries[Entry.Key] = Entry.Value; } } } catch (Exception Exception) { ConsoleSys.Error("Failed to parse locale manifest at " + LocaleFiles[i]); ConsoleSys.Error(Exception.Message); continue; } } }
private void Load(string ModID, string Path) { if (Entries.ContainsKey(ModID)) { ConsoleSys.Error(ModID + " binds are already loaded in the system"); return; } string FullPath = Path + '/' + "Binds.json"; if (!FilesystemUtil.Sys.FileExists(FullPath)) { ConsoleSys.Error("Tried loading binds at " + Path + " but file is not here"); return; } Binds NewBinds = new Binds(); NewBinds.Init(FullPath); Entries[ModID] = NewBinds; }