Skip to content

Commit 4ea3227

Browse files
committed
v1.8.0-beta4
- Sprite Editor; - Bug fixed: Keyboard shortcuts now work in the sprite editor - Export to MaskedSprites: - Added a warning when sprites do not meet the requirements for export to MaskedSprites: - 16x16 - Sprites with a mask - Even frames - The ‘Save’ button no longer closes the export window
1 parent 982e30e commit 4ea3227

File tree

8 files changed

+89
-11
lines changed

8 files changed

+89
-11
lines changed

ZXBStudio/DocumentEditors/ZXGraphics/SpriteEditor.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ private void _Initialize(string fileName)
342342
btnInk.Tapped += BtnInk_Tapped;
343343
UpdateColorPanel();
344344

345+
InitializeShortcuts();
346+
345347
this.AddHandler(KeyDownEvent, Keyboard_Down, handledEventsToo: true);
346348
this.Focus();
347349
grdProcesando.IsVisible = false;

ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia;
22
using Avalonia.Controls;
33
using Avalonia.Platform.Storage;
4+
using MsBox.Avalonia;
45
using System;
56
using System.Collections;
67
using System.Collections.Generic;
@@ -279,20 +280,29 @@ private void CreateExample_MaskedSprites()
279280
txtCode.Text = "";
280281
}
281282

283+
var sprite = sprites.ElementAt(0);
284+
var exportData = ExportManager.Export_Sprite_MaskedSprites(exportConfig, sprites);
285+
if (exportData.StartsWith("ERROR:"))
286+
{
287+
txtError.Text = exportData;
288+
txtError.IsVisible = true;
289+
return;
290+
}
291+
txtError.IsVisible = false;
292+
282293
var sb = new StringBuilder();
283294
switch (exportConfig.ExportDataType)
284295
{
285296
case ExportDataTypes.DIM:
286297
{
287-
var sprite = sprites.ElementAt(0);
288298
sb.AppendLine("'- Includes -----------------------------------------------");
289299
sb.AppendLine("#INCLUDE <retrace.bas>");
290300
sb.AppendLine("#INCLUDE \"maskedsprites.bas\"");
291301
sb.AppendLine("");
292302
sb.AppendLine("'- Sprites definition -------------------------------------");
293303
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
294304
Path.GetFileName(exportConfig.ExportFilePath)));
295-
sb.AppendLine(ExportManager.Export_Sprite_MaskedSprites(exportConfig, sprites));
305+
sb.AppendLine(exportData);
296306
sb.AppendLine("' - Init vars ---------------------------------------------");
297307
sb.AppendLine("#define NumberofMaskedSprites 1");
298308
sb.AppendLine("DIM sprDir, sprBackDir AS UInteger");
@@ -324,7 +334,6 @@ private void CreateExample_MaskedSprites()
324334

325335
case ExportDataTypes.ASM:
326336
{
327-
var sprite = sprites.ElementAt(0);
328337
sb.AppendLine("'- Includes -----------------------------------------------");
329338
sb.AppendLine("#INCLUDE <retrace.bas>");
330339
sb.AppendLine("#INCLUDE \"maskedsprites.bas\"");
@@ -358,7 +367,7 @@ private void CreateExample_MaskedSprites()
358367
sb.AppendLine("' - This section must not be executed --------------------");
359368
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
360369
Path.GetFileName(exportConfig.ExportFilePath)));
361-
sb.AppendLine(ExportManager.Export_Sprite_MaskedSprites(exportConfig, sprites));
370+
sb.AppendLine(exportData);
362371
}
363372
break;
364373

@@ -368,7 +377,6 @@ private void CreateExample_MaskedSprites()
368377
sb.AppendLine("#INCLUDE <putchars.bas>");
369378
sb.AppendLine("");
370379
sb.AppendLine("'- Draw sprite --------------------------------------------");
371-
var sprite = sprites.ElementAt(0);
372380
sb.AppendLine(string.Format(
373381
"putChars(10,5,{0},{1},@{2})",
374382
sprite.Width / 8,
@@ -395,7 +403,6 @@ private void CreateExample_MaskedSprites()
395403
sb.AppendLine("LOAD \"\" CODE");
396404
sb.AppendLine("");
397405
sb.AppendLine("'- Draw sprite --------------------------------------------");
398-
var sprite = sprites.ElementAt(0);
399406
sb.AppendLine(string.Format(
400407
"putChars(10,5,{0},{1},@{2})",
401408
sprite.Width / 8,
@@ -431,7 +438,7 @@ private void BtnSave_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)
431438
GetConfigFromUI();
432439
ServiceLayer.Export_SetConfigFile(fileName + ".zbs", exportConfig);
433440
Export();
434-
this.Close();
441+
//this.Close();
435442
}
436443

437444
private async void BtnOutputFile_Tapped(object? sender, Avalonia.Input.TappedEventArgs e)

ZXBStudio/DocumentEditors/ZXGraphics/SpritePatternEditor.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ private void SetAttribute(Pattern pattern, int x, int y)
475475

476476
private AttributeColor GetAttribute(Pattern pattern, int x, int y)
477477
{
478+
if(pattern.Attributes == null)
479+
{
480+
pattern.Attributes = new AttributeColor[(SpriteData.Width / 8) * (SpriteData.Height / 8)];
481+
}
478482
int cW = SpriteData.Width / 8;
479483
int cX = x / 8;
480484
int cY = y / 8;
@@ -1163,6 +1167,10 @@ private void GrdEditor_InvertColorsCell(double mx, double my)
11631167
var inkBak = PrimaryColorIndex;
11641168
var paperBak = SecondaryColorIndex;
11651169
var attr=GetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);
1170+
if (attr == null)
1171+
{
1172+
return;
1173+
}
11661174
PrimaryColorIndex = attr.Paper;
11671175
SecondaryColorIndex = attr.Ink;
11681176
SetAttribute(SpriteData.Patterns[SpriteData.CurrentFrame], x, y);

ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ExportManager : IZXDocumentBuilder
2828
public Guid[]? DependsOn => null;
2929

3030
private FileTypes fileType = FileTypes.Undefined;
31+
private static TextWriter OutputLog = null;
3132

3233
public bool Initialize(FileTypes fileType)
3334
{
@@ -38,6 +39,7 @@ public bool Initialize(FileTypes fileType)
3839

3940
public bool Build(string BuildPath, ZXBuildStage Stage, ZXBuildType BuildType, ZXProgram? program, TextWriter OutputLog)
4041
{
42+
ExportManager.OutputLog = OutputLog;
4143
if (!ServiceLayer.Initialized)
4244
{
4345
ServiceLayer.Initialize();
@@ -80,7 +82,10 @@ public bool Build(string BuildPath, ZXBuildStage Stage, ZXBuildType BuildType, Z
8082
case FileTypes.Sprite:
8183
{
8284
var sprites = CreateSprites(fileData);
83-
ExportSprites(exportConfig, sprites);
85+
if(!ExportSprites(exportConfig, sprites))
86+
{
87+
return false;
88+
}
8489
}
8590
break;
8691

@@ -442,6 +447,10 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable<Sprite> sprites
442447
break;
443448
case ExportTypes.MaskedSprites:
444449
exportedData = Export_Sprite_MaskedSprites(exportConfig, sprites);
450+
if(exportedData.StartsWith("ERROR:"))
451+
{
452+
return false;
453+
}
445454
createTextFile = true;
446455
break;
447456
default:
@@ -1065,6 +1074,11 @@ private static byte[] Export_Sprite_PutChars_GetBinaryData(IEnumerable<Sprite> s
10651074
/// <returns>string with the conversion commands for the export dialog samble textbox</returns>
10661075
public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnumerable<Sprite> sprites)
10671076
{
1077+
var res= Export_Sprite_MaskedSprites_Check(exportConfig, sprites);
1078+
if(res.StartsWith("ERROR:"))
1079+
{
1080+
return res;
1081+
}
10681082
switch (exportConfig.ExportDataType)
10691083
{
10701084
case ExportDataTypes.DIM:
@@ -1081,6 +1095,51 @@ public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnu
10811095
}
10821096

10831097

1098+
/// <summary>
1099+
/// Validates a collection of sprites to ensure that each sprite marked for export meets the required criteria
1100+
/// for masked sprite export.
1101+
/// </summary>
1102+
/// <remarks>A sprite is considered valid for masked export if it is masked, has an even number of
1103+
/// frames, and its dimensions are exactly 16x16 pixels. Only sprites with the export flag set are validated.
1104+
/// The method returns immediately upon finding the first invalid sprite.</remarks>
1105+
/// <param name="exportConfig">The export configuration settings that may influence validation requirements for the sprites.</param>
1106+
/// <param name="sprites">An enumerable collection of sprites to be validated for export readiness. Each sprite is checked for
1107+
/// masking, frame count, and dimensions if it is marked for export.</param>
1108+
/// <returns>A string indicating the result of the validation. Returns "OK" if all sprites are valid for export;
1109+
/// otherwise, returns an error message describing the first encountered issue.</returns>
1110+
private static string Export_Sprite_MaskedSprites_Check(ExportConfig exportConfig, IEnumerable<Sprite> sprites)
1111+
{
1112+
string txt = "";
1113+
foreach(var sprite in sprites)
1114+
{
1115+
if (sprite != null && sprite.Export)
1116+
{
1117+
if (!sprite.Masked)
1118+
{
1119+
txt=$"ERROR: Sprite {sprite.Name} is not masked.";
1120+
}
1121+
if (sprite.Frames % 2 != 0)
1122+
{
1123+
txt=$"ERROR: Sprite {sprite.Name} has an odd number of frames.";
1124+
}
1125+
if(sprite.Width!=16 || sprite.Height != 16)
1126+
{
1127+
txt=$"ERROR: Sprite {sprite.Name} has a size different than 16x16.";
1128+
}
1129+
if (!string.IsNullOrEmpty(txt))
1130+
{
1131+
if(OutputLog != null)
1132+
{
1133+
OutputLog.WriteLine(txt);
1134+
}
1135+
return txt;
1136+
}
1137+
}
1138+
}
1139+
return "OK";
1140+
}
1141+
1142+
10841143
private static byte[] Export_Sprite_MaskedSprites_GenerateData(ExportConfig exportConfig, Sprite sprite)
10851144
{
10861145
try

ZXBStudio/DocumentEditors/ZXTextEditor/Controls/ZXTextEditor.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ private void TextArea_Down(object? sender, Avalonia.Input.KeyEventArgs e)
421421
var commandId = ZXKeybMapper.GetCommandId(_docTypeId, e.Key, e.KeyModifiers);
422422

423423
if (commandId != null && _keybCommands.ContainsKey(commandId.Value))
424+
{
424425
_keybCommands[commandId.Value]();
426+
}
425427
}
426428

427429
#endregion

ZXBStudio/DocumentModel/Classes/ZXDocumentProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Avalonia.Platform.Storage;
1+
 using Avalonia.Platform.Storage;
22
using System;
33
using System.Collections.Generic;
44
using System.IO;

ZXBStudio/ZXBasicStudio.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Title>ZX Basic Studio</Title>
1414
<AssemblyVersion></AssemblyVersion>
1515
<Deterministic>False</Deterministic>
16-
<Version>1.8.0.3</Version>
16+
<Version>1.8.0.4</Version>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

ZXBStudio/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.0.3
1+
1.8.0.4

0 commit comments

Comments
 (0)