From e27187bab767b2d88b1a43305882387a5f10a4ac Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sat, 29 Mar 2008 00:01:25 +0100 Subject: [PATCH] Added filtering to DetailManager. --- UnsignedByte/Core/DetailManager.cpp | 39 ++++++++++ UnsignedByte/Core/DetailManager.h | 12 ++++ UnsignedByte/Core/EditorDetail.cpp | 138 ++++++++++++++++++++++++++++++++++++ UnsignedByte/Core/EditorDetail.h | 18 +++++ UnsignedByte/Core/EditorOLC.cpp | 4 +- 5 files changed, 210 insertions(+), 1 deletion(-) diff --git a/UnsignedByte/Core/DetailManager.cpp b/UnsignedByte/Core/DetailManager.cpp index 16d3429..46e803e 100644 --- a/UnsignedByte/Core/DetailManager.cpp +++ b/UnsignedByte/Core/DetailManager.cpp @@ -22,6 +22,9 @@ #include "Detail.h" #include "TableImpls.h" #include "db.h" +#include "Area.h" +#include "Room.h" +#include "Chunk.h" using mud::DetailManager; using mud::Detail; @@ -33,6 +36,42 @@ std::vector DetailManager::List() return GetTable()->tableList(mask); } +std::vector DetailManager::List(mud::AreaPtr parentArea) +{ + Assert(parentArea); + + SelectionMaskPtr mask(new SelectionMask(GetTable())); + mask->addJoin(db::TableImpls::Get()->DETAILAREA , db::DetailsFields::Get()->DETAILID, db::DetailAreaFields::Get()->FKDETAILS); + ValuePtr value(new KeyValue(db::DetailAreaFields::Get()->FKAREAS, parentArea->getID())); + mask->addField(value); + + return GetTable()->tableList(mask); +} + +std::vector DetailManager::List(mud::RoomPtr parentRoom) +{ + Assert(parentRoom); + + SelectionMaskPtr mask(new SelectionMask(GetTable())); + mask->addJoin(db::TableImpls::Get()->DETAILROOM, db::DetailsFields::Get()->DETAILID, db::DetailRoomFields::Get()->FKDETAILS); + ValuePtr value(new KeyValue(db::DetailRoomFields::Get()->FKROOMS, parentRoom->getID())); + mask->addField(value); + + return GetTable()->tableList(mask); +} + +std::vector DetailManager::List(mud::ChunkPtr parentChunk) +{ + Assert(parentChunk); + + SelectionMaskPtr mask(new SelectionMask(GetTable())); + mask->addJoin(db::TableImpls::Get()->DETAILCHUNK, db::DetailsFields::Get()->DETAILID, db::DetailRoomFields::Get()->FKDETAILS); + ValuePtr value(new KeyValue(db::DetailChunkFields::Get()->FKCHUNKS, parentChunk->getID())); + mask->addField(value); + + return GetTable()->tableList(mask); +} + TableImplPtr DetailManager::GetTable() { return db::TableImpls::Get()->DETAILS; diff --git a/UnsignedByte/Core/DetailManager.h b/UnsignedByte/Core/DetailManager.h index 7929407..b696d45 100644 --- a/UnsignedByte/Core/DetailManager.h +++ b/UnsignedByte/Core/DetailManager.h @@ -25,6 +25,15 @@ namespace mud { class Detail; typedef SmartPtr DetailPtr; + + class Area; + typedef SmartPtr AreaPtr; + + class Room; + typedef SmartPtr RoomPtr; + + class Chunk; + typedef SmartPtr ChunkPtr; } namespace mud @@ -34,6 +43,9 @@ namespace mud public: TableImplPtr GetTable(); std::vector List(); + std::vector List(mud::AreaPtr parentArea); + std::vector List(mud::RoomPtr parentRoom); + std::vector List(mud::ChunkPtr parentChunk); void Close(DetailPtr detail); KeysPtr Add(); diff --git a/UnsignedByte/Core/EditorDetail.cpp b/UnsignedByte/Core/EditorDetail.cpp index e6b23f1..19cdd4b 100644 --- a/UnsignedByte/Core/EditorDetail.cpp +++ b/UnsignedByte/Core/EditorDetail.cpp @@ -29,23 +29,38 @@ #include "StringUtilities.h" #include "TableImpls.h" #include "UBSocket.h" +#include "Exceptions.h" #include "Account.h" #include "Detail.h" #include "DetailManager.h" +#include "Area.h" +#include "AreaManager.h" +#include "Room.h" +#include "RoomManager.h" +#include "Chunk.h" +#include "ChunkManager.h" + +#include typedef EditorDetail E; typedef CommandObject O; typedef CommandBinding B; +using namespace boost::spirit; + static O editKey("Key", &E::editKey); static O editDescription("Description", &E::editDescription); static O showDetail("Show", &E::showDetail); static O saveDetail("Save", &E::saveDetail); static O quitEditor("Quit", &E::quitEditor); +static O clearParents("ClearParents", &E::clearParents); +static O setParent("SetParent", &E::setParent); static const B commands[] = { + B("all", clearParents), B("description", editDescription), + B("filter", setParent), B("name", editKey), B("quit", quitEditor), B("save", saveDetail), @@ -70,6 +85,39 @@ m_target(M_NONE) } +EditorDetail::EditorDetail(UBSocket* sock, mud::AreaPtr parentArea) : +OLCEditor(sock), +m_commands(commands, array_size(commands)), +m_detail(), +m_parentArea(parentArea), +m_target(M_NONE) +{ + listCommands(Global::Get()->EmptyString); + m_sock->Sendf("Only Details that belong to area '%d' are shown, to clear this restriction type 'all'.\n", parentArea->getID()); +} + +EditorDetail::EditorDetail(UBSocket* sock, mud::RoomPtr parentRoom) : +OLCEditor(sock), +m_commands(commands, array_size(commands)), +m_detail(), +m_parentRoom(parentRoom), +m_target(M_NONE) +{ + listCommands(Global::Get()->EmptyString); + m_sock->Sendf("Only Details that belong to room '%d' are shown, to clear this restriction type 'all'.\n", parentRoom->getID()); +} + +EditorDetail::EditorDetail(UBSocket* sock, mud::ChunkPtr parentChunk) : +OLCEditor(sock), +m_commands(commands, array_size(commands)), +m_detail(), +m_parentChunk(parentChunk), +m_target(M_NONE) +{ + listCommands(Global::Get()->EmptyString); + m_sock->Sendf("Only Details that belong to chunk '%d' are shown, to clear this restriction type 'all'.\n", parentChunk->getID()); +} + EditorDetail::~EditorDetail(void) { @@ -124,6 +172,15 @@ KeysPtr EditorDetail::addNew() std::vector EditorDetail::getList() { + if(m_parentArea) + return mud::DetailManager::Get()->List(m_parentArea); + + if(m_parentRoom) + return mud::DetailManager::Get()->List(m_parentRoom); + + if(m_parentChunk) + return mud::DetailManager::Get()->List(m_parentChunk); + return mud::DetailManager::Get()->List(); } @@ -198,3 +255,84 @@ void EditorDetail::saveDetail(const std::string& argument) m_sock->Send("Saved.\n"); return; } + +void EditorDetail::clearParents(const std::string& argument) +{ + m_sock->Send("Ok.\n"); + m_parentArea.reset(); + m_parentRoom.reset(); + m_parentChunk.reset(); + return; +} + +void EditorDetail::setParent(const std::string& argument) +{ + if(!argument.size()) + { + m_sock->Send("Please provide an area, room, or chunk to filter on.\n"); + return; + } + + value_type id = 0; + bool area = false; + bool chunk = false; + bool room = false; + + bool good = parse(argument.c_str(), + // Begin grammar + ( + (str_p("area")[assign_a(area, true)] | + str_p("chunk")[assign_a(chunk, true)] | + str_p("room")[assign_a(room, true)]) + + >> int_p[assign_a(id)] + ) + , + // End grammar + space_p).full; + + if(!good) + { + m_sock->Send("Please specify what area, room, or chunk to filter on in the following format:\n"); + m_sock->Send("area/room/chunk id\n"); + return; + } + + Assert(area || chunk || room); + + if(area) + { + try { + mud::AreaPtr area = mud::AreaManager::Get()->GetByKey(id); + m_parentArea = area; + m_sock->Send("Ok.\n"); + m_sock->Sendf("Only Details that belong to area '%d' are shown, to clear this restriction type 'all'.\n", m_parentArea->getID()); + } catch(RowNotFoundException& e) { + m_sock->Sendf("'%s' is not an area.\n", argument.c_str()); + } + } + + if(room) + { + try { + mud::RoomPtr room = mud::RoomManager::Get()->GetByKey(id); + m_parentRoom = room; + m_sock->Send("Ok.\n"); + m_sock->Sendf("Only Details that belong to room '%d' are shown, to clear this restriction type 'all'.\n", m_parentRoom->getID()); + } catch(RowNotFoundException& e) { + m_sock->Sendf("'%s' is not a room.\n", argument.c_str()); + } + } + + if(chunk) + { + try { + mud::ChunkPtr chunk = mud::ChunkManager::Get()->GetByKey(id); + m_parentChunk = chunk; + m_sock->Send("Ok.\n"); + m_sock->Sendf("Only Details that belong to chunk '%d' are shown, to clear this restriction type 'all'.\n", m_parentChunk->getID()); + } catch(RowNotFoundException& e) { + m_sock->Sendf("'%d' is not a chunk.\n", id); + } + } +} diff --git a/UnsignedByte/Core/EditorDetail.h b/UnsignedByte/Core/EditorDetail.h index cb152f7..22394ff 100644 --- a/UnsignedByte/Core/EditorDetail.h +++ b/UnsignedByte/Core/EditorDetail.h @@ -30,6 +30,15 @@ namespace mud { class Detail; typedef SmartPtr DetailPtr; + + class Area; + typedef SmartPtr AreaPtr; + + class Room; + typedef SmartPtr RoomPtr; + + class Chunk; + typedef SmartPtr ChunkPtr; }; class EditorDetail : public OLCEditor @@ -39,6 +48,9 @@ public: EditorDetail(UBSocket* sock); EditorDetail(UBSocket* sock, mud::DetailPtr detail); + EditorDetail(UBSocket* sock, mud::AreaPtr parentArea); + EditorDetail(UBSocket* sock, mud::RoomPtr parentRoom); + EditorDetail(UBSocket* sock, mud::ChunkPtr parentChunk); ~EditorDetail(void); void OnFocus(); @@ -60,6 +72,8 @@ public: void editDescription(const std::string& argument); void showDetail(const std::string& argument); void saveDetail(const std::string& argument); + void clearParents(const std::string& argument); + void setParent(const std::string& argument); private: enum E_TARGET @@ -70,6 +84,10 @@ private: CommandTable m_commands; mud::DetailPtr m_detail; + mud::AreaPtr m_parentArea; + mud::RoomPtr m_parentRoom; + mud::ChunkPtr m_parentChunk; + std::string m_value; EditorDetail::E_TARGET m_target; diff --git a/UnsignedByte/Core/EditorOLC.cpp b/UnsignedByte/Core/EditorOLC.cpp index 88b829a..1d103c4 100644 --- a/UnsignedByte/Core/EditorOLC.cpp +++ b/UnsignedByte/Core/EditorOLC.cpp @@ -44,6 +44,7 @@ typedef CommandBinding B; static O startAreas("Areas", &E::startAreas); static O startRooms("Rooms", &E::startRooms); static O startChunks("Chunks", &E::startChunks); +static O startDetails("Details", &E::startDetails); static O startScripts("Scripts", &E::startScripts); static O startMobiles("Mobiles", &E::startMobiles); static O startSectors("Sectors", &E::startSectors); @@ -59,6 +60,7 @@ static B commands[] = { B("chunks", startChunks), B("colour", startColours), B("commands", startCommands), + B("details", startDetails), B("mobiles", startMobiles), B("quit", quitEditor), B("races", startRaces), @@ -155,7 +157,7 @@ void EditorOLC::startRaces(const std::string& argument) void EditorOLC::startDetails(const std::string& argument) { - m_sock->Send("Dropping you into Eetail Edit mode!\n"); + m_sock->Send("Dropping you into Detail Edit mode!\n"); m_sock->SetEditor(new EditorDetail(m_sock)); return; } -- 2.11.4.GIT