Skip to content

Commit

Permalink
Add LogicFormatExtensions, override LogicDef.ToString, bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
homothetyhk committed Feb 3, 2024
1 parent f4a4e0b commit 0018cfb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions RandomizerCore/Logic/ILogicFormat.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Returns the result of the ILogicFormat method corresponding to the LogicFileType.
/// </summary>
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),
};
}

/// <summary>
/// Converts the string to a stream, and returns the result of the ILogicFormat method corresponding to the LogicFileType.
/// </summary>
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);
}
}

/// <summary>
/// Interface describing a strategy for loading a specific file format into a <see cref="LogicManagerBuilder"/>.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions RandomizerCore/Logic/LogicDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public virtual string ToInfix() => ToLogicClauseBuilder().ToInfix();
public override string ToString() => $"{Name}: {InfixSource}";
}
}
2 changes: 1 addition & 1 deletion RandomizerCore/RandomizerCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<ProjectGuid>ae78b8e8-a733-44a2-be63-d264c82118b7</ProjectGuid>
<AssemblyTitle>RandomizerCore</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<VersionPrefix>2.0.1</VersionPrefix>
<VersionSuffix></VersionSuffix>
<TargetFrameworks>netstandard2.1;net472;net6.0;net8.0</TargetFrameworks>
<Deterministic>true</Deterministic>
Expand Down

0 comments on commit 0018cfb

Please sign in to comment.