Skip to content

Commit

Permalink
add item comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
matronator committed Nov 16, 2023
1 parent e5209df commit fed726e
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 11 deletions.
49 changes: 48 additions & 1 deletion app/model/ItemsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
}
}
30 changes: 30 additions & 0 deletions app/modules/Front/components/Inventory/EquippedItemTooltip.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{varType array $equippedItems}
{varType object $item}

{foreach $equippedItems as $equipped}
{continueIf $equipped === null}
<div class="uk-width-auto uk-background-secondary uk-light uk-padding-small equipped-item-content" data-dropdown-content>
<div class="uk-width-auto item-image">
<div class="uk-inline">
<img src="{$basePath.$uploadDir.$equipped->image}" width="64" height="64" alt="{$equipped->name}" data-rarity="{$equipped->rarity}">
<div class="uk-overlay uk-position-bottom item-unlock-at uk-padding-remove-vertical uk-padding-small">{$equipped->unlock_at}</div>
</div>
</div>
<ul class="uk-list uk-list-collapse item-stats-list">
{var $newAttack = ($item->attack ?? 0) - ($equipped->attack ?? 0)}
{var $newArmor = ($item->armor ?? 0) - ($equipped->armor ?? 0)}
{var $newStrength = ($item->strength ?? 0) - ($equipped->strength ?? 0)}
{var $newStamina = ($item->stamina ?? 0) - ($equipped->stamina ?? 0)}
{var $newSpeed = ($item->speed ?? 0) - ($equipped->speed ?? 0)}
{var $newEnergyMax = ($item->energy_max ?? 0) - ($equipped->energy_max ?? 0)}
{var $newXpBoost = ($item->xp_boost ?? 0) - ($equipped->xp_boost ?? 0)}
<li n:if="$item->attack || $equipped->attack" n:class="$newAttack > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newAttack > 0}+{/if}{$newAttack} <span uk-icon="sword"></span></li>
<li n:if="$item->armor || $equipped->armor" n:class="$newArmor > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newArmor > 0}+{/if}{$newArmor} <span uk-icon="shield"></span></li>
<li n:if="$item->strength || $equipped->strength" n:class="$newStrength > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newStrength > 0}+{/if}{$newStrength} <span uk-icon="strength"></span></li>
<li n:if="$item->stamina || $equipped->stamina" n:class="$newStamina > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newStamina > 0}+{/if}{$newStamina} <span uk-icon="heart"></span></li>
<li n:if="$item->speed || $equipped->speed" n:class="$newSpeed > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newSpeed > 0}+{/if}{$newSpeed} <span uk-icon="speed"></span></li>
<li n:if="$item->energy_max || $equipped->energy_max" n:class="$newEnergyMax > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newEnergyMax > 0}+{/if}{$newEnergyMax} <span uk-icon="bolt"></span></li>
<li n:if="$item->xp_boost || $equipped->xp_boost" n:class="$newXpBoost > 0 ? 'uk-text-success' : 'uk-text-danger'">{if $newXpBoost > 0}+{/if}{$newXpBoost}&times; {_general.stats.xp}</li>
</ul>
</div>
{/foreach}
23 changes: 16 additions & 7 deletions app/modules/Front/components/Inventory/Inventory.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
}

.item-dropdown,
.equipped-dropdown {
.equipped-dropdown,
.tippy-content {
z-index: 99;
}

Expand Down Expand Up @@ -102,21 +103,16 @@
}

.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;
grid-auto-flow: column;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -163,6 +171,7 @@

& .item-text {
grid-area: txt;
padding-bottom: 0;
}

& .item-stats-list {
Expand Down
4 changes: 4 additions & 0 deletions app/modules/Front/components/Inventory/Inventory.latte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
</div>
<div class="uk-width-max-content item-dropdown uk-hidden" data-item-slot="{$item->slot}" data-dropdown>
{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}
</div>
{/if}
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/modules/Front/components/Inventory/ItemTooltip.latte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{varType object $item}
{varType string $img}

<div class="uk-width-1-1 uk-flex uk-background-secondary uk-light uk-padding-small" data-dropdown-content>
<div class="uk-width-1-1 uk-background-secondary uk-light uk-padding-small" data-dropdown-content>
<div class="uk-width-auto item-image">
<div class="uk-inline">
<img src="{$img}" width="128" height="128" alt="{$item->name}" data-rarity="{$item->rarity}">
Expand All @@ -11,7 +11,7 @@
<div class="uk-padding-small uk-padding-remove-horizontal uk-width-expand item-text">
<strong class="uk-text-bold inventory-item-title">{$item->name}</strong>
<span class="inventory-item-subtitle">{$item->type|firstUpper} | {$item->subtype|firstUpper}</span>
<p class="uk-text-small uk-text-meta uk-text-italic"><small>{$item->description}</small></p>
<p class="uk-text-small uk-text-meta uk-text-italic uk-margin-remove"><small>{$item->description}</small></p>
</div>
<ul class="uk-list uk-list-collapse item-stats-list">
<li n:if="$item->attack">+{$item->attack} <span uk-icon="sword"></span></li>
Expand Down
4 changes: 4 additions & 0 deletions app/modules/Front/components/Inventory/MarketInventory.latte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
</div>
<div class="uk-width-max-content item-dropdown uk-hidden" data-dropdown>
{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}
</div>
</div>
<div class="market-buy-button">
Expand Down
2 changes: 1 addition & 1 deletion app/modules/Front/presenters/ItemsBasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class ItemsBasePresenter extends GamePresenter
protected $inventoryRepository;

/** @var ItemsRepository */
protected $itemsRepository;
public $itemsRepository;

/** @var MarketRepository */
public $marketRepository;
Expand Down

0 comments on commit fed726e

Please sign in to comment.