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 "EditorColour.h"
22 #include "EditorOLC.h"
24 #include "StringUtilities.h"
25 #include "TableImpls.h"
28 #include "Permission.h"
31 #include "ColourManager.h"
36 typedef EditorColour E
;
37 typedef CommandInfoObject
<E
> O
;
38 typedef CommandBinding
<E
> B
;
40 // name function need: object lock
41 static O
editName( "Name", &E::editName
, true, true);
42 static O
editColourString("ColourString",&E::editColourString
,true,true);
43 static O
saveColour("Save", &E::saveColour
, true, true);
44 static O
showColour("Show", &E::showColour
, true, false);
46 static const B commands
[] = {
47 B("colourstring", editColourString
),
49 B("save", saveColour
),
50 B("show", showColour
),
53 EditorColour::EditorColour(UBSocket
* sock
) :
55 m_commands(commands
, array_size(commands
)),
58 listCommands(Global::Get()->EmptyString
);
61 EditorColour::~EditorColour(void)
66 std::string
EditorColour::lookup(const std::string
& action
)
68 std::string name
= OLCEditor::lookup(action
);
72 const ColourCommand
* act
= (ColourCommand
*)m_commands
.getObject(action
);
74 return act
->getName();
76 return Global::Get()->EmptyString
;
79 void EditorColour::dispatch(const std::string
& action
, const std::string
& argument
)
81 const ColourCommand
* act
= (ColourCommand
*)m_commands
.getObject(action
);
85 OLCEditor::dispatch(action
, argument
);
91 m_sock
->Send("You need to be editing a colour first.\n");
92 m_sock
->Send("(Use the 'edit' command.)\n");
100 } catch(SavableLocked
& e
) {
101 m_sock
->Send("The colour you are currently editing is locked (being edited by someone else), so you cannot edit it right now.\n");
102 m_sock
->Send("Please try again later.\n");
107 act
->Run(this, argument
);
111 SavablePtr
EditorColour::getEditing()
116 TableImplPtr
EditorColour::getTable()
118 return db::TableImpls::Get()->COLOURS
;
121 KeysPtr
EditorColour::addNew()
123 return mud::Managers::Get()->Colour
->Add();
126 std::vector
<std::string
> EditorColour::getList()
128 return mud::Managers::Get()->Colour
->List();
131 void EditorColour::setEditing(KeysPtr keys
)
139 m_colour
= mud::Managers::Get()->Colour
->GetByKey(keys
->first()->getIntegerValue());
143 std::vector
<std::string
> EditorColour::getCommands()
145 return m_commands
.getCommandsVector();
148 void EditorColour::editName(const std::string
& argument
)
150 if(argument
.size() == 0)
152 m_sock
->Send("Colour name can't be zero length!\n");
156 m_sock
->Sendf("Colour name changed from '%s' to '%s'.\n", m_colour
->getName().c_str(), argument
.c_str());
157 m_colour
->setName(argument
);
161 void EditorColour::editColourString(const std::string
& argument
)
163 if(!m_colour
->Exists())
165 m_sock
->Send("For some reason the colour you are editing does not exist.\n");
169 if(argument
.size() == 0)
171 m_sock
->Send("No argument, dropping you into the string editor!\n");
175 m_sock
->Sendf("Colour ColourString changed from '%s' to '%s'.\n", m_colour
->getColourString().c_str(), argument
.c_str());
176 m_colour
->setColourString(argument
);
180 void EditorColour::saveColour(const std::string
& argument
)
182 m_sock
->Send("Saving...\n");
184 m_sock
->Send("Saved.\n");
188 void EditorColour::showColour(const std::string
& argument
)
190 m_sock
->Send(m_colour
->toString());