@@ -13,24 +13,36 @@ class SpriteConverter extends AbstractConverter {
1313 async convert ( ) {
1414 const to_delete = [ ] ;
1515
16- for await ( const [ width , height , sprites , to , scale = 1 ] of this . getData ( ) ) {
16+ for await ( const [ width , height , sprites , to , min_factor = 1 ] of this . getData ( ) ) {
1717 let image = null ;
18+ let factor = null ;
1819
19- let factor = 1 ;
20+ if ( await this . output . exists ( to ) ) {
21+ Utils . log ( `Convert sprite ${ to } ` ) ;
2022
21- for ( const [ sprite , x , y , factor_detect , not_scale ] of sprites ) {
23+ image = await this . readImage ( to ) ; // Load already exists sprites image - Some texture packs have may a mix with sprites (1.13) and separate images (1.14)
24+
25+ factor = ( image . getWidth ( ) / width ) ;
26+ }
27+
28+ for ( const [ sprite , x , y , factor_detect ] of sprites ) {
2229 if ( await this . output . exists ( sprite ) ) {
2330 const image_sprite = await this . readImage ( sprite ) ;
2431
25- factor = ( image_sprite . getWidth ( ) / factor_detect * scale ) ;
32+ if ( factor === null ) {
33+ factor = Math . max ( ( image_sprite . getWidth ( ) / factor_detect ) , min_factor ) ; // Take the factor of the first image
34+ }
2635
2736 if ( image === null ) {
2837 Utils . log ( `Create sprite ${ to } ` ) ;
2938
3039 image = await Jimp . create ( ( width * factor ) , ( height * factor ) ) ;
3140 }
3241
33- image . composite ( ( scale > 1 && ! not_scale ? image_sprite . scale ( scale , "nearestNeighbor" ) : image_sprite ) , ( x * factor ) , ( y * factor ) ) ;
42+ image . scan ( ( x * factor ) , ( y * factor ) , ( factor_detect * factor ) , ( factor_detect * factor ) , ( x , y , idx ) => {
43+ image . bitmap . data [ idx ] = image . bitmap . data [ idx + 1 ] = image . bitmap . data [ idx + 2 ] = image . bitmap . data [ idx + 3 ] = 0 ; // Delete previous area, if the sprite already exists
44+ } ) ;
45+ image . composite ( image_sprite . resize ( ( factor_detect * factor ) , ( factor_detect * factor ) , "nearestNeighbor" ) , ( x * factor ) , ( y * factor ) ) ;
3446
3547 to_delete . push ( sprite ) ;
3648 }
@@ -182,22 +194,22 @@ class SpriteConverter extends AbstractConverter {
182194 [ "textures/particle/spell_5.png" , 40 , 72 , 8 ] ,
183195 [ "textures/particle/spell_6.png" , 48 , 72 , 8 ] ,
184196 [ "textures/particle/spell_7.png" , 56 , 72 , 8 ] ,
185- [ "textures/particle/explosion_0.png" , 0 , 80 , 32 , true ] ,
186- [ "textures/particle/explosion_1.png" , 8 , 80 , 32 , true ] ,
187- [ "textures/particle/explosion_2.png" , 16 , 80 , 32 , true ] ,
188- [ "textures/particle/explosion_3.png" , 24 , 80 , 32 , true ] ,
189- [ "textures/particle/explosion_4.png" , 32 , 80 , 32 , true ] ,
190- [ "textures/particle/explosion_5.png" , 40 , 80 , 32 , true ] ,
191- [ "textures/particle/explosion_6.png" , 48 , 80 , 32 , true ] ,
192- [ "textures/particle/explosion_7.png" , 56 , 80 , 32 , true ] ,
193- [ "textures/particle/explosion_8.png" , 64 , 80 , 32 , true ] ,
194- [ "textures/particle/explosion_9.png" , 72 , 80 , 32 , true ] ,
195- [ "textures/particle/explosion_10.png" , 80 , 80 , 32 , true ] ,
196- [ "textures/particle/explosion_11.png" , 88 , 80 , 32 , true ] ,
197- [ "textures/particle/explosion_12.png" , 96 , 80 , 32 , true ] ,
198- [ "textures/particle/explosion_13.png" , 104 , 80 , 32 , true ] ,
199- [ "textures/particle/explosion_14.png" , 112 , 80 , 32 , true ] ,
200- [ "textures/particle/explosion_15.png" , 120 , 80 , 32 , true ] ,
197+ [ "textures/particle/explosion_0.png" , 0 , 80 , 8 ] ,
198+ [ "textures/particle/explosion_1.png" , 8 , 80 , 8 ] ,
199+ [ "textures/particle/explosion_2.png" , 16 , 80 , 8 ] ,
200+ [ "textures/particle/explosion_3.png" , 24 , 80 , 8 ] ,
201+ [ "textures/particle/explosion_4.png" , 32 , 80 , 8 ] ,
202+ [ "textures/particle/explosion_5.png" , 40 , 80 , 8 ] ,
203+ [ "textures/particle/explosion_6.png" , 48 , 80 , 8 ] ,
204+ [ "textures/particle/explosion_7.png" , 56 , 80 , 8 ] ,
205+ [ "textures/particle/explosion_8.png" , 64 , 80 , 8 ] ,
206+ [ "textures/particle/explosion_9.png" , 72 , 80 , 8 ] ,
207+ [ "textures/particle/explosion_10.png" , 80 , 80 , 8 ] ,
208+ [ "textures/particle/explosion_11.png" , 88 , 80 , 8 ] ,
209+ [ "textures/particle/explosion_12.png" , 96 , 80 , 8 ] ,
210+ [ "textures/particle/explosion_13.png" , 104 , 80 , 8 ] ,
211+ [ "textures/particle/explosion_14.png" , 112 , 80 , 8 ] ,
212+ [ "textures/particle/explosion_15.png" , 120 , 80 , 8 ] ,
201213 [ "textures/particle/glitter_0.png" , 0 , 88 , 8 ] ,
202214 [ "textures/particle/glitter_1.png" , 8 , 88 , 8 ] ,
203215 [ "textures/particle/glitter_2.png" , 16 , 88 , 8 ] ,
@@ -240,7 +252,7 @@ class SpriteConverter extends AbstractConverter {
240252 [ "textures/particle/sga_x.png" , 64 , 120 , 8 ] ,
241253 [ "textures/particle/sga_y.png" , 72 , 120 , 8 ] ,
242254 [ "textures/particle/sga_z.png" , 80 , 120 , 8 ]
243- ] , "textures/particle/particles.png" , 4 ] ,
255+ ] , "textures/particle/particles.png" , 4 /* Needs a minimal 4x factor because the explosion images are bigger than the others */ ] , // 1.14
244256 [ 16 , 192 , [
245257 [ "textures/particle/big_smoke_0.png" , 0 , 0 , 16 ] ,
246258 [ "textures/particle/big_smoke_1.png" , 0 , 16 , 16 ] ,
0 commit comments