Skip to content

Commit b624f5a

Browse files
committed
fix enabling of item plating / powered cross blueprint
1 parent dcdfd5b commit b624f5a

3 files changed

Lines changed: 88 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.11.13
4+
5+
### Bugfixes
6+
7+
- The blueprints for Item Plating and Powered Cross will now properly appear in the crafting book when added to the
8+
inventory
9+
310
## v0.11.12
411

512
### Features

SOTFEdit/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// app, or any theme specific resource dictionaries)
1313
)]
1414
[assembly: AssemblyCompany("codengine")]
15-
[assembly: AssemblyFileVersion("0.11.12")]
16-
[assembly: AssemblyInformationalVersion("0.11.12")]
15+
[assembly: AssemblyFileVersion("0.11.13")]
16+
[assembly: AssemblyInformationalVersion("0.11.13")]
1717
[assembly: AssemblyProduct("SOTFEdit")]
1818
[assembly: AssemblyTitle("SOTFEdit")]
19-
[assembly: AssemblyVersion("0.11.12")]
19+
[assembly: AssemblyVersion("0.11.13")]
2020
[assembly: TargetPlatform("Windows7.0")]
2121
[assembly: SupportedOSPlatform("Windows7.0")]
2222
[assembly: Guid("d59ec208-5fc6-4336-a9db-dbeb36938f78")]

SOTFEdit/ViewModel/InventoryPageViewModel.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using CommunityToolkit.Mvvm.ComponentModel;
88
using CommunityToolkit.Mvvm.Input;
99
using CommunityToolkit.Mvvm.Messaging;
10+
using Newtonsoft.Json.Linq;
1011
using SOTFEdit.Infrastructure;
1112
using SOTFEdit.Model;
1213
using SOTFEdit.Model.Events;
@@ -17,6 +18,8 @@ namespace SOTFEdit.ViewModel;
1718

1819
public partial class InventoryPageViewModel : ObservableObject
1920
{
21+
private const int ItemPlatingItemId = 665;
22+
private const int PoweredCrossItemId = 666;
2023
private readonly ObservableCollectionEx<InventoryItem> _inventory = new();
2124

2225
private readonly DispatcherTimer _inventoryFilterTimer = new()
@@ -225,7 +228,81 @@ public bool Update(Savegame savegame)
225228

226229
var selectedItems = new List<InventoryItem>(_inventory);
227230

228-
return PlayerInventoryDataModel.Merge(saveDataWrapper, selectedItems);
231+
var hasChanged = PlayerInventoryDataModel.Merge(saveDataWrapper, selectedItems);
232+
return EnsureBlueprintStatusUpdated(savegame.SavegameStore, selectedItems) || hasChanged;
233+
}
234+
235+
private bool EnsureBlueprintStatusUpdated(SavegameStore savegameStore, List<InventoryItem> inventoryItems)
236+
{
237+
if (savegameStore.LoadJsonRaw(SavegameStore.FileType.PlayerStateSaveData) is not { } saveDataWrapper)
238+
{
239+
return false;
240+
}
241+
242+
if (saveDataWrapper.GetJsonBasedToken(Constants.JsonKeys.PlayerState) is not { } playerState ||
243+
playerState["_entries"] is not JArray entries)
244+
{
245+
return false;
246+
}
247+
248+
var blueprintItemIds = new HashSet<int>
249+
{
250+
ItemPlatingItemId, PoweredCrossItemId
251+
};
252+
253+
var addedBlueprintItems = new HashSet<int>();
254+
255+
var hasChanges = false;
256+
257+
foreach (var inventoryItem in
258+
inventoryItems.Where(inventoryItem => blueprintItemIds.Contains(inventoryItem.Id)))
259+
{
260+
addedBlueprintItems.Add(inventoryItem.Id);
261+
}
262+
263+
var blueprintTokensExisting = new HashSet<int>();
264+
265+
foreach (var jToken in entries)
266+
{
267+
var name = jToken["Name"]?.Value<string>();
268+
269+
foreach (var itemId in blueprintItemIds.Where(itemId => name == $"DiscoverablePageUnlocked_{itemId}"))
270+
{
271+
blueprintTokensExisting.Add(itemId);
272+
273+
var isEnabled = jToken["BoolValue"]?.Value<bool>() ?? false;
274+
var isAdded = addedBlueprintItems.Contains(itemId);
275+
if (isEnabled != isAdded)
276+
{
277+
jToken["BoolValue"] = isAdded;
278+
hasChanges = true;
279+
}
280+
281+
break;
282+
}
283+
}
284+
285+
foreach (var blueprintItemId in blueprintItemIds)
286+
{
287+
if (blueprintTokensExisting.Contains(blueprintItemId) || !addedBlueprintItems.Contains(blueprintItemId))
288+
{
289+
continue;
290+
}
291+
292+
entries.Add(new JObject
293+
{
294+
{ "Name", $"DiscoverablePageUnlocked_{blueprintItemId}" },
295+
{ "BoolValue", true }
296+
});
297+
hasChanges = true;
298+
}
299+
300+
if (hasChanges)
301+
{
302+
saveDataWrapper.MarkAsModified(Constants.JsonKeys.PlayerState);
303+
}
304+
305+
return hasChanges;
229306
}
230307

231308
[RelayCommand(CanExecute = nameof(HasInventoryItems))]

0 commit comments

Comments
 (0)