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 ***************************************************************************/
23 #include "CommandBinding.h"
24 #include "CommandTable.h"
25 #include "EditorOLC.h"
26 #include "EditorRace.h"
29 #include "RaceManager.h"
30 #include "StringUtilities.h"
31 #include "TableImpls.h"
35 typedef CommandInfoObject
<E
> O
;
36 typedef CommandBinding
<E
> B
;
38 // name function need: object lock
39 static O
editName ("Name", &E::editName
, true, true);
40 static O
saveRace ("Save", &E::saveRace
, true, true);
41 static O
showRace ("Show", &E::showRace
, true, false);
43 static const B commands
[] = {
49 EditorRace::EditorRace(UBSocket
* sock
) :
51 m_commands(commands
, array_size(commands
)),
54 listCommands(Global::Get()->EmptyString
);
57 EditorRace::~EditorRace(void)
61 std::string
EditorRace::lookup(const std::string
& action
)
63 std::string name
= OLCEditor::lookup(action
);
67 const RaceCommand
* act
= (RaceCommand
*)m_commands
.getObject(action
);
69 return act
->getName();
71 return Global::Get()->EmptyString
;
74 void EditorRace::dispatch(const std::string
& action
, const std::string
& argument
)
76 const RaceCommand
* act
= (RaceCommand
*)m_commands
.getObject(action
);
80 OLCEditor::dispatch(action
, argument
);
86 m_sock
->Send("You need to be editing an race first.\n");
87 m_sock
->Send("(Use the 'edit' command.)\n");
95 } catch(SavableLocked
& e
) {
96 m_sock
->Send("The race you are currently editing is locked (being edited by someone else), so you cannot edit it right now.\n");
97 m_sock
->Send("Please try again later.\n");
102 act
->Run(this, argument
);
106 SavablePtr
EditorRace::getEditing()
111 TableImplPtr
EditorRace::getTable()
113 return db::TableImpls::Get()->RACES
;
116 KeysPtr
EditorRace::addNew()
118 return mud::Managers::Get()->Race
->Add();
121 std::vector
<std::string
> EditorRace::getList()
123 return mud::Managers::Get()->Race
->List();
126 std::vector
<std::string
> EditorRace::getCommands()
128 return m_commands
.getCommandsVector();
131 void EditorRace::setEditing(KeysPtr keys
)
139 m_race
= mud::Managers::Get()->Race
->GetByKey(keys
->first()->getIntegerValue());
143 void EditorRace::editName(const std::string
& argument
)
145 if(argument
.size() == 0)
147 m_sock
->Send("Race name can't be zero length!\n");
151 m_sock
->Sendf("Race name changed from '%s' to '%s'.\n", m_race
->getName().c_str(), argument
.c_str());
152 m_race
->setName(argument
);
156 void EditorRace::showRace(const std::string
& argument
)
158 m_sock
->Send(m_race
->toString());
161 void EditorRace::saveRace(const std::string
& argument
)
163 m_sock
->Sendf("Saving race '%s'.\n", m_race
->getName().c_str());
165 m_sock
->Send("Saved.\n");