diff --git a/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml b/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml
index fa3e3c2..c5321e1 100644
--- a/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml
+++ b/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml
@@ -52,7 +52,7 @@
-
+
You have not selected any sprite to export. Check the "Include in the export" box of the sprites you want to include in the export.
diff --git a/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs b/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs
index 0407678..4d64348 100644
--- a/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs
+++ b/ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs
@@ -178,6 +178,19 @@ private void CreateExample_PutChars()
txtCode.Text = "";
}
+ var sprite = sprites.ElementAt(0);
+ var res = ExportManager.Export_Sprite_PutChars(exportConfig, sprites);
+ if (res.StartsWith("ERROR:"))
+ {
+ txtError.Text = res;
+ txtError.IsVisible = true;
+ return;
+ }
+ else
+ {
+ txtError.IsVisible = false;
+ }
+
var sb = new StringBuilder();
switch (exportConfig.ExportDataType)
{
@@ -188,11 +201,10 @@ private void CreateExample_PutChars()
sb.AppendLine("");
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
Path.GetFileName(exportConfig.ExportFilePath)));
- sb.AppendLine(ExportManager.Export_Sprite_PutChars(exportConfig, sprites));
+ sb.AppendLine(res);
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
- var sprite = sprites.ElementAt(0);
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2}{3}({4}))",
sprite.Width / 8,
@@ -210,7 +222,6 @@ private void CreateExample_PutChars()
sb.AppendLine("#INCLUDE ");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
- var sprite = sprites.ElementAt(0);
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2}{3})",
sprite.Width / 8,
@@ -221,7 +232,7 @@ private void CreateExample_PutChars()
sb.AppendLine("' This section must not be executed");
sb.AppendLine(string.Format("' Can use: #INCLUDE \"{0}\"",
Path.GetFileName(exportConfig.ExportFilePath)));
- sb.AppendLine(ExportManager.Export_Sprite_PutChars(exportConfig, sprites));
+ sb.AppendLine(res);
}
break;
@@ -231,7 +242,6 @@ private void CreateExample_PutChars()
sb.AppendLine("#INCLUDE ");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
- var sprite = sprites.ElementAt(0);
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2})",
sprite.Width / 8,
@@ -258,7 +268,6 @@ private void CreateExample_PutChars()
sb.AppendLine("LOAD \"\" CODE");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
- var sprite = sprites.ElementAt(0);
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2})",
sprite.Width / 8,
diff --git a/ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs b/ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs
index 6882bd1..b0c94ef 100644
--- a/ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs
+++ b/ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs
@@ -82,10 +82,10 @@ public bool Build(string BuildPath, ZXBuildStage Stage, ZXBuildType BuildType, Z
case FileTypes.Sprite:
{
var sprites = CreateSprites(fileData);
- if(!ExportSprites(exportConfig, sprites))
+ if (!ExportSprites(exportConfig, sprites))
{
return false;
- }
+ }
}
break;
@@ -447,7 +447,7 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable sprites
break;
case ExportTypes.MaskedSprites:
exportedData = Export_Sprite_MaskedSprites(exportConfig, sprites);
- if(exportedData.StartsWith("ERROR:"))
+ if (exportedData.StartsWith("ERROR:"))
{
return false;
}
@@ -482,6 +482,15 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable sprites
/// string with the conversion commands for the export dialog samble textbox
public static string Export_Sprite_PutChars(ExportConfig exportConfig, IEnumerable sprites)
{
+ string res = Export_Sprite_PutChars_Check(exportConfig, sprites);
+ if (res.StartsWith("ERROR:"))
+ {
+ if (OutputLog != null)
+ {
+ OutputLog.WriteLine(res);
+ }
+ return res;
+ }
switch (exportConfig.ExportDataType)
{
case ExportDataTypes.DIM:
@@ -497,6 +506,26 @@ public static string Export_Sprite_PutChars(ExportConfig exportConfig, IEnumerab
}
}
+ private static string Export_Sprite_PutChars_Check(ExportConfig exportConfig, IEnumerable sprites)
+ {
+ foreach (var sprite in sprites)
+ {
+ if (sprite == null)
+ {
+ continue;
+ }
+ if (sprite.Masked)
+ {
+ if ((sprite.Patterns.Count % 2) != 0)
+ {
+ var name = sprite.Name.Replace(' ', '_');
+ return $"ERROR: The number of frames in the sprite \"{name}\" must be even if it has a mask.";
+ }
+ }
+ }
+ return "OK";
+ }
+
#region DIM
@@ -674,19 +703,31 @@ public static string Export_Sprite_PutChars_DIM(ExportConfig exportConfig, IEnum
}
else
{
- // Mulriple sprites attributes
+ // Multiple sprites attributes
// Header
+ int fr = sprite.Masked ? (sprite.Frames / 2) : (sprite.Frames - 1);
sb.AppendLine(string.Format(
"DIM {0}{1}_Attr({2},{3}) AS UByte => {{ _",
exportConfig.LabelName,
sprite.Name.Replace(" ", "_"),
- sprite.Frames - 1 + min,
+ fr - 1 + min,
((sprite.Width / 8) * (sprite.Height / 8)) - 1 + min));
// Data
- for (int n = 0; n < sprite.Patterns.Count; n++)
+ if (sprite.Masked)
{
- var data = Export_Sprite_PutChars_Attribute(sprite, n, exportConfig, 0);
- sb.Append(data);
+ for (int n = 0; n < sprite.Patterns.Count; n += 2)
+ {
+ var data = Export_Sprite_PutChars_Attribute(sprite, n, exportConfig, 0);
+ sb.Append(data);
+ }
+ }
+ else
+ {
+ for (int n = 0; n < sprite.Patterns.Count; n++)
+ {
+ var data = Export_Sprite_PutChars_Attribute(sprite, n, exportConfig, 0);
+ sb.Append(data);
+ }
}
// Footer
sb.Append(" _\r\n}");
@@ -775,19 +816,37 @@ private static string Export_Sprite_PutChars_Attribute(Sprite sprite, int n, Exp
return "";
}
- if (sprite.Frames > 1)
+ if (sprite.Masked)
{
- if (n > firstItem)
+ if (sprite.Frames > 2)
{
- sb.AppendLine(", _");
+ if (n > firstItem)
+ {
+ sb.AppendLine(", _");
+ }
+ sb.AppendLine("\t{ _");
}
- sb.AppendLine("\t{ _");
}
+ else
+ if (sprite.Frames > 1)
+ {
+ if (n > firstItem)
+ {
+ sb.AppendLine(", _");
+ }
+ sb.AppendLine("\t{ _");
+ }
int col = 0;
int row = 0;
+ int max = (sprite.Width / 8) * (sprite.Height / 8);
+ int idx = 0;
foreach (var d in pattern.Attributes)
{
+ if (idx++ >= max)
+ {
+ break;
+ }
if (col == 0)
{
if (row == 0)
@@ -984,8 +1043,14 @@ private static string Export_Sprite_PutChars_Attribute_ASM(Sprite sprite, int n,
int col = 0;
int row = 0;
+ int max = (sprite.Width / 8) * (sprite.Height / 8);
+ int idx = 0;
foreach (var d in pattern.Attributes)
{
+ if (idx++ >= max)
+ {
+ break;
+ }
if (col == 0)
{
if (row == 0)
@@ -1074,9 +1139,9 @@ private static byte[] Export_Sprite_PutChars_GetBinaryData(IEnumerable s
/// string with the conversion commands for the export dialog samble textbox
public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnumerable sprites)
{
- var res= Export_Sprite_MaskedSprites_Check(exportConfig, sprites);
- if(res.StartsWith("ERROR:"))
- {
+ var res = Export_Sprite_MaskedSprites_Check(exportConfig, sprites);
+ if (res.StartsWith("ERROR:"))
+ {
return res;
}
switch (exportConfig.ExportDataType)
@@ -1110,28 +1175,28 @@ public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnu
private static string Export_Sprite_MaskedSprites_Check(ExportConfig exportConfig, IEnumerable sprites)
{
string txt = "";
- foreach(var sprite in sprites)
+ foreach (var sprite in sprites)
{
if (sprite != null && sprite.Export)
{
if (!sprite.Masked)
{
- txt=$"ERROR: Sprite {sprite.Name} is not masked.";
+ txt = $"ERROR: Sprite {sprite.Name} is not masked.";
}
if (sprite.Frames % 2 != 0)
{
- txt=$"ERROR: Sprite {sprite.Name} has an odd number of frames.";
+ txt = $"ERROR: Sprite {sprite.Name} has an odd number of frames.";
}
- if(sprite.Width!=16 || sprite.Height != 16)
+ if (sprite.Width != 16 || sprite.Height != 16)
{
- txt=$"ERROR: Sprite {sprite.Name} has a size different than 16x16.";
+ txt = $"ERROR: Sprite {sprite.Name} has a size different than 16x16.";
}
if (!string.IsNullOrEmpty(txt))
{
- if(OutputLog != null)
+ if (OutputLog != null)
{
OutputLog.WriteLine(txt);
- }
+ }
return txt;
}
}
@@ -1202,7 +1267,7 @@ public static string Export_Sprite_MaskedSprites_DIM(ExportConfig exportConfig,
else
{
sb.AppendLine(
- $"DIM {exportConfig.LabelName}{sprite.Name.Replace(" ", "_")}({(sprite.Frames/2)-1},63) AS UByte => {{ _");
+ $"DIM {exportConfig.LabelName}{sprite.Name.Replace(" ", "_")}({(sprite.Frames / 2) - 1},63) AS UByte => {{ _");
}
var rawData = Export_Sprite_MaskedSprites_GenerateData(exportConfig, sprite);
int i = 0;
diff --git a/ZXBStudio/ZXBasicStudio.csproj b/ZXBStudio/ZXBasicStudio.csproj
index 9cada25..2db2105 100644
--- a/ZXBStudio/ZXBasicStudio.csproj
+++ b/ZXBStudio/ZXBasicStudio.csproj
@@ -13,7 +13,7 @@
ZX Basic Studio
False
- 1.8.0.4
+ 1.8.0.5
diff --git a/ZXBStudio/version.txt b/ZXBStudio/version.txt
index 72e7a6e..655bd5f 100644
--- a/ZXBStudio/version.txt
+++ b/ZXBStudio/version.txt
@@ -1 +1 @@
-1.8.0.4
\ No newline at end of file
+1.8.0.5
\ No newline at end of file