@@ -82,10 +82,10 @@ public bool Build(string BuildPath, ZXBuildStage Stage, ZXBuildType BuildType, Z
8282 case FileTypes . Sprite :
8383 {
8484 var sprites = CreateSprites ( fileData ) ;
85- if ( ! ExportSprites ( exportConfig , sprites ) )
85+ if ( ! ExportSprites ( exportConfig , sprites ) )
8686 {
8787 return false ;
88- }
88+ }
8989 }
9090 break ;
9191
@@ -447,7 +447,7 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable<Sprite> sprites
447447 break ;
448448 case ExportTypes . MaskedSprites :
449449 exportedData = Export_Sprite_MaskedSprites ( exportConfig , sprites ) ;
450- if ( exportedData . StartsWith ( "ERROR:" ) )
450+ if ( exportedData . StartsWith ( "ERROR:" ) )
451451 {
452452 return false ;
453453 }
@@ -482,6 +482,15 @@ public bool ExportSprites(ExportConfig exportConfig, IEnumerable<Sprite> sprites
482482 /// <returns>string with the conversion commands for the export dialog samble textbox</returns>
483483 public static string Export_Sprite_PutChars ( ExportConfig exportConfig , IEnumerable < Sprite > sprites )
484484 {
485+ string res = Export_Sprite_PutChars_Check ( exportConfig , sprites ) ;
486+ if ( res . StartsWith ( "ERROR:" ) )
487+ {
488+ if ( OutputLog != null )
489+ {
490+ OutputLog . WriteLine ( res ) ;
491+ }
492+ return res ;
493+ }
485494 switch ( exportConfig . ExportDataType )
486495 {
487496 case ExportDataTypes . DIM :
@@ -497,6 +506,26 @@ public static string Export_Sprite_PutChars(ExportConfig exportConfig, IEnumerab
497506 }
498507 }
499508
509+ private static string Export_Sprite_PutChars_Check ( ExportConfig exportConfig , IEnumerable < Sprite > sprites )
510+ {
511+ foreach ( var sprite in sprites )
512+ {
513+ if ( sprite == null )
514+ {
515+ continue ;
516+ }
517+ if ( sprite . Masked )
518+ {
519+ if ( ( sprite . Patterns . Count % 2 ) != 0 )
520+ {
521+ var name = sprite . Name . Replace ( ' ' , '_' ) ;
522+ return $ "ERROR: The number of frames in the sprite \" { name } \" must be even if it has a mask.";
523+ }
524+ }
525+ }
526+ return "OK" ;
527+ }
528+
500529
501530 #region DIM
502531
@@ -674,19 +703,31 @@ public static string Export_Sprite_PutChars_DIM(ExportConfig exportConfig, IEnum
674703 }
675704 else
676705 {
677- // Mulriple sprites attributes
706+ // Multiple sprites attributes
678707 // Header
708+ int fr = sprite . Masked ? ( sprite . Frames / 2 ) : ( sprite . Frames - 1 ) ;
679709 sb . AppendLine ( string . Format (
680710 "DIM {0}{1}_Attr({2},{3}) AS UByte => {{ _" ,
681711 exportConfig . LabelName ,
682712 sprite . Name . Replace ( " " , "_" ) ,
683- sprite . Frames - 1 + min ,
713+ fr - 1 + min ,
684714 ( ( sprite . Width / 8 ) * ( sprite . Height / 8 ) ) - 1 + min ) ) ;
685715 // Data
686- for ( int n = 0 ; n < sprite . Patterns . Count ; n ++ )
716+ if ( sprite . Masked )
687717 {
688- var data = Export_Sprite_PutChars_Attribute ( sprite , n , exportConfig , 0 ) ;
689- sb . Append ( data ) ;
718+ for ( int n = 0 ; n < sprite . Patterns . Count ; n += 2 )
719+ {
720+ var data = Export_Sprite_PutChars_Attribute ( sprite , n , exportConfig , 0 ) ;
721+ sb . Append ( data ) ;
722+ }
723+ }
724+ else
725+ {
726+ for ( int n = 0 ; n < sprite . Patterns . Count ; n ++ )
727+ {
728+ var data = Export_Sprite_PutChars_Attribute ( sprite , n , exportConfig , 0 ) ;
729+ sb . Append ( data ) ;
730+ }
690731 }
691732 // Footer
692733 sb . Append ( " _\r \n }" ) ;
@@ -775,19 +816,37 @@ private static string Export_Sprite_PutChars_Attribute(Sprite sprite, int n, Exp
775816 return "" ;
776817 }
777818
778- if ( sprite . Frames > 1 )
819+ if ( sprite . Masked )
779820 {
780- if ( n > firstItem )
821+ if ( sprite . Frames > 2 )
781822 {
782- sb . AppendLine ( ", _" ) ;
823+ if ( n > firstItem )
824+ {
825+ sb . AppendLine ( ", _" ) ;
826+ }
827+ sb . AppendLine ( "\t { _" ) ;
783828 }
784- sb . AppendLine ( "\t { _" ) ;
785829 }
830+ else
831+ if ( sprite . Frames > 1 )
832+ {
833+ if ( n > firstItem )
834+ {
835+ sb . AppendLine ( ", _" ) ;
836+ }
837+ sb . AppendLine ( "\t { _" ) ;
838+ }
786839
787840 int col = 0 ;
788841 int row = 0 ;
842+ int max = ( sprite . Width / 8 ) * ( sprite . Height / 8 ) ;
843+ int idx = 0 ;
789844 foreach ( var d in pattern . Attributes )
790845 {
846+ if ( idx ++ >= max )
847+ {
848+ break ;
849+ }
791850 if ( col == 0 )
792851 {
793852 if ( row == 0 )
@@ -984,8 +1043,14 @@ private static string Export_Sprite_PutChars_Attribute_ASM(Sprite sprite, int n,
9841043
9851044 int col = 0 ;
9861045 int row = 0 ;
1046+ int max = ( sprite . Width / 8 ) * ( sprite . Height / 8 ) ;
1047+ int idx = 0 ;
9871048 foreach ( var d in pattern . Attributes )
9881049 {
1050+ if ( idx ++ >= max )
1051+ {
1052+ break ;
1053+ }
9891054 if ( col == 0 )
9901055 {
9911056 if ( row == 0 )
@@ -1074,9 +1139,9 @@ private static byte[] Export_Sprite_PutChars_GetBinaryData(IEnumerable<Sprite> s
10741139 /// <returns>string with the conversion commands for the export dialog samble textbox</returns>
10751140 public static string Export_Sprite_MaskedSprites ( ExportConfig exportConfig , IEnumerable < Sprite > sprites )
10761141 {
1077- var res = Export_Sprite_MaskedSprites_Check ( exportConfig , sprites ) ;
1078- if ( res . StartsWith ( "ERROR:" ) )
1079- {
1142+ var res = Export_Sprite_MaskedSprites_Check ( exportConfig , sprites ) ;
1143+ if ( res . StartsWith ( "ERROR:" ) )
1144+ {
10801145 return res ;
10811146 }
10821147 switch ( exportConfig . ExportDataType )
@@ -1110,28 +1175,28 @@ public static string Export_Sprite_MaskedSprites(ExportConfig exportConfig, IEnu
11101175 private static string Export_Sprite_MaskedSprites_Check ( ExportConfig exportConfig , IEnumerable < Sprite > sprites )
11111176 {
11121177 string txt = "" ;
1113- foreach ( var sprite in sprites )
1178+ foreach ( var sprite in sprites )
11141179 {
11151180 if ( sprite != null && sprite . Export )
11161181 {
11171182 if ( ! sprite . Masked )
11181183 {
1119- txt = $ "ERROR: Sprite { sprite . Name } is not masked.";
1184+ txt = $ "ERROR: Sprite { sprite . Name } is not masked.";
11201185 }
11211186 if ( sprite . Frames % 2 != 0 )
11221187 {
1123- txt = $ "ERROR: Sprite { sprite . Name } has an odd number of frames.";
1188+ txt = $ "ERROR: Sprite { sprite . Name } has an odd number of frames.";
11241189 }
1125- if ( sprite . Width != 16 || sprite . Height != 16 )
1190+ if ( sprite . Width != 16 || sprite . Height != 16 )
11261191 {
1127- txt = $ "ERROR: Sprite { sprite . Name } has a size different than 16x16.";
1192+ txt = $ "ERROR: Sprite { sprite . Name } has a size different than 16x16.";
11281193 }
11291194 if ( ! string . IsNullOrEmpty ( txt ) )
11301195 {
1131- if ( OutputLog != null )
1196+ if ( OutputLog != null )
11321197 {
11331198 OutputLog . WriteLine ( txt ) ;
1134- }
1199+ }
11351200 return txt ;
11361201 }
11371202 }
@@ -1202,7 +1267,7 @@ public static string Export_Sprite_MaskedSprites_DIM(ExportConfig exportConfig,
12021267 else
12031268 {
12041269 sb . AppendLine (
1205- $ "DIM { exportConfig . LabelName } { sprite . Name . Replace ( " " , "_" ) } ({ ( sprite . Frames / 2 ) - 1 } ,63) AS UByte => {{ _") ;
1270+ $ "DIM { exportConfig . LabelName } { sprite . Name . Replace ( " " , "_" ) } ({ ( sprite . Frames / 2 ) - 1 } ,63) AS UByte => {{ _") ;
12061271 }
12071272 var rawData = Export_Sprite_MaskedSprites_GenerateData ( exportConfig , sprite ) ;
12081273 int i = 0 ;
0 commit comments