public static CharacterDescriptor getRandomDescriptor ( ComponentRepository crepo , String gender , String [ ] COMP_CLASSES , ColorPository cpos , String [ ] COLOR_CLASSES ) { // get all available classes ArrayList < ComponentClass > classes = Lists . newArrayList ( ) ; for ( String element : COMP_CLASSES ) { String cname = gender + "/" + element ; ComponentClass cclass = crepo . getComponentClass ( cname ) ; // make sure the component class exists if ( cclass == null ) { log . warning ( "Missing definition for component class" , "class" , cname ) ; continue ; } // make sure there are some components in this class Iterator < Integer > iter = crepo . enumerateComponentIds ( cclass ) ; if ( ! iter . hasNext ( ) ) { log . info ( "Skipping class for which we have no components" , "class" , cclass ) ; continue ; } classes . add ( cclass ) ; } // select the components int [ ] components = new int [ classes . size ( ) ] ; Colorization [ ] [ ] zations = new Colorization [ components . length ] [ ] ; for ( int ii = 0 ; ii < components . length ; ii ++ ) { ComponentClass cclass = classes . get ( ii ) ; // get the components available for this class ArrayList < Integer > choices = Lists . newArrayList ( ) ; Iterators . addAll ( choices , crepo . enumerateComponentIds ( cclass ) ) ; // each of our components has up to four colorizations: two "global" skin colorizations // and potentially a primary and secondary clothing colorization; in a real system one // would probably keep a separate database of which character component required which // colorizations, but here we just assume everything could have any of the four // colorizations; it *usually* doesn't hose an image if you apply a recoloring that it // does not support, but it can match stray colors unnecessarily zations [ ii ] = new Colorization [ COLOR_CLASSES . length ] ; for ( int zz = 0 ; zz < COLOR_CLASSES . length ; zz ++ ) { zations [ ii ] [ zz ] = cpos . getRandomStartingColor ( COLOR_CLASSES [ zz ] ) . getColorization ( ) ; } // choose a random component if ( choices . size ( ) > 0 ) { int idx = RandomUtil . getInt ( choices . size ( ) ) ; components [ ii ] = choices . get ( idx ) . intValue ( ) ; } else { log . info ( "Have no components in class" , "class" , cclass ) ; } } return new CharacterDescriptor ( components , zations ) ; }
Returns a new character descriptor populated with a random set of components .