diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04d251a1..a6161517 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -213,8 +213,8 @@ set(ZEPHA_SRC game/hud/components/compound/GuiInventoryList.h game/hud/components/basic/GuiInventoryItem.cpp game/hud/components/basic/GuiInventoryItem.h - game/inventory/InventoryList.cpp - game/inventory/InventoryList.h + game/inventory/ServerInventoryList.cpp + game/inventory/ServerInventoryList.h game/inventory/ItemStack.h server/LocalServerInstance.cpp server/LocalServerInstance.h diff --git a/src/game/hud/DebugGui.h b/src/game/hud/DebugGui.h index d9c9fbc9..b6c523a3 100644 --- a/src/game/hud/DebugGui.h +++ b/src/game/hud/DebugGui.h @@ -15,7 +15,7 @@ #include "components/basic/GuiGraph.h" #include "components/basic/GuiText.h" #include "components/basic/GuiContainer.h" -#include "../inventory/InventoryList.h" +#include "../inventory/ServerInventoryList.h" class DebugGui : public GuiContainer { public: diff --git a/src/game/hud/GameGui.h b/src/game/hud/GameGui.h index d7cbd9a5..3a191527 100644 --- a/src/game/hud/GameGui.h +++ b/src/game/hud/GameGui.h @@ -10,7 +10,7 @@ #include "components/basic/GuiRect.h" #include "components/basic/GuiContainer.h" #include "../graph/drawable/DrawableGroup.h" -#include "../inventory/InventoryList.h" +#include "../inventory/ServerInventoryList.h" #include "../entity/Entity.h" #include "../../util/Util.h" #include "components/compound/GuiInventoryList.h" diff --git a/src/game/hud/components/compound/GuiInventoryList.cpp b/src/game/hud/components/compound/GuiInventoryList.cpp index 758cfb16..68c2b953 100644 --- a/src/game/hud/components/compound/GuiInventoryList.cpp +++ b/src/game/hud/components/compound/GuiInventoryList.cpp @@ -40,10 +40,10 @@ void GuiInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 inn this->scale = scale; this->padding = padding; this->innerPadding = innerPadding; - this->hitbox = glm::ivec2 { + this->hitbox = (list->getWidth() == 0 ? glm::ivec2 {} : glm::ivec2 { padding.x + list->getWidth() * (innerPadding.x*scale.x), padding.y + (list->getLength() / list->getWidth()) * (innerPadding.y*scale.y) - }; + }); drawContents(); list->setGuiCallback(std::bind(&GuiInventoryList::drawContents, this)); @@ -94,7 +94,7 @@ void GuiInventoryList::hoverEvent(bool hovered, glm::ivec2 pos) { } void GuiInventoryList::leftClick(bool down, glm::ivec2 pos) { - if (!down) return; + if (!down || list->getWidth() == 0) return; pos += glm::ivec2(glm::vec2(this->padding.x, this->padding.y) * this->scale); @@ -110,6 +110,8 @@ void GuiInventoryList::leftClick(bool down, glm::ivec2 pos) { } void GuiInventoryList::rightClick(bool down, glm::ivec2 pos) { + if (!down || list->getWidth() == 0) return; + pos += glm::ivec2(glm::vec2(this->padding.x, this->padding.y) * this->scale); glm::ivec2 slot = pos / (glm::ivec2(this->scale) * this->innerPadding); @@ -119,32 +121,32 @@ void GuiInventoryList::rightClick(bool down, glm::ivec2 pos) { unsigned short index = slot.x + slot.y * list->getWidth(); if (index >= list->getLength()) return; - if (down) { + auto handStack = hand->getStack(0); + if (handStack.count == 0) { + hand->setStack(0, list->splitStack(index, true)); + } + else { auto handStack = hand->getStack(0); - if (handStack.count == 0) { - hand->setStack(0, list->splitStack(index, true)); + auto listStack = list->getStack(index); + if (listStack.id == 0 || listStack.id == handStack.id) { + auto overflow = list->placeStack(index, {handStack.id, 1}, true); + handStack.count -= 1; + if (handStack.count == 0) handStack.id = 0; + if (overflow.count != 0) handStack.count += overflow.count; + hand->setStack(0, handStack); } else { - auto handStack = hand->getStack(0); - auto listStack = list->getStack(index); - if (listStack.id == 0 || listStack.id == handStack.id) { - auto overflow = list->placeStack(index, {handStack.id, 1}, true); - handStack.count -= 1; - if (handStack.count == 0) handStack.id = 0; - if (overflow.count != 0) handStack.count += overflow.count; - hand->setStack(0, handStack); - } - else { - hand->setStack(0, list->placeStack(index, hand->getStack(0), true)); - } + hand->setStack(0, list->placeStack(index, hand->getStack(0), true)); } } } void GuiInventoryList::drawContents() { + if (list->getWidth() == 0) return; + this->hitbox = glm::ivec2 { - padding.x + list->getWidth() * (innerPadding.x*scale.x), - padding.y + (list->getLength() / list->getWidth()) * (innerPadding.y*scale.y) + padding.x + list->getWidth() * (innerPadding.x*scale.x), + padding.y + (list->getLength() / list->getWidth()) * (innerPadding.y*scale.y) }; empty(); diff --git a/src/game/inventory/Inventory.cpp b/src/game/inventory/Inventory.cpp index 4ef3d773..8ba35603 100644 --- a/src/game/inventory/Inventory.cpp +++ b/src/game/inventory/Inventory.cpp @@ -14,10 +14,10 @@ void Inventory::sendDirtyLists() { } void Inventory::createList(std::string name, unsigned short length, unsigned short width) { - lists.emplace(name, std::make_shared(defs, clients, this->name, name, length, width)); + lists.emplace(name, std::make_shared(defs, clients, this->name, name, length, width)); } -std::shared_ptr Inventory::operator[](std::string name) { +std::shared_ptr Inventory::operator[](std::string name) { if (lists.count(name)) return lists[name]; else return nullptr; } diff --git a/src/game/inventory/Inventory.h b/src/game/inventory/Inventory.h index 8565130c..39f96d07 100644 --- a/src/game/inventory/Inventory.h +++ b/src/game/inventory/Inventory.h @@ -7,7 +7,7 @@ #include #include #include -#include "InventoryList.h" +#include "ServerInventoryList.h" class ClientList; @@ -18,12 +18,12 @@ public: void sendDirtyLists(); void createList(std::string name, unsigned short length, unsigned short width); - std::shared_ptr operator[](std::string name); + std::shared_ptr operator[](std::string name); void removeList(std::string name); DefinitionAtlas& defs; std::string name; private: ClientList* clients; - std::map> lists; + std::map> lists; }; diff --git a/src/game/inventory/InventoryRefs.cpp b/src/game/inventory/InventoryRefs.cpp index 34cecccf..c1148e99 100644 --- a/src/game/inventory/InventoryRefs.cpp +++ b/src/game/inventory/InventoryRefs.cpp @@ -4,7 +4,7 @@ #include "InventoryRefs.h" -#include "InventoryList.h" +#include "ServerInventoryList.h" InventoryRefs::InventoryRefs(ServerDefinitionAtlas &defs, ClientList* clients) : defs(defs), clients(clients) {} @@ -24,7 +24,7 @@ std::shared_ptr InventoryRefs::getInv(const std::string &inv) { return inventories[inv]; } -std::shared_ptr InventoryRefs::getList(const std::string &inv, const std::string &list) { +std::shared_ptr InventoryRefs::getList(const std::string &inv, const std::string &list) { if (!inventories.count(inv)) return nullptr; return inventories[inv]->operator[](list); } diff --git a/src/game/inventory/InventoryRefs.h b/src/game/inventory/InventoryRefs.h index 0de782b3..c2ffeef9 100644 --- a/src/game/inventory/InventoryRefs.h +++ b/src/game/inventory/InventoryRefs.h @@ -7,7 +7,7 @@ #include "../../def/ServerDefinitionAtlas.h" #include "Inventory.h" -class InventoryList; +class ServerInventoryList; class InventoryRefs { public: @@ -17,7 +17,7 @@ public: std::shared_ptr createInv(const std::string& inv); std::shared_ptr getInv(const std::string& inv); - std::shared_ptr getList(const std::string& inv, const std::string& list); + std::shared_ptr getList(const std::string& inv, const std::string& list); bool addWatcher(const std::string& inv, const std::string& list, unsigned int cid); bool removeWatcher(const std::string& inv, const std::string& list, unsigned int cid); diff --git a/src/game/inventory/LocalInventoryList.h b/src/game/inventory/LocalInventoryList.h index 2dd15998..9e0d6466 100644 --- a/src/game/inventory/LocalInventoryList.h +++ b/src/game/inventory/LocalInventoryList.h @@ -46,8 +46,6 @@ public: DefinitionAtlas& defs; private: - bool initialized = false; - void triggerCallback(); std::vector itemstacks {}; diff --git a/src/game/inventory/LocalInventoryRefs.cpp b/src/game/inventory/LocalInventoryRefs.cpp index fc7611a7..bf21d367 100644 --- a/src/game/inventory/LocalInventoryRefs.cpp +++ b/src/game/inventory/LocalInventoryRefs.cpp @@ -33,7 +33,7 @@ std::shared_ptr LocalInventoryRefs::getInv(const std::string& in std::shared_ptr LocalInventoryRefs::getList(const std::string& inv, const std::string& list) { if (!inventories.count(inv)) inventories.insert({inv, {}}); if (inventories[inv]->operator[](list) == nullptr) { - inventories[inv]->createList(list, 1, 1); + inventories[inv]->createList(list, 0, 0); watchFn(inv, list); } return inventories[inv]->operator[](list); diff --git a/src/game/inventory/InventoryList.cpp b/src/game/inventory/ServerInventoryList.cpp similarity index 84% rename from src/game/inventory/InventoryList.cpp rename to src/game/inventory/ServerInventoryList.cpp index 1c488a1f..c10ef24f 100644 --- a/src/game/inventory/InventoryList.cpp +++ b/src/game/inventory/ServerInventoryList.cpp @@ -5,14 +5,14 @@ #include #include -#include "InventoryList.h" +#include "ServerInventoryList.h" #include "../../util/net/Packet.h" #include "../../util/net/Serializer.h" #include "../../server/conn/ClientList.h" #include "../../lua/api/class/LuaItemStack.h" -InventoryList::InventoryList(DefinitionAtlas& defs, ClientList* list, const std::string& invName, const std::string& name, unsigned short size, unsigned short width) : +ServerInventoryList::ServerInventoryList(DefinitionAtlas& defs, ClientList* list, const std::string& invName, const std::string& name, unsigned short size, unsigned short width) : defs(defs), name(name), width(width), @@ -20,26 +20,26 @@ InventoryList::InventoryList(DefinitionAtlas& defs, ClientList* list, const std: invName(invName), itemstacks(size) {} -void InventoryList::setLuaCallback(InventoryList::Callback type, sol::function cb) { +void ServerInventoryList::setLuaCallback(ServerInventoryList::Callback type, sol::function cb) { luaCallbacks[static_cast(type)] = cb; } -sol::function InventoryList::getLuaCallback(InventoryList::Callback type) { +sol::function ServerInventoryList::getLuaCallback(ServerInventoryList::Callback type) { return luaCallbacks[static_cast(type)]; } -ItemStack InventoryList::getStack(unsigned short i) { +ItemStack ServerInventoryList::getStack(unsigned short i) { return itemstacks[i]; } -void InventoryList::setStack(unsigned short i, const ItemStack &stack) { +void ServerInventoryList::setStack(unsigned short i, const ItemStack &stack) { if (stack != getStack(i)) { itemstacks[i] = stack; setDirty(); } } -ItemStack InventoryList::placeStack(unsigned short i, const ItemStack &stack, bool playerInitiated) { +ItemStack ServerInventoryList::placeStack(unsigned short i, const ItemStack &stack, bool playerInitiated) { auto otherStack = getStack(i); unsigned short allowedTake = otherStack.count; @@ -104,7 +104,7 @@ ItemStack InventoryList::placeStack(unsigned short i, const ItemStack &stack, bo } } -ItemStack InventoryList::splitStack(unsigned short i, bool playerInitiated) { +ItemStack ServerInventoryList::splitStack(unsigned short i, bool playerInitiated) { auto stack = getStack(i); unsigned short allowedTake = stack.count; @@ -122,7 +122,7 @@ ItemStack InventoryList::splitStack(unsigned short i, bool playerInitiated) { return {stack.id, takeCount}; } -ItemStack InventoryList::addStack(ItemStack stack, bool playerInitiated) { +ItemStack ServerInventoryList::addStack(ItemStack stack, bool playerInitiated) { unsigned short maxStack = defs.fromId(stack.id).maxStackSize; unsigned short i = 0; @@ -158,7 +158,7 @@ ItemStack InventoryList::addStack(ItemStack stack, bool playerInitiated) { return stack; } -unsigned short InventoryList::stackFits(const ItemStack &stack) { +unsigned short ServerInventoryList::stackFits(const ItemStack &stack) { unsigned short maxStack = defs.fromId(stack.id).maxStackSize; unsigned short i = 0; @@ -183,7 +183,7 @@ unsigned short InventoryList::stackFits(const ItemStack &stack) { return fits; } -ItemStack InventoryList::takeStack(ItemStack request, bool playerInitiated) { +ItemStack ServerInventoryList::takeStack(ItemStack request, bool playerInitiated) { unsigned short i = 0; unsigned short to_remove = request.count; @@ -208,7 +208,7 @@ ItemStack InventoryList::takeStack(ItemStack request, bool playerInitiated) { return request; } -ItemStack InventoryList::removeStack(unsigned short ind, unsigned short count) { +ItemStack ServerInventoryList::removeStack(unsigned short ind, unsigned short count) { auto stack = getStack(ind); if (count >= stack.count) { setStack(ind, {0, 0}); @@ -222,23 +222,23 @@ ItemStack InventoryList::removeStack(unsigned short ind, unsigned short count) { } } -void InventoryList::setDirty() { +void ServerInventoryList::setDirty() { dirty = true; } -unsigned short InventoryList::getLength() { +unsigned short ServerInventoryList::getLength() { return itemstacks.size(); } -unsigned short InventoryList::getWidth() { +unsigned short ServerInventoryList::getWidth() { return width; } -std::string InventoryList::getName() { +std::string ServerInventoryList::getName() { return name; } -bool InventoryList::addWatcher(unsigned int cid) { +bool ServerInventoryList::addWatcher(unsigned int cid) { auto& client = clients->getClient(cid); if (!client) return false; @@ -248,7 +248,7 @@ bool InventoryList::addWatcher(unsigned int cid) { sendTo(client); } -bool InventoryList::removeWatcher(unsigned int cid) { +bool ServerInventoryList::removeWatcher(unsigned int cid) { for (auto it = watchers.cbegin(); it != watchers.cend();) { if (*it == cid) { watchers.erase(it); @@ -259,7 +259,7 @@ bool InventoryList::removeWatcher(unsigned int cid) { return false; } -Packet InventoryList::createPacket() { +Packet ServerInventoryList::createPacket() { Serializer s{}; s.append(invName) .append(name) @@ -274,13 +274,13 @@ Packet InventoryList::createPacket() { return s.packet(PacketType::INVENTORY, false); } -void InventoryList::sendTo(std::shared_ptr client) { +void ServerInventoryList::sendTo(std::shared_ptr client) { if (!client) return; auto p = createPacket(); p.sendTo(client->peer, PacketChannel::INVENTORY); } -void InventoryList::sendAll() { +void ServerInventoryList::sendAll() { auto p = createPacket(); for (auto it = watchers.cbegin(); it != watchers.cend();) { diff --git a/src/game/inventory/InventoryList.h b/src/game/inventory/ServerInventoryList.h similarity index 90% rename from src/game/inventory/InventoryList.h rename to src/game/inventory/ServerInventoryList.h index 76c19f16..2c0089c6 100644 --- a/src/game/inventory/InventoryList.h +++ b/src/game/inventory/ServerInventoryList.h @@ -14,12 +14,12 @@ class ClientList; class ServerClient; class Packet; -class InventoryList { +class ServerInventoryList { public: enum class Callback { ALLOW_TAKE, ALLOW_PUT, ON_TAKE, ON_PUT }; - InventoryList(DefinitionAtlas& defs, ClientList* list, const std::string& invName, - const std::string& name, unsigned short size, unsigned short width); + ServerInventoryList(DefinitionAtlas& defs, ClientList* list, const std::string& invName, + const std::string& name, unsigned short size, unsigned short width); unsigned short getLength(); unsigned short getWidth(); diff --git a/src/lua/VenusParser.cpp b/src/lua/VenusParser.cpp index 8dd104f5..e149cfd2 100644 --- a/src/lua/VenusParser.cpp +++ b/src/lua/VenusParser.cpp @@ -11,10 +11,10 @@ namespace { #ifdef _WIN32 const static char* EXECUTABLE_NAME = "zepha-venus-win.exe"; -#elif __APPLE__ - const static char* EXECUTABLE_NAME = "zepha-venus-macos"; #else const static char* EXECUTABLE_NAME = "zepha-venus-linux"; + #define _popen popen + #define _pclose pclose #endif } diff --git a/src/lua/api/class/ServerLuaInventoryList.cpp b/src/lua/api/class/ServerLuaInventoryList.cpp index 5ca8602f..8846b8dd 100644 --- a/src/lua/api/class/ServerLuaInventoryList.cpp +++ b/src/lua/api/class/ServerLuaInventoryList.cpp @@ -68,10 +68,10 @@ LuaItemStack ServerLuaInventoryList::remove_stack(unsigned short ind, unsigned s return LuaItemStack(list.removeStack(ind - 1, count), list.defs); } -void ServerLuaInventoryList::set_callback(InventoryList::Callback t, sol::function fun) { +void ServerLuaInventoryList::set_callback(ServerInventoryList::Callback t, sol::function fun) { list.setLuaCallback(t, fun); } -sol::function ServerLuaInventoryList::get_callback(InventoryList::Callback t) { +sol::function ServerLuaInventoryList::get_callback(ServerInventoryList::Callback t) { return list.getLuaCallback(t); } diff --git a/src/lua/api/class/ServerLuaInventoryList.h b/src/lua/api/class/ServerLuaInventoryList.h index ce9e29f8..a7549314 100644 --- a/src/lua/api/class/ServerLuaInventoryList.h +++ b/src/lua/api/class/ServerLuaInventoryList.h @@ -4,15 +4,15 @@ #pragma once -#include "../../../game/inventory/InventoryList.h" +#include "../../../game/inventory/ServerInventoryList.h" #include "LuaItemStack.h" class ServerLuaInventoryList { public: - ServerLuaInventoryList(InventoryList& list) : + ServerLuaInventoryList(ServerInventoryList& list) : list(list) {} - InventoryList& list; + ServerInventoryList& list; int get_length(); int get_width(); @@ -39,6 +39,6 @@ public: LuaItemStack remove_stack(unsigned short ind, unsigned short count); - void set_callback(InventoryList::Callback t, sol::function fun); - sol::function get_callback(InventoryList::Callback t); + void set_callback(ServerInventoryList::Callback t, sol::function fun); + sol::function get_callback(ServerInventoryList::Callback t); }; diff --git a/src/lua/api/usertype/sInventoryRef.h b/src/lua/api/usertype/sInventoryRef.h index 7798eb94..5132d1d8 100644 --- a/src/lua/api/usertype/sInventoryRef.h +++ b/src/lua/api/usertype/sInventoryRef.h @@ -40,17 +40,17 @@ namespace ServerApi { "remove_stack", &ServerLuaInventoryList::remove_stack, "on_put", sol::property( - [](ServerLuaInventoryList l){ return l.get_callback(InventoryList::Callback::ON_PUT); }, - [](ServerLuaInventoryList l, sol::function f){ l.set_callback(InventoryList::Callback::ON_PUT, f); }), + [](ServerLuaInventoryList l){ return l.get_callback(ServerInventoryList::Callback::ON_PUT); }, + [](ServerLuaInventoryList l, sol::function f){ l.set_callback(ServerInventoryList::Callback::ON_PUT, f); }), "on_take", sol::property( - [](ServerLuaInventoryList l){ return l.get_callback(InventoryList::Callback::ON_TAKE); }, - [](ServerLuaInventoryList l, sol::function f){ l.set_callback(InventoryList::Callback::ON_TAKE, f); }), + [](ServerLuaInventoryList l){ return l.get_callback(ServerInventoryList::Callback::ON_TAKE); }, + [](ServerLuaInventoryList l, sol::function f){ l.set_callback(ServerInventoryList::Callback::ON_TAKE, f); }), "allow_put", sol::property( - [](ServerLuaInventoryList l){ return l.get_callback(InventoryList::Callback::ALLOW_PUT); }, - [](ServerLuaInventoryList l, sol::function f){ l.set_callback(InventoryList::Callback::ALLOW_PUT, f); }), + [](ServerLuaInventoryList l){ return l.get_callback(ServerInventoryList::Callback::ALLOW_PUT); }, + [](ServerLuaInventoryList l, sol::function f){ l.set_callback(ServerInventoryList::Callback::ALLOW_PUT, f); }), "allow_take", sol::property( - [](ServerLuaInventoryList l){ return l.get_callback(InventoryList::Callback::ALLOW_TAKE); }, - [](ServerLuaInventoryList l, sol::function f){ l.set_callback(InventoryList::Callback::ALLOW_TAKE, f); }) + [](ServerLuaInventoryList l){ return l.get_callback(ServerInventoryList::Callback::ALLOW_TAKE); }, + [](ServerLuaInventoryList l, sol::function f){ l.set_callback(ServerInventoryList::Callback::ALLOW_TAKE, f); }) ); } } diff --git a/src/server/conn/ServerClient.h b/src/server/conn/ServerClient.h index 99eda2d8..40c36320 100644 --- a/src/server/conn/ServerClient.h +++ b/src/server/conn/ServerClient.h @@ -9,7 +9,7 @@ #include #include "../../util/Vec.h" -#include "../../game/inventory/InventoryList.h" +#include "../../game/inventory/ServerInventoryList.h" #include "../../game/inventory/Inventory.h" class InventoryRefs; diff --git a/subgames/zeus/mods/aurailus_item_collection/script/mode/direct.venus b/subgames/zeus/mods/aurailus_item_collection/script/mode/direct.venus index a466d7ef..6b92c618 100644 --- a/subgames/zeus/mods/aurailus_item_collection/script/mode/direct.venus +++ b/subgames/zeus/mods/aurailus_item_collection/script/mode/direct.venus @@ -5,6 +5,6 @@ if (zepha.server) { local yields = get_yield(pos) if (yields == nil) { return } - player.get_inventory():get_list("main"):add_stack({yields, 1}) + player:get_inventory():get_list("main"):add_stack({yields, 1}) }) } \ No newline at end of file