Skip to content

Commit

Permalink
Implemented Save/Load. Incremented version number from 0.5.0 to 0.6.0…
Browse files Browse the repository at this point in the history
… for release.
  • Loading branch information
trippsc2 committed Mar 30, 2020
1 parent 6ac5a37 commit 87ac969
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 52 deletions.
42 changes: 28 additions & 14 deletions OpenTracker.Models/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace OpenTracker.Models
{
public class Mode : INotifyPropertyChanging, INotifyPropertyChanged
{
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;

private ItemPlacement? _itemPlacement;
public ItemPlacement? ItemPlacement
{
Expand Down Expand Up @@ -95,8 +98,31 @@ public bool? EnemyShuffle
}
}

public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
public Mode()
{
}

public Mode(Mode source)
{
ItemPlacement = source.ItemPlacement;
DungeonItemShuffle = source.DungeonItemShuffle;
WorldState = source.WorldState;
EntranceShuffle = source.EntranceShuffle;
BossShuffle = source.BossShuffle;
EnemyShuffle = source.EnemyShuffle;
}

private void OnPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
PropertyChanging.Invoke(this, new PropertyChangingEventArgs(propertyName));
}

private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public bool Validate(Mode gameMode)
{
Expand Down Expand Up @@ -145,17 +171,5 @@ public bool Validate(Mode gameMode)

return true;
}

private void OnPropertyChanging(string propertyName)
{
if (PropertyChanging != null)
PropertyChanging.Invoke(this, new PropertyChangingEventArgs(propertyName));
}

private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
1 change: 0 additions & 1 deletion OpenTracker.Models/OpenTracker.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon>triforce.ico</ApplicationIcon>
</PropertyGroup>

</Project>
Binary file removed OpenTracker.Models/triforce.ico
Binary file not shown.
22 changes: 11 additions & 11 deletions OpenTracker.Setup/OpenTracker.Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
"Entry"
{
"MsmKey" = "8:_582274CEB8A7425789CE7B6B45EFE16C"
"MsmKey" = "8:_8BEB0D6860DB4F80B56A45FAD1BDE151"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
Expand Down Expand Up @@ -189,15 +189,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:OpenTracker"
"ProductCode" = "8:{69BC09D7-A658-4CB4-A62C-53432514C370}"
"PackageCode" = "8:{F3B764AD-9DCE-48AA-A136-6058A7DB0D66}"
"ProductCode" = "8:{4D04BD5B-2D57-47E5-9852-30E687820805}"
"PackageCode" = "8:{C476505C-9AB8-4659-9C0C-5CE283C7DA0B}"
"UpgradeCode" = "8:{C98C2121-B4C5-473A-9B86-5407FEFFE8F1}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:TRUE"
"ProductVersion" = "8:0.5.0"
"ProductVersion" = "8:0.6.0"
"Manufacturer" = "8:OpenTracker"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
Expand Down Expand Up @@ -310,31 +310,31 @@
}
"Shortcut"
{
"{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_904FE0DE8C7E47E6B1BBC5E9A8C687F2"
"{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_077012C5F76F407DB79E7B88D8ABB09B"
{
"Name" = "8:OpenTracker"
"Arguments" = "8:"
"Description" = "8:"
"ShowCmd" = "3:1"
"IconIndex" = "3:0"
"Transitive" = "11:FALSE"
"Target" = "8:_582274CEB8A7425789CE7B6B45EFE16C"
"Target" = "8:_8BEB0D6860DB4F80B56A45FAD1BDE151"
"Folder" = "8:_68CF9C3C7353438A9C1B8145DC8FAE43"
"WorkingFolder" = "8:_B21EA2C01C014AC99A33B72F50C26B5D"
"Icon" = "8:_52B4232ADD464606B80710F676FAD771"
"Feature" = "8:"
}
"{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_FAE56B1DAFA643A4B47DD08F08E6CB9C"
"{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_2E82BC7017114BC3AFA6C98FCBDD9E07"
{
"Name" = "8:OpenTracker"
"Arguments" = "8:"
"Description" = "8:"
"ShowCmd" = "3:1"
"IconIndex" = "3:0"
"Transitive" = "11:FALSE"
"Target" = "8:_582274CEB8A7425789CE7B6B45EFE16C"
"Target" = "8:_8BEB0D6860DB4F80B56A45FAD1BDE151"
"Folder" = "8:_53C29DC8DB594D14845D067B17A97FCE"
"WorkingFolder" = "8:"
"WorkingFolder" = "8:_B21EA2C01C014AC99A33B72F50C26B5D"
"Icon" = "8:_52B4232ADD464606B80710F676FAD771"
"Feature" = "8:"
}
Expand Down Expand Up @@ -737,7 +737,7 @@
}
"ProjectOutput"
{
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_582274CEB8A7425789CE7B6B45EFE16C"
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_8BEB0D6860DB4F80B56A45FAD1BDE151"
{
"SourcePath" = "8:..\\OpenTracker\\obj\\Debug\\netcoreapp3.1\\OpenTracker.exe"
"TargetName" = "8:"
Expand All @@ -758,7 +758,7 @@
"IsolateTo" = "8:"
"ProjectOutputGroupRegister" = "3:1"
"OutputConfiguration" = "8:"
"OutputGroupCanonicalName" = "8:PublishItemsOutputGroup"
"OutputGroupCanonicalName" = "8:PublishItems"
"OutputProjectGuid" = "8:{9D32A24F-7FF0-4632-B663-5AD2D64A6C87}"
"ShowKeyOutput" = "11:TRUE"
"ExcludeFilters"
Expand Down
6 changes: 3 additions & 3 deletions OpenTracker/Actions/ClearLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public class ClearLocation : IUndoable
{
private readonly Game _game;
private readonly Location _location;
private List<int?> _previousLocationCounts;
private List<MarkingType?> _previousMarkings;
private List<Item> _markedItems;
private readonly List<int?> _previousLocationCounts;
private readonly List<MarkingType?> _previousMarkings;
private readonly List<Item> _markedItems;

public ClearLocation(Game game, Location location)
{
Expand Down
2 changes: 2 additions & 0 deletions OpenTracker/Interfaces/IMainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public interface IMainWindowVM
{
void SaveAppSettings();
void Save(string path);
void Open(string path);
}
}
12 changes: 6 additions & 6 deletions OpenTracker/OpenTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon>triforce.ico</ApplicationIcon>
<Win32Resource />
<Version>0.5.0</Version>
<Version>0.6.0</Version>
<Authors>Tripp</Authors>
<AssemblyVersion>0.5.0.0</AssemblyVersion>
<FileVersion>0.5.0.0</FileVersion>
<AssemblyVersion>0.6.0.0</AssemblyVersion>
<FileVersion>0.6.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<Compile Update="**\*.xaml.cs">
Expand Down Expand Up @@ -40,9 +40,9 @@
<None Remove="Views\SectionControl.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.9.6" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.6" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.6" />
<PackageReference Include="Avalonia" Version="0.9.4" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.4" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ThemeEditor.Controls.ColorPicker" Version="0.9.4" />
</ItemGroup>
Expand Down
91 changes: 89 additions & 2 deletions OpenTracker/ViewModels/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using OpenTracker.JsonConverters;
using OpenTracker.Models;
using OpenTracker.Models.Enums;
using OpenTracker.Models.Interfaces;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.IO;
using System.Reactive;
using System.Threading.Tasks;

namespace OpenTracker.ViewModels
{
Expand Down Expand Up @@ -524,12 +526,97 @@ private void Redo()
_undoRedoManager.Redo();
}

public void Save(string path)
{
if (File.Exists(path))
File.Delete(path);

SaveData saveData = new SaveData(_game);

string json = JsonConvert.SerializeObject(saveData);

File.WriteAllText(path, json);
}

public void Open(string path)
{
string jsonContent = File.ReadAllText(path);

SaveData saveData = JsonConvert.DeserializeObject<SaveData>(jsonContent);

_game.Mode.ItemPlacement = saveData.Mode.ItemPlacement;
_game.Mode.DungeonItemShuffle = saveData.Mode.DungeonItemShuffle;
_game.Mode.WorldState = saveData.Mode.WorldState;
_game.Mode.EntranceShuffle = saveData.Mode.EntranceShuffle;
_game.Mode.BossShuffle = saveData.Mode.BossShuffle;
_game.Mode.EnemyShuffle = saveData.Mode.EnemyShuffle;

foreach (ItemType item in saveData.ItemCounts.Keys)
_game.Items[item].SetCurrent(saveData.ItemCounts[item]);

foreach (LocationID location in saveData.LocationSectionCounts.Keys)
{
foreach (int i in saveData.LocationSectionCounts[location].Keys)
{
switch (_game.Locations[location].Sections[i])
{
case BossSection bossSection:

bossSection.Available = saveData.LocationSectionCounts[location][i] == 1;

break;
case EntranceSection entranceSection:

entranceSection.Available = saveData.LocationSectionCounts[location][i] == 1;

break;
case ItemSection itemSection:

itemSection.Available = saveData.LocationSectionCounts[location][i];

break;
}
}
}

foreach (LocationID location in saveData.LocationSectionMarkings.Keys)
{
foreach (int i in saveData.LocationSectionMarkings[location].Keys)
{
_game.Locations[location].Sections[i].Marking =
saveData.LocationSectionMarkings[location][i];
}
}

foreach (LocationID location in saveData.PrizePlacements.Keys)
{
if (saveData.PrizePlacements[location] == null)
_game.Locations[location].BossSection.Prize = null;
else
{
_game.Locations[location].BossSection.Prize =
_game.Items[saveData.PrizePlacements[location].Value];
}
}

foreach (LocationID location in saveData.BossPlacements.Keys)
{
if (saveData.BossPlacements[location] == null)
_game.Locations[location].BossSection.Boss = null;
else
{
_game.Locations[location].BossSection.Boss =
_game.Bosses[saveData.BossPlacements[location].Value];
}
}
}

private void ToggleDisplayAllLocations()
{
_appSettings.DisplayAllLocations = !_appSettings.DisplayAllLocations;
}

public async void Reset()
public async Task Reset()
{
bool? result = await _dialogService.ShowDialog(
new MessageBoxDialogVM("Warning",
Expand All @@ -539,7 +626,7 @@ public async void Reset()
_game.Reset();
}

public async void ColorSelect()
public async Task ColorSelect()
{
bool? result = await _dialogService.ShowDialog(_appSettings);
}
Expand Down
Loading

0 comments on commit 87ac969

Please sign in to comment.