Skip to content

Commit b3f4bbb

Browse files
committed
add support for all 3 hardcoded openloco game object folders
1 parent 646582e commit b3f4bbb

File tree

5 files changed

+81
-6
lines changed

5 files changed

+81
-6
lines changed

Gui/EditorSettings.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ public HashSet<string> ObjDataDirectories
3838

3939
public string DownloadFolder { get; set; } = string.Empty;
4040

41+
public string AppDataObjDataFolder { get; set; } = string.Empty;
42+
public string LocomotionObjDataFolder { get; set; } = string.Empty;
43+
public string OpenLocoObjDataFolder { get; set; } = string.Empty;
44+
45+
public string GetGameObjDataFolder(GameObjDataFolder folder)
46+
=> folder switch
47+
{
48+
GameObjDataFolder.AppData => AppDataObjDataFolder,
49+
GameObjDataFolder.Locomotion => LocomotionObjDataFolder,
50+
GameObjDataFolder.OpenLoco => OpenLocoObjDataFolder,
51+
_ => throw new NotImplementedException(),
52+
};
53+
4154
[JsonIgnore]
4255
public string IndexFileName
4356
=> GetObjDataFullPath(ObjectIndex.DefaultIndexFileName);

Gui/GameObjDataFolder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace OpenLoco.Gui
2+
{
3+
public enum GameObjDataFolder { AppData, Locomotion, OpenLoco }
4+
}

Gui/ViewModels/DatTypes/DatObjectEditorViewModel.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace OpenLoco.Gui.ViewModels
2222
{
23+
2324
public class DatObjectEditorViewModel : BaseLocoFileViewModel
2425
{
2526
[Reactive]
@@ -45,6 +46,12 @@ public class DatObjectEditorViewModel : BaseLocoFileViewModel
4546
public ReactiveCommand<Unit, Unit> ViewHexCommand { get; }
4647
public Interaction<HexWindowViewModel, HexWindowViewModel?> HexViewerShowDialog { get; }
4748

49+
public ReactiveCommand<GameObjDataFolder, Unit> CopyToGameObjDataCommand { get; }
50+
[Reactive]
51+
public GameObjDataFolder LastGameObjDataFolder { get; set; } = GameObjDataFolder.Locomotion;
52+
[Reactive]
53+
public string LastGameObjDataFolderText { get; set; } = "Copy to Locomotion game folder";
54+
4855
//public ReactiveCommand<Unit, ObjectIndexEntry?> SelectObjectCommand { get; }
4956
public Interaction<ObjectSelectionWindowViewModel, ObjectSelectionWindowViewModel?> SelectObjectShowDialog { get; }
5057

@@ -64,6 +71,28 @@ public DatObjectEditorViewModel(FileSystemItemBase currentFile, ObjectEditorMode
6471
_ = await HexViewerShowDialog.Handle(vm);
6572
});
6673

74+
CopyToGameObjDataCommand = ReactiveCommand.Create((GameObjDataFolder targetFolder) =>
75+
{
76+
var folder = model.Settings.GetGameObjDataFolder(targetFolder);
77+
if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
78+
{
79+
logger.Error($"The specified [{targetFolder}] ObjData directory is invalid: \"{folder}\"");
80+
return;
81+
}
82+
83+
try
84+
{
85+
File.Copy(currentFile.Filename, Path.Combine(folder, Path.GetFileName(currentFile.Filename)));
86+
logger.Info($"Copied {Path.GetFileName(currentFile.Filename)} to [[{targetFolder}]] {folder}");
87+
LastGameObjDataFolder = targetFolder;
88+
LastGameObjDataFolderText = $"Copy to {LastGameObjDataFolder} game folder";
89+
}
90+
catch (Exception ex)
91+
{
92+
logger.Error($"Could not copy {currentFile.Filename} to {folder}:", ex);
93+
}
94+
});
95+
6796
SelectObjectShowDialog = new();
6897
_ = SelectObjectShowDialog.RegisterHandler(DoShowDialogAsync<ObjectSelectionWindowViewModel, ObjectSelectionWindow>);
6998

Gui/ViewModels/EditorSettingsWindowViewModel.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ public EditorSettingsWindowViewModel(EditorSettings settings)
2222
ServerAddressHttp = settings.ServerAddressHttp;
2323
ServerAddressHttps = settings.ServerAddressHttps;
2424
DownloadFolder = settings.DownloadFolder;
25-
ObjDataDirectory = settings.ObjDataDirectory;
25+
CurrentObjDataFolder = settings.ObjDataDirectory;
2626
ObjDataDirectories = settings.ObjDataDirectories.ToBindingList();
27+
28+
AppDataObjDataFolder = settings.AppDataObjDataFolder;
29+
LocomotionObjDataFolder = settings.LocomotionObjDataFolder;
30+
OpenLocoObjDataFolder = settings.OpenLocoObjDataFolder;
2731
}
2832

2933
public void Commit()
@@ -34,22 +38,37 @@ public void Commit()
3438
_Settings.ServerAddressHttp = ServerAddressHttp;
3539
_Settings.ServerAddressHttps = ServerAddressHttps;
3640
_Settings.DownloadFolder = DownloadFolder;
37-
_Settings.ObjDataDirectory = ObjDataDirectory;
41+
_Settings.ObjDataDirectory = CurrentObjDataFolder;
3842
_Settings.ObjDataDirectories = [.. ObjDataDirectories];
43+
44+
_Settings.AppDataObjDataFolder = AppDataObjDataFolder;
45+
_Settings.LocomotionObjDataFolder = LocomotionObjDataFolder;
46+
_Settings.OpenLocoObjDataFolder = OpenLocoObjDataFolder;
3947
}
4048

4149
[Reactive, Category("Misc"), DisplayName("Allow saving as vanilla object"), Description("If enabled, the editor will allow saving objects with \"Vanilla\" flag set. If disabled, the object will be forcefully saved as \"Custom\" instead.")]
4250
public bool AllowSavingAsVanillaObject { get; set; }
4351

4452
#region Object Folders
4553

46-
[Reactive, PathBrowsable(PathBrowsableType.Directory), Category("Object Folders"), DisplayName("Downloads"), Description("The folder to store downloaded objects")]
54+
const string GameObjectFolderCategory = "Folders OpenLoco can use objects from";
55+
const string UserObjectFolderCategory = "Folders where you store custom objects";
56+
57+
[Reactive, PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("AppData ObjData Folder"), Description("The ObjData folder in %AppData%\\OpenLoco\\objects.")]
58+
public string AppDataObjDataFolder { get; set; } = string.Empty;
59+
60+
[Reactive, PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("Locomotion ObjData Folder"), Description("The ObjData folder in your Locomotion installation.")]
61+
public string LocomotionObjDataFolder { get; set; } = string.Empty;
62+
[Reactive, PathBrowsable(PathBrowsableType.Directory), Category(GameObjectFolderCategory), DisplayName("OpenLoco ObjData Folder"), Description("The ObjData folder in the OpenLoco\\Objects directory.")]
63+
public string OpenLocoObjDataFolder { get; set; } = string.Empty;
64+
65+
[Reactive, PathBrowsable(PathBrowsableType.Directory), Category(UserObjectFolderCategory), DisplayName("Downloads"), Description("The folder to store downloaded objects.")]
4766
public string DownloadFolder { get; set; } = string.Empty;
4867

49-
[Reactive, ReadOnly(true), Category("Object Folders"), DisplayName("Current ObjectData folder"), Description("The currently-selected ObjectData folder. This is readonly and only used to remember the previous location when you start up the editor.")]
50-
public string ObjDataDirectory { get; set; }
68+
[Reactive, ReadOnly(true), Category(UserObjectFolderCategory), DisplayName("Current ObjectData folder"), Description("The currently-selected ObjectData folder. This is readonly and only used to remember the previous location when you start up the editor.")]
69+
public string CurrentObjDataFolder { get; set; }
5170

52-
[Reactive, Category("Object Folders"), DisplayName("ObjectData folders"), Description("The list of all ObjectData folders.")]
71+
[Reactive, Category(UserObjectFolderCategory), DisplayName("ObjectData folders"), Description("The list of all ObjectData folders.")]
5372
public BindingList<string> ObjDataDirectories { get; set; }
5473

5574
#endregion

Gui/Views/DatObjectEditorView.axaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:vm="using:OpenLoco.Gui.ViewModels"
7+
xmlns:gui="using:OpenLoco.Gui"
78
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
89
x:Class="OpenLoco.Gui.Views.DatObjectEditorView"
910
x:DataType="vm:DatObjectEditorViewModel">
@@ -13,6 +14,15 @@
1314
<StackPanel Grid.Row="0" Grid.ColumnSpan="3" Orientation="Horizontal">
1415
<Button Margin="4" Command="{Binding ExportUncompressedCommand}" ToolTip.Tip="Equivalent to saving the object with 'Uncompressed' encoding">Export as uncompressed DAT file</Button>
1516
<Button Margin="4" Command="{Binding ViewHexCommand}">Hex Viewer</Button>
17+
<SplitButton Content="{Binding LastGameObjDataFolderText}" Command="{Binding CopyToGameObjDataCommand}" CommandParameter="{Binding LastGameObjDataFolder}" >
18+
<SplitButton.Flyout>
19+
<MenuFlyout Placement="Bottom">
20+
<MenuItem Header="Copy to AppData game folder" Command="{Binding CopyToGameObjDataCommand}" CommandParameter="{x:Static gui:GameObjDataFolder.AppData}"/>
21+
<MenuItem Header="Copy to Locomotion game folder" Command="{Binding CopyToGameObjDataCommand}" CommandParameter="{x:Static gui:GameObjDataFolder.Locomotion}"/>
22+
<MenuItem Header="Copy to OpenLoco game folder" Command="{Binding CopyToGameObjDataCommand}" CommandParameter="{x:Static gui:GameObjDataFolder.OpenLoco}"/>
23+
</MenuFlyout>
24+
</SplitButton.Flyout>
25+
</SplitButton>
1626
</StackPanel>
1727
<TabControl Grid.Column="0" Grid.Row="1">
1828
<TabControl.Styles>

0 commit comments

Comments
 (0)