Skip to content

Commit

Permalink
Update CrafterName on items when saving
Browse files Browse the repository at this point in the history
Adds a pass to the save profile code that re-sets the crafterName field on any item that was made by the current player. This ensures if their name was changed the item shows as crafted by their new name. This is done by just matching the crafter ID values to the current profile player ID.
  • Loading branch information
Wufflez committed Mar 17, 2021
1 parent 02f7138 commit 42a1743
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Loki/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public float Durability
public int Quality { get; }
public int Variant { get; }
public long CrafterId { get; }
public string CrafterName { get; }
public string CrafterName { get; set; }

public bool HasCrafterTag => CrafterId != 0;

Expand Down
11 changes: 11 additions & 0 deletions Loki/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public async void LoadProfile(CharacterFile character)
try
{
Profile = await Task.Run(() => PlayerProfile.Read(File.OpenRead(character.FilePath)));
character.PlayerName = Profile.PlayerName;
}
catch (Exception ex)
{
Expand All @@ -127,6 +128,16 @@ public async void SaveProfile(CharacterFile character)

await Task.Run(() =>
{

// Re-Tag any items with new character name if needed.
foreach (var slot in profile.Player.Inventory.Slots)
{
if (slot.Item != null && slot.Item.CrafterId == profile.PlayerId)
{
slot.Item.CrafterName = profile.PlayerName;
}
}

if (makeBackup)
Backup.BackupCharacter(character);

Expand Down

0 comments on commit 42a1743

Please sign in to comment.