Files
MagicSetEditor2/src/data/action/set.hpp
T
2026-02-01 17:39:33 +01:00

207 lines
6.9 KiB
C++

//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make card games |
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#pragma once
/** @file data/action/set.hpp
*
* Actions operating on Sets
*/
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/action_stack.hpp>
#include <data/action/generic.hpp>
class Set;
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(StyleSheet);
DECLARE_POINTER_TYPE(Field);
DECLARE_POINTER_TYPE(Value);
DECLARE_POINTER_TYPE(PackType);
// ----------------------------------------------------------------------------- : Add card
/// An Action the changes the card list of a set
class CardListAction : public Action {
public:
inline CardListAction(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 card to a set
class AddCardAction : public CardListAction {
public:
/// Add a newly allocated card
AddCardAction(Set& set);
AddCardAction(AddingOrRemoving, Set& set, const vector<CardP>& cards);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
const GenericAddAction<CardP> action;
vector<ActionP> card_link_actions;
};
// ----------------------------------------------------------------------------- : Reorder cards
/// Change the position of a card in the card list by swapping two cards
class ReorderCardsAction : public CardListAction {
public:
ReorderCardsAction(Set& set, size_t card_id1, size_t card_id2);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
//private:
const size_t card_id1, card_id2; ///< Positions of the two cards to swap
};
// ----------------------------------------------------------------------------- : Link cards
/// Add a link between two or more cards
class OneWayLinkCardsAction : public CardListAction {
public:
OneWayLinkCardsAction(Set& set, CardP& card, const String& uid, const String& relation, int index);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
//private:
CardP card; ///< The card we change the link of. We hold a reference so it doesn't get destroyed before this.
String* linked_uid; ///< The uid slot we need to change
String* linked_relation; ///< The relation slot we need to change
String uid; ///< The uid we have to change the link to
String relation; ///< The relation we have to change the link to
};
// ----------------------------------------------------------------------------- : Change stylesheet
/// An action that affects the rendering/display/look of a set or cards in the set
class DisplayChangeAction : public Action {
public:
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
};
/// Changing the style of a a card
class ChangeCardStyleAction : public DisplayChangeAction {
public:
ChangeCardStyleAction(const CardP& card, const StyleSheetP& stylesheet);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
//private:
CardP card; ///< The affected card
StyleSheetP stylesheet; ///< Its old stylesheet
bool has_styling; ///< Its old has_styling
IndexMap<FieldP,ValueP> styling_data; ///< Its old styling data
};
/// Changing the style of a set to that of a card
class ChangeSetStyleAction : public DisplayChangeAction {
public:
ChangeSetStyleAction(Set& set, const CardP& card);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
private:
Set& set; ///< The affected set
CardP card; ///< The card whos stylesheet is copied to the set
StyleSheetP stylesheet; ///< The old stylesheet of the set
vector<int> has_styling; ///< The old has_styling values of all cards (vector<bool> is evil)
};
/// Changing the styling of a card to become custom/non-custom
/** i.e. toggle card->has_styling */
class ChangeCardHasStylingAction : public DisplayChangeAction {
public:
ChangeCardHasStylingAction(Set& set, const CardP& card);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
//private:
Set& set; ///< The set to copy styling from
CardP card; ///< The affected card
IndexMap<FieldP,ValueP> styling_data; ///< The old styling of the card
};
// ----------------------------------------------------------------------------- : Change notes
/// Changing the notes of a card
class ChangeCardNotesAction : public Action {
public:
ChangeCardNotesAction(const CardP& card, const String& notes);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
//private:
CardP card; ///< The affected card
String notes; ///< Its old notes
};
// ----------------------------------------------------------------------------- : Change uid
/// Changing the uid of a card
class ChangeCardUIDAction : public CardListAction {
public:
ChangeCardUIDAction(Set& set, const CardP& card, const String& id);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
//private:
CardP card; ///< The affected card
String uid; ///< Its old uid
};
// ----------------------------------------------------------------------------- : Pack types
/// An Action the changes the pack types of a set
class PackTypesAction : public Action {
public:
inline PackTypesAction(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/removing a pack from a Set
class AddPackAction : public PackTypesAction {
public:
/// Add a newly allocated card
AddPackAction(AddingOrRemoving, Set& set, const PackTypeP& pack);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
const GenericAddAction<PackTypeP> action;
};
/// Updating a pack in a Set
class ChangePackAction : public PackTypesAction {
public:
/// Add a newly allocated card
ChangePackAction(Set& set, size_t pos, const PackTypeP& new_pack);
String getName(bool to_undo) const override;
void perform(bool to_undo) override;
private:
PackTypeP pack;
size_t pos;
};