@@ -335,6 +335,95 @@ function compileShaders(invocations: Invocation[]): Promise<void> {
335335 } ) ;
336336}
337337
338+ function compileKong ( from : string , to : string , platform : string , dirs : string [ ] ) : Promise < void > {
339+ return new Promise < void > ( ( resolve , reject ) => {
340+ let compilerPath = '' ;
341+
342+ if ( Project . kincDir !== '' ) {
343+ compilerPath = path . resolve ( __dirname , 'kongruent' + exec . sys ( ) ) ;
344+ }
345+
346+ let libsdir = path . join ( from , 'Backends' ) ;
347+ if ( Project . kincDir ) {
348+ libsdir = path . join ( Project . kincDir , '..' , 'Backends' ) ;
349+ }
350+ if ( fs . existsSync ( libsdir ) && fs . statSync ( libsdir ) . isDirectory ( ) ) {
351+ let libdirs = fs . readdirSync ( path . join ( libsdir ) ) ;
352+ for ( let ld in libdirs ) {
353+ let libdir = path . join ( libsdir , libdirs [ ld ] ) ;
354+ if ( fs . statSync ( libdir ) . isDirectory ( ) ) {
355+ let exe = path . join ( libdir , 'krafix' , 'kong-' + platform + '.exe' ) ;
356+ if ( fs . existsSync ( exe ) ) {
357+ compilerPath = exe ;
358+ }
359+ }
360+ }
361+ }
362+
363+ if ( compilerPath !== '' ) {
364+ let params : string [ ] = [ ] ;
365+ params . push ( '--platform' ) ;
366+ params . push ( platform ) ;
367+ for ( const dir of dirs ) {
368+ params . push ( '--input' ) ;
369+ params . push ( dir ) ;
370+ }
371+ params . push ( '--output' ) ;
372+ params . push ( to ) ;
373+ let compiler = child_process . spawn ( compilerPath , params ) ;
374+
375+ compiler . stdout . on ( 'data' , ( data : any ) => {
376+ log . info ( data . toString ( ) ) ;
377+ } ) ;
378+
379+ let errorLine = '' ;
380+ let newErrorLine = true ;
381+ let errorData = false ;
382+
383+ function parseData ( data : string ) {
384+
385+ }
386+
387+ compiler . stderr . on ( 'data' , ( data : any ) => {
388+ let str : string = data . toString ( ) ;
389+ for ( let char of str ) {
390+ if ( char === '\n' ) {
391+ if ( errorData ) {
392+ parseData ( errorLine . trim ( ) ) ;
393+ }
394+ else {
395+ log . error ( errorLine . trim ( ) ) ;
396+ }
397+ errorLine = '' ;
398+ newErrorLine = true ;
399+ errorData = false ;
400+ }
401+ else if ( newErrorLine && char === '#' ) {
402+ errorData = true ;
403+ newErrorLine = false ;
404+ }
405+ else {
406+ errorLine += char ;
407+ newErrorLine = false ;
408+ }
409+ }
410+ } ) ;
411+
412+ compiler . on ( 'close' , ( code : number ) => {
413+ if ( code === 0 ) {
414+ resolve ( ) ;
415+ }
416+ else {
417+ reject ( compilerPath + ' ' + params . join ( ' ' ) ) ;
418+ }
419+ } ) ;
420+ }
421+ else {
422+ throw 'Could not find Kong.' ;
423+ }
424+ } ) ;
425+ }
426+
338427async function exportKoremakeProject ( from : string , to : string , platform : string , korefile : string , retro : boolean , veryretro : boolean , options : any ) {
339428 log . info ( 'kfile found.' ) ;
340429 if ( options . onlyshaders ) {
@@ -377,64 +466,69 @@ async function exportKoremakeProject(from: string, to: string, platform: string,
377466 let files = project . getFiles ( ) ;
378467
379468 if ( ! options . noshaders && ! options . json ) {
380- /*let compilerPath = '';
381- if (Project.kincDir !== '') {
382- compilerPath = path.resolve(__dirname, 'krafix' + exec.sys());
469+ if ( project . kongDirs . length > 0 ) {
470+ await compileKong ( from , to , platform , project . kongDirs ) ;
383471 }
384-
385- const matches = [];
386- for (let file of files) {
387- if (file.file.endsWith('.glsl')) {
388- matches.push({match: file.file, options: null});
472+ else {
473+ /*let compilerPath = '';
474+ if (Project.kincDir !== '') {
475+ compilerPath = path.resolve(__dirname, 'krafix' + exec.sys());
389476 }
390- }
391-
392- let shaderCompiler = new ShaderCompiler(platform, compilerPath, project.getDebugDir(), options.to,
393- options.to builddir, matches);
394- try {
395- await shaderCompiler.run(false, false);
396- }
397- catch (err) {
398- return Promise.reject(err);
399- }*/
400477
401- let shaderCount = 0 ;
402- for ( let file of files ) {
403- if ( file . file . endsWith ( '.glsl' ) ) {
404- ++ shaderCount ;
478+ const matches = [];
479+ for (let file of files) {
480+ if (file.file.endsWith('.glsl')) {
481+ matches.push({match: file.file, options: null});
482+ }
405483 }
406- }
407- let shaderIndex = 0 ;
408- let invocations : Invocation [ ] = [ ] ;
409- for ( let file of files ) {
410- if ( file . file . endsWith ( '.glsl' ) ) {
411- let outfile = file . file ;
412- const index = outfile . lastIndexOf ( '/' ) ;
413- if ( index > 0 ) outfile = outfile . substr ( index ) ;
414- outfile = outfile . substr ( 0 , outfile . length - 5 ) ;
415-
416- let parsedFile = path . parse ( file . file ) ;
417484
418- const shader = path . isAbsolute ( file . file ) ? file . file : path . join ( file . projectDir , file . file ) ;
419-
420- ++ shaderIndex ;
485+ let shaderCompiler = new ShaderCompiler(platform, compilerPath, project.getDebugDir(), options.to,
486+ options.to builddir, matches);
487+ try {
488+ await shaderCompiler.run(false, false);
489+ }
490+ catch (err) {
491+ return Promise.reject(err);
492+ }*/
421493
422- invocations . push ( {
423- projectDir : from ,
424- type : shaderLang ( platform ) ,
425- from : shader ,
426- to : path . join ( project . getDebugDir ( ) , outfile ) ,
427- temp : options . to ,
428- platform : platform ,
429- builddir : options . to ,
430- name : parsedFile . name ,
431- shaderversion : project . shaderVersion ,
432- } ) ;
433- //await compileShader(from, shaderLang(platform), shader, path.join(project.getDebugDir(), outfile), options.to, platform, options.to);
494+ let shaderCount = 0 ;
495+ for ( let file of files ) {
496+ if ( file . file . endsWith ( '.glsl' ) ) {
497+ ++ shaderCount ;
498+ }
499+ }
500+ let shaderIndex = 0 ;
501+ let invocations : Invocation [ ] = [ ] ;
502+ for ( let file of files ) {
503+ if ( file . file . endsWith ( '.glsl' ) ) {
504+ let outfile = file . file ;
505+ const index = outfile . lastIndexOf ( '/' ) ;
506+ if ( index > 0 ) outfile = outfile . substr ( index ) ;
507+ outfile = outfile . substr ( 0 , outfile . length - 5 ) ;
508+
509+ let parsedFile = path . parse ( file . file ) ;
510+
511+ const shader = path . isAbsolute ( file . file ) ? file . file : path . join ( file . projectDir , file . file ) ;
512+
513+ ++ shaderIndex ;
514+
515+ invocations . push ( {
516+ projectDir : from ,
517+ type : shaderLang ( platform ) ,
518+ from : shader ,
519+ to : path . join ( project . getDebugDir ( ) , outfile ) ,
520+ temp : options . to ,
521+ platform : platform ,
522+ builddir : options . to ,
523+ name : parsedFile . name ,
524+ shaderversion : project . shaderVersion ,
525+ } ) ;
526+ //await compileShader(from, shaderLang(platform), shader, path.join(project.getDebugDir(), outfile), options.to, platform, options.to);
527+ }
434528 }
435- }
436529
437- await compileShaders ( invocations ) ;
530+ await compileShaders ( invocations ) ;
531+ }
438532 }
439533
440534 if ( options . onlyshaders ) {
0 commit comments