Skip to content

Commit

Permalink
3.3: Big cleanup + ShitRimworldSays support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Byass committed Feb 17, 2022
1 parent d423139 commit 663832c
Show file tree
Hide file tree
Showing 32 changed files with 505 additions and 251 deletions.
Binary file modified 1.3/Assemblies/BetterLoading.dll
Binary file not shown.
Binary file added 1.3/Assemblies/Tomlet.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>BetterLoading</name>
<author>Samboy063</author>
<packageId>me.samboycoding.betterloading.dev</packageId>
<url></url>
<url>https://github.com/SamboyCoding/RimworldBetterLoading</url>
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>BetterLoading</identifier>
<version>3.2.0.1</version>
<version>3.3.0.0</version>
<loadBefore>
<li>Core &gt;= 1.0</li>
<li>Startupimpact</li>
Expand Down
10 changes: 8 additions & 2 deletions README.md
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.
5 changes: 3 additions & 2 deletions Source/BetterLoading.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<TargetFramework>TargetFramework</TargetFramework>
<OutputType>Library</OutputType>
<TargetFramework>net48</TargetFramework>
<LangVersion>8</LangVersion>
<Nullable>annotations</Nullable>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down Expand Up @@ -45,5 +45,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.1.0" />
<PackageReference Include="Samboy063.Tomlet" Version="3.1.3" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions Source/BetterLoading.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterLoading", "BetterLoading.csproj", "{E08CFC22-1BA8-41FE-A60B-491C308B8B65}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{46226B08-22BA-455E-8B99-F496E90EDCBC}"
ProjectSection(SolutionItems) = preProject
.gitignore = ..\.gitignore
README.md = ..\README.md
LoadFolders.xml = ..\LoadFolders.xml
About\About.xml = ..\About\About.xml
About\Manifest.xml = ..\About\Manifest.xml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
33 changes: 33 additions & 0 deletions Source/BetterLoadingConfig.cs
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>();
}
}
61 changes: 61 additions & 0 deletions Source/BetterLoadingConfigManager.cs
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);
}
}
Loading

0 comments on commit 663832c

Please sign in to comment.