Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Goz3rr committed Mar 30, 2019
2 parents 60c5ba1 + 472edbb commit 5dcc720
Show file tree
Hide file tree
Showing 23 changed files with 562 additions and 63 deletions.
31 changes: 29 additions & 2 deletions SatisfactorySaveEditor/Converter/SaveNodeItemToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using SatisfactorySaveEditor.Model;

Expand All @@ -11,21 +13,46 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
if (!(value is SaveObjectModel saveNodeItem)) return string.Empty;

var totalCount = Traverse(saveNodeItem.Items, obj => obj.Items).Count(obj => obj.Items.Count == 0);
var count = saveNodeItem.Items.Count;
string formatString;

switch (count)
{
case 0:
return $"{saveNodeItem.Title}";
case 1:
return $"{saveNodeItem.Title} (1 entry)";
formatString = $"{saveNodeItem.Title} (1 entry, ";
break;
default:
formatString = $"{saveNodeItem.Title} ({count} entries, ";
break;
}

return $"{saveNodeItem.Title} ({count} entries)";
switch (totalCount)
{
case 1:
return formatString + $"{totalCount} object)";
default:
return formatString + $"{totalCount} objects)";
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}

public static IEnumerable<T> Traverse<T>(IEnumerable<T> items, Func<T, IEnumerable<T>> childSelector)
{
var stack = new Stack<T>(items);

while (stack.Any())
{
var next = stack.Pop();
yield return next;
foreach (var child in childSelector(next)) stack.Push(child);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Windows.Data;
using SatisfactorySaveEditor.ViewModel;
using SatisfactorySaveEditor.ViewModel.Property;
using SatisfactorySaveParser.PropertyTypes;

namespace SatisfactorySaveEditor.Converter
Expand All @@ -12,29 +13,29 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
switch (value)
{
case ArrayProperty arp:
case ArrayPropertyViewModel arp:
return $"Array ({AddViewModel.FromStringType(arp.Type)})";
case BoolProperty bop:
case BoolPropertyViewModel bop:
return "Boolean";
case ByteProperty byp:
case BytePropertyViewModel byp:
return "Byte";
case EnumProperty enp:
case EnumPropertyViewModel enp:
return "Enum";
case FloatProperty flp:
case FloatPropertyViewModel flp:
return "Float";
case IntProperty inp:
case IntPropertyViewModel inp:
return "Int";
case MapProperty map: // heh
case MapPropertyViewModel map: // heh
return "Map";
case NameProperty nap: // THESE NAMES KEEP GETTING BETTER
case NamePropertyViewModel nap: // THESE NAMES KEEP GETTING BETTER
return "Name";
case ObjectProperty obp:
case ObjectPropertyViewModel obp:
return "Object";
case StrProperty strip:
case StrPropertyViewModel strip:
return "String";
case StructProperty strup:
case StructPropertyViewModel strup:
return "Struct";
case TextProperty tep:
case TextPropertyViewModel tep:
return "text";
default:
throw new ArgumentOutOfRangeException(nameof(value), value, null);
Expand Down
19 changes: 17 additions & 2 deletions SatisfactorySaveEditor/Model/SaveObjectModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.ObjectModel;
using System.Linq;
using GalaSoft.MvvmLight;
using SatisfactorySaveEditor.Util;
using SatisfactorySaveEditor.ViewModel.Property;
using SatisfactorySaveParser;
using SatisfactorySaveParser.PropertyTypes;

namespace SatisfactorySaveEditor.Model
{
Expand All @@ -13,7 +15,8 @@ public class SaveObjectModel : ObservableObject
private bool isExpanded;

public ObservableCollection<SaveObjectModel> Items { get; } = new ObservableCollection<SaveObjectModel>();
public ObservableCollection<SerializedProperty> Fields => Model.DataFields;

public ObservableCollection<SerializedPropertyViewModel> Fields { get; }

public string Title
{
Expand Down Expand Up @@ -46,6 +49,8 @@ public SaveObjectModel(SaveObject model)
Model = model;
Title = model.InstanceName;
RootObject = model.RootObject;

Fields = new ObservableCollection<SerializedPropertyViewModel>(Model.DataFields.Select(PropertyViewModelMapper.Convert));
}

public SaveObjectModel(string title)
Expand Down Expand Up @@ -92,6 +97,16 @@ public virtual void ApplyChanges()
{
item.ApplyChanges();
}

// This is because the named only (pink) nodes aren't actually a valid object in the game
if (Model == null) return;

Model.DataFields.Clear();
foreach (var field in Fields)
{
field.ApplyChanges();
Model.DataFields.Add(field.Model);
}
}
}
}
14 changes: 14 additions & 0 deletions SatisfactorySaveEditor/SatisfactorySaveEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,22 @@
<Compile Include="Model\SaveObjectModel.cs" />
<Compile Include="Util\EditorTreeNode.cs" />
<Compile Include="Util\BindingProxy.cs" />
<Compile Include="Util\PropertyViewModelMapper.cs" />
<Compile Include="ViewModel\AddViewModel.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\Property\ArrayPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\BoolPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\BytePropertyViewModel.cs" />
<Compile Include="ViewModel\Property\EnumPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\FloatPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\IntPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\MapPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\NamePropertyViewModel.cs" />
<Compile Include="ViewModel\Property\ObjectPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\SerializedPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\StrPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\StructPropertyViewModel.cs" />
<Compile Include="ViewModel\Property\TextPropertyViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="View\PropertiesControl.xaml.cs">
<DependentUpon>PropertiesControl.xaml</DependentUpon>
Expand Down
42 changes: 42 additions & 0 deletions SatisfactorySaveEditor/Util/PropertyViewModelMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using SatisfactorySaveEditor.ViewModel.Property;
using SatisfactorySaveParser.PropertyTypes;

namespace SatisfactorySaveEditor.Util
{
public static class PropertyViewModelMapper
{
public static SerializedPropertyViewModel Convert(SerializedProperty property)
{
switch (property)
{
case ArrayProperty arp:
return new ArrayPropertyViewModel(arp);
case BoolProperty bop:
return new BoolPropertyViewModel(bop);
case ByteProperty byp:
return new BytePropertyViewModel(byp);
case EnumProperty enp:
return new EnumPropertyViewModel(enp);
case FloatProperty flp:
return new FloatPropertyViewModel(flp);
case IntProperty inp:
return new IntPropertyViewModel(inp);
case MapProperty map:
return new MapPropertyViewModel(map);
case NameProperty nap:
return new NamePropertyViewModel(nap);
case ObjectProperty obp:
return new ObjectPropertyViewModel(obp);
case StrProperty strip:
return new StrPropertyViewModel(strip);
case StructProperty strup:
return new StructPropertyViewModel(strup);
case TextProperty tep:
return new TextPropertyViewModel(tep);
default:
throw new ArgumentOutOfRangeException(nameof(property), property, null);
}
}
}
}
36 changes: 22 additions & 14 deletions SatisfactorySaveEditor/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
</Window.Resources>
<Window.InputBindings>
<KeyBinding Modifiers="Control" Key="O" Command="{Binding OpenCommand}" />
<KeyBinding Modifiers="Control" Key="S" Command="{Binding SaveCommand}" CommandParameter="False"/>
<KeyBinding Key="F12" Command="{Binding SaveCommand}" CommandParameter="True"/>
<KeyBinding Modifiers="Control" Key="S" Command="{Binding SaveCommand}">
<KeyBinding.CommandParameter>
<sys:Boolean>False</sys:Boolean>
</KeyBinding.CommandParameter>
</KeyBinding>
<KeyBinding Key="F12" Command="{Binding SaveCommand}">
<KeyBinding.CommandParameter>
<sys:Boolean>True</sys:Boolean>
</KeyBinding.CommandParameter>
</KeyBinding>
</Window.InputBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
Expand Down Expand Up @@ -130,23 +138,23 @@
<ContentControl.Resources>
<DataTemplate DataType="{x:Type model:SaveEntityModel}">
<DockPanel>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Title, FallbackValue='No item selected', StringFormat='Entity name: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding RootObject, FallbackValue='No item selected', StringFormat='Root: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Int4, FallbackValue='No item selected', StringFormat='Int4: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Int6, FallbackValue='No item selected', StringFormat='Int6: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Rotation, FallbackValue='No item selected', StringFormat='Rotation: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Position, FallbackValue='No item selected', StringFormat='Position: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Scale, FallbackValue='No item selected', StringFormat='Scale: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding ParentObjectName, FallbackValue='No item selected', StringFormat='ParentObjectName: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding ParentObjectRoot, FallbackValue='No item selected', StringFormat='ParentObjectRoot: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Title, StringFormat='Entity name: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding RootObject, StringFormat='Root: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Int4, StringFormat='Int4: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Int6, StringFormat='Int6: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Rotation, StringFormat='Rotation: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Position, StringFormat='Position: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding Scale, StringFormat='Scale: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding ParentObjectName, StringFormat='ParentObjectName: {0}'}"/>
<TextBlock TextWrapping="Wrap" DockPanel.Dock="Top" Text="{Binding ParentObjectRoot, StringFormat='ParentObjectRoot: {0}'}"/>
<view:PropertiesControl Properties="{Binding Fields}" AddPropertyCommand="{Binding Source={StaticResource Proxy}, Path=Data.AddPropertyCommand}"/>
</DockPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type model:SaveComponentModel}">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{Binding Title, FallbackValue='No item selected', StringFormat='Component name: {0}'}"/>
<TextBlock DockPanel.Dock="Top" Text="{Binding RootObject, FallbackValue='No item selected', StringFormat='Root: {0}'}"/>
<TextBlock DockPanel.Dock="Top" Text="{Binding ParentEntityName, FallbackValue='No item selected', StringFormat='ParentEntityName: {0}'}"/>
<TextBlock DockPanel.Dock="Top" Text="{Binding Title, StringFormat='Component name: {0}'}"/>
<TextBlock DockPanel.Dock="Top" Text="{Binding RootObject, StringFormat='Root: {0}'}"/>
<TextBlock DockPanel.Dock="Top" Text="{Binding ParentEntityName, StringFormat='ParentEntityName: {0}'}"/>
<view:PropertiesControl Properties="{Binding Fields}" AddPropertyCommand="{Binding Source={StaticResource Proxy}, Path=Data.AddPropertyCommand}"/>
</DockPanel>
</DataTemplate>
Expand Down
8 changes: 4 additions & 4 deletions SatisfactorySaveEditor/View/PropertiesControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using SatisfactorySaveParser.PropertyTypes;
using SatisfactorySaveEditor.ViewModel.Property;

namespace SatisfactorySaveEditor.View
{
Expand All @@ -22,13 +22,13 @@ public ICommand AddPropertyCommand
set => SetValue(AddPropertyCommandProperty, value);
}

public ObservableCollection<SerializedProperty> Properties
public ObservableCollection<SerializedPropertyViewModel> Properties
{
get => (ObservableCollection<SerializedProperty>)GetValue(PropertiesProperty);
get => (ObservableCollection<SerializedPropertyViewModel>)GetValue(PropertiesProperty);
set => SetValue(PropertiesProperty, value);
}

public static readonly DependencyProperty AddPropertyCommandProperty = DependencyProperty.Register("AddPropertyCommand", typeof(ICommand), typeof(PropertiesControl));
public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(ObservableCollection<SerializedProperty>), typeof(PropertiesControl));
public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(ObservableCollection<SerializedPropertyViewModel>), typeof(PropertiesControl));
}
}
Loading

0 comments on commit 5dcc720

Please sign in to comment.