changes to enums and element names are now reflected immediately.

This commit is contained in:
Benjamin Popp
2019-03-31 22:16:52 -05:00
parent 1cc4145108
commit c4c182a32f
2 changed files with 21 additions and 1 deletions

View File

@@ -155,6 +155,8 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
cachedOptions = results;
return results;
}
public void ClearCache() { cachedOptions = null; }
}
public class ArrayOffset {
@@ -580,6 +582,21 @@ namespace HavenSoft.HexManiac.Core.Models.Runs {
return new ArrayRun(owner, FormatString, LengthFromAnchor, newStart, ElementCount, ElementContent, PointerSources, PointerSourcesForInnerElements);
}
/// <summary>
/// For performance reasons, arrays store copies of strings from arrays that they're based on.
/// For example, if the array contains an enum of types, that enum segment will store the list of types.
/// For example, if the array is the same length as the pokemon array, the array will store the list of pokemon names.
/// Calling this method will clear those caches and force re-evaluation.
/// </summary>
public void ClearCache() {
cachedElementNames = null;
foreach (var child in ElementContent) {
if (child is ArrayRunEnumSegment enumSegment) {
enumSegment.ClearCache();
}
}
}
public override IFormattedRun RemoveSource(int source) {
if (!SupportsPointersToElements) return base.RemoveSource(source);
var newPointerSources = PointerSources.Where(item => item != source).ToList();

View File

@@ -1281,7 +1281,10 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
for (int y = 0; y < Height; y++) {
for (int x = 0; x < Width; x++) {
var index = scroll.ViewPointToDataIndex(new Point(x, y));
if (run == null || index >= run.Start + run.Length) run = Model.GetNextRun(index) ?? new NoInfoRun(Model.Count);
if (run == null || index >= run.Start + run.Length) {
run = Model.GetNextRun(index) ?? new NoInfoRun(Model.Count);
if (run is ArrayRun array) array.ClearCache();
}
if (index < 0 || index >= Model.Count) {
currentView[x, y] = HexElement.Undefined;
} else if (index >= run.Start) {