QcClientInventory Class
The local player's items as the server last reported them (QcMsg::InventoryState): inventory, selected hotbar slot, worn equipment and the crafting grid with its result; and the requests that move items between these slots or craft (the server answers with a new InventoryState). More...
| Header: | #include <clientcore/player/QcClientInventory.h> |
Public Types
Public Functions
| QcClientInventory(QcClientInventory::Sender send) | |
| QcClientInventory(const QcClientInventory &) | |
| ~QcClientInventory() | |
| bool | apply(const QcMsg::InventoryState &state, const QcContentRegistry *content) |
| void | closeCrafting() const |
| void | craftRecipe(const QString &recipe, int count = 1) const |
| const QList<QcItemStack> & | craftingGrid() const |
| QcItemStack | craftingResult() const |
| int | craftingSize() const |
| const QcEquipment & | equipment() const |
| const QcItemDefinition * | heldDefinition(const QcContentRegistry &content) const |
| QcItemId | heldItem() const |
| const QcInventory & | inventory() const |
| void | moveItem(int from, int to, int count = 0) const |
| qsizetype | pendingSelections() const |
| void | quickMoveItem(int slot) const |
| void | resendLostSelection() |
| void | selectHotbarSlot(int slot) |
| void | setClock(QcClientInventory::Clock clock) |
| void | takeCraftingResult() const |
| QcClientInventory & | operator=(const QcClientInventory &) |
Static Public Members
| const qint64 | pendingSelectionMs |
Detailed Description
The selected slot changes at once on the client (decision E-582): while selections the server has not answered yet are on their way, a state's selection is older than the local one and is not taken; the server answers each selection with a state carrying it, in order. A selection unanswered for pendingSelectionMs (dropped by the server's rate limit) is given up and the local selection is sent again, so client and server agree once more (checked with each state and tick).
Member Type Documentation
[alias] QcClientInventory::Clock
Milliseconds on a steady clock (tests pass their own).
[alias] QcClientInventory::Sender
Sends a request to the server.
Member Function Documentation
[explicit] QcClientInventory::QcClientInventory(QcClientInventory::Sender send)
send: how requests reach the server (the session's connection, never empty).
[delete] QcClientInventory::QcClientInventory(const QcClientInventory &)
The default clock refers to this object.
[noexcept default] QcClientInventory::~QcClientInventory()
Destroys the instance of QcClientInventory.
bool QcClientInventory::apply(const QcMsg::InventoryState &state, const QcContentRegistry *content)
Takes the server's state (content: the session's, null before it arrived). Returns false without a change when the state has the wrong number of slots.
void QcClientInventory::closeCrafting() const
Asks the server to close the crafting grid; its items go back.
void QcClientInventory::craftRecipe(const QString &recipe, int count = 1) const
Asks the server to craft the recipe named recipe count times from the inventory.
const QList<QcItemStack> &QcClientInventory::craftingGrid() const
Returns the slots of the crafting grid (9; the inventory's grid uses 2 x 2 of them).
QcItemStack QcClientInventory::craftingResult() const
Returns the result of the crafting grid as the server reported it.
int QcClientInventory::craftingSize() const
Returns the edge length of the open crafting grid: 2 in the inventory, 3 at a crafting table.
const QcEquipment &QcClientInventory::equipment() const
Returns the worn equipment.
const QcItemDefinition *QcClientInventory::heldDefinition(const QcContentRegistry &content) const
Returns the definition of the item in the selected hotbar slot in content; null for an empty hand or an unknown item.
QcItemId QcClientInventory::heldItem() const
Returns the item in the selected hotbar slot: its id (qcNoItem for an empty hand) and its definition (null for an empty hand or an item unknown to content).
const QcInventory &QcClientInventory::inventory() const
Returns the inventory as the server last reported it.
void QcClientInventory::moveItem(int from, int to, int count = 0) const
Asks the server to move count items (0: all) from slot from to slot to: slots 0..35 inventory, 36..44 crafting grid (see QcMsg::MoveInventoryItem).
qsizetype QcClientInventory::pendingSelections() const
Returns the number of selections sent and not answered yet.
void QcClientInventory::quickMoveItem(int slot) const
Shift-click on slot: the server moves the stack to where it belongs (QcMsg::QuickMoveItem).
void QcClientInventory::resendLostSelection()
When the oldest selection has waited longer than pendingSelectionMs: gives the waiting ones up and sends the local selection again (the session's tick, and each state).
void QcClientInventory::selectHotbarSlot(int slot)
Selects the hotbar slot at once and tells the server.
void QcClientInventory::setClock(QcClientInventory::Clock clock)
Replaces the clock of the selections with clock (tests).
void QcClientInventory::takeCraftingResult() const
Asks the server to move the crafting result to the inventory.
[delete] QcClientInventory &QcClientInventory::operator=(const QcClientInventory &)
Copy-assigns other to this QcClientInventory instance. This function is deleted.
Member Variable Documentation
const qint64 QcClientInventory::pendingSelectionMs
An unanswered selection is given up after this long, and the server's selection counts again.