added inventory logic
This commit is contained in:
1 parent
64ec35415c
commit
f5cf579115
3 files changed
+94
-3
No files matched your search
@@ -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
@@ -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();
|
||||
}
|
||||
@@ -17,6 +17,9 @@
|
||||
#include "BoneAnimatedModel.h"
|
||||
#include "TextModel.h"
|
||||
|
||||
#include "Inventory.h"
|
||||
#include <memory>
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
@@ -339,6 +342,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() {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user