Skip to content

Commit 87927a9

Browse files
committed
actually save img data to new g1 element
1 parent 74cc120 commit 87927a9

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Gui/ViewModels/SubObjectTypes/ImageTableViewModel.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ void LoadSprite(string filename, SpriteOffset? offset = null)
265265
var match = Regex.Match(Path.GetFileNameWithoutExtension(filename), @".*?(\d+).*?");
266266
if (!match.Success)
267267
{
268-
Logger.Warning($"Couldn't parse sprite index from filename: \"{filename}\"");
268+
Logger.Error($"Couldn't parse sprite index from filename: \"{filename}\"");
269269
return;
270270
}
271271

@@ -274,7 +274,10 @@ void LoadSprite(string filename, SpriteOffset? offset = null)
274274

275275
if (index >= G1Provider.G1Elements.Count)
276276
{
277-
var newElement = new G1Element32(0, (int16_t)img.Width, (int16_t)img.Height, 0, 0, ~G1ElementFlags.IsRLECompressed, 0);
277+
var newElement = new G1Element32(0, (int16_t)img.Width, (int16_t)img.Height, 0, 0, G1ElementFlags.None, 0)
278+
{
279+
ImageData = PaletteMap.ConvertRgba32ImageToG1Data(img, G1ElementFlags.None)
280+
};
278281
G1Provider.G1Elements.Insert(index, newElement);
279282
Images.Insert(index, img); // update the UI
280283
}
@@ -306,16 +309,19 @@ public async Task ExportImages()
306309
}
307310

308311
var dirPath = dir.Path.LocalPath;
309-
if (Directory.Exists(dirPath))
312+
if (!Directory.Exists(dirPath))
310313
{
311-
var counter = 0;
312-
foreach (var image in Images)
313-
{
314-
var imageName = counter++.ToString(); // todo: use GetImageName from winforms project
315-
var path = Path.Combine(dir.Path.LocalPath, $"{imageName}.png");
316-
//logger.Debug($"Saving image to {path}");
317-
await image.SaveAsPngAsync(path);
318-
}
314+
return;
315+
}
316+
317+
Logger.Info($"Saving images to {dirPath}");
318+
319+
var counter = 0;
320+
foreach (var image in Images)
321+
{
322+
var imageName = counter++.ToString(); // todo: maybe use image name provider below (but number must still exist)
323+
var path = Path.Combine(dir.Path.LocalPath, $"{imageName}.png");
324+
await image.SaveAsPngAsync(path);
319325
}
320326
}
321327

0 commit comments

Comments
 (0)