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 "CommandBinding.h"
22 #include "CommandObject.h"
23 #include "CommandTable.h"
24 #include "EditorRace.h"
25 #include "EditorOLC.h"
30 #include "StringUtilities.h"
31 #include "TableImpls.h"
35 #include "RaceManager.h"
38 typedef CommandObject
<E
> O
;
39 typedef CommandBinding
<E
> B
;
41 static O
editDescription("Description", NULL
);
42 static O
editHeight ("Height", NULL
);
43 static O
editName ("Name", &E::editName
);
44 static O
saveRace ("Save", &E::saveRace
);
45 static O
showRace ("Show", &E::showRace
);
46 static O
editWidth ("Width", NULL
);
48 static const B commands
[] = {
49 B("description", editDescription
),
50 B("height", editHeight
),
54 B("width", editWidth
),
57 EditorRace::EditorRace(UBSocket
* sock
) :
59 m_commands(commands
, array_size(commands
)),
62 listCommands(Global::Get()->EmptyString
);
65 EditorRace::~EditorRace(void)
69 std::string
EditorRace::lookup(const std::string
& action
)
71 std::string name
= OLCEditor::lookup(action
);
75 const RaceCommand
* act
= m_commands
.getObject(action
);
77 return act
->getName();
79 return Global::Get()->EmptyString
;
82 void EditorRace::dispatch(const std::string
& action
, const std::string
& argument
)
84 const RaceCommand
* act
= m_commands
.getObject(action
);
88 m_sock
->Send("You need to be editing an race first.\n");
89 m_sock
->Send("(Use the 'edit' command.)\n");
94 act
->Run(this, argument
);
96 OLCEditor::dispatch(action
, argument
);
101 SavablePtr
EditorRace::getEditing()
106 TableImplPtr
EditorRace::getTable()
108 return db::TableImpls::Get()->RACES
;
111 KeysPtr
EditorRace::addNew()
113 return mud::RaceManager::Get()->Add();
116 std::vector
<std::string
> EditorRace::getList()
118 return mud::RaceManager::Get()->List();
121 std::vector
<std::string
> EditorRace::getCommands()
123 return m_commands
.getCommandsVector();
126 void EditorRace::setEditing(KeysPtr keys
)
134 m_race
= mud::RaceManager::Get()->GetByKey(keys
->first()->getValue());
138 void EditorRace::editName(const std::string
& argument
)
140 if(argument
.size() == 0)
142 m_sock
->Send("Race name can't be zero length!\n");
146 m_sock
->Sendf("Race name changed from '%s' to '%s'.\n", m_race
->getName().c_str(), argument
.c_str());
147 m_race
->setName(argument
);
151 void EditorRace::showRace(const std::string
& argument
)
153 m_sock
->Send(String::Get()->box(m_race
->Show(), "Race"));
156 void EditorRace::saveRace(const std::string
& argument
)
158 m_sock
->Sendf("Saving race '%s'.\n", m_race
->getName().c_str());
160 m_sock
->Send("Saved.\n");