-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3.3: Big cleanup + ShitRimworldSays support
- Loading branch information
Sam Byass
committed
Feb 17, 2022
1 parent
d423139
commit 663832c
Showing
32 changed files
with
505 additions
and
251 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# RimworldBetterLoading | ||
# BetterLoading | ||
## A mod to make RimWorld loading screens look nice | ||
|
||
See the [steam workshop](https://steamcommunity.com/sharedfiles/filedetails/?id=1999454301) page for a full description. | ||
|
||
If you encounter issues, feel free to @ me on the Rimworld discord (my name there is `Samboy [BetterLoading]`) or DM me (Samboy#0063) - I do want to know of them, and will fix them ASAP. | ||
If you encounter issues, I would really appreciate knowing about them. You can reach me via several methods: | ||
- I have a [dedicated discord server](https://discord.gg/https://discord.gg/3d8xvnBJgX) for my code projects, including BetterLoading. | ||
- I'm in the [official RimWorld discord](https://discord.gg/rimworld) as `Samboy [BetterLoading]`, and you can mention me in the mod-general channel. | ||
- You can DM me (Samboy#0063) on discord, I accept random friend requests. | ||
- You can leave a comment on the steam workshop page (though these don't get checked quite as often) | ||
- You can open an issue here on github, which will send a message to my discord server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using Tomlet.Attributes; | ||
|
||
namespace BetterLoading; | ||
|
||
public class BetterLoadingConfig | ||
{ | ||
|
||
public static BetterLoadingConfig CreateDefault() | ||
{ | ||
return new() | ||
{ | ||
TipCache = new() | ||
{ | ||
Version = TipCacheConfig.SupportedVersion, | ||
} | ||
}; | ||
} | ||
|
||
[TomlPrecedingComment("The TipCache caches information about loading screen tips so that they can be displayed as soon as the loading screen starts after the first run.")] | ||
public TipCacheConfig TipCache; | ||
|
||
[TomlDoNotInlineObject] | ||
public class TipCacheConfig | ||
{ | ||
public static readonly int SupportedVersion = 1; | ||
|
||
[TomlPrecedingComment("The internal version number of the TipCache tip blob. If this number is different from the one expected by the mod, the TipCache will be cleared.")] | ||
public int Version; | ||
[TomlPrecedingComment("The raw tip blob. NOT intended to be manually edited.")] | ||
public byte[] Tips = Array.Empty<byte>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.IO; | ||
using Tomlet; | ||
using Tomlet.Exceptions; | ||
using Tomlet.Models; | ||
using Verse; | ||
|
||
namespace BetterLoading; | ||
|
||
/// <summary> | ||
/// This class exists because XML is the spawn of the devil and I refuse to use it for config files. | ||
/// </summary> | ||
public static class BetterLoadingConfigManager | ||
{ | ||
private static string _oldCachedLoadingTipsPath = Path.Combine(GenFilePaths.ConfigFolderPath, "BetterLoading_Cached_Tips"); | ||
public static string ConfigFilePath = Path.Combine(GenFilePaths.ConfigFolderPath, "BetterLoading.toml"); | ||
|
||
public static BetterLoadingConfig Config { get; private set; } = new(); | ||
|
||
static BetterLoadingConfigManager() | ||
{ | ||
//Register a byte array <=> base64 string converter | ||
TomletMain.RegisterMapper(bytes => new TomlString(Convert.ToBase64String(bytes ?? throw new NullReferenceException("Cannot serialize a null byte array"))), tomlValue => | ||
{ | ||
if (tomlValue is not TomlString tomlString) | ||
throw new TomlTypeMismatchException(typeof(TomlString), tomlValue.GetType(), typeof(byte[])); | ||
return Convert.FromBase64String(tomlString.Value); | ||
}); | ||
} | ||
|
||
public static void Load() | ||
{ | ||
if(File.Exists(_oldCachedLoadingTipsPath)) | ||
File.Delete(_oldCachedLoadingTipsPath); | ||
|
||
if (!File.Exists(ConfigFilePath)) | ||
{ | ||
Config = BetterLoadingConfig.CreateDefault(); | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
var doc = TomlParser.ParseFile(ConfigFilePath); | ||
Config = TomletMain.To<BetterLoadingConfig>(doc); | ||
LoadingScreenTipManager.TryReadCachedTipsFromConfig(); | ||
} | ||
catch (TomlException e) | ||
{ | ||
Log.Error($"[BetterLoading] {e.GetType()} thrown while parsing config file: {e.Message}. Config will be reset."); | ||
File.Delete(ConfigFilePath); | ||
Config = BetterLoadingConfig.CreateDefault(); | ||
} | ||
} | ||
|
||
public static void Save() | ||
{ | ||
var tomlString = TomletMain.TomlStringFrom(Config); | ||
File.WriteAllText(ConfigFilePath, tomlString); | ||
} | ||
} |
Oops, something went wrong.