Skip to content

Commit

Permalink
- added an ItemXmlNodeIdx property to Item, so that it always selects…
Browse files Browse the repository at this point in the history
… the correct xmlnode when writing item changes.
  • Loading branch information
AnthonyZJiang committed May 28, 2018
1 parent 9c6add8 commit cbb9f27
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
5 changes: 2 additions & 3 deletions D-OS Save Editor/SE/InventoryTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,12 @@ private void ApplyChangesButton_OnClick(object sender, RoutedEventArgs e)
// add changes
if (Player.ItemChanges.ContainsKey(item.Slot))
{
Player.ItemChanges[item.Slot] = new ItemChange(item, Player.ItemChanges[item.Slot].ChangeType,
ItemsListBox.SelectedIndex);
Player.ItemChanges[item.Slot] = new ItemChange(item, Player.ItemChanges[item.Slot].ChangeType);
}
else
{
Player.ItemChanges.Add(item.Slot,
new ItemChange(item, ChangeType.Modify, ItemsListBox.SelectedIndex));
new ItemChange(item, ChangeType.Modify));
}

// apply changes to the original item
Expand Down
11 changes: 7 additions & 4 deletions D-OS Save Editor/savegame/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public enum ItemRarityType { Common = 0, Uncommon, Rare, Epic, Legendary, Divine
/// </summary>
public string Xml { get; set; }

/// <summary>
/// The index of the item in xml inventory node list.
/// </summary>
public int ItemXmlNodeIdx { get; set; }

/// <summary>
/// Item category
/// </summary>
Expand Down Expand Up @@ -498,16 +503,14 @@ public StatsNode DeepClone()
public class ItemChange
{
public Item Item { get; }
public ChangeType ChangeType { get;}
public int ItemIndex { get; set; }
public ChangeType ChangeType { get; }

public ItemChange() { }

public ItemChange(Item item, ChangeType changeType, int itemIndex)
public ItemChange(Item item, ChangeType changeType)
{
Item = item.DeepClone();
ChangeType = changeType;
ItemIndex = itemIndex;
}
}

Expand Down
9 changes: 2 additions & 7 deletions D-OS Save Editor/savegame/LsxParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static Player[] ParsePlayer(XmlDocument doc)
try
{
item = ParseItem(inventoryData[j].ParentNode);
item.ItemXmlNodeIdx = j;
}
catch (ObjectNullException)
{
Expand All @@ -65,12 +66,6 @@ public static Player[] ParsePlayer(XmlDocument doc)
throw new ItemParserException(e, inventoryData[j].ParentNode);
}
if (item == null)
{
notAnItemIdx.Enqueue(j);
return;
}
players[i].Items[j] = item;
players[i].SlotsOccupation[int.Parse(item.Slot)] = true;
});
Expand Down Expand Up @@ -382,7 +377,7 @@ public static XmlDocument WriteItemChanges(XmlDocument doc, Player player)
}
else if (ic.Value.ChangeType == ChangeType.Modify)
{
var itemNode = inventoryData[ic.Value.ItemIndex].ParentNode;
var itemNode = inventoryData[ic.Value.Item.ItemXmlNodeIdx].ParentNode;

var allowedChanges = ic.Value.Item.GetAllowedChangeType();
if (allowedChanges.Contains(nameof(ic.Value.Item.Amount)))
Expand Down

0 comments on commit cbb9f27

Please sign in to comment.