Skip to content

Commit

Permalink
labels/comments: use SortedDictionary for comments and labels
Browse files Browse the repository at this point in the history
- when they save in XML or exported, now it'll be in order
  • Loading branch information
binary1230 committed Jan 21, 2024
1 parent 2fa905f commit 96f29c4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Diz.Core.Interfaces/ModelInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public interface IData :
// TODO: temp hack for serialization, do this better somehow.
Dictionary<int, IAnnotationLabel> LabelsSerialization { get; }

public ObservableDictionary<int, string> Comments { get; }
public SortedDictionary<int, string> Comments { get; }
}

public static class DataExtensions
Expand Down
2 changes: 1 addition & 1 deletion Diz.Core/model/LabelProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void AddLabel(int snesAddress, IAnnotationLabel labelToAdd, bool overwrit
public class LabelsCollection : LabelProviderBase, ILabelService, IEquatable<LabelsCollection>
{
// ReSharper disable once MemberCanBePrivate.Global
public Dictionary<int, IAnnotationLabel> Labels { get; } = new();
public SortedDictionary<int, IAnnotationLabel> Labels { get; } = new();

[XmlIgnore]
IEnumerable<KeyValuePair<int, IAnnotationLabel>> IReadOnlyLabelProvider.Labels => Labels;
Expand Down
9 changes: 4 additions & 5 deletions Diz.Core/model/snes/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Xml.Serialization;
using Diz.Core.Interfaces;
using Diz.Core.util;
using IX.Observable;

namespace Diz.Core.model.snes;

Expand All @@ -15,7 +14,7 @@ public class Data : IData
public IDataStoreProvider<IArchitectureApi> Apis { get; } = new DataStoreProvider<IArchitectureApi>();
public IDataStoreProvider<IDataTag> Tags { get; } = new DataStoreProvider<IDataTag>();

private ObservableDictionary<int, string> comments;
private SortedDictionary<int, string> comments;
private RomBytes romBytes;

// NOTE: snes specific stuff (rom map mode/speed) should eventually be removed from here.
Expand Down Expand Up @@ -44,7 +43,7 @@ public RomSpeed RomSpeed
}

// next 2 dictionaries store in SNES address format (since memory labels can't be represented as a PC address)
public ObservableDictionary<int, string> Comments
public SortedDictionary<int, string> Comments
{
get => comments;
set => this.SetField(PropertyChanged, ref comments, value);
Expand All @@ -68,11 +67,11 @@ public RomBytes RomBytes
IRomBytes<IRomByte> IRomBytesProvider.RomBytes => romBytes;

[XmlIgnore]
public bool RomBytesLoaded { get; set; } = false;
public bool RomBytesLoaded { get; set; }

public Data()
{
comments = new ObservableDictionary<int, string>();
comments = new SortedDictionary<int, string>();
Labels = new LabelsServiceWithTemp(this);
romBytes = new RomBytes();
}
Expand Down
2 changes: 1 addition & 1 deletion Diz.Cpu.65816/src/SampleRomData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public Data Create()
new() { Rom = 0x34, TypeFlag = FlagType.Data8Bit, DataBank = 0x80, DirectPage = 0x2100 },
new() { Rom = 0x6D, TypeFlag = FlagType.Data8Bit, DataBank = 0x80, DirectPage = 0x2100 },
};
data.Comments = new ObservableDictionary<int, string>
data.Comments = new SortedDictionary<int, string>
{
{ 0x808000 + 0x03, "this sets FastROM" },
{ 0x808000 + 0x0F, "direct page = $2100" },
Expand Down

0 comments on commit 96f29c4

Please sign in to comment.