1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _ConsoleCommand_H__ |
---|
30 | #define _ConsoleCommand_H__ |
---|
31 | |
---|
32 | #include "CorePrereqs.h" |
---|
33 | |
---|
34 | #include "Executor.h" |
---|
35 | #include "ClassManager.h" |
---|
36 | #include "Identifier.h" |
---|
37 | #include "CommandExecutor.h" |
---|
38 | |
---|
39 | |
---|
40 | #define SetConsoleCommand(classname, function, bCreateShortcut) \ |
---|
41 | SetConsoleCommandGeneric(classname##function##consolecommand__, classname, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function), bCreateShortcut) |
---|
42 | |
---|
43 | #define SetConsoleCommandGeneric(fakevariable, classname, executor, bCreateShortcut) \ |
---|
44 | Executor& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ConsoleCommand*)executor, bCreateShortcut) |
---|
45 | |
---|
46 | |
---|
47 | #define SetConsoleCommandShortcut(classname, function) \ |
---|
48 | SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&classname::function), #function)) |
---|
49 | |
---|
50 | #define SetConsoleCommandShortcutExtern(function) \ |
---|
51 | SetConsoleCommandShortcutGeneric(function##consolecommand__, orxonox::createConsoleCommand(orxonox::createFunctor(&function), #function)) |
---|
52 | |
---|
53 | #define SetConsoleCommandShortcutGeneric(fakevariable, executor) \ |
---|
54 | Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)executor) |
---|
55 | |
---|
56 | |
---|
57 | namespace orxonox |
---|
58 | { |
---|
59 | namespace AccessLevel |
---|
60 | { |
---|
61 | enum Level |
---|
62 | { |
---|
63 | None, |
---|
64 | User, |
---|
65 | Admin, |
---|
66 | Offline, |
---|
67 | Debug, |
---|
68 | Disabled |
---|
69 | }; |
---|
70 | } |
---|
71 | |
---|
72 | class _CoreExport ConsoleCommand : public ExecutorStatic |
---|
73 | { |
---|
74 | public: |
---|
75 | ConsoleCommand(FunctorStatic* functor, const std::string& name = "") : ExecutorStatic(functor, name), accessLevel_(AccessLevel::None) {} |
---|
76 | |
---|
77 | inline ConsoleCommand& setDescription(const std::string& description) |
---|
78 | { this->ExecutorStatic::setDescription(description); return (*this); } |
---|
79 | inline ConsoleCommand& setDescriptionParam(int param, const std::string& description) |
---|
80 | { this->ExecutorStatic::setDescriptionParam(param, description); return (*this); } |
---|
81 | inline ConsoleCommand& setDescriptionReturnvalue(const std::string& description) |
---|
82 | { this->ExecutorStatic::setDescriptionReturnvalue(description); return (*this); } |
---|
83 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1) |
---|
84 | { this->ExecutorStatic::setDefaultValues(param1); return (*this); } |
---|
85 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2) |
---|
86 | { this->ExecutorStatic::setDefaultValues(param1, param2); return (*this); } |
---|
87 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3) |
---|
88 | { this->ExecutorStatic::setDefaultValues(param1, param2, param3); return (*this); } |
---|
89 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4) |
---|
90 | { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4); return (*this); } |
---|
91 | inline ConsoleCommand& setDefaultValues(const MultiTypeMath& param1, const MultiTypeMath& param2, const MultiTypeMath& param3, const MultiTypeMath& param4, const MultiTypeMath& param5) |
---|
92 | { this->ExecutorStatic::setDefaultValues(param1, param2, param3, param4, param5); return (*this); } |
---|
93 | inline ConsoleCommand& setDefaultValue(unsigned int index, const MultiTypeMath& param) |
---|
94 | { this->ExecutorStatic::setDefaultValue(index, param); return (*this); } |
---|
95 | |
---|
96 | inline ConsoleCommand& setAccessLevel(AccessLevel::Level level) |
---|
97 | { this->accessLevel_ = level; return (*this); } |
---|
98 | inline AccessLevel::Level getAccessLevel() const |
---|
99 | { return this->accessLevel_; } |
---|
100 | |
---|
101 | private: |
---|
102 | AccessLevel::Level accessLevel_; |
---|
103 | }; |
---|
104 | |
---|
105 | inline ConsoleCommand* createConsoleCommand(FunctorStatic* functor, const std::string& name = "") |
---|
106 | { |
---|
107 | return new ConsoleCommand(functor, name); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | #endif /* _ConsoleCommand_H__ */ |
---|