2025-08-29 15:12:38 +08:00

57 lines
1.0 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "BagShapeAsset.h"
UBagShapeAsset::UBagShapeAsset()
{
InitializeBagShape();
}
void UBagShapeAsset::InitializeBagShape()
{
BagSlots.Empty();
for (int x = 0; x < BagWidth; x++)
{
for (int y = 0; y < BagHeight; y++)
{
BagSlots.Add(FBagSlot(x, y, true));
}
}
}
bool UBagShapeAsset::IsSlotActive(int32 X, int32 Y) const
{
if (X < 0 || X >= BagWidth || Y < 0 || Y >= BagHeight)
return false;
for (auto BagSlot: BagSlots)
{
if (BagSlot.X == X && BagSlot.Y == Y)
return BagSlot.bIsActive;
}
return false;
}
void UBagShapeAsset::SetSlotActive(int32 X, int32 Y, bool Active)
{
if (X < 0 || X >= BagWidth || Y < 0 || Y >= BagHeight)
return;
int SlotIndex = FIndSlotIndex(X, Y);
if (SlotIndex != INDEX_NONE)
{
BagSlots[SlotIndex].bIsActive = Active;
}
}
int32 UBagShapeAsset::FIndSlotIndex(int32 X, int32 Y) const
{
for (int i = 0; i < BagSlots.Num(); i++)
{
if (BagSlots[i].X == X && BagSlots[i].Y == Y)
return i;
}
return INDEX_NONE;
}