Skip to content

Commit

Permalink
Added AppDataDirectory to App. Moved AvailableTemplates to AppViewMod…
Browse files Browse the repository at this point in the history
…el. ViewModel in App renamed to CommandsViewModel. Added AppViewmodel as ViewModel.

#22
#23
  • Loading branch information
TheHeadmaster committed Jul 30, 2024
1 parent 634ee6e commit 34ab9f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
29 changes: 24 additions & 5 deletions Horizon/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Horizon.ObjectModel;
using Horizon.View.Windows;
using Horizon.View.Windows;
using Horizon.ViewModel;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
Expand Down Expand Up @@ -53,17 +52,37 @@ public static string UserDirectory
?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? "unknown-alpha";

/// <inheritdoc cref="CommandsViewModel" />
/// <inheritdoc cref="ViewModel.CommandsViewModel" />
[Reactive]
public static CommandsViewModel ViewModel { get; } = new CommandsViewModel();
public static CommandsViewModel CommandsViewModel { get; } = new();

public static List<ProjectTemplate> AvailableTemplates { get; set; } = [new() { Name = "Starbound Mod Project", Description = "A mod project for the game Starbound", Tags = ["Starbound", "Mod"] }];
[Reactive]
public static AppViewModel ViewModel { get; } = new();

public static string AppDataDirectory
{
get
{
if (appDataDirectory is null)
{
appDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Horizon");
if (!Directory.Exists(appDataDirectory))
{
Directory.CreateDirectory(appDataDirectory);
}
}

return appDataDirectory;
}
}

/// <summary>
/// The workspace.
/// </summary>
private static Workspace? workspace;

private static string? appDataDirectory;

/// <summary>
/// Gets all the startup tasks that run while the splash screen is displayed.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Horizon/View/Controls/MainMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public MainMenu()
this.NewProjectMenuItem.Events()
.Click
.Select(x => new Unit())
.InvokeCommand(App.ViewModel, x => x.NewProjectDialog)
.InvokeCommand(App.CommandsViewModel, x => x.NewProjectDialog)
.DisposeWith(dispose);
});
}
Expand Down
2 changes: 1 addition & 1 deletion Horizon/View/Windows/Workspace.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Workspace()
/// <param name="dispose">The disposable.</param>
private void Interactions(CompositeDisposable dispose)
{
App.ViewModel
App.CommandsViewModel
.NewProjectDialogInteraction
.RegisterHandler(interaction =>
{
Expand Down
4 changes: 3 additions & 1 deletion Horizon/ViewModel/NewProjectWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Nito.Disposables.Internals;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using System.Collections.ObjectModel;
using System.IO;
using System.Reactive.Linq;

Expand Down Expand Up @@ -68,5 +69,6 @@ public NewProjectWindowViewModel()
[Reactive]
public ProjectFile Project { get; set; } = new() { Name = "Project Name", FilePath = Path.Combine(App.UserDirectory, "Project.horizon") };

public List<ProjectTemplate> AvailableTemplates { get; init; } = [];
[Reactive]
public ObservableCollection<ProjectTemplate> AvailableTemplates { get; init; } = [];
}

0 comments on commit 34ab9f5

Please sign in to comment.