1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "EditorArea.h"
22 #include "EditorCluster.h"
23 #include "EditorDetail.h"
25 #include "StringUtilities.h"
26 #include "TableImpls.h"
30 #include "AreaManager.h"
34 typedef CommandInfoObject
<E
> O
;
35 typedef CommandBinding
<E
> B
;
37 // name function need: object lock
38 static O
editName( "Name", &E::editName
, true, true);
39 static O
editDescription("Description",&E::editDescription
,true, true);
40 static O
editHeight("Height", &E::editHeight
, true, true);
41 static O
editWidth( "Width", &E::editWidth
, true, true);
42 static O
showArea( "Show", &E::showArea
, true, false);
43 static O
saveArea( "Save", &E::saveArea
, true, true);
44 static O
startClusters("Clusters", &E::startClusters
);
45 static O
startDetails("Details",&E::startDetails
);
47 static B commands
[] = {
48 B("clusters", startClusters
),
49 B("description", editDescription
),
50 B("details", startDetails
),
51 B("height", editHeight
),
55 B("width", editWidth
),
59 EditorArea::EditorArea(UBSocket
* sock
) :
61 m_commands(commands
, array_size(commands
)),
64 listCommands(Global::Get()->EmptyString
);
67 EditorArea::~EditorArea(void)
72 std::string
EditorArea::lookup(const std::string
& action
)
74 std::string name
= OLCEditor::lookup(action
);
78 const AreaCommand
* act
= (AreaCommand
*)m_commands
.getObject(action
);
80 return act
->getName();
82 return Global::Get()->EmptyString
;
85 void EditorArea::dispatch(const std::string
& action
, const std::string
& argument
)
87 const AreaCommand
* act
= (AreaCommand
*)m_commands
.getObject(action
);
91 OLCEditor::dispatch(action
, argument
);
97 m_sock
->Send("You need to be editing an area first.\n");
98 m_sock
->Send("(Use the 'edit' command.)\n");
106 } catch(SavableLocked
& e
) {
107 m_sock
->Send("The area you are currently editing is locked (being edited by someone else), so you cannot edit it right now.\n");
108 m_sock
->Send("Please try again later.\n");
113 act
->Run(this, argument
);
117 SavablePtr
EditorArea::getEditing()
122 TableImplPtr
EditorArea::getTable()
124 return db::TableImpls::Get()->AREAS
;
127 KeysPtr
EditorArea::addNew()
129 return mud::Managers::Get()->Area
->Add();
132 std::vector
<std::string
> EditorArea::getList()
134 return mud::Managers::Get()->Area
->List();
137 void EditorArea::setEditing(KeysPtr keys
)
145 m_area
= mud::Managers::Get()->Area
->GetByKey(keys
->first()->getIntegerValue());
149 std::vector
<std::string
> EditorArea::getCommands()
151 return m_commands
.getCommandsVector();
154 void EditorArea::editName(const std::string
& argument
)
156 if(argument
.size() == 0)
158 m_sock
->Send("Area name can't be zero length!\n");
162 m_sock
->Sendf("Area name changed from '%s' to '%s'.\n", m_area
->getName().c_str(), argument
.c_str());
163 m_area
->setName(argument
);
167 void EditorArea::editDescription(const std::string
& argument
)
169 if(argument
.size() == 0)
171 m_sock
->Send("No argument, dropping you into the string editor!\n");
175 m_sock
->Sendf("Area description changed from '%s' to '%s'.\n", m_area
->getDescription().c_str(), argument
.c_str());
176 m_area
->setDescription(argument
);
180 void EditorArea::editHeight(const std::string
& argument
)
182 if(argument
.size() == 0)
184 m_sock
->Send("Please specify the area's height!\n");
188 int height
= atoi(argument
.c_str());
191 m_sock
->Sendf("Please specify a height > 0!\n");
195 m_sock
->Sendf("Area height changed from '%d' to '%d'.\n", m_area
->getHeight(), height
);
196 m_area
->setHeight(height
);
200 void EditorArea::editWidth(const std::string
& argument
)
202 if(argument
.size() == 0)
204 m_sock
->Send("Please specify the area's width!\n");
208 int width
= atoi(argument
.c_str());
211 m_sock
->Sendf("Please specify a width > 0!\n");
215 m_sock
->Sendf("Area width changed from '%d' to '%d'.\n", m_area
->getWidth(), width
);
216 m_area
->setWidth(width
);
220 void EditorArea::showArea(const std::string
& argument
)
222 m_sock
->Send(m_area
->toString());
225 void EditorArea::saveArea(const std::string
& argument
)
227 m_sock
->Sendf("Saving area '%s'.\n", m_area
->getName().c_str());
229 m_sock
->Send("Saved.\n");
233 void EditorArea::startClusters(const std::string
& argument
)
235 if(!argument
.compare("."))
239 m_sock
->Send("You can only use '.' when you are already editing an area.\n");
240 m_sock
->Send("You may specifiy an area to filter the Cluster Editor on by it's id.\n");
244 m_sock
->Send("Dropping you into filtered Cluster Edit mode!\n");
245 m_sock
->SetEditor(new EditorCluster(m_sock
, m_area
));
251 value_type id
= atoi(argument
.c_str());
254 mud::AreaPtr area
= mud::Managers::Get()->Area
->GetByKey(id
);
255 m_sock
->Send("dropping you into filtered Cluster Edit mode!\n");
256 m_sock
->SetEditor(new EditorCluster(m_sock
, area
));
257 } catch(RowNotFoundException
& e
) {
258 m_sock
->Sendf("Unknown cluster '%s'.\n", argument
.c_str());
264 m_sock
->Send("Dropping you into Cluster Edit mode!\n");
265 m_sock
->SetEditor(new EditorCluster(m_sock
));
269 void EditorArea::startDetails(const std::string
& argument
)
271 m_sock
->Send("Dropping you into Detail Edit mode!\n");
272 m_sock
->SetEditor(new EditorDetail(m_sock
));