diff --git a/RandomizerCore/Logic/ILogicFormat.cs b/RandomizerCore/Logic/ILogicFormat.cs index 7fbcb4c..2a8e6da 100644 --- a/RandomizerCore/Logic/ILogicFormat.cs +++ b/RandomizerCore/Logic/ILogicFormat.cs @@ -1,9 +1,48 @@ using RandomizerCore.Logic.StateLogic; using RandomizerCore.LogicItems; using RandomizerCore.StringItems; +using System.ComponentModel; namespace RandomizerCore.Logic { + [EditorBrowsable(EditorBrowsableState.Never)] + public static class LogicFormatExtentions + { + /// + /// Returns the result of the ILogicFormat method corresponding to the LogicFileType. + /// + public static object LoadFile(this ILogicFormat fmt, LogicFileType type, Stream s) + { + return type switch + { + LogicFileType.Terms => fmt.LoadTerms(s), + LogicFileType.Waypoints => fmt.LoadWaypoints(s), + LogicFileType.Transitions => fmt.LoadTransitions(s), + LogicFileType.Macros => fmt.LoadMacros(s), + LogicFileType.Items => fmt.LoadItems(s), + LogicFileType.Locations => fmt.LoadLocations(s), + LogicFileType.LogicEdit => fmt.LoadLogicEdits(s), + LogicFileType.MacroEdit => fmt.LoadMacroEdits(s), + LogicFileType.LogicSubst => fmt.LoadLogicSubstitutions(s), + LogicFileType.ItemTemplates => fmt.LoadItemTemplates(s), + LogicFileType.StateData => fmt.LoadStateData(s), + LogicFileType.ItemStrings => fmt.LoadItemStrings(s), + _ => throw new NotImplementedException("Unrecognized logic format " + type), + }; + } + + /// + /// Converts the string to a stream, and returns the result of the ILogicFormat method corresponding to the LogicFileType. + /// + public static object LoadFile(this ILogicFormat fmt, LogicFileType type, string s) + { + byte[] data = System.Text.Encoding.Unicode.GetBytes(s); + using MemoryStream ms = new(data); + using StreamReader sr = new(ms, System.Text.Encoding.Unicode); + return fmt.LoadFile(type, s); + } + } + /// /// Interface describing a strategy for loading a specific file format into a . /// diff --git a/RandomizerCore/Logic/LogicDef.cs b/RandomizerCore/Logic/LogicDef.cs index 863df15..6eb68fd 100644 --- a/RandomizerCore/Logic/LogicDef.cs +++ b/RandomizerCore/Logic/LogicDef.cs @@ -47,5 +47,6 @@ public LogicDef(string name, string infixSource) /// The string representation of the LogicDef. Must be logically equivalent to InfixSource, but generally does not contain macros and may be expanded or simplified in other ways. /// public virtual string ToInfix() => ToLogicClauseBuilder().ToInfix(); + public override string ToString() => $"{Name}: {InfixSource}"; } } diff --git a/RandomizerCore/RandomizerCore.csproj b/RandomizerCore/RandomizerCore.csproj index 1cfb7a6..eb736cb 100644 --- a/RandomizerCore/RandomizerCore.csproj +++ b/RandomizerCore/RandomizerCore.csproj @@ -2,7 +2,7 @@ ae78b8e8-a733-44a2-be63-d264c82118b7 RandomizerCore - 2.0.0 + 2.0.1 netstandard2.1;net472;net6.0;net8.0 true