@@ -79,6 +79,8 @@ public ImageTableViewModel(IHasG1Elements g1ElementProvider, IImageTableNameProv
79
79
. Subscribe ( _ => this . RaisePropertyChanged ( nameof ( Images ) ) ) ;
80
80
_ = this . WhenAnyValue ( o => o . SelectedImageIndex )
81
81
. Subscribe ( _ => this . RaisePropertyChanged ( nameof ( SelectedG1Element ) ) ) ;
82
+ _ = this . WhenAnyValue ( o => o . SelectedBitmapPreview )
83
+ . Subscribe ( _ => this . RaisePropertyChanged ( nameof ( SelectedBitmapPreviewBorder ) ) ) ;
82
84
_ = this . WhenAnyValue ( o => o . Images )
83
85
. Subscribe ( _ => this . RaisePropertyChanged ( nameof ( Images ) ) ) ;
84
86
_ = this . WhenAnyValue ( o => o . AnimationSpeed )
@@ -108,11 +110,10 @@ public ImageTableViewModel(IHasG1Elements g1ElementProvider, IImageTableNameProv
108
110
109
111
public IList < Bitmap > SelectedBitmaps { get ; set ; }
110
112
111
- [ Reactive ]
112
- public Bitmap SelectedBitmapPreview { get ; set ; }
113
+ [ Reactive ] public Bitmap SelectedBitmapPreview { get ; set ; }
114
+ public Avalonia . Size SelectedBitmapPreviewBorder => SelectedBitmapPreview == null ? new Avalonia . Size ( ) : new Avalonia . Size ( SelectedBitmapPreview . Size . Width + 2 , SelectedBitmapPreview . Size . Height + 2 ) ;
113
115
114
- [ Reactive ]
115
- public int AnimationWindowHeight { get ; set ; }
116
+ [ Reactive ] public int AnimationWindowHeight { get ; set ; }
116
117
117
118
void SelectionChanged ( object sender , SelectionModelSelectionChangedEventArgs e )
118
119
{
@@ -203,6 +204,7 @@ public IList<Bitmap?> Bitmaps
203
204
prevValue = list [ i ] ;
204
205
}
205
206
}
207
+
206
208
return list ;
207
209
}
208
210
}
@@ -224,60 +226,62 @@ public async Task ImportImages()
224
226
animationTimer . Stop ( ) ;
225
227
226
228
var folders = await PlatformSpecific . OpenFolderPicker ( ) ;
227
- var dir = folders . FirstOrDefault ( ) ;
228
- if ( dir == null )
229
+ using ( var dir = folders . FirstOrDefault ( ) )
229
230
{
230
- return ;
231
- }
232
-
233
- var dirPath = dir . Path . LocalPath ;
234
- if ( ! Directory . Exists ( dirPath ) )
235
- {
236
- return ;
237
- }
231
+ if ( dir == null )
232
+ {
233
+ return ;
234
+ }
238
235
239
- try
240
- {
241
- var offsetsFile = Path . Combine ( dirPath , "sprites.json" ) ;
242
- if ( File . Exists ( offsetsFile ) )
236
+ var dirPath = dir . Path . LocalPath ;
237
+ if ( ! Directory . Exists ( dirPath ) )
243
238
{
244
- // found blender folder
245
- var offsets = JsonSerializer . Deserialize < ICollection < SpriteOffset > > ( File . ReadAllText ( offsetsFile ) ) ; // sprites.json is an unnamed array so we need ICollection here, not IEnumerable
246
- Logger . Debug ( "Found sprites.json file, using that" ) ;
239
+ return ;
240
+ }
247
241
248
- if ( offsets ? . Count != G1Provider . G1Elements . Count )
242
+ try
243
+ {
244
+ var offsetsFile = Path . Combine ( dirPath , "sprites.json" ) ;
245
+ if ( File . Exists ( offsetsFile ) )
249
246
{
250
- Logger . Warning ( $ "Expected { G1Provider . G1Elements . Count } offsets, got { offsets ? . Count } offsets. Continue at your peril.") ;
247
+ // found blender folder
248
+ var offsets = JsonSerializer . Deserialize < ICollection < SpriteOffset > > ( File . ReadAllText ( offsetsFile ) ) ; // sprites.json is an unnamed array so we need ICollection here, not IEnumerable
249
+ Logger . Debug ( "Found sprites.json file, using that" ) ;
250
+
251
+ if ( offsets ? . Count != G1Provider . G1Elements . Count )
252
+ {
253
+ Logger . Warning ( $ "Expected { G1Provider . G1Elements . Count } offsets, got { offsets ? . Count } offsets. Continue at your peril.") ;
254
+ }
255
+
256
+ foreach ( var offset in offsets )
257
+ {
258
+ var filename = Path . Combine ( dirPath , offset . Path ) ;
259
+ LoadSprite ( filename , offset ) ;
260
+ }
251
261
}
252
-
253
- foreach ( var offset in offsets )
262
+ else
254
263
{
255
- var filename = Path . Combine ( dirPath , offset . Path ) ;
256
- LoadSprite ( filename , offset ) ;
264
+ Logger . Debug ( "No sprites.json file found" ) ;
265
+ var files = Directory . GetFiles ( dirPath , "*" , SearchOption . AllDirectories ) ;
266
+
267
+ if ( files . Length != G1Provider . G1Elements . Count )
268
+ {
269
+ Logger . Warning ( $ "Expected { G1Provider . G1Elements . Count } images, got { files . Length } images. Continue at your peril.") ;
270
+ }
271
+
272
+ foreach ( var filename in files )
273
+ {
274
+ LoadSprite ( filename ) ;
275
+ }
257
276
}
277
+
278
+ Logger . Debug ( "Import successful" ) ;
279
+ this . RaisePropertyChanged ( nameof ( Bitmaps ) ) ;
258
280
}
259
- else
281
+ catch ( Exception ex )
260
282
{
261
- Logger . Debug ( "No sprites.json file found" ) ;
262
- var files = Directory . GetFiles ( dirPath , "*" , SearchOption . AllDirectories ) ;
263
-
264
- if ( files . Length != G1Provider . G1Elements . Count )
265
- {
266
- Logger . Warning ( $ "Expected { G1Provider . G1Elements . Count } images, got { files . Length } images. Continue at your peril.") ;
267
- }
268
-
269
- foreach ( var filename in files )
270
- {
271
- LoadSprite ( filename ) ;
272
- }
283
+ Logger . Error ( ex ) ;
273
284
}
274
-
275
- Logger . Debug ( "Import successful" ) ;
276
- this . RaisePropertyChanged ( nameof ( Bitmaps ) ) ;
277
- }
278
- catch ( Exception ex )
279
- {
280
- Logger . Error ( ex ) ;
281
285
}
282
286
283
287
animationTimer . Start ( ) ;
0 commit comments