Skip to content

Commit 7db6958

Browse files
committed
add game state data page
1 parent 5a687ca commit 7db6958

12 files changed

Lines changed: 316 additions & 27 deletions

README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44

55
A savegame editor for "Sons of The Forest".
66

7-
- [SOTFEdit](#sotfedit)
7+
- [SOTFEdit - Sons of The Forest Savegame Editor](#sotfedit---sons-of-the-forest-savegame-editor)
88
- [Disclaimer](#disclaimer)
99
- [Features](#features)
1010
- [Download](#download)
11+
- [Requirements](#requirements)
1112
- [Usage](#usage)
12-
- [Hints](#hints)
13+
- [Inventory](#inventory)
14+
- [Armor](#armor)
15+
- [Weather](#weather)
1316
- [Troubleshooting](#troubleshooting)
1417
- [Contributing](#contributing)
1518
- [Final Words](#final-words)
19+
- [Links and Credits](#links-and-credits)
1620

1721
# Disclaimer
1822

@@ -23,15 +27,19 @@ This project is in no way or form associated with the developers of the game. It
2327
- Edit Game Setup (Game Mode, Spawn Rate etc.)
2428
- Edit Inventory (Add/Remove items, change quantities)
2529
- Edit Armor Data (Add Armor Pieces, change durability)
30+
- Edit Weather Data (Weather, Seasons...)
31+
- Edit Game State Data (Playtime,..)
2632
- Revive Virginia & Kelvin
2733
- Regrow Trees
2834
- Backup changed files automatically
2935
- ... more features are planned
3036

3137
# Download
38+
3239
- You can find the newest version at the [Releases page](https://github.com/codengine/SOTFEdit/releases)
3340

3441
# Requirements
42+
3543
- Windows 7+ (I guess...)
3644
- [.net 6.0+ Runtime](https://dotnet.microsoft.com/en-us/download/dotnet)
3745

@@ -44,9 +52,39 @@ This project is in no way or form associated with the developers of the game. It
4452

4553
If you use one of the "Tools" this will trigger a reload of the savegames, which will discard any pending changes. I'd recommend to use the tools after you're done with editing.
4654

47-
# Hints
55+
# Inventory
56+
57+
- In order to add or remove items, just double click on the row
58+
- There is no sanity check on the values entered at the player's inventory. So something like "100" for backpack will most likely lead to undesired behaviors.
59+
60+
# Armor
61+
62+
Armor protects you from most hazards. However you are still going to drown and die from fall damage.
63+
64+
# Weather
65+
66+
There is one very important thing. If you only change the season, it will be reverted immediately when the game progresses.
67+
To fix that, you also have to adjust the played time at "Game State". It is calculated based on the length of the season. Here is an example:
4868

49-
There is no sanity check on the values entered at the player's inventory. So something like "100" for backpack will most likely lead to undesired behaviors.
69+
- Starting Season: Spring
70+
- Season Length: Long
71+
- Played Time: 31 Days
72+
73+
The in-game season will be winter, because:
74+
75+
- Day 0-9 = Spring
76+
- Day 10-19 = Summer
77+
- Day 20-29 = Autumn
78+
- Day 30-39 = Winter
79+
80+
So if you want to change the weather to Summer, you need to adjust the playtime days to something between 10 and 19.
81+
82+
Here is a list of number of days per season per season length setting:
83+
84+
- Short: ???
85+
- Default (non-custom games): 5 days
86+
- Long: 10 days
87+
- Realistig: 90 days
5088

5189
# Troubleshooting
5290

@@ -59,6 +97,9 @@ My game does not work anymore?
5997
I get errors and the application does strange things
6098
- Please upload any logs to https://pastebin.com and create an issue
6199

100+
I can not change "IsRobbyDead" or "IsVirginiaDead"
101+
- In order to revive both there is a special button at "Tools" that does the job
102+
62103
# Contributing
63104

64105
Feel free to report any unknown items or any feature requests. PRs are also welcome.

SOTFEdit/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private static void ConfigureServices()
4444
services.AddSingleton<GameSetupPageViewModel>();
4545
services.AddSingleton<InventoryPageViewModel>();
4646
services.AddSingleton<WeatherPageViewModel>();
47+
services.AddSingleton<GameStatePageViewModel>();
4748
services.AddSingleton(_ => BuildItemListInstance());
4849
Ioc.Default.ConfigureServices(services.BuildServiceProvider());
4950
}

SOTFEdit/Infrastructure/GenericSettingTypeToVisibilityConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
3131
{
3232
return Visibility.Visible;
3333
}
34+
35+
if (type == GenericSetting.DataType.ReadOnly && paramStr == "ReadOnly")
36+
{
37+
return Visibility.Visible;
38+
}
3439
}
3540

3641
return Visibility.Hidden;

SOTFEdit/Model/GenericSetting.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Linq;
43
using CommunityToolkit.Mvvm.ComponentModel;
54

65
namespace SOTFEdit.Model;
@@ -10,6 +9,7 @@ public partial class GenericSetting
109
{
1110
public enum DataType
1211
{
12+
ReadOnly,
1313
String,
1414
Boolean,
1515
Integer,
@@ -21,12 +21,12 @@ public enum DataType
2121
public DataType Type { get; }
2222

2323
[ObservableProperty] private string? _stringValue;
24-
[ObservableProperty] private int? _intValue;
24+
[ObservableProperty] private int? _intValue = 0;
2525
[ObservableProperty] private bool? _boolValue;
2626

2727
public Dictionary<object, string> PossibleValues { get; init; } = new();
2828
public int MinInt { get; init; } = 0;
29-
public int MaxInt { get; init; } = 0;
29+
public int MaxInt { get; init; } = 1;
3030

3131
[ObservableProperty] private object? _selectedItem;
3232

@@ -41,6 +41,7 @@ public GenericSetting(string name, string dataPath, DataType type)
4141
{
4242
return Type switch
4343
{
44+
DataType.ReadOnly => StringValue,
4445
DataType.String => StringValue,
4546
DataType.Boolean => BoolValue,
4647
DataType.Integer => IntValue,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Newtonsoft.Json.Linq;
2+
3+
namespace SOTFEdit.Model;
4+
5+
public static class GenericSettingExtensions
6+
{
7+
public static bool MergeTo(this GenericSetting setting, JToken target)
8+
{
9+
if (setting.Type == GenericSetting.DataType.ReadOnly)
10+
{
11+
return false;
12+
}
13+
14+
var newToken = setting.GetValue() is { } value ? JToken.FromObject(value) : JValue.CreateNull();
15+
16+
if (target[setting.DataPath] is not { } token || newToken.Equals(token))
17+
{
18+
return false;
19+
}
20+
21+
token.Replace(newToken);
22+
return true;
23+
}
24+
}

SOTFEdit/View/GameStatePage.xaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<UserControl x:Class="SOTFEdit.View.GameStatePage"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:viewModel="clr-namespace:SOTFEdit.ViewModel"
7+
xmlns:infrastructure="clr-namespace:SOTFEdit.Infrastructure"
8+
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
9+
mc:Ignorable="d"
10+
d:DesignHeight="450" d:DesignWidth="800">
11+
<UserControl.DataContext>
12+
<viewModel:GameStatePageViewModel />
13+
</UserControl.DataContext>
14+
<UserControl.Resources>
15+
<infrastructure:GenericSettingTypeToVisibilityConverter x:Key="GenericSettingTypeToVisibilityConverter" />
16+
</UserControl.Resources>
17+
<Grid>
18+
<Grid.ColumnDefinitions>
19+
<ColumnDefinition />
20+
<ColumnDefinition />
21+
</Grid.ColumnDefinitions>
22+
<GroupBox Header="Settings" Margin="0 0 5 0">
23+
<DockPanel Margin="10">
24+
<DataGrid Height="Auto" DockPanel.Dock="Top" AutoGenerateColumns="False" x:Name="WeatherGrid"
25+
SelectionMode="Single" ItemsSource="{Binding Settings, Mode=OneWay}" CanUserAddRows="false"
26+
CanUserDeleteRows="False">
27+
<DataGrid.Resources>
28+
<DataTemplate x:Key="DataTemplate">
29+
<Grid>
30+
<TextBlock VerticalAlignment="Center" Text="{Binding StringValue}" Visibility="{Binding Path=Type, Converter={StaticResource GenericSettingTypeToVisibilityConverter}, ConverterParameter=ReadOnly}"></TextBlock>
31+
<TextBox Text="{Binding StringValue, UpdateSourceTrigger=PropertyChanged}"
32+
Visibility="{Binding Path=Type, Converter={StaticResource GenericSettingTypeToVisibilityConverter}, ConverterParameter=String}" />
33+
<CheckBox IsChecked="{Binding BoolValue, UpdateSourceTrigger=PropertyChanged}"
34+
Visibility="{Binding Path=Type, Converter={StaticResource GenericSettingTypeToVisibilityConverter}, ConverterParameter=Bool}">
35+
</CheckBox>
36+
<ComboBox ItemsSource="{Binding PossibleValues}"
37+
DisplayMemberPath="Value"
38+
SelectedValuePath="Key"
39+
SelectedValue="{Binding SelectedItem, UpdateSourceTrigger=PropertyChanged}"
40+
Visibility="{Binding Path=Type, Converter={StaticResource GenericSettingTypeToVisibilityConverter}, ConverterParameter=Combo}">
41+
</ComboBox>
42+
<mah:NumericUpDown Minimum="{Binding MinInt}" Maximum="{Binding MaxInt}"
43+
Value="{Binding IntValue, UpdateSourceTrigger=PropertyChanged}"
44+
Visibility="{Binding Path=Type, Converter={StaticResource GenericSettingTypeToVisibilityConverter}, ConverterParameter=Int}" />
45+
</Grid>
46+
</DataTemplate>
47+
</DataGrid.Resources>
48+
<DataGrid.Columns>
49+
<DataGridTextColumn Binding="{Binding Name, Mode=OneWay}" Header="Setting" IsReadOnly="True" />
50+
<DataGridTemplateColumn Header="Value" CellTemplate="{StaticResource DataTemplate}" />
51+
</DataGrid.Columns>
52+
</DataGrid>
53+
</DockPanel>
54+
</GroupBox>
55+
</Grid>
56+
</UserControl>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CommunityToolkit.Mvvm.DependencyInjection;
2+
using SOTFEdit.ViewModel;
3+
using SOTFEdit.Model;
4+
5+
namespace SOTFEdit.View;
6+
7+
/// <summary>
8+
/// Interaction logic for GameStatePage.xaml
9+
/// </summary>
10+
public partial class GameStatePage
11+
{
12+
public GameStatePage()
13+
{
14+
DataContext = Ioc.Default.GetRequiredService<GameStatePageViewModel>();
15+
InitializeComponent();
16+
}
17+
18+
public void Update(Savegame savegame, bool createBackup)
19+
{
20+
((GameStatePageViewModel)DataContext).Update(savegame, createBackup);
21+
}
22+
}

SOTFEdit/View/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<TabItem Foreground="White" Header="Inventory" Content="{Binding InventoryPage, Mode=OneTime}" />
9090
<TabItem Foreground="White" Header="Armor" Content="{Binding ArmorPage, Mode=OneTime}" />
9191
<TabItem Foreground="White" Header="Weather" Content="{Binding WeatherPage, Mode=OneTime}" />
92+
<TabItem Foreground="White" Header="Game State" Content="{Binding GameStatePage, Mode=OneTime}" />
9293
<TabItem Foreground="White" Header="Tools">
9394
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
9495
<StackPanel.Resources>

SOTFEdit/View/WeatherPage.xaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:local="clr-namespace:SOTFEdit.View"
7-
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
86
xmlns:viewModel="clr-namespace:SOTFEdit.ViewModel"
97
xmlns:infrastructure="clr-namespace:SOTFEdit.Infrastructure"
108
mc:Ignorable="d"

0 commit comments

Comments
 (0)