88 writeBIN ,
99 writeASM ,
1010} from '#formats/scripts' ;
11- import { compressionFormats } from '#formats/compression' ;
11+ import { decompress , compress , compressionFormats } from '#formats/compression' ;
1212import { bufferToTiles , tilesToBuffer } from '#formats/art' ;
1313import { buffersToColors , colorsToBuffers } from '#formats/palette' ;
1414import { environment } from '#store/environment' ;
@@ -37,7 +37,7 @@ export const FileObject = observer(({ obj }) => {
3737 const scriptArt = scriptSafe && script . art ;
3838 const scriptPalettes = scriptSafe && script . palettes ;
3939 const toggleDPLCs = ( ) => ( obj . dplcs . enabled = ! obj . dplcs . enabled ) ;
40- const parseASM = ( ( scriptSafe && script . parseASM ) || parseASMInternal ) ;
40+ const parseASM = ( scriptSafe && script . parseASM ) || parseASMInternal ;
4141
4242 function ioWrap ( filePath , setError , e , cb ) {
4343 setError ( ) ;
@@ -83,10 +83,16 @@ export const FileObject = observer(({ obj }) => {
8383 function loadArt ( e ) {
8484 ioWrap ( obj . art . path , setArtError , e , async ( path ) => {
8585 const buffer = ( await fs . readFile ( path ) ) . slice ( obj . art . offset || 0 ) ;
86- const tiles = scriptArt
87- ? script . readArt ( buffer )
88- : bufferToTiles ( buffer , obj . art . compression ) ;
89- environment . tiles . replace ( tiles ) ;
86+
87+ if ( scriptArt ) {
88+ environment . tiles . replace ( script . readArt ( buffer ) ) ;
89+ } else {
90+ const decompBuffer = await decompress (
91+ buffer ,
92+ obj . art . compression ,
93+ ) ;
94+ environment . tiles . replace ( bufferToTiles ( decompBuffer ) ) ;
95+ }
9096 } ) ;
9197 }
9298
@@ -99,6 +105,16 @@ export const FileObject = observer(({ obj }) => {
99105 ? script . writeArt ( tiles )
100106 : tilesToBuffer ( environment . tiles , obj . art . compression ) ;
101107 await fs . writeFile ( path , tiles ) ;
108+
109+ if ( scriptArt ) {
110+ await fs . writeFile ( path , script . writeArt ( tiles ) ) ;
111+ } else {
112+ const buffer = tilesToBuffer ( environment . tiles ) ;
113+ await fs . writeFile (
114+ path ,
115+ Buffer . from ( await compress ( buffer , obj . art . compression ) ) ,
116+ ) ;
117+ }
102118 } ) ;
103119 }
104120
@@ -214,13 +230,9 @@ export const FileObject = observer(({ obj }) => {
214230 ? palPath
215231 : workspace . absolutePath ( palPath ) ;
216232
217- const chunk = ( scriptPalettes
218- ? script . writePalettes
219- : colorsToBuffers ) (
220- environment . palettes ,
221- cursor ,
222- cursor + length ,
223- ) ;
233+ const chunk = (
234+ scriptPalettes ? script . writePalettes : colorsToBuffers
235+ ) ( environment . palettes , cursor , cursor + length ) ;
224236 await fs . writeFile ( path , chunk ) ;
225237 cursor += length ;
226238 }
0 commit comments