]> git.tdb.fi Git - poefilter.git/blob - source/category.cpp
Associate categories and appearances at filter level
[poefilter.git] / source / category.cpp
1 #include "category.h"
2 #include "choicecondition.h"
3 #include "filter.h"
4 #include "poefilter.h"
5 #include "rangecondition.h"
6 #include "theme.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 Category::Category(const string &n):
12         name(n),
13         condition(0),
14         order(0)
15 { }
16
17 Category::Category(const Category &other):
18         name(other.name),
19         condition(other.condition ? other.condition->clone() : 0),
20         order(other.order),
21         appearance(other.appearance)
22 { }
23
24 Category &Category::operator=(const Category &other)
25 {
26         delete condition;
27         name = other.name;
28         condition = (other.condition ? other.condition->clone() : 0);
29         order = other.order;
30         appearance = other.appearance;
31         return *this;
32 }
33
34 Category::~Category()
35 {
36         delete condition;
37 }
38
39 void Category::create_statements(list<FilterStatement> &st) const
40 {
41         if(st.empty())
42                 st.push_back(FilterStatement());
43
44         if(condition)
45                 condition->add_lines(st);
46 }
47
48
49 Category::Loader::Loader(Category &c, const PoeFilter &p, CompoundCondition *n):
50         DataFile::ObjectLoader<Category>(c),
51         poe(p),
52         compound(n),
53         app_loader(c.appearance)
54 {
55         add("and", &Loader::and_);
56         add("base_type", &Loader::condition<BaseTypeCondition>);
57         add("class", &Loader::condition<ClassCondition>);
58         add_range<DropLevelCondition>("drop_level");
59         add_range<HeightCondition>("height");
60         add_range<ItemLevelCondition>("item_level");
61         add("linked_colors", &Loader::linked_colors);
62         add_range<LinkedSocketsCondition>("linked_sockets");
63         add_range<SocketsCondition>("sockets");
64         add("or", &Loader::or_);
65         add("order", &Category::order);
66         add_range<QualityCondition>("quality");
67         add_range<RarityCondition>("rarity");
68         add_range<WidthCondition>("width");
69
70         add_auxiliary_loader(app_loader);
71 }
72
73 template<typename T>
74 void Category::Loader::add_range(const string &keyword)
75 {
76         add(keyword, &Loader::condition<T>);
77         add(keyword, &Loader::condition_range<T>);
78         add("min_"+keyword, &Loader::condition_min<T>);
79         add("max_"+keyword, &Loader::condition_max<T>);
80 }
81
82 void Category::Loader::add_condition(Condition *cond)
83 {
84         if(compound)
85                 compound->add(cond);
86         else if(!obj.condition)
87                 obj.condition = cond;
88         else
89         {
90                 compound = new AndCondition;
91                 compound->add(obj.condition);
92                 compound->add(cond);
93                 obj.condition = compound;
94         }
95 }
96
97 void Category::Loader::and_()
98 {
99         RefPtr<AndCondition> cond = new AndCondition;
100         Loader sub_ldr(obj, poe, cond.get());
101         load_sub_with(sub_ldr);
102         add_condition(cond.release());
103 }
104
105 template<typename T>
106 void Category::Loader::condition(typename T::Type value)
107 {
108         add_condition(new T(value));
109 }
110
111 template<typename T>
112 void Category::Loader::condition_max(typename T::Type max)
113 {
114         add_condition(new T(T::Traits::get_min(), max));
115 }
116
117 template<typename T>
118 void Category::Loader::condition_min(typename T::Type min)
119 {
120         add_condition(new T(min, T::Traits::get_max()));
121 }
122
123 template<typename T>
124 void Category::Loader::condition_range(typename T::Type min, typename T::Type max)
125 {
126         add_condition(new T(min, max));
127 }
128
129 void Category::Loader::linked_colors(const LinkedColorsCondition::Colors &colors)
130 {
131         add_condition(new LinkedColorsCondition(colors));
132 }
133
134 void Category::Loader::or_()
135 {
136         RefPtr<OrCondition> cond = new OrCondition;
137         Loader sub_ldr(obj, poe, cond.get());
138         load_sub_with(sub_ldr);
139         add_condition(cond.release());
140 }