• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 9389846283

05 Jun 2024 07:07PM UTC coverage: 50.394% (-0.01%) from 50.405%
9389846283

push

github

web-flow
Merge pull request #1662 from ottml/add_map_selection_to_campaign_lua

Add map selection to campaign lua

80 of 148 new or added lines in 7 files covered. (54.05%)

12 existing lines in 5 files now uncovered.

22079 of 43813 relevant lines covered (50.39%)

31733.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/libs/libGamedata/gameData/SelectionMapInputData.cpp
1
// Copyright (C) 2024 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "SelectionMapInputData.h"
6
#include "lua/CheckedLuaTable.h"
7

8
namespace kaguya {
9
template<>
10
struct lua_type_traits<MissionSelectionInfo>
11
{
12
    using get_type = MissionSelectionInfo;
13
    using push_type = const MissionSelectionInfo&;
14

15
    struct checkTypeForEach
16
    {
17
        checkTypeForEach(bool& valid) : valid_(valid) {}
3✔
18
        bool& valid_;
19
        bool operator()(const LuaStackRef& k, const LuaStackRef& v)
9✔
20
        {
21
            if(k.isConvertible<size_t>())
9✔
22
            {
23
                size_t idx = k;
9✔
24
                if(idx == 1)
9✔
25
                    valid_ = v.isConvertible<unsigned>();
3✔
26
                else if(idx == 2 || idx == 3)
6✔
27
                    valid_ = v.isConvertible<int>();
6✔
28
                else
NEW
29
                    valid_ = false;
×
30
            } else
NEW
31
                valid_ = false;
×
32
            return valid_;
9✔
33
        }
34
    };
35
    struct strictCheckTypeForEach
36
    {
37
        strictCheckTypeForEach(bool& valid) : valid_(valid) {}
38
        bool& valid_;
39
        bool operator()(const LuaStackRef& k, const LuaStackRef& v)
40
        {
41
            if(k.isType<size_t>())
42
            {
43
                size_t idx = k;
44
                if(idx == 1)
45
                    valid_ = v.isType<unsigned>();
46
                else if(idx == 2 || idx == 3)
47
                    valid_ = v.isType<int>();
48
                else
49
                    valid_ = false;
50
            } else
51
                valid_ = false;
52
            return valid_;
53
        }
54
    };
55

56
    static bool checkType(lua_State* l, int index)
3✔
57
    {
58
        const LuaStackRef table(l, index);
6✔
59
        if(table.type() != LUA_TTABLE || table.size() != 3)
3✔
NEW
60
            return false;
×
61
        bool valid = true;
3✔
62
        table.foreach_table_breakable<LuaStackRef, LuaStackRef>(checkTypeForEach(valid));
3✔
63
        return valid;
3✔
64
    }
65
    static bool strictCheckType(lua_State* l, int index)
66
    {
67
        const LuaStackRef table(l, index);
68
        if(table.type() != LUA_TTABLE || table.size() != 3)
69
            return false;
70
        bool valid = true;
71
        table.foreach_table_breakable<LuaStackRef, LuaStackRef>(strictCheckTypeForEach(valid));
72
        return valid;
73
    }
74
    static get_type get(lua_State* l, int index)
3✔
75
    {
76
        const LuaStackRef table(l, index);
3✔
77
        if(table.type() != LUA_TTABLE || table.size() != 3)
3✔
NEW
78
            throw LuaTypeMismatch();
×
79
        return get_type{table[1], Position(table[2], table[3])};
6✔
80
    }
81
    static int push(lua_State* l, push_type v)
82
    {
83
        return util::push_args(l, v.maskAreaColor, v.ankerPos.x, v.ankerPos.y);
84
    }
85
};
86

87
template<>
88
struct lua_type_traits<Position>
89
{
90
    using get_type = Position;
91
    using push_type = const Position&;
92

93
    struct checkTypeForEach
94
    {
95
        checkTypeForEach(bool& valid) : valid_(valid) {}
1✔
96
        bool& valid_;
97
        bool operator()(const LuaStackRef& k, const LuaStackRef& v)
2✔
98
        {
99
            if(k.isConvertible<size_t>())
2✔
100
            {
101
                size_t idx = k;
2✔
102
                if(idx == 1 || idx == 2)
2✔
103
                    valid_ = v.isConvertible<int>();
2✔
104
                else
NEW
105
                    valid_ = false;
×
106
            } else
NEW
107
                valid_ = false;
×
108
            return valid_;
2✔
109
        }
110
    };
111
    struct strictCheckTypeForEach
112
    {
113
        strictCheckTypeForEach(bool& valid) : valid_(valid) {}
114
        bool& valid_;
115
        bool operator()(const LuaStackRef& k, const LuaStackRef& v)
116
        {
117
            if(k.isType<size_t>())
118
            {
119
                size_t idx = k;
120
                if(idx == 1 || idx == 2)
121
                    valid_ = v.isType<int>();
122
                else
123
                    valid_ = false;
124
            } else
125
                valid_ = false;
126
            return valid_;
127
        }
128
    };
129

130
    static bool checkType(lua_State* l, int index)
1✔
131
    {
132
        const LuaStackRef table(l, index);
2✔
133
        if(table.type() != LUA_TTABLE || table.size() != 2)
1✔
NEW
134
            return false;
×
135
        bool valid = true;
1✔
136
        table.foreach_table_breakable<LuaStackRef, LuaStackRef>(checkTypeForEach(valid));
1✔
137
        return valid;
1✔
138
    }
139
    static bool strictCheckType(lua_State* l, int index)
140
    {
141
        const LuaStackRef table(l, index);
142
        if(table.type() != LUA_TTABLE || table.size() != 2)
143
            return false;
144
        bool valid = true;
145
        table.foreach_table_breakable<LuaStackRef, LuaStackRef>(strictCheckTypeForEach(valid));
146
        return valid;
147
    }
148
    static get_type get(lua_State* l, int index)
1✔
149
    {
150
        const LuaStackRef table(l, index);
1✔
151
        if(table.type() != LUA_TTABLE || table.size() != 2)
1✔
NEW
152
            throw LuaTypeMismatch();
×
153
        return get_type(table[1], table[2]);
2✔
154
    }
155
    static int push(lua_State* l, push_type v) { return util::push_args(l, v.x, v.y); }
156
};
157

158
template<>
159
struct lua_type_traits<ImageResource>
160
{
161
    using get_type = ImageResource;
162
    using push_type = const ImageResource&;
163

164
    struct checkTypeForEach
165
    {
166
        checkTypeForEach(bool& valid) : valid_(valid) {}
5✔
167
        bool& valid_;
168
        bool operator()(const LuaStackRef& k, const LuaStackRef& v)
10✔
169
        {
170
            if(k.isConvertible<size_t>())
10✔
171
            {
172
                size_t idx = k;
10✔
173
                if(idx == 1)
10✔
174
                    valid_ = v.isConvertible<std::string>();
5✔
175
                else if(idx == 2)
5✔
176
                    valid_ = v.isConvertible<unsigned>();
5✔
177
                else
NEW
178
                    valid_ = false;
×
179
            } else
NEW
180
                valid_ = false;
×
181
            return valid_;
10✔
182
        }
183
    };
184
    struct strictCheckTypeForEach
185
    {
186
        strictCheckTypeForEach(bool& valid) : valid_(valid) {}
187
        bool& valid_;
188
        bool operator()(const LuaStackRef& k, const LuaStackRef& v)
189
        {
190
            if(k.isType<size_t>())
191
            {
192
                size_t idx = k;
193
                if(idx == 1)
194
                    valid_ = v.isType<std::string>();
195
                else if(idx == 2)
196
                    valid_ = v.isType<unsigned>();
197
                else
198
                    valid_ = false;
199
            } else
200
                valid_ = false;
201
            return valid_;
202
        }
203
    };
204

205
    static bool checkType(lua_State* l, int index)
5✔
206
    {
207
        const LuaStackRef table(l, index);
10✔
208
        if(table.type() != LUA_TTABLE || table.size() != 2)
5✔
NEW
209
            return false;
×
210
        bool valid = true;
5✔
211
        table.foreach_table_breakable<LuaStackRef, LuaStackRef>(checkTypeForEach(valid));
5✔
212
        return valid;
5✔
213
    }
214
    static bool strictCheckType(lua_State* l, int index)
215
    {
216
        const LuaStackRef table(l, index);
217
        if(table.type() != LUA_TTABLE || table.size() != 2)
218
            return false;
219
        bool valid = true;
220
        table.foreach_table_breakable<LuaStackRef, LuaStackRef>(strictCheckTypeForEach(valid));
221
        return valid;
222
    }
223
    static get_type get(lua_State* l, int index)
5✔
224
    {
225
        const LuaStackRef table(l, index);
10✔
226
        if(table.type() != LUA_TTABLE || table.size() != 2)
5✔
NEW
227
            throw LuaTypeMismatch();
×
228
        std::string path = table[1];
5✔
229
        return get_type(boost::filesystem::path(path), table[2]);
10✔
230
    }
231
    static int push(lua_State* l, push_type v) { return util::push_args(l, v.filePath, v.index); }
232
};
233
} // namespace kaguya
234

235
SelectionMapInputData::SelectionMapInputData(const kaguya::LuaRef& table)
1✔
236
{
237
    CheckedLuaTable luaMapSelection(table);
2✔
238
    luaMapSelection.getOrThrow(background, "background");
1✔
239
    luaMapSelection.getOrThrow(map, "map");
1✔
240
    luaMapSelection.getOrThrow(missionMapMask, "missionMapMask");
1✔
241
    luaMapSelection.getOrThrow(marker, "marker");
1✔
242
    luaMapSelection.getOrThrow(conquered, "conquered");
1✔
243
    luaMapSelection.getOrThrow(mapOffsetInBackground, "backgroundOffset");
1✔
244
    luaMapSelection.getOrThrow(disabledColor, "disabledColor");
1✔
245
    luaMapSelection.getOrThrow(missionSelectionInfos, "missionSelectionInfos");
1✔
246
    luaMapSelection.checkUnused();
1✔
247
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc