-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable the ERE restoration decision if the ERE has no holder in hist…
- Loading branch information
1 parent
2c5c62b
commit 3e20ab2
Showing
3 changed files
with
89 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using commonItems; | ||
using commonItems.Mods; | ||
using CWTools.CSharp; | ||
using CWTools.Parser; | ||
using CWTools.Process; | ||
using ImperatorToCK3.CK3.Titles; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ImperatorToCK3.Outputter; | ||
|
||
internal static class DecisionsOutputter { | ||
internal static async Task TweakERERestorationDecision(Title.LandedTitles titles, ModFilesystem ck3ModFS, | ||
string outputModPath) { | ||
if (!titles.ContainsKey("e_byzantium")) { | ||
return; | ||
} | ||
|
||
Logger.Info("Tweaking ERE restoration decision..."); | ||
const string relativeDecisionsFilePath = "common/decisions/dlc_decisions/ep3_decisions.txt"; | ||
|
||
// The file may already be in the output mod. | ||
string? decisionsFilePath; | ||
string fileInOutputPath = Path.Join(outputModPath, relativeDecisionsFilePath); | ||
if (File.Exists(fileInOutputPath)) { | ||
decisionsFilePath = fileInOutputPath; | ||
} else { | ||
decisionsFilePath = ck3ModFS.GetActualFileLocation(relativeDecisionsFilePath); | ||
} | ||
|
||
if (decisionsFilePath is null) { | ||
Logger.Warn($"Can't find {relativeDecisionsFilePath}!"); | ||
return; | ||
} | ||
|
||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); | ||
|
||
var fileName = Path.GetFileName(decisionsFilePath); | ||
|
||
var text = await File.ReadAllTextAsync(decisionsFilePath); | ||
var parsed = Parsers.ParseScriptFile(fileName, text); | ||
var decisionsFile = parsed.GetResult(); | ||
|
||
var processed = Parsers.ProcessStatements(fileName, decisionsFilePath, decisionsFile); | ||
|
||
const string decisionName = "recreate_byzantine_empire_decision"; | ||
var decisionNode = processed.Nodes.FirstOrDefault(n => n.Key == decisionName); | ||
if (decisionNode is null) { | ||
Logger.Warn($"Decision {decisionName} not found!"); | ||
return; | ||
} | ||
|
||
var isShownNode = decisionNode.Nodes.FirstOrDefault(n => n.Key == "is_shown"); | ||
if (isShownNode is null) { | ||
Logger.Warn($"is_shown node not found in decision {decisionName}!"); | ||
return; | ||
} | ||
|
||
const string additionalCondition = "\t\texists = title:e_byzantium.previous_holder"; | ||
var additionalStatements = CKParser.parseString(additionalCondition, fileName).GetResult(); | ||
var rootNodeForStatements = Parsers.ProcessStatements(fileName, decisionsFilePath, additionalStatements); | ||
|
||
var newChild = Child.NewLeafC(rootNodeForStatements.Leaves.First()); | ||
isShownNode.SetTag(newChild.leaf.Key, newChild); | ||
|
||
StringBuilder sb = new(); | ||
foreach (var child in processed.Children) { | ||
sb.AppendLine(CKPrinter.api.prettyPrintStatement.Invoke(child.ToRaw)); | ||
} | ||
|
||
// Output the modified file with UTF8-BOM encoding. | ||
var outputFilePath = Path.Join(outputModPath, relativeDecisionsFilePath); | ||
await File.WriteAllTextAsync(outputFilePath, sb.ToString(), Encoding.UTF8); | ||
} | ||
} |
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