Added actions for adding/removing keywords

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@254 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-04-13 17:21:35 +00:00
parent f915a491a8
commit 1be1304c94
9 changed files with 233 additions and 5 deletions
+71
View File
@@ -0,0 +1,71 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <data/action/keyword.hpp>
#include <data/keyword.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
DECLARE_TYPEOF_COLLECTION(KeywordModeP);
// ----------------------------------------------------------------------------- : Add Keyword
AddKeywordAction::AddKeywordAction(Set& set)
: KeywordListAction(set), keyword(new Keyword())
{
// find default mode
FOR_EACH(mode, set.game->keyword_modes) {
if (mode->is_default) {
keyword->mode = mode->name;
break;
}
}
}
AddKeywordAction::AddKeywordAction(Set& set, const KeywordP& keyword)
: KeywordListAction(set), keyword(keyword)
{}
String AddKeywordAction::getName(bool to_undo) const {
return _("Add keyword");
}
void AddKeywordAction::perform(bool to_undo) {
if (!to_undo) {
set.keywords.push_back(keyword);
} else {
assert(!set.keywords.empty());
set.keywords.pop_back();
}
}
// ----------------------------------------------------------------------------- : Remove Keyword
RemoveKeywordAction::RemoveKeywordAction(Set& set, const KeywordP& keyword)
: KeywordListAction(set), keyword(keyword)
// find the keyword_id of the keyword we want to remove
, keyword_id(find(set.keywords.begin(), set.keywords.end(), keyword) - set.keywords.begin())
{
if (keyword_id >= set.keywords.size()) {
throw InternalError(_("Keyword to remove not found in set"));
}
}
String RemoveKeywordAction::getName(bool to_undo) const {
return _("Remove keyword");
}
void RemoveKeywordAction::perform(bool to_undo) {
if (!to_undo) {
assert(keyword_id < set.keywords.size());
set.keywords.erase(set.keywords.begin() + keyword_id);
} else {
assert(keyword_id <= set.keywords.size());
set.keywords.insert(set.keywords.begin() + keyword_id, keyword);
}
}
+66
View File
@@ -0,0 +1,66 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_ACTION_KEYWORD
#define HEADER_DATA_ACTION_KEYWORD
/** @file data/action/keyword.hpp
*
* Actions operating on Keywords and the keyword list of a set
*/
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/action_stack.hpp>
class Set;
DECLARE_POINTER_TYPE(Keyword);
// ----------------------------------------------------------------------------- : Add Keyword
/// An Action the changes the keyword list of a set
class KeywordListAction : public Action {
public:
inline KeywordListAction(Set& set) : set(set) {}
protected:
Set& set; // the set owns this action, so the set will not be destroyed before this
// therefore we don't need a smart pointer
};
/// Adding a new keyword to a set
class AddKeywordAction : public KeywordListAction {
public:
AddKeywordAction(Set& set);
AddKeywordAction(Set& set, const KeywordP& keyword);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
//private:
const KeywordP keyword; ///< The new keyword
};
// ----------------------------------------------------------------------------- : Remove Keyword
/// Removing a keyword from a set
class RemoveKeywordAction : public KeywordListAction {
public:
RemoveKeywordAction(Set& set, const KeywordP& keyword);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
//private:
const KeywordP keyword; ///< The removed keyword
const size_t keyword_id; ///< Position of the keyword in the set
};
// ----------------------------------------------------------------------------- : Changing keywords
// ----------------------------------------------------------------------------- : EOF
#endif
+1
View File
@@ -30,6 +30,7 @@ class CardListAction : public Action {
protected:
Set& set; // the set owns this action, so the set will not be destroyed before this
// therefore we don't need a smart pointer
};
/// Adding a new card to a set
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef HEADER_DATA_ACTION_VALUE
#define HEADER_DATA_ACTION_VALUE
/** @file data/action/set.hpp
/** @file data/action/value.hpp
*
* Actions operating on Values (and derived classes, "*Value")
*/
+3
View File
@@ -39,6 +39,7 @@ class KeywordParam {
/// Information on when and how to use a keyword
class KeywordMode {
public:
String name; ///< Name of the mode
String description; ///< Description of the type
bool is_default; ///< This is the default mode for new keywords
@@ -51,6 +52,8 @@ class KeywordMode {
/// A keyword for a set or a game
class Keyword {
public:
Keyword() : fixed(false) {}
String keyword; ///< The keyword, only for human use
String rules; ///< Rules/explanation
String match; ///< String to match, <param> tags are used for parameters