Skip to content

Commit

Permalink
add tool to reset traps
Browse files Browse the repository at this point in the history
  • Loading branch information
codengine committed Feb 28, 2024
1 parent ccbc11f commit b51329a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
1 change: 1 addition & 0 deletions SOTFEdit/Model/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static class JsonKeys
public const string StructureDestruction = "Data.StructureDestruction";
public const string WorldItemManager = "Data.WorldItemManager";
public const string ZipLineManager = "Data.ZipLineManager";
public const string ScrewTraps = "Data.ScrewTraps";
}


Expand Down
3 changes: 2 additions & 1 deletion SOTFEdit/Model/Savegame/SavegameStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public enum FileType
ScrewStructureNodeInstancesSaveData,
StructureDestructionSaveData,
WorldItemManagerSaveData,
ZipLineManagerSaveData
ZipLineManagerSaveData,
ScrewTrapsSaveData
}

private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
Expand Down
9 changes: 6 additions & 3 deletions SOTFEdit/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,15 @@
<MenuItem Header="{infrastructure:Translate 'menu.tools.resetNumberOfCutTrees.text'}"
Command="{Binding ExperimentResetNumberCutTreesCommand}"
ToolTip="{infrastructure:Translate 'menu.tools.resetNumberOfCutTrees.tooltip'}" />
<MenuItem Header="{infrastructure:Translate 'menu.tools.unlocks.text'}"
Command="{Binding UnlocksCommand}"
ToolTip="{infrastructure:Translate 'menu.tools.unlocks.tooltip'}" />
<MenuItem Header="{infrastructure:Translate 'menu.tools.resetContainers.text'}"
Command="{Binding ResetContainersCommand}"
ToolTip="{infrastructure:Translate 'menu.tools.resetContainers.tooltip'}" />
<MenuItem Header="{infrastructure:Translate 'menu.tools.resetTraps.text'}"
Command="{Binding ResetTrapsCommand}"
ToolTip="{infrastructure:Translate 'menu.tools.resetTraps.tooltip'}" />
<MenuItem Header="{infrastructure:Translate 'menu.tools.unlocks.text'}"
Command="{Binding UnlocksCommand}"
ToolTip="{infrastructure:Translate 'menu.tools.unlocks.tooltip'}" />
</MenuItem>
<MenuItem Header="{infrastructure:Translate 'menu.tools.map.text'}"
Command="{Binding OpenMapCommand}"
Expand Down
50 changes: 50 additions & 0 deletions SOTFEdit/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private void RefreshCanExecuteChanged()
ResetStructureDamageCommand.NotifyCanExecuteChanged();
TeleportWorldItemCommand.NotifyCanExecuteChanged();
ResetContainersCommand.NotifyCanExecuteChanged();
ResetTrapsCommand.NotifyCanExecuteChanged();
OnPropertyChanged(nameof(CanEditTabs));
}

Expand Down Expand Up @@ -465,6 +466,55 @@ private static void ResetContainers()
WeakReferenceMessenger.Default.Send(new RequestResetContainersEvent());
}

[RelayCommand(CanExecute = nameof(CanSaveAndEdit))]
private static void ResetTraps()
{
if (SavegameManager.SelectedSavegame is not { } selectedSavegame ||
selectedSavegame.SavegameStore.LoadJsonRaw(SavegameStore.FileType.ScrewTrapsSaveData) is not
{ } saveDataWrapper ||
saveDataWrapper.GetJsonBasedToken(Constants.JsonKeys.ScrewTraps) is not { } traps ||
traps["_tarpStructureData"] is not JArray structureData || structureData.Count == 0)
{
ShowNoTrapsToResetMessage();
return;
}

var countReset = 0;

foreach (var trapData in structureData)
{
if (trapData["IsTriggered"] is { } isTriggeredToken && isTriggeredToken.Value<bool>())
{
trapData["IsTriggered"] = false;
countReset++;
}

if (trapData["Data1"] is { } data1Token && data1Token.Value<int>() < 5)
{
trapData["Data1"] = 5;
countReset++;
}
}

if (countReset == 0)
{
ShowNoTrapsToResetMessage();
return;
}

saveDataWrapper.MarkAsModified(Constants.JsonKeys.ScrewTraps);
WeakReferenceMessenger.Default.Send(new GenericMessageEvent(
TranslationManager.GetFormatted("windows.resetTraps.messages.trapsReset.text", countReset),
TranslationManager.Get("windows.resetTraps.messages.trapsReset.title")));
}

private static void ShowNoTrapsToResetMessage()
{
WeakReferenceMessenger.Default.Send(new GenericMessageEvent(
TranslationManager.Get("windows.resetTraps.messages.nothingToReset.text"),
TranslationManager.Get("windows.resetTraps.messages.nothingToReset.title")));
}

public void OnPreviewKeyDown(KeyEventArgs e)
{
if (e.Key == Key.F5 && ReloadSavegameCommand.CanExecute(null))
Expand Down
16 changes: 16 additions & 0 deletions SOTFEdit/data/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,10 @@
"text": "Schadenszähler für Gebäude zurücksetzen",
"tooltip": "Ermöglicht es, alle Gebäude zu reparieren."
},
"resetTraps": {
"text": "Fallen zurücksetzen",
"tooltip": "Setzt alle Fallen zurück"
},
"text": "Tools",
"unlocks": {
"text": "Freischaltung",
Expand Down Expand Up @@ -1439,6 +1443,18 @@
}
}
},
"resetTraps": {
"messages": {
"nothingToReset": {
"text": "Nichts zum zurücksetzen gefunden",
"title": "Nichts gefunden"
},
"trapsReset": {
"text": "{0} Fallen wurden zurückgesetzt. Bitte speichere die Änderungen um sie anzuwenden",
"title": "Fallen zurückgesetzt"
}
}
},
"selectSavegame": {
"buttons": {
"change": "Ändern...",
Expand Down
16 changes: 16 additions & 0 deletions SOTFEdit/data/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,10 @@
"text": "Reset Structure Damage",
"tooltip": "Lets you repair all structures"
},
"resetTraps": {
"text": "Reset Traps",
"tooltip": "Resets all traps"
},
"text": "Tools",
"unlocks": {
"text": "Unlocks",
Expand Down Expand Up @@ -1439,6 +1443,18 @@
}
}
},
"resetTraps": {
"messages": {
"nothingToReset": {
"text": "Nothing to reset found",
"title": "Nothing found"
},
"trapsReset": {
"text": "{0} traps have been reset. Please save the changes to apply them to the savegame",
"title": "Traps reset"
}
}
},
"selectSavegame": {
"buttons": {
"change": "Change...",
Expand Down

0 comments on commit b51329a

Please sign in to comment.