1- import { readFile , writeFile } from 'fs' ;
1+ import { readFile , readFileSync , writeFile } from 'fs' ;
22import { extname } from 'path' ;
33import { observable , computed , action , autorun , toJS , spy } from 'mobx' ;
44import range from 'lodash/range' ;
@@ -101,10 +101,12 @@ class Environment {
101101 // load art
102102 if ( obj . art . path ) {
103103 const artPath = workspace . absolutePath ( obj . art . path ) ;
104- readFile ( artPath , ( err , buffer ) => {
105- if ( err ) return errorMsg ( 'Error Reading Art File' , err ) ;
104+ try {
105+ const buffer = readFileSync ( artPath ) ;
106106 this . tiles . replace ( bufferToTiles ( buffer , obj . art . compression ) ) ;
107- } ) ;
107+ } catch ( e ) {
108+ errorMsg ( 'Error Reading Art File' , e . message ) ;
109+ }
108110 }
109111 else {
110112 this . tiles . replace ( [ ] ) ;
@@ -113,14 +115,17 @@ class Environment {
113115 if ( obj . mappings . path ) {
114116 const mappingPath = workspace . absolutePath ( obj . mappings . path ) ;
115117 const isAsm = extname ( obj . mappings . path ) == '.asm' ;
116- readFile ( mappingPath , ( err , buffer ) => {
117- if ( err ) return errorMsg ( 'Error Reading Mapping File' , err ) ;
118+ try {
119+ const buffer = readFileSync ( mappingPath ) ;
118120 const newMappings = bufferToMappings (
119121 isAsm ? asmToBin ( buffer ) : buffer ,
120122 obj . mappingDefinition ,
121123 ) ;
122124 this . mappings . replace ( newMappings ) ;
123- } ) ;
125+
126+ } catch ( e ) {
127+ errorMsg ( 'Error Reading Mapping File' , e . message ) ;
128+ }
124129 }
125130 else {
126131 this . mappings . replace ( [ ] ) ;
@@ -130,41 +135,35 @@ class Environment {
130135 if ( this . config . dplcsEnabled && obj . dplcs . path ) {
131136 const dplcPath = workspace . absolutePath ( obj . dplcs . path ) ;
132137 const isAsm = extname ( obj . dplcs . path ) == '.asm' ;
133- readFile ( dplcPath , ( err , buffer ) => {
134- if ( err ) return errorMsg ( 'Error Reading DPLC File' , err ) ;
138+ try {
139+ const buffer = readFileSync ( dplcPath ) ;
135140 const newDPLCs = bufferToDPLCs (
136141 isAsm ? asmToBin ( buffer ) : buffer ,
137142 obj . dplcDefinition ,
138143 ) ;
139144 this . dplcs . replace ( newDPLCs ) ;
140- } ) ;
145+ } catch ( e ) {
146+ errorMsg ( 'Error Reading DPLC File' , e . message ) ;
147+ }
141148 }
142149 else {
143150 this . dplcs . replace ( [ ] ) ;
144151 }
145152
146- // load palettes
147- Promise
148- . all (
149- obj . palettes . map ( ( { path, length} ) => {
150- const palettePath = workspace . absolutePath ( path ) ;
151- return new Promise ( ( resolve , reject ) => {
152- readFile ( palettePath , ( err , buffer ) => {
153- if ( err ) reject ( err ) ;
154- resolve ( { buffer, length} ) ;
155- } ) ;
156- } ) ;
157- } )
158- )
159- . then ( ( all ) => {
160- buffersToColors ( all )
161- . forEach ( ( line , i ) => {
162- this . palettes [ i ] = line ;
163- } ) ;
164- } )
165- . catch ( ( err ) => {
166- errorMsg ( 'Error Reading Palette File' , err . message ) ;
153+ try {
154+ const paletteBuffers = obj . palettes . map ( ( { path, length} ) => {
155+ const palettePath = workspace . absolutePath ( path ) ;
156+ return { buffer : readFileSync ( palettePath ) , length } ;
167157 } ) ;
158+
159+ buffersToColors ( paletteBuffers )
160+ . forEach ( ( line , i ) => {
161+ this . palettes [ i ] = line ;
162+ } ) ;
163+ } catch ( e ) {
164+ errorMsg ( 'Error Reading DPLC File' , e . message ) ;
165+ }
166+
168167 } ;
169168
170169 @action saveObject = ( obj ) => {
0 commit comments