Skip to content

Commit 8427fa0

Browse files
committed
export sprites.json when exporting images
1 parent 060f49b commit 8427fa0

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

Gui/ViewModels/MainWindowViewModel.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ public MainWindowViewModel()
101101
});
102102

103103
_ = CurrentTabModel.WhenAnyValue(o => o.SelectedDocument)
104-
.Subscribe((x) =>
105-
{
106-
FolderTreeViewModel.CurrentlySelectedObject = x?.CurrentFile;
107-
});
104+
.Subscribe((x) => FolderTreeViewModel.CurrentlySelectedObject = x?.CurrentFile);
108105

109106
ObjDataItems = new ObservableCollection<MenuItemViewModel>(Model.Settings.ObjDataDirectories
110107
.Select(x => new MenuItemViewModel(

Gui/ViewModels/SubObjectTypes/ImageTableViewModel.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia.Controls.Selection;
22
using Avalonia.Media.Imaging;
33
using Avalonia.Threading;
4+
using Common.Json;
45
using DynamicData;
56
using OpenLoco.Common;
67
using OpenLoco.Common.Logging;
@@ -134,9 +135,9 @@ public ImageTableViewModel(IHasG1Elements g1ElementProvider, IImageTableNameProv
134135
_ = this.WhenAnyValue(o => o.AnimationSpeed)
135136
.Subscribe(_ => UpdateAnimationSpeed());
136137

137-
ImportImagesCommand = ReactiveCommand.Create(ImportImages);
138-
ExportImagesCommand = ReactiveCommand.Create(ExportImages);
139-
ReplaceImageCommand = ReactiveCommand.Create(ReplaceImage);
138+
ImportImagesCommand = ReactiveCommand.CreateFromTask(ImportImages);
139+
ExportImagesCommand = ReactiveCommand.CreateFromTask(ExportImages);
140+
ReplaceImageCommand = ReactiveCommand.CreateFromTask(ReplaceImage);
140141
CropAllImagesCommand = ReactiveCommand.Create(CropAllImages);
141142

142143
CreateSelectionModel();
@@ -357,12 +358,24 @@ public async Task ExportImages()
357358
Logger.Info($"Saving images to {dirPath}");
358359

359360
var counter = 0;
361+
var offsets = new List<SpriteOffset>();
362+
360363
foreach (var image in Images)
361364
{
362-
var imageName = counter++.ToString(); // todo: maybe use image name provider below (but number must still exist)
363-
var path = Path.Combine(dir.Path.LocalPath, $"{imageName}.png");
365+
var g1Element = G1Provider.G1Elements[counter];
366+
var imageName = counter.ToString(); // todo: maybe use image name provider below (but number must still exist)
367+
counter++;
368+
369+
var fileName = $"{imageName}.png";
370+
var path = Path.Combine(dir.Path.LocalPath, fileName);
364371
await image.SaveAsPngAsync(path);
372+
373+
offsets.Add(new SpriteOffset(fileName, g1Element.XOffset, g1Element.YOffset));
365374
}
375+
376+
var offsetsFile = Path.Combine(dir.Path.LocalPath, "sprites.json");
377+
Logger.Info($"Saving sprite offsets to {offsetsFile}");
378+
await JsonFile.SerializeToFileAsync(offsets, offsetsFile);
366379
}
367380

368381
public void CropAllImages()

0 commit comments

Comments
 (0)