Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,51 @@ abbr.legality.banned {
#rules div.example {
padding-left: 3em;
}

/**** Restricted Lists ****/
.restrictions-container .active-restrictions {
border-left: 3px solid green;
padding: 1rem;
}

.restrictions-container .inactive-restrictions {
border-left: 3px solid red;
padding: 1rem;

}

.restrictions-container .restricted-list {
border-bottom: 2px dotted grey;
padding-bottom: 2rem;
}

.restrictions-container .restricted-list h2 a {
display: none;
}

.restrictions-container .restricted-list h2:hover a {
display: inline;
}

.restrictions-container .pod {
border: 1px solid grey;
border-radius: .5rem;
margin-bottom: 1rem;
}

.restrictions-container .pod .pod-card {
padding: .5rem;
}

.restrictions-container .pod .restricted-card {
font-weight: bold;
}

.restrictions-container .pod .title {
background-color: lightblue;
border-bottom: 1px solid black;
font-weight: bold;
padding: .5rem;
}


8 changes: 8 additions & 0 deletions src/Command/ImportRestrictionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class ImportRestrictionsCommand extends Command

const ISSUER_FFG_SHORTNAME = 'FFG';

const FORMAT_JOUST = 'joust';

const FORMAT_MELEE = 'melee';

protected array $faqIssuers = [
self::ISSUER_FFG,
self::ISSUER_CONCLAVE,
Expand Down Expand Up @@ -183,6 +187,10 @@ protected function buildContents(array $data): array
$rhett[$name]['banned'] = $banned;
if (array_key_exists('pods', $format)) {
$rhett[$name]['restricted_pods'] = $format['pods'];
for ($i = 0, $n = count($rhett[$name]['restricted_pods']); $i < $n; $i++) {
$rhett[$name]['restricted_pods'][$i]['title']
= (self::FORMAT_JOUST === $name ? 'P' : 'MP') . ($i + 1);
}
}
}

Expand Down
192 changes: 178 additions & 14 deletions src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace App\Controller;

use App\Entity\Card;
use App\Entity\CardInterface;
use App\Entity\DecklistInterface;
use App\Entity\Faction;
use App\Entity\Restriction;
use App\Entity\RestrictionInterface;
use App\Entity\Type;
use App\Entity\TypeInterface;
use App\Services\AgendaHelper;
use App\Services\CardsData;
use App\Services\DecklistManager;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -70,11 +75,11 @@ public function indexAction(
$counts = [];
foreach ($countByType as $code => $qty) {
$typeName = $typeNames[$code];
$counts[] = $qty . " " . $typeName . "s";
$counts[] = $qty." ".$typeName."s";
}
$array['count_by_type'] = join(' &bull; ', $counts);

$factions = [ $faction->getName() ];
$factions = [$faction->getName()];
foreach ($decklist->getSlots()->getAgendas() as $agenda) {
$minor_faction = $agendaHelper->getMinorFaction($agenda->getCard());
if ($minor_faction) {
Expand All @@ -89,13 +94,17 @@ public function indexAction(
}
}

return $this->render('Default/index.html.twig', [
'pagetitle' => "${gameName} Deckbuilder",
'pagedescription' => "Build your deck for ${gameName} by ${publisherName}."
. " Browse the cards and the thousand of decklists submitted by the community."
. " Publish your own decks and get feedback.",
'decklists_by_faction' => $decklists_by_faction
], $response);
return $this->render(
'Default/index.html.twig',
[
'pagetitle' => "${gameName} Deckbuilder",
'pagedescription' => "Build your deck for ${gameName} by ${publisherName}."
." Browse the cards and the thousand of decklists submitted by the community."
." Publish your own decks and get feedback.",
'decklists_by_faction' => $decklists_by_faction,
],
$response
);
}

/**
Expand All @@ -115,6 +124,7 @@ public function rulesreferenceAction(int $cacheExpiration, TranslatorInterface $
array("pagetitle" => $translator->trans("nav.rules"), "pagedescription" => "Rules Reference")
);
$response->setContent($page);

return $response;
}

Expand All @@ -135,6 +145,151 @@ public function faqAction(int $cacheExpiration, TranslatorInterface $translator)
array("pagetitle" => $translator->trans("nav.rules"), "pagedescription" => "F.A.Q")
);
$response->setContent($page);

return $response;
}

/**
* @Route("/restrictions", name="restrictions", methods={"GET"})
* @param int $cacheExpiration
* @param TranslatorInterface $translator
* @return Response
*/
public function restrictionsAction(
int $cacheExpiration,
TranslatorInterface $translator,
CardsData $cardsData
): Response {
$response = new Response();
$response->setPublic();
$response->setMaxAge($cacheExpiration);

$restrictionsRepo = $this->getDoctrine()->getRepository(Restriction::class);
$cardsRepo = $this->getDoctrine()->getRepository(Card::class);
$restrictions = $restrictionsRepo->findBy([], ['effectiveOn' => 'DESC']);

// get all card codes from all RLs
$allCardCodes = [];
foreach ($restrictions as $restriction) {
$allCardCodes = array_merge($allCardCodes, $restriction->getReferencedCards());
}

// preload all cards data for those so we don't have to take multiple trips to the database.
$cards = $cardsRepo->findBy(
['code' => array_unique($allCardCodes)],
['faction' => 'ASC', 'type' => 'ASC', 'code' => 'ASC']
);

// create a lookup map of cards by their code
$cardsMap = [];
/* @var CardInterface $card */
foreach ($cards as $card) {
$cardsMap[$card->getCode()] = $cardsData->getCardInfo($card, false, null);
}

$extractAndSortList = function (array $cardCodes, array $cardsMap): array {
$rhett = array_values(array_intersect_key($cardsMap, array_fill_keys($cardCodes, null)));
usort(
$rhett,
function (array $a, array $b): int {
$factions = [
'neutral',
'baratheon',
'greyjoy',
'lannister',
'martell',
'thenightswatch',
'stark',
'tyrell',
'targaryen',
];
$types = [
'agenda',
'plot',
'character',
'attachment',
'location',
'event',
];

return array_search($a['faction_code'], $factions) <=> array_search($b['faction_code'], $factions)
?: array_search($a['type_code'], $types) <=> array_search($b['type_code'], $types);
}
);

return $rhett;
};

$extractAndSortPods = function (array $pods, array $cardsMap, $extractAndSortList): array {
return array_map(function (array $pod) use ($cardsMap, $extractAndSortList) {
$rhett = [
'title' => $pod['title'],
];
if (array_key_exists('restricted', $pod) && $pod['restricted']) {
$rhett['restricted'] = $cardsMap[$pod['restricted']];
}
$rhett['cards'] = $extractAndSortList($pod['cards'], $cardsMap);
return $rhett;
}, $pods);
};

// transmogrify restricted lists for output
$restrictions = array_map(
function (RestrictionInterface $restriction) use ($extractAndSortList, $extractAndSortPods, $cardsMap) {
$rhett = [
'code' => $restriction->getcode(),
'cardSet' => $restriction->getCardSet(),
'title' => $restriction->getTitle(),
'effectiveOn' => $restriction->getEffectiveOn(),
'active' => $restriction->isActive(),
'issuer' => $restriction->getIssuer(),
];
$rhett['joustRestrictedList'] = $extractAndSortList($restriction->getJoustRestrictedList(), $cardsMap);
$rhett['joustRestrictedPods'] = $extractAndSortPods(
$restriction->getJoustRestrictedPods(),
$cardsMap,
$extractAndSortList
);
$rhett['joustBannedList'] = $extractAndSortList($restriction->getJoustBannedList(), $cardsMap);
$rhett['meleeRestrictedList'] = $extractAndSortList($restriction->getMeleeRestrictedList(), $cardsMap);
$rhett['meleeRestrictedPods'] = $extractAndSortPods(
$restriction->getMeleeRestrictedPods(),
$cardsMap,
$extractAndSortList
);
$rhett['meleeBannedList'] = $extractAndSortList($restriction->getMeleeBannedList(), $cardsMap);

return $rhett;
},
$restrictions
);


// split RLs into active and inactive
// and populate them with full card info
$activeRestrictions = [];
$inactiveRestrictions = [];

foreach ($restrictions as $restriction) {
if ($restriction['active']) {
$activeRestrictions[] = $restriction;
} else {
$inactiveRestrictions[] = $restriction;
}
}


$page = $this->renderView(
'Default/restrictions.html.twig',
[
"pagetitle" => $translator->trans("nav.restrictions"),
"pagedescription" => "Restricted and Banned Cards",
"inactive_lists" => $inactiveRestrictions,
"active_lists" => $activeRestrictions,
]
);
$response->setContent($page);

return $response;
}

Expand All @@ -154,10 +309,11 @@ public function tournamentregulationsAction(int $cacheExpiration, TranslatorInte
'Default/tournamentregulations.html.twig',
array(
"pagetitle" => $translator->trans("nav.rules"),
"pagedescription" => "Tournament Regulations"
"pagedescription" => "Tournament Regulations",
)
);
$response->setContent($page);

return $response;
}

Expand All @@ -174,10 +330,14 @@ public function aboutAction(Request $request, int $cacheExpiration, string $game
$response->setPublic();
$response->setMaxAge($cacheExpiration);

return $this->render($this->getLocaleSpecificViewPath('about', $request->getLocale()), array(
return $this->render(
$this->getLocaleSpecificViewPath('about', $request->getLocale()),
array(
"pagetitle" => "About",
"game_name" => $gameName,
), $response);
),
$response
);
}

/**
Expand All @@ -193,10 +353,14 @@ public function apiIntroAction(int $cacheExpiration, string $gameName, string $p
$response->setPublic();
$response->setMaxAge($cacheExpiration);

return $this->render('Default/apiIntro.html.twig', array(
return $this->render(
'Default/apiIntro.html.twig',
array(
"pagetitle" => "API",
"game_name" => $gameName,
"publisher_name" => $publisherName,
), $response);
),
$response
);
}
}
Loading