Allow selection of random starting color using a specified random so we can consistently randomly pick colors.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1005 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2010-08-29 00:40:36 +00:00
parent 26ad64ade6
commit 795d63b901
@@ -25,6 +25,7 @@ package com.threerings.media.image;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -133,6 +134,12 @@ public class ColorPository implements Serializable
/** Returns a random starting id from the entries in this class. */ /** Returns a random starting id from the entries in this class. */
public ColorRecord randomStartingColor () public ColorRecord randomStartingColor ()
{
return randomStartingColor(RandomUtil.rand);
}
/** Returns a random starting id from the entries in this class. */
public ColorRecord randomStartingColor (Random rand)
{ {
// figure out our starter ids if we haven't already // figure out our starter ids if we haven't already
if (_starters == null) { if (_starters == null) {
@@ -153,7 +160,7 @@ public class ColorPository implements Serializable
} }
// return a random entry from the array // return a random entry from the array
return _starters[RandomUtil.getInt(_starters.length)]; return _starters[RandomUtil.getInt(_starters.length, rand)];
} }
/** /**
@@ -316,9 +323,16 @@ public class ColorPository implements Serializable
*/ */
public ColorRecord getRandomStartingColor (String className) public ColorRecord getRandomStartingColor (String className)
{ {
// make sure the class exists return getRandomStartingColor(className, RandomUtil.rand);
}
/**
* Returns a random starting color from the specified color class.
*/
public ColorRecord getRandomStartingColor (String className, Random rand)
{
// make sure the class exists
ClassRecord record = getClassRecord(className); ClassRecord record = getClassRecord(className);
return (record == null) ? null : record.randomStartingColor(); return (record == null) ? null : record.randomStartingColor(rand);
} }
/** /**