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

Method PlayerInventory

source/game/StarPlayerInventory.cpp:41–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41PlayerInventory::PlayerInventory() {
42 auto config = Root::singleton().assets()->json("/player.config:inventory");
43
44 auto bags = config.get("itemBags");
45 auto bagOrder = bags.toObject().keys().sorted([&bags](String const& a, String const& b) {
46 return bags.get(a).getInt("priority", 0) < bags.get(b).getInt("priority", 0);
47 });
48 for (auto name : bagOrder) {
49 size_t size = bags.get(name).getUInt("size");
50 m_bags[name] = make_shared<ItemBag>(size);
51 m_bagsNetState[name].resize(size);
52 }
53
54 auto currenciesConfig = Root::singleton().assets()->json("/currencies.config");
55 for (auto p : currenciesConfig.iterateObject())
56 m_currencies[p.first] = 0;
57
58 size_t customBarGroups = config.getUInt("customBarGroups");
59 size_t customBarIndexes = config.getUInt("customBarIndexes");
60 m_customBarGroup = 0;
61 m_customBar.resize(customBarGroups, customBarIndexes);
62
63 for (auto slot : EquipmentSlotNames) {
64 auto& element = m_equipmentNetState[slot.first];
65 if (slot.first > EquipmentSlot::BackCosmetic)
66 element.setCompatibilityVersion(9);
67 addNetElement(&element);
68 }
69
70 for (auto& p : m_bagsNetState) {
71 for (auto& e : p.second)
72 addNetElement(&e);
73 }
74
75 addNetElement(&m_swapSlotNetState);
76 addNetElement(&m_trashSlotNetState);
77
78 addNetElement(&m_currenciesNetState);
79
80 addNetElement(&m_customBarGroupNetState);
81 m_customBarNetState.resize(customBarGroups, customBarIndexes);
82 m_customBarNetState.forEach([this](Array2S const&, NetElementData<CustomBarLink>& e) {
83 addNetElement(&e);
84 });
85
86 addNetElement(&m_selectedActionBarNetState);
87
88 addNetElement(&m_essentialNetState[EssentialItem::BeamAxe]);
89 addNetElement(&m_essentialNetState[EssentialItem::WireTool]);
90 addNetElement(&m_essentialNetState[EssentialItem::PaintTool]);
91 addNetElement(&m_essentialNetState[EssentialItem::InspectionTool]);
92
93 m_equipmentVisibilityMask = 0xFFFFFFFF;
94}
95
96ItemPtr PlayerInventory::itemsAt(InventorySlot const& slot) const {
97 return retrieve(slot);

Callers

nothing calls this directly

Calls 13

singletonClass · 0.85
jsonMethod · 0.80
assetsMethod · 0.80
toObjectMethod · 0.80
getIntMethod · 0.80
getUIntMethod · 0.80
iterateObjectMethod · 0.80
getMethod · 0.45
sortedMethod · 0.45
keysMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected