allow TableStreamRun to match an ArrayRun if the format matches

This can happen if the user gives a name to a tablestreamrun with a fixed length - it becomes an ArrayRun.

Allow the StreamElementViewModel to accept pointers of both streams and arrays when judging the UsageCount.

Allow
This commit is contained in:
Haven1433 2022-09-10 20:48:51 -05:00
parent 0db2ce46e1
commit 5a104b3039
2 changed files with 6 additions and 3 deletions

View File

@ -30,7 +30,10 @@ namespace HavenSoft.HexManiac.Core.Models.Runs.Factory {
}
return false;
}
public override bool Matches(IFormattedRun run) => run is TableStreamRun streamRun && streamRun.FormatString == Format;
public override bool Matches(IFormattedRun run) {
if (run == null || run.FormatString != Format) return false;
return run is ITableRun;
}
public override IFormattedRun WriteNewRun(IDataModel owner, ModelDelta token, int source, int destination, string name, IReadOnlyList<ArrayRunElementSegment> sourceSegments) {
// don't bother checking the TryParse result: we very much expect that the data originally in the run won't fit the parse.
TableStreamRun.TryParseTableStream(owner, destination, new SortedSpan<int>(source), name, Format, sourceSegments, out var tableStream);

View File

@ -148,8 +148,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels.Tools {
if (destination == Pointer.NULL) {
UsageCount = 0;
} else {
var run = Model.GetNextRun(destination) as IStreamRun;
UsageCount = run?.PointerSources?.Count ?? 0;
var run = Model.GetNextRun(destination);
UsageCount = run is IStreamRun || run is ITableRun ? run.PointerSources?.Count ?? 0 : 0;
}
}