mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-07 18:43:26 -08:00
[DeckDiff] Use namespace instead of static-only class per review
This commit is contained in:
parent
02ccad2374
commit
507a80f0b2
2 changed files with 27 additions and 27 deletions
|
|
@ -55,7 +55,9 @@ bool changeLessThan(const DeckCardChange &a, const DeckCardChange &b)
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
DeckDiffResult DeckDiff::diff(const DeckList &oldDeck, const DeckList &newDeck)
|
namespace DeckDiff
|
||||||
|
{
|
||||||
|
DeckDiffResult diff(const DeckList &oldDeck, const DeckList &newDeck)
|
||||||
{
|
{
|
||||||
const QMap<ZoneCardKey, int> oldCounts = zoneCardCounts(oldDeck);
|
const QMap<ZoneCardKey, int> oldCounts = zoneCardCounts(oldDeck);
|
||||||
const QMap<ZoneCardKey, ZoneCardInfo> newInfos = zoneCardInfos(newDeck);
|
const QMap<ZoneCardKey, ZoneCardInfo> newInfos = zoneCardInfos(newDeck);
|
||||||
|
|
@ -82,7 +84,7 @@ DeckDiffResult DeckDiff::diff(const DeckList &oldDeck, const DeckList &newDeck)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckDiff::canAutoMerge(const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges)
|
bool canAutoMerge(const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges)
|
||||||
{
|
{
|
||||||
QSet<ZoneCardKey> localKeys;
|
QSet<ZoneCardKey> localKeys;
|
||||||
for (const DeckCardChange &change : localChanges.changes) {
|
for (const DeckCardChange &change : localChanges.changes) {
|
||||||
|
|
@ -96,8 +98,7 @@ bool DeckDiff::canAutoMerge(const DeckDiffResult &localChanges, const DeckDiffRe
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckList
|
DeckList merge(const DeckList &baseDeck, const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges)
|
||||||
DeckDiff::merge(const DeckList &baseDeck, const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges)
|
|
||||||
{
|
{
|
||||||
QMap<ZoneCardKey, int> counts = zoneCardCounts(baseDeck);
|
QMap<ZoneCardKey, int> counts = zoneCardCounts(baseDeck);
|
||||||
QMap<ZoneCardKey, DeckCardChange> printings;
|
QMap<ZoneCardKey, DeckCardChange> printings;
|
||||||
|
|
@ -138,3 +139,4 @@ DeckDiff::merge(const DeckList &baseDeck, const DeckDiffResult &localChanges, co
|
||||||
merged.refreshDeckHash();
|
merged.refreshDeckHash();
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
} // namespace DeckDiff
|
||||||
|
|
|
||||||
|
|
@ -40,35 +40,33 @@ struct DeckDiffResult
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class DeckDiff
|
* @namespace DeckDiff
|
||||||
* @brief Pure card-count diff and three-way merge for deck sync.
|
* @brief Pure card-count diff and three-way merge for deck sync.
|
||||||
*
|
*
|
||||||
* Compares card names and copy counts per zone only; a merged deck keeps
|
* Compares card names and copy counts per zone only; a merged deck keeps
|
||||||
* base printings for existing cards and carries the changed side's printing
|
* base printings for existing cards and carries the changed side's printing
|
||||||
* for newly added cards.
|
* for newly added cards.
|
||||||
*/
|
*/
|
||||||
class DeckDiff
|
namespace DeckDiff
|
||||||
{
|
{
|
||||||
public:
|
/** @brief Diffs oldDeck against newDeck. */
|
||||||
/** @brief Diffs oldDeck against newDeck. */
|
DeckDiffResult diff(const DeckList &oldDeck, const DeckList &newDeck);
|
||||||
static DeckDiffResult diff(const DeckList &oldDeck, const DeckList &newDeck);
|
/**
|
||||||
/**
|
* @brief True when both change sets touch disjoint (zone, card) keys and a merge needs no arbitration.
|
||||||
* @brief True when both change sets touch disjoint (zone, card) keys and a merge needs no arbitration.
|
*/
|
||||||
*/
|
bool canAutoMerge(const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges);
|
||||||
static bool canAutoMerge(const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges);
|
/**
|
||||||
/**
|
* @brief Applies both change sets onto a copy of baseDeck.
|
||||||
* @brief Applies both change sets onto a copy of baseDeck.
|
*
|
||||||
*
|
* @precondition localChanges and remoteChanges were both computed with
|
||||||
* @precondition localChanges and remoteChanges were both computed with
|
* diff() against baseDeck. Stale or foreign change sets silently
|
||||||
* diff() against baseDeck. Stale or foreign change sets silently
|
* resurrect or delete cards.
|
||||||
* resurrect or delete cards.
|
*
|
||||||
*
|
* Counts are clamped at zero. On overlapping keys the remote change wins;
|
||||||
* Counts are clamped at zero. On overlapping keys the remote change wins;
|
* callers offer this result as "Use Merge" only when canAutoMerge is true.
|
||||||
* callers offer this result as "Use Merge" only when canAutoMerge is true.
|
* Metadata and sideboard plans come from baseDeck.
|
||||||
* Metadata and sideboard plans come from baseDeck.
|
*/
|
||||||
*/
|
DeckList merge(const DeckList &baseDeck, const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges);
|
||||||
static DeckList
|
} // namespace DeckDiff
|
||||||
merge(const DeckList &baseDeck, const DeckDiffResult &localChanges, const DeckDiffResult &remoteChanges);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DECK_DIFF_H
|
#endif // DECK_DIFF_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue