From df4ef2965a677db97343ef9758a83338affa2a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Gim=C3=A9nez?= Date: Sun, 29 Sep 2024 22:20:43 +0900 Subject: [PATCH] calculate inventory matrix based on current inv items --- pkg/data/items.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/data/items.go b/pkg/data/items.go index c09a50b..5a4ed90 100644 --- a/pkg/data/items.go +++ b/pkg/data/items.go @@ -57,6 +57,20 @@ func (i Inventory) ByLocation(locations ...item.LocationType) []Item { return items } +func (i Inventory) Matrix() [4][10]bool { + invMatrix := [4][10]bool{} // false = empty, true = occupied + for _, itm := range i.ByLocation(item.LocationInventory) { + for k := range itm.Desc().InventoryWidth { + invMatrix[itm.Position.Y][itm.Position.X+k] = true + } + for k := range itm.Desc().InventoryHeight { + invMatrix[itm.Position.Y+k][itm.Position.X] = true + } + } + + return invMatrix +} + type UnitID int type Item struct {