scripts/generateAssetsClass.js
/**
 * Decide asset type from file name and extensions
 * 
 * @param {string} name file name
 * @param {Array<string>} exts file extensions
 * @results asset type by string
 */
Decide asset type from file name and extensions

@param {string} name file name
@param {Array} exts file extensions
@results asset type by string
Decide asset type from file name and extensions @param { string } name file name @param { Array } exts file extensions @results asset type by string
function decideAssetType(name, exts) {
  let type = {
    image: findExtension(exts, ASSET_TYPE_EXTENSIONS.image),
    audio: findExtension(exts, ASSET_TYPE_EXTENSIONS.audio),
    font: findExtension(exts, ASSET_TYPE_EXTENSIONS.font),
    bitmapfont: findExtension(exts, ASSET_TYPE_EXTENSIONS.bitmapFont),
    json: findExtension(exts, ASSET_TYPE_EXTENSIONS.json),
    xml: findExtension(exts, ASSET_TYPE_EXTENSIONS.xml),
    text: findExtension(exts, ASSET_TYPE_EXTENSIONS.text),
    script: findExtension(exts, ASSET_TYPE_EXTENSIONS.script),
    shader: findExtension(exts, ASSET_TYPE_EXTENSIONS.shader),
  };
  if (type.bitmapfont) {
    type.bitmapfont = (exts.findIndex((ext) => shell.grep(/^[\s\S]*?<font>/g, `${name}.${ext}`).length > 1) >= 0);
  }
  if (type.bitmapfont && type.image) {
    return 'bitmapfont';
  }
  if (type.audio && type.json) {
    return 'audiosprites';
  }
  if (type.image) {
    if (type.json || type.xml) {
      return 'atlas';
    } else if (name.match(/\[(-?[0-9],?)*]/)) {
      return 'spritesheet';
    }
    return 'image';
  }
  return Object.keys(type).find((key) => type[key]) || 'misc';
}
function decideAssetType ( name , exts ) { let type = { image : findExtension ( exts , ASSET_TYPE_EXTENSIONS . image ) , audio : findExtension ( exts , ASSET_TYPE_EXTENSIONS . audio ) , font : findExtension ( exts , ASSET_TYPE_EXTENSIONS . font ) , bitmapfont : findExtension ( exts , ASSET_TYPE_EXTENSIONS . bitmapFont ) , json : findExtension ( exts , ASSET_TYPE_EXTENSIONS . json ) , xml : findExtension ( exts , ASSET_TYPE_EXTENSIONS . xml ) , text : findExtension ( exts , ASSET_TYPE_EXTENSIONS . text ) , script : findExtension ( exts , ASSET_TYPE_EXTENSIONS . script ) , shader : findExtension ( exts , ASSET_TYPE_EXTENSIONS . shader ) , } ; if ( type . bitmapfont ) { type . bitmapfont = ( exts . findIndex ( ( ext ) => shell . grep ( / ^[\s\S]*?<font> / g , ` ${ name } ${ ext } ` ) . length > 1 ) >= 0 ) ; } if ( type . bitmapfont && type . image ) { return 'bitmapfont' ; } if ( type . audio && type . json ) { return 'audiosprites' ; } if ( type . image ) { if ( type . json || type . xml ) { return 'atlas' ; } else if ( name . match ( / \[(-?[0-9],?)*] / ) ) { return 'spritesheet' ; } return 'image' ; } return Object . keys ( type ) . find ( ( key ) => type [ key ] ) || 'misc' ; }
Decide asset type from file name and extensions
Decide asset type from file name and extensions