Static method Ship.roles() lists all valid roles, including [ roles. Issue #26

This commit is contained in:
cim 2013-06-30 16:41:51 +01:00
parent 2aa670f4f6
commit 701a750822
3 changed files with 19 additions and 0 deletions

View File

@ -60,6 +60,7 @@ SOFTWARE.
@interface OOShipRegistry (OOConveniences)
- (NSArray *) shipKeys;
- (NSArray *) shipRoles;
- (NSArray *) shipKeysWithRole:(NSString *)role;
- (NSString *) randomShipKeyForRole:(NSString *)role;

View File

@ -245,6 +245,11 @@ static NSString * const kVisualEffectDataCacheKey = @"visual effect data";
return [_shipData allKeys];
}
- (NSArray *) shipRoles
{
return [_probabilitySets allKeys];
}
- (NSArray *) shipKeysWithRole:(NSString *)role
{
return [[self probabilitySetForRole:role] allObjects];

View File

@ -101,6 +101,7 @@ static JSBool ShipSetMaterialsInternal(JSContext *context, uintN argc, jsval *vp
static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipStaticKeys(JSContext *context, uintN argc, jsval *vp);
static JSBool ShipStaticRoles(JSContext *context, uintN argc, jsval *vp);
static JSClass sShipClass =
@ -418,6 +419,7 @@ static JSFunctionSpec sShipStaticMethods[] =
// JS name Function min args
{ "keys", ShipStaticKeys, 0 },
{ "keysForRole", ShipStaticKeysForRole, 1 },
{ "roles", ShipStaticRoles, 0 },
{ 0 }
};
@ -2747,3 +2749,14 @@ static JSBool ShipStaticKeysForRole(JSContext *context, uintN argc, jsval *vp)
OOJS_NATIVE_EXIT
}
static JSBool ShipStaticRoles(JSContext *context, uintN argc, jsval *vp)
{
OOJS_NATIVE_ENTER(context);
OOShipRegistry *registry = [OOShipRegistry sharedRegistry];
NSArray *keys = [registry shipRoles];
OOJS_RETURN_OBJECT(keys);
OOJS_NATIVE_EXIT
}