Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
54adf711
Commit
54adf711
authored
Oct 19, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
action for modifying the card list
parent
5f24d667
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
158 additions
and
0 deletions
+158
-0
src/data/action/set.cpp
src/data/action/set.cpp
+81
-0
src/data/action/set.hpp
src/data/action/set.hpp
+77
-0
No files found.
src/data/action/set.cpp
0 → 100644
View file @
54adf711
//+----------------------------------------------------------------------------+
//| 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/set.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <util/error.hpp>
// ----------------------------------------------------------------------------- : Add card
AddCardAction
::
AddCardAction
(
Set
&
set
)
:
CardListAction
(
set
),
card
(
new
Card
(
*
set
.
game
))
{}
AddCardAction
::
AddCardAction
(
Set
&
set
,
const
CardP
&
card
)
:
CardListAction
(
set
),
card
(
card
)
{}
String
AddCardAction
::
getName
(
bool
to_undo
)
const
{
return
_
(
"Add card"
);
}
void
AddCardAction
::
perform
(
bool
to_undo
)
{
if
(
!
to_undo
)
{
set
.
cards
.
push_back
(
card
);
}
else
{
assert
(
!
set
.
cards
.
empty
());
set
.
cards
.
pop_back
();
}
}
// ----------------------------------------------------------------------------- : Remove card
RemoveCardAction
::
RemoveCardAction
(
Set
&
set
,
const
CardP
&
card
)
:
CardListAction
(
set
),
card
(
card
)
{
// find the card_id of the card we want to remove
vector
<
CardP
>::
iterator
it
=
find
(
set
.
cards
.
begin
(),
set
.
cards
.
end
(),
card
);
if
(
it
!=
set
.
cards
.
end
())
{
card_id
=
it
-
set
.
cards
.
begin
();
}
else
{
throw
InternalError
(
_
(
"Card to remove not found in set"
));
}
}
String
RemoveCardAction
::
getName
(
bool
to_undo
)
const
{
return
_
(
"Remove card"
);
}
void
RemoveCardAction
::
perform
(
bool
to_undo
)
{
if
(
!
to_undo
)
{
assert
(
card_id
<
set
.
cards
.
size
());
set
.
cards
.
erase
(
set
.
cards
.
begin
()
+
card_id
);
}
else
{
assert
(
card_id
<=
set
.
cards
.
size
());
set
.
cards
.
insert
(
set
.
cards
.
begin
()
+
card_id
,
card
);
}
}
// ----------------------------------------------------------------------------- : Reorder cards
ReorderCardsAction
::
ReorderCardsAction
(
Set
&
set
,
size_t
card_id1
,
size_t
card_id2
)
:
CardListAction
(
set
),
card_id1
(
card_id1
),
card_id2
(
card_id2
)
{}
String
ReorderCardsAction
::
getName
(
bool
to_undo
)
const
{
return
_
(
"Reorder cards"
);
}
void
ReorderCardsAction
::
perform
(
bool
to_undo
)
{
assert
(
card_id1
<
set
.
cards
.
size
());
assert
(
card_id2
<
set
.
cards
.
size
());
swap
(
set
.
cards
[
card_id1
],
set
.
cards
[
card_id2
]);
}
src/data/action/set.hpp
0 → 100644
View file @
54adf711
//+----------------------------------------------------------------------------+
//| 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_SET
#define HEADER_DATA_ACTION_SET
/** @file data/action/set.hpp
*
* Actions operating on Sets
*/
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/action_stack.hpp>
class
Set
;
DECLARE_POINTER_TYPE
(
Card
);
// ----------------------------------------------------------------------------- : 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
};
/// Adding a new card to a set
class
AddCardAction
:
public
CardListAction
{
public:
AddCardAction
(
Set
&
set
);
AddCardAction
(
Set
&
set
,
const
CardP
&
card
);
virtual
String
getName
(
bool
to_undo
)
const
;
virtual
void
perform
(
bool
to_undo
);
private:
CardP
card
;
///< The new card
};
// ----------------------------------------------------------------------------- : Remove card
/// Removing a card from a set
class
RemoveCardAction
:
public
CardListAction
{
public:
RemoveCardAction
(
Set
&
set
,
const
CardP
&
card
);
virtual
String
getName
(
bool
to_undo
)
const
;
virtual
void
perform
(
bool
to_undo
);
private:
CardP
card
;
///< The removed card
size_t
card_id
;
///< Position of the card in the set
};
// ----------------------------------------------------------------------------- : 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
);
virtual
String
getName
(
bool
to_undo
)
const
;
virtual
void
perform
(
bool
to_undo
);
private:
size_t
card_id1
,
card_id2
;
///< Positions of the two cards to swap
};
// ----------------------------------------------------------------------------- : EOF
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment