Moved TileUtil to cast.util, added CastUtil to provide an easy way to

get a random character descriptor for use until we have fancified
storage of character descriptions.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@587 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-11-02 15:28:20 +00:00
parent bd998aff3d
commit e9211f8fd5
5 changed files with 240 additions and 42 deletions
@@ -0,0 +1,49 @@
//
// $Id: CastUtil.java,v 1.1 2001/11/02 15:28:20 shaper Exp $
package com.threerings.cast.util;
import java.util.ArrayList;
import java.util.Iterator;
import com.samskivert.util.CollectionUtil;
import com.threerings.media.util.RandomUtil;
import com.threerings.cast.*;
/**
* Miscellaneous cast utility routines.
*/
public class CastUtil
{
/**
* Returns a new character descriptor populated with a random set
* of components.
*/
public static CharacterDescriptor
getRandomDescriptor (CharacterManager charmgr)
{
// get all available classes
ArrayList classes = new ArrayList();
CollectionUtil.addAll(classes, charmgr.enumerateComponentClasses());
// select the components
int size = classes.size();
int components[] = new int[size];
for (int ii = 0; ii < size; ii++) {
ComponentClass cclass = (ComponentClass)classes.get(ii);
// get the components available for this class
ArrayList choices = new ArrayList();
Iterator iter = charmgr.enumerateComponentsByClass(cclass.clid);
CollectionUtil.addAll(choices, iter);
// choose a random component
int idx = RandomUtil.getInt(choices.size());
components[cclass.clid] = ((Integer)choices.get(idx)).intValue();
}
return new CharacterDescriptor(components);
}
}