#include "Store.hpp" namespace Screeps { Store::Store(JS::Value value) : Object(std::move(value)) { } std::optional getCapacity(JS::Value& store, const char* method, const std::optional& resource) { JS::Value capacity = resource ? store.call(method, *resource) : store.call(method); if (capacity.isUndefined()) return std::nullopt; else return capacity.as(); } std::optional Store::getCapacity(const std::optional& resource) { return Screeps::getCapacity(value(), "getCapacity", *resource); } std::optional Store::getFreeCapacity(const std::optional& resource) { return Screeps::getCapacity(value(), "getFreeCapacity", *resource); } std::optional Store::getUsedCapacity(const std::optional& resource) { return Screeps::getCapacity(value(), "getUsedCapacity", *resource); } int Store::operator[](const std::string& resource) { return *getUsedCapacity(resource); } } // namespace Screeps