Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<CheckBox Name="chkAttr" Grid.Row="5" Grid.Column="1" Classes="dialog"></CheckBox>
</Grid>

<TextBlock Name="txtError" FontSize="14" Foreground="Red" Margin="0,16,0,16" IsVisible="False">
<TextBlock Name="txtError" FontSize="14" Foreground="Red" Margin="0,16,0,16" TextWrapping="Wrap" IsVisible="False">
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.
</TextBlock>
<TextBlock FontSize="14" Margin="0,16,0,0">
Expand Down
21 changes: 15 additions & 6 deletions ZXBStudio/DocumentEditors/ZXGraphics/SpriteExportDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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,
Expand All @@ -210,7 +222,6 @@ private void CreateExample_PutChars()
sb.AppendLine("#INCLUDE <putchars.bas>");
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,
Expand All @@ -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;

Expand All @@ -231,7 +242,6 @@ private void CreateExample_PutChars()
sb.AppendLine("#INCLUDE <putchars.bas>");
sb.AppendLine("");
sb.AppendLine("'- Draw sprite --------------------------------------------");
var sprite = sprites.ElementAt(0);
sb.AppendLine(string.Format(
"putChars(10,5,{0},{1},@{2})",
sprite.Width / 8,
Expand All @@ -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,
Expand Down
111 changes: 88 additions & 23 deletions ZXBStudio/DocumentEditors/ZXGraphics/log/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -447,7 +447,7 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable<Sprite> sprites
break;
case ExportTypes.MaskedSprites:
exportedData = Export_Sprite_MaskedSprites(exportConfig, sprites);
if(exportedData.StartsWith("ERROR:"))
if (exportedData.StartsWith("ERROR:"))
{
return false;
}
Expand Down Expand Up @@ -482,6 +482,15 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable<Sprite> sprites
/// <returns>string with the conversion commands for the export dialog samble textbox</returns>
public static string Export_Sprite_PutChars(ExportConfig exportConfig, IEnumerable<Sprite> 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:
Expand All @@ -497,6 +506,26 @@ public static string Export_Sprite_PutChars(ExportConfig exportConfig, IEnumerab
}
}

private static string Export_Sprite_PutChars_Check(ExportConfig exportConfig, IEnumerable<Sprite> 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

Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1074,9 +1139,9 @@ private static byte[] Export_Sprite_PutChars_GetBinaryData(IEnumerable<Sprite> s
/// <returns>string with the conversion commands for the export dialog samble textbox</returns>
public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnumerable<Sprite> 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)
Expand Down Expand Up @@ -1110,28 +1175,28 @@ public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnu
private static string Export_Sprite_MaskedSprites_Check(ExportConfig exportConfig, IEnumerable<Sprite> 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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ZXBStudio/ZXBasicStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Title>ZX Basic Studio</Title>
<AssemblyVersion></AssemblyVersion>
<Deterministic>False</Deterministic>
<Version>1.8.0.4</Version>
<Version>1.8.0.5</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion ZXBStudio/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.0.4
1.8.0.5
Loading