From f5cf579115e4badd814feaf271935f7c386fa4d8 Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sat, 1 Mar 2025 17:08:49 +0600 Subject: [PATCH] added inventory logic --- Inventory.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Inventory.h | 32 ++++++++++++++++++++++++++++++++ main.cpp | 26 +++++++++++++++++++++++--- 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 Inventory.cpp create mode 100644 Inventory.h diff --git a/Inventory.cpp b/Inventory.cpp new file mode 100644 index 0000000..7a9b42b --- /dev/null +++ b/Inventory.cpp @@ -0,0 +1,39 @@ +#include "Inventory.h" +#include // Для std::remove_if + +namespace ZL +{ + // Определяем глобальный инвентарь + std::vector gInventory; + + void AddItemToInventory(const std::string& name, std::shared_ptr tex) + { + gInventory.push_back({ name, tex }); + } + + void RemoveItemFromInventory(const std::string& name) + { + gInventory.erase( + std::remove_if(gInventory.begin(), gInventory.end(), + [&name](const InventoryItem& item) { + return item.name == name; + }), + gInventory.end()); + } + + void PrintInventory() + { + for (const auto& item : gInventory) + { + std::cout << "Item: " << item.name + << ", texture ID = " + << (item.texture ? item.texture->getTexID() : 0) + << std::endl; + } + } + + const std::vector& ReturnInventory() + { + return gInventory; + } +} diff --git a/Inventory.h b/Inventory.h new file mode 100644 index 0000000..8f771fd --- /dev/null +++ b/Inventory.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include +#include +#include +#include "TextureManager.h" + +namespace ZL +{ + // Структура, описывающая элемент инвентаря + struct InventoryItem + { + std::string name; + std::shared_ptr texture; + }; + + // Глобальный список инвентаря + extern std::vector gInventory; + + // Добавить предмет в инвентарь + void AddItemToInventory(const std::string& name, std::shared_ptr tex); + + // Удалить предмет из инвентаря + void RemoveItemFromInventory(const std::string& name); + + // Вывести все предметы в инвентаре + void PrintInventory(); + + // Получить список предметов инвентаря + const std::vector& ReturnInventory(); +} diff --git a/main.cpp b/main.cpp index 2abc35f..4903612 100755 --- a/main.cpp +++ b/main.cpp @@ -17,6 +17,9 @@ #include "BoneAnimatedModel.h" #include "TextModel.h" +#include "Inventory.h" +#include + namespace ZL { @@ -339,6 +342,23 @@ namespace ZL std::cout << "Hello test 5x" << std::endl; + +// ТЕСТИРУЕМ ВЗАИМОДЕЙСТВИЕ С ИНВЕНТАРЕМ + auto roomTexturePtr = std::make_shared(ZL::CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")); + auto coneTexturePtr = std::make_shared(ZL::CreateTextureDataFromBmp24("./conus.bmp")); + + // Добавляем предметы в инвентарь + ZL::AddItemToInventory("RoomCeramics", roomTexturePtr); + ZL::AddItemToInventory("Cone", coneTexturePtr); + + std::cout << "Before removal:\n"; + ZL::PrintInventory(); + + // Удаляем "Cone" из инвентаря + ZL::RemoveItemFromInventory("Cone"); + + std::cout << "\nAfter removal:\n"; + ZL::PrintInventory(); } void render() { @@ -373,14 +393,14 @@ namespace ZL static const float zoomstep = 1.0f; if (event.wheel.y > 0) { - // - zoom + // ��������� ����� - ����������� zoom Env::zoom -= zoomstep; } else if (event.wheel.y < 0) { - // - zoom + // ��������� ���� - ��������� zoom Env::zoom += zoomstep; } - // zoom, + // ������������ zoom, ����� �� �� ���� ������������� if (Env::zoom < zoomstep) { Env::zoom = zoomstep; }