From 6352e8e3196f78388b6c771073f9e03eaa612673 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:33:09 +1000 Subject: everything everywhere all at once --- source/frontend/StarContainerInteractor.cpp | 92 +++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 source/frontend/StarContainerInteractor.cpp (limited to 'source/frontend/StarContainerInteractor.cpp') diff --git a/source/frontend/StarContainerInteractor.cpp b/source/frontend/StarContainerInteractor.cpp new file mode 100644 index 0000000..2500f77 --- /dev/null +++ b/source/frontend/StarContainerInteractor.cpp @@ -0,0 +1,92 @@ +#include "StarContainerInteractor.hpp" + +namespace Star { + +void ContainerInteractor::openContainer(ContainerEntityPtr containerEntity) { + if (m_openContainer && m_openContainer->inWorld()) + m_openContainer->containerClose(); + m_openContainer = move(containerEntity); + if (m_openContainer) { + starAssert(m_openContainer->inWorld()); + m_openContainer->containerOpen(); + } +} + +void ContainerInteractor::closeContainer() { + openContainer({}); +} + +bool ContainerInteractor::containerOpen() const { + return openContainerId() != NullEntityId; +} + +EntityId ContainerInteractor::openContainerId() const { + if (m_openContainer && !m_openContainer->inWorld()) + m_openContainer = {}; + + if (m_openContainer) + return m_openContainer->entityId(); + + return NullEntityId; +} + +ContainerEntityPtr const& ContainerInteractor::openContainer() const { + if (m_openContainer && !m_openContainer->inWorld()) + m_openContainer = {}; + + if (!m_openContainer) + throw StarException("ContainerInteractor has no open container"); + + return m_openContainer; +} + +List ContainerInteractor::pullContainerResults() { + List> results; + eraseWhere(m_pendingResults, [&results](auto& promise) { + if (auto res = promise.result()) + results.append(res.take()); + return promise.finished(); + }); + return results; +} + +void ContainerInteractor::swapInContainer(size_t slot, ItemPtr const& items) { + m_pendingResults.append(openContainer()->swapItems(slot, items).wrap(resultFromItem)); +} + +void ContainerInteractor::addToContainer(ItemPtr const& items) { + m_pendingResults.append(openContainer()->addItems(items).wrap(resultFromItem)); +} + +void ContainerInteractor::takeFromContainerSlot(size_t slot, size_t count) { + m_pendingResults.append(openContainer()->takeItems(slot, count).wrap(resultFromItem)); +} + +void ContainerInteractor::applyAugmentInContainer(size_t slot, ItemPtr const& augment) { + m_pendingResults.append(openContainer()->applyAugment(slot, augment).wrap(resultFromItem)); +} + +void ContainerInteractor::startCraftingInContainer() { + openContainer()->startCrafting(); +} + +void ContainerInteractor::stopCraftingInContainer() { + openContainer()->stopCrafting(); +} + +void ContainerInteractor::burnContainer() { + openContainer()->burnContainerContents(); +} + +void ContainerInteractor::clearContainer() { + m_pendingResults.append(openContainer()->clearContainer()); +} + +ContainerResult ContainerInteractor::resultFromItem(ItemPtr const& item) { + if (item) + return {item}; + else + return {}; +} + +} -- cgit v1.2.3