From fed726e697c39b66ae66ad549ec747083b3b2270 Mon Sep 17 00:00:00 2001 From: Matronator <5470780+matronator@users.noreply.github.com> Date: Thu, 16 Nov 2023 04:44:23 +0100 Subject: [PATCH] add item comparison --- app/model/ItemsRepository.php | 49 ++++++++++++++++++- .../Inventory/EquippedItemTooltip.latte | 30 ++++++++++++ .../Front/components/Inventory/Inventory.css | 23 ++++++--- .../components/Inventory/Inventory.latte | 4 ++ .../components/Inventory/ItemTooltip.latte | 4 +- .../Inventory/MarketInventory.latte | 4 ++ .../Front/presenters/ItemsBasePresenter.php | 2 +- 7 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 app/modules/Front/components/Inventory/EquippedItemTooltip.latte diff --git a/app/model/ItemsRepository.php b/app/model/ItemsRepository.php index 870d5fa..b382b94 100644 --- a/app/model/ItemsRepository.php +++ b/app/model/ItemsRepository.php @@ -24,8 +24,55 @@ public function findAll() return $this->database->table('items'); } - public function get(int $id): Nette\Database\Table\ActiveRow + public function get(?int $id): ?Nette\Database\Table\ActiveRow { + if (!$id) return null; return $this->findAll()->get($id); } + + public function getSlotByType(string $type, object $playerBody) + { + switch ($type) { + case 'headgear': + return [$this->get($playerBody->head), $this->get($playerBody->face)]; + case 'helmet': + $face = $playerBody->face; + if ($face) { + $headgear = $this->get($face); + if ($headgear->subtype === 'headgear') { + return [$headgear]; + } + } + return [$this->get($playerBody->head)]; + case 'mask': + return [$this->get($playerBody->face)]; + case 'chest': + return [$this->get($playerBody->body)]; + case 'legs': + return [$this->get($playerBody->legs)]; + case 'boots': + return [$this->get($playerBody->feet)]; + case 'shoulders': + return [$this->get($playerBody->shoulders)]; + case 'shield': + $mainHand = $playerBody->melee ?? $playerBody->ranged; + if ($mainHand) { + $mainHandItem = $this->get($mainHand); + if ($mainHandItem->type === 'two-handed-melee' || $mainHandItem->subtype === 'two-handed-ranged') { + return [$this->get($playerBody->shield), $mainHandItem]; + } + } + return [$this->get($playerBody->shield)]; + case 'melee': + return [$this->get($playerBody->melee)]; + case 'ranged': + return [$this->get($playerBody->ranged)]; + case 'two-handed-melee': + return [$this->get($playerBody->melee), $this->get($playerBody->shield)]; + case 'two-handed-ranged': + return [$this->get($playerBody->ranged), $this->get($playerBody->shield)]; + default: + return []; + } + } } diff --git a/app/modules/Front/components/Inventory/EquippedItemTooltip.latte b/app/modules/Front/components/Inventory/EquippedItemTooltip.latte new file mode 100644 index 0000000..038e015 --- /dev/null +++ b/app/modules/Front/components/Inventory/EquippedItemTooltip.latte @@ -0,0 +1,30 @@ +{varType array $equippedItems} +{varType object $item} + +{foreach $equippedItems as $equipped} + {continueIf $equipped === null} +
+
+
+ {$equipped->name} +
{$equipped->unlock_at}
+
+
+ +
+{/foreach} diff --git a/app/modules/Front/components/Inventory/Inventory.css b/app/modules/Front/components/Inventory/Inventory.css index e89215b..ac9f4ee 100644 --- a/app/modules/Front/components/Inventory/Inventory.css +++ b/app/modules/Front/components/Inventory/Inventory.css @@ -46,7 +46,8 @@ } .item-dropdown, -.equipped-dropdown { +.equipped-dropdown, +.tippy-content { z-index: 99; } @@ -102,11 +103,6 @@ } .item-stats-list { - /* display: flex; - flex-direction: row; - flex-wrap: wrap; - align-items: center; - justify-content: space-between; */ display: grid; grid-template-columns: 1fr auto auto; grid-template-rows: 1fr 1fr 1fr; @@ -114,9 +110,9 @@ justify-content: space-evenly; align-items: stretch; gap: 10px; + margin: 0 auto; margin-top: 0; margin-bottom: 0; - margin: 0 auto; & > li { font-size: 0.875rem; @@ -133,6 +129,18 @@ "img stats" "txt txt"; + &.equipped-item-content { + width: max-content; + grid-template-areas: "img stats"; + & .item-image .item-unlock-at { + font-size: 0.875rem; + } + + & .item-stats-list { + grid-template-rows: 1fr 1fr auto; + } + } + & .item-image { grid-area: img; margin-right: 1rem; @@ -163,6 +171,7 @@ & .item-text { grid-area: txt; + padding-bottom: 0; } & .item-stats-list { diff --git a/app/modules/Front/components/Inventory/Inventory.latte b/app/modules/Front/components/Inventory/Inventory.latte index 9498bfe..5cece9b 100644 --- a/app/modules/Front/components/Inventory/Inventory.latte +++ b/app/modules/Front/components/Inventory/Inventory.latte @@ -41,6 +41,10 @@
{include 'ItemTooltip.latte', item => $item->item, img => $img} + {var $equippedItems = $presenter->itemsRepository->getSlotByType($item->item->subtype, $playerBody)} + {if $equippedItems !== []} + {include 'EquippedItemTooltip.latte', equippedItems => $equippedItems, item => $item->item} + {/if}
{/if} diff --git a/app/modules/Front/components/Inventory/ItemTooltip.latte b/app/modules/Front/components/Inventory/ItemTooltip.latte index a8e453a..19d5536 100644 --- a/app/modules/Front/components/Inventory/ItemTooltip.latte +++ b/app/modules/Front/components/Inventory/ItemTooltip.latte @@ -1,7 +1,7 @@ {varType object $item} {varType string $img} -
+
{$item->name} @@ -11,7 +11,7 @@
{$item->name} {$item->type|firstUpper} | {$item->subtype|firstUpper} -

{$item->description}

+

{$item->description}

  • +{$item->attack}
  • diff --git a/app/modules/Front/components/Inventory/MarketInventory.latte b/app/modules/Front/components/Inventory/MarketInventory.latte index 60aaf95..f666772 100644 --- a/app/modules/Front/components/Inventory/MarketInventory.latte +++ b/app/modules/Front/components/Inventory/MarketInventory.latte @@ -12,6 +12,10 @@
{include 'ItemTooltip.latte', item => $item->item, img => $img} + {var $equippedItems = $presenter->itemsRepository->getSlotByType($item->item->subtype, $playerBody)} + {if $equippedItems !== []} + {include 'EquippedItemTooltip.latte', equippedItems => $equippedItems, item => $item->item} + {/if}
diff --git a/app/modules/Front/presenters/ItemsBasePresenter.php b/app/modules/Front/presenters/ItemsBasePresenter.php index b559fe0..6b1ea75 100755 --- a/app/modules/Front/presenters/ItemsBasePresenter.php +++ b/app/modules/Front/presenters/ItemsBasePresenter.php @@ -14,7 +14,7 @@ abstract class ItemsBasePresenter extends GamePresenter protected $inventoryRepository; /** @var ItemsRepository */ - protected $itemsRepository; + public $itemsRepository; /** @var MarketRepository */ public $marketRepository;