-
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.
- Re-fixed "not allowed artisan builds" tooltip - Fixed "Could not find player faction" error on new game - Fixed ability to train animals if an animal has a food policy set - New Global option: Allow food if malnourished (if a pawn is is suffering from malnutrition they will ignore all food rules) [Default: False] - New Global option: Allow food if training (if an animal is being trained they ignore all food rules) [Default: False] - Plans can be imported/exported between games. A plan consists of all rule presets and defaults bundled into one file.
- Loading branch information
Showing
36 changed files
with
810 additions
and
300 deletions.
There are no files selected for viewing
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,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<Defs> | ||
|
||
<HugsLib.UpdateFeatureDef Abstract="true" Name="UpdateFeatureBase"> | ||
<modNameReadable>Pawn Rules</modNameReadable> | ||
<modIdentifier>PawnRules</modIdentifier> | ||
</HugsLib.UpdateFeatureDef> | ||
|
||
<HugsLib.UpdateFeatureDef ParentName="UpdateFeatureBase"> | ||
<defName>PawnRules_1_1_1</defName> | ||
<assemblyVersion>1.1.1</assemblyVersion> | ||
<content>- Re-fixed "not allowed artisan builds" tooltip\n\n- Fixed "Could not find player faction" error on new game\n\n- Fixed ability to train animals if an animal has a food policy set\n\n- New Global option: Allow food if malnourished (if a pawn is is suffering from malnutrition they will ignore all food rules) [Default: False]\n\n- New Global option: Allow food if training (if an animal is being trained they ignore all food rules) [Default: False]\n\n- Plans can be imported/exported between games. A plan consists of all rule presets and defaults bundled into one file.</content> | ||
</HugsLib.UpdateFeatureDef> | ||
|
||
</Defs> |
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
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,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Xml.Linq; | ||
using RimWorld; | ||
using Verse; | ||
|
||
namespace PawnRules.Data | ||
{ | ||
internal static class Persistent | ||
{ | ||
private const string ExportsDirectoryName = "Plans"; | ||
private const string ExportsExtension = ".xml"; | ||
private const string ExportPrefix = "Plan_"; | ||
|
||
private static readonly Regex ValidNameRegex = new Regex("^(?:[a-zA-Z0-9_\\-]|[a-zA-Z0-9_\\-]+[a-zA-Z0-9_\\- ]*[a-zA-Z0-9_\\-]+)$"); | ||
|
||
private static readonly DirectoryInfo ExportsDirectory = Mod.ConfigDirectory.CreateSubdirectory(ExportsDirectoryName); | ||
|
||
private static FileInfo GetPlanFile(string name) => new FileInfo(Path.Combine(ExportsDirectory.FullName, ExportPrefix + name + ExportsExtension)); | ||
private static string GetPlanName(FileInfo file) => Path.GetFileNameWithoutExtension(file.Name).Substring(ExportPrefix.Length); | ||
|
||
public static IEnumerable<string> GetPlans() => ExportsDirectory.GetFiles(ExportPrefix + "*" + ExportsExtension).OrderByDescending(file => file.LastAccessTime).Select(GetPlanName); | ||
|
||
public static void DeletePlan(string name) | ||
{ | ||
var file = GetPlanFile(name); | ||
|
||
Mod.Warning($"Delete => {file.FullName}"); | ||
if (!file.Exists) { return; } | ||
|
||
file.Delete(); | ||
} | ||
|
||
public static bool Load(string name) | ||
{ | ||
var file = GetPlanFile(name); | ||
if (!file.Exists) { return false; } | ||
|
||
var xml = XDocument.Load(file.FullName).Root; | ||
|
||
Registry.FromXml(xml); | ||
|
||
return true; | ||
} | ||
|
||
public static void Save(string name = null) | ||
{ | ||
var file = GetPlanFile(name.NullOrEmpty() ? CreateDefaultName() : name); | ||
if (file.Exists) { file.Delete(); } | ||
|
||
var doc = new XDocument(); | ||
doc.Add(Registry.ToXml()); | ||
|
||
doc.Save(file.FullName); | ||
} | ||
|
||
public static bool NameIsValid(string name) => !name.NullOrEmpty() && (name.Length <= 250 - ExportsDirectory.FullName.Length) && ValidNameRegex.IsMatch(name); | ||
|
||
public static string CreateDefaultName() => Faction.OfPlayer.Name + "_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss"); | ||
} | ||
} |
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
Oops, something went wrong.