Skip to content

Commit

Permalink
Add information about format to decks (#12)
Browse files Browse the repository at this point in the history
* add format info

* change color to increase contrast

* small updates

* prevent tag duplication on repeated saves, cleans up code a bit.

* version bump.

---------

Co-authored-by: Stefan Topfstedt <[email protected]>
  • Loading branch information
mmeldo and stopfstedt authored Feb 15, 2023
1 parent c186680 commit 6d8fe36
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 8 deletions.
2 changes: 1 addition & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
assets:
version: '2023012702'
version: '2023021400'
# json_manifest_path: "%kernel.project_dir%/public/manifest.json"
default_locale: '%locale%'
translator: { fallbacks: ['%locale%'] }
Expand Down
19 changes: 18 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,24 @@ h1, #index_page .section {
}

#tag_toggles button {
margin: 0 1px 1px 0
margin: 0 1px 1px 0;
}


#tag_toggles .tag-wwe {
background-color: rgba(1, 177, 1, 0.2);
}

#tag_toggles .tag-oldtimer {
background-color: rgba(177, 123, 1, 0.2);
}

.deck-list-tags .tag-wwe {
background-color: darkgreen;
}

.deck-list-tags .tag-oldtimer {
background-color: rgb(150, 110, 8);
}

.label {
Expand Down
2 changes: 1 addition & 1 deletion public/js/decks.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ function update_tag_toggles() {
}
var container = $('#tag_toggles').empty();
tags.sort().forEach(function (tag) {
$('<button type="button" class="btn btn-default btn-xs" data-toggle="button">' + tag + '</button>').data('deck_id', tag_dict[tag].join(' ')).appendTo(container);
$('<button type="button" class="btn btn-default btn-xs tag-' + tag + '" data-toggle="button">' + tag + '</button>').data('deck_id', tag_dict[tag].join(' ')).appendTo(container);
});

}
Expand Down
19 changes: 16 additions & 3 deletions public/js/dtdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ function update_deck(options) {
}


var latestpack = DTDB.data.sets({name: Outfit.pack}).first();
LatestPack = DTDB.data.sets({name: Outfit.pack}).first();
EarliestPack = LatestPack;
if (DisplaySort === 'type') {
var preSort = 'value,title';
} else if (DisplaySort === 'gang') {
Expand All @@ -317,7 +318,8 @@ function update_deck(options) {
}
DTDB.data.cards({indeck: {'gt': 0}, type_code: {'!is': 'outfit'}}).order(preSort).each(function (record) {
var pack = DTDB.data.sets({name: record.pack}).first();
if (latestpack.cyclenumber < pack.cyclenumber || (latestpack.cyclenumber == pack.cyclenumber && latestpack.number < pack.number)) latestpack = pack;
if (LatestPack.cyclenumber < pack.cyclenumber || (LatestPack.cyclenumber == pack.cyclenumber && LatestPack.number < pack.number)) LatestPack = pack;
if (EarliestPack.cyclenumber > pack.cyclenumber || (EarliestPack.cyclenumber == pack.cyclenumber && EarliestPack.number > pack.number)) EarliestPack = pack;

var criteria = null;
var additional_info = '';
Expand Down Expand Up @@ -382,9 +384,16 @@ function update_deck(options) {
}
}
});
$('#latestpack').html('Cards up to <i>' + latestpack.name + '</i>');
$('#latestpack').html('Cards up to <i>' + LatestPack.name + '</i>');
check_composition();
check_distribution();
// TCaR is used to distinguish between WWE (standard) format and
// Old Timer (legacy) format
var format = 'Old Timer';
if (EarliestPack.cyclenumber > TCaRPack.cyclenumber || (EarliestPack.cyclenumber == TCaRPack.cyclenumber && EarliestPack.number >= TCaRPack.number)) {
format = 'Weird West Edition';
}
$('#wweformat').html('Format is <b>' + format + '</b>');
$('#deck').show();
}

Expand Down Expand Up @@ -522,6 +531,10 @@ var DudeStarter = [];
var SuitNumbers = {Spades: 0, Diams: 1, Hearts: 2, Clubs: 3};
var SuitNames = ['Spades', 'Diams', 'Hearts', 'Clubs'];
var RankNames = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
var EarliestPack = null;
var LatestPack = null;
// TCaR (There Comes a Reckoning) is the first pack published by PBE
var TCaRPack = {cyclenumber: 11, number: 1};
$(function () {

if (Modernizr.touch) {
Expand Down
35 changes: 33 additions & 2 deletions src/Services/Decks.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ class Decks
protected Diff $diff;
protected LoggerInterface $logger;

// TCaR (There Comes a Reckoning) is a first expansion published by PBE
public const TCAR_CYCLENUMBER = 11;
public const TCAR_NUMBER = 1;

public const FORMAT_TAG_OLDTIMER = 'oldtimer';
public const FORMAT_TAG_WWE = 'wwe';

public function __construct(
EntityManagerInterface $entityManager,
Judge $judge,
Expand Down Expand Up @@ -196,6 +203,7 @@ public function saveDeck($user, $deck, $decklist_id, $name, $description, $tags,
$cards = array();
/* @var Pack $latestPack */
$latestPack = null;
$earliestPack = null;
foreach ($content as $card_code => $info) {
$card = $this->entityManager->getRepository(Card::class)->findOneBy(array(
"code" => $card_code
Expand All @@ -211,6 +219,13 @@ public function saveDeck($user, $deck, $decklist_id, $name, $description, $tags,
} elseif ($latestPack->getCycle()->getNumber() == $pack->getCycle()->getNumber() && $latestPack->getNumber() < $pack->getNumber()) {
$latestPack = $pack;
}
if (! $earliestPack) {
$earliestPack = $pack;
} elseif ($earliestPack->getCycle()->getNumber() > $pack->getCycle()->getNumber()) {
$earliestPack = $pack;
} elseif ($earliestPack->getCycle()->getNumber() == $pack->getCycle()->getNumber() && $earliestPack->getNumber() > $pack->getNumber()) {
$earliestPack = $pack;
}
if ($card->getType()->getName() == "Outfit") {
$outfit = $card;
}
Expand All @@ -229,10 +244,26 @@ public function saveDeck($user, $deck, $decklist_id, $name, $description, $tags,
// tags can never be empty. if it is we put gang in
$gang_code = $outfit->getGang()->getCode();
$tags = array($gang_code);
} elseif (!is_array($tags)) {
$tags = explode(' ', $tags);
}
if (is_array($tags)) {
$tags = implode(' ', $tags);

// remove any pre-existing format tags
$tags = array_diff($tags, [self::FORMAT_TAG_OLDTIMER, self::FORMAT_TAG_WWE]);

// TCaR is used to distinguish between WWE (standard) format and Old Timer (legacy) format
$formattag = self::FORMAT_TAG_OLDTIMER;
if (
$earliestPack->getCycle()->getNumber() > self::TCAR_CYCLENUMBER
|| ($earliestPack->getCycle()->getNumber() == self::TCAR_CYCLENUMBER
&& $earliestPack->getNumber() >= self::TCAR_NUMBER
)
) {
$formattag = self::FORMAT_TAG_WWE;
}
$tags[] = $formattag;

$tags = implode(' ', $tags);
$deck->setTags($tags);
$this->entityManager->persist($deck);

Expand Down
1 change: 1 addition & 0 deletions templates/Builder/deck.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<div id="deckcomposition"></div>
<div id="deckdistribution"></div>
<div id="latestpack"></div>
<div id="wweformat"></div>
</div><!-- /.col-sm-9 -->
</div><!-- /.row -->
<!-- Outfit and Stats -->
Expand Down
1 change: 1 addition & 0 deletions templates/Builder/decks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<div id="deckcomposition"></div>
<div id="deckdistribution"></div>
<div id="latestpack"></div>
<div id="wweformat"></div>
<!-- Outfit and Stats -->
<!-- Deck Content -->
<div class="row" id="deck-content" style="margin-bottom:10px">
Expand Down
1 change: 1 addition & 0 deletions templates/Builder/deckview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<div id="startingnumbers"></div>
<div id="cardcount"></div>
<div id="latestpack"></div>
<div id="wweformat"></div>
</div><!-- /.col-sm-9 -->
</div><!-- /.row -->
<!-- Outfit and Stats -->
Expand Down
1 change: 1 addition & 0 deletions templates/Decklist/decklist.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
</div>
<div id="startingnumbers"></div>
<div id="latestpack"></div>
<div id="wweformat"></div>
{% if decklist.tournament %}
<a class="btn btn-ghost btn-success btn-sm"
href="{{ path('decklists_list', {type:'tournament'}) }}">
Expand Down
1 change: 1 addition & 0 deletions templates/Default/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<h6 id="legend"></h6>
<div id="startingnumbers"></div>
<div id="latestpack" class="small"></div>
<div id="wweformat"></div>
</div>
</div>
<!-- Identity and Stats -->
Expand Down

0 comments on commit 6d8fe36

Please sign in to comment.