Merge pull request #1 from mephi1984/pavel

added inventory logic
This commit is contained in:
Pavel Makarov 2025-03-01 17:09:45 +06:00 committed by GitHub
commit 69a03cf524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 94 additions and 3 deletions

39
Inventory.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "Inventory.h"
#include <algorithm> // Для std::remove_if
namespace ZL
{
// Определяем глобальный инвентарь
std::vector<InventoryItem> gInventory;
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> 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<InventoryItem>& ReturnInventory()
{
return gInventory;
}
}

32
Inventory.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include <string>
#include <memory>
#include <vector>
#include <iostream>
#include "TextureManager.h"
namespace ZL
{
// Структура, описывающая элемент инвентаря
struct InventoryItem
{
std::string name;
std::shared_ptr<Texture> texture;
};
// Глобальный список инвентаря
extern std::vector<InventoryItem> gInventory;
// Добавить предмет в инвентарь
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex);
// Удалить предмет из инвентаря
void RemoveItemFromInventory(const std::string& name);
// Вывести все предметы в инвентаре
void PrintInventory();
// Получить список предметов инвентаря
const std::vector<InventoryItem>& ReturnInventory();
}

View File

@ -17,6 +17,9 @@
#include "BoneAnimatedModel.h"
#include "TextModel.h"
#include "Inventory.h"
#include <memory>
namespace ZL
{
void worldToScreenCoordinates(Vector3f objectPos,
@ -377,6 +380,23 @@ namespace ZL
std::cout << "Hello test 5x" << std::endl;
// ТЕСТИРУЕМ ВЗАИМОДЕЙСТВИЕ С ИНВЕНТАРЕМ
auto roomTexturePtr = std::make_shared<ZL::Texture>(ZL::CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
auto coneTexturePtr = std::make_shared<ZL::Texture>(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() {
@ -411,14 +431,14 @@ namespace ZL
static const float zoomstep = 1.0f;
if (event.wheel.y > 0) {
// Прокрутка вверх - увеличиваем zoom
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zoom
Env::zoom -= zoomstep;
}
else if (event.wheel.y < 0) {
// Прокрутка вниз - уменьшаем zoom
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zoom
Env::zoom += zoomstep;
}
// Ограничиваем zoom, чтобы он не стал отрицательным
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> zoom, <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (Env::zoom < zoomstep) {
Env::zoom = zoomstep;
}