Renamed some of Get() methods to Find(), read more
From now on, ideally any function with "get" in the name should always return a valid value. A function with "find" in the name, however, does the same thing, but may also return an invalid result such as an error code.
This commit is contained in:
@@ -116,7 +116,7 @@ void RoomManager::PushCharacter(CharacterData* character) {
|
||||
throw(std::runtime_error("Failed to push a null character to a room"));
|
||||
}
|
||||
|
||||
RoomData* room = Get(character->GetRoomIndex());
|
||||
RoomData* room = Find(character->GetRoomIndex());
|
||||
|
||||
if (!room) {
|
||||
throw(std::runtime_error("Failed to push an character to a non-existant room"));
|
||||
@@ -131,7 +131,7 @@ void RoomManager::PopCharacter(CharacterData const* character) {
|
||||
throw(std::runtime_error("Failed to pop a null character to a room"));
|
||||
}
|
||||
|
||||
RoomData* room = Get(character->GetRoomIndex());
|
||||
RoomData* room = Find(character->GetRoomIndex());
|
||||
|
||||
if (!room) {
|
||||
throw(std::runtime_error("Failed to pop an character to a non-existant room"));
|
||||
@@ -143,7 +143,7 @@ void RoomManager::PopCharacter(CharacterData const* character) {
|
||||
}
|
||||
|
||||
//TODO: rename these functions from Get to Find
|
||||
RoomData* RoomManager::Get(int uid) {
|
||||
RoomData* RoomManager::Find(int uid) {
|
||||
std::map<int, RoomData>::iterator it = elementMap.find(uid);
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
@@ -153,7 +153,7 @@ RoomData* RoomManager::Get(int uid) {
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
RoomData* RoomManager::Get(std::string name) {
|
||||
RoomData* RoomManager::Find(std::string name) {
|
||||
for (std::map<int, RoomData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) {
|
||||
if (it->second.GetName() == name) {
|
||||
return &it->second;
|
||||
|
||||
@@ -43,8 +43,8 @@ public:
|
||||
void PopCharacter(CharacterData const* character);
|
||||
|
||||
//accessors and mutators
|
||||
RoomData* Get(int uid);
|
||||
RoomData* Get(std::string name);
|
||||
RoomData* Find(int uid);
|
||||
RoomData* Find(std::string name);
|
||||
int GetLoadedCount();
|
||||
std::map<int, RoomData>* GetContainer();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ int createRoom(lua_State* L) {
|
||||
//create & get the room
|
||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||
int uid = roomMgr.Create(lua_tostring(L, 1), lua_tostring(L, 2));
|
||||
RoomData* room = roomMgr.Get(uid);
|
||||
RoomData* room = roomMgr.Find(uid);
|
||||
|
||||
//TODO: initialization parameters here?
|
||||
|
||||
@@ -70,7 +70,7 @@ int unloadRoom(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getRoom(lua_State* L) {
|
||||
int findRoom(lua_State* L) {
|
||||
//integer vs name for getRoom()
|
||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||
RoomData* room = nullptr;
|
||||
@@ -78,11 +78,11 @@ int getRoom(lua_State* L) {
|
||||
switch(lua_type(L, 1)) {
|
||||
case LUA_TNUMBER:
|
||||
//number
|
||||
room = roomMgr.Get(lua_tointeger(L, 1));
|
||||
room = roomMgr.Find(lua_tointeger(L, 1));
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
//name
|
||||
room = roomMgr.Get(lua_tostring(L, 1));
|
||||
room = roomMgr.Find(lua_tostring(L, 1));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ static int setOnUnload(lua_State* L) {
|
||||
static const luaL_Reg roomManagerLib[] = {
|
||||
{"CreateRoom", createRoom},
|
||||
{"UnloadRoom", unloadRoom},
|
||||
{"GetRoom", getRoom},
|
||||
{"FindRoom", findRoom},
|
||||
{"SetOnCreate", setOnCreate},
|
||||
{"SetOnUnload", setOnUnload},
|
||||
{nullptr, nullptr}
|
||||
|
||||
Reference in New Issue
Block a user