MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / buildItemList

Method buildItemList

source/frontend/StarMerchantInterface.cpp:195–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195void MerchantPane::buildItemList() {
196 m_itemGuiList->clear();
197 m_itemList = m_settings.getArray("items");
198
199 auto itemDatabase = Root::singleton().itemDatabase();
200 filter(m_itemList, [&](Json const& itemConfig) {
201 if (!itemDatabase->hasItem(ItemDescriptor(itemConfig.get("item")).name()))
202 return false;
203
204 if (auto prerequisite = itemConfig.optString("prerequisiteQuest")) {
205 if (!m_player->questManager()->hasCompleted(*prerequisite))
206 return false;
207 }
208
209 if (auto quests = itemConfig.optArray("exclusiveQuests")) {
210 for (auto quest : *quests) {
211 if (m_player->questManager()->hasQuest(quest.toString()))
212 return false;
213 }
214 }
215
216 if (auto prerequisite = itemConfig.optUInt("prerequisiteShipLevel")) {
217 if (m_player->shipUpgrades().shipLevel < *prerequisite)
218 return false;
219 }
220
221 if (auto maxLevel = itemConfig.optUInt("maxShipLevel")) {
222 if (m_player->shipUpgrades().shipLevel > *maxLevel)
223 return false;
224 }
225
226 return true;
227 });
228
229 for (auto itemConfig : m_itemList) {
230 auto widget = m_itemGuiList->addItem();
231 setupWidget(widget, itemConfig);
232 }
233}
234
235void MerchantPane::setupWidget(WidgetPtr const& widget, Json const& itemConfig) {
236 auto& root = Root::singleton();

Callers

nothing calls this directly

Calls 15

singletonClass · 0.85
filterFunction · 0.85
ItemDescriptorClass · 0.85
getArrayMethod · 0.80
itemDatabaseMethod · 0.80
optStringMethod · 0.80
hasCompletedMethod · 0.80
optArrayMethod · 0.80
hasQuestMethod · 0.80
optUIntMethod · 0.80
addItemMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected