-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvestitionModelFactory.cpp
More file actions
93 lines (80 loc) · 3.13 KB
/
InvestitionModelFactory.cpp
File metadata and controls
93 lines (80 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "InvestitionModelFactory.h"
#include <QtAlgorithms>
#include <map>
#include <qdebug.h>
void InvestitionModelFactory::translateRewardRawNameToItemData(DivinationCard *divinationCard)
{
QString rewardName = QRegularExpression("\{(.*?)\}").match(divinationCard->rewardRawName).captured(1);
QString amountStr = QRegularExpression("[\\d]+x").match(rewardName).captured(0);
int gemLevel = 0;
if(!amountStr.isEmpty())
{
rewardName = rewardName.remove(amountStr);
}
if(rewardName.contains("Level "))
{
gemLevel = rewardName.mid(5, 2).toInt();
rewardName = rewardName.remove(0, 8) + " Support";
}
if(rewardName[0] == ' ')
{
rewardName = rewardName.remove(0, 1);
}
divinationCard->reward = {rewardName, amountStr.replace("x", "").toInt(), 1, gemLevel};
}
QString InvestitionModelFactory::getRewardItemColor(DivinationCard *divinationCard)
{
std::map<QString, QString> keywordsAndItsColors = {{"<prophecy>", "#b54bff"}, {"<currencyitem>", "#aa9e82"}, {"<uniqueitem>", "#af6025"}, {"<divination>", "#0ebaff"}, {"<gemitem>", "#1ba29b"}};
for(auto &entery : keywordsAndItsColors)
{
if(divinationCard->rewardRawName.contains(entery.first))
{
return entery.second;
}
}
}
InvestitionModelFactory::InvestitionModelFactory(){}
InvestitionModelFactory::InvestitionModelFactory(const QVector<std::shared_ptr<DivinationCard>> &cards, const QVector<std::shared_ptr<ItemData>> &items, const QVector<DivinationCardFilter *> &filters) : cards(cards),
items(items),
filters(filters){}
InvestitionModelFactory::~InvestitionModelFactory()
{
}
InvestitionModel* InvestitionModelFactory::getModel()
{
model = new InvestitionModel();
return model;
}
void InvestitionModelFactory::populateModel()
{
for(auto filter : qAsConst(filters))
{
filter->filter(&cards);
}
for(auto card : qAsConst(cards))
{
translateRewardRawNameToItemData(card.get());
auto correspondingItem = std::find_if(items.begin(), items.end(), [card](std::shared_ptr<ItemData> item)
{
return item->name == card->reward.name && ((item->gemLevel == card->reward.gemLevel && card->reward.gemLevel != 0) || card->reward.gemLevel == 0);
});
if(correspondingItem == items.end())
{
continue;
}
Investition investition {card->stackSize, card->name, (*correspondingItem)->name, getRewardItemColor(card.get()), card->stackSize*card->chaosValue,
"qrc:/Graphic/Currency/ChaosOrbIcon.png", (*correspondingItem)->chaosValue*(*correspondingItem)->amount - card->stackSize*card->chaosValue,
"qrc:/Graphic/Currency/ChaosOrbIcon.png", (*correspondingItem)->amount};
model->addInvestition(investition);
}
}
void InvestitionModelFactory::initialize(const QVector<std::shared_ptr<DivinationCard>> &cards, const QVector<std::shared_ptr<ItemData>> &items, const QVector<DivinationCardFilter *> &filters)
{
this->cards = cards;
this->items = items;
this->filters = filters;
}
void InvestitionModelFactory::clear()
{
model->clear();
}