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
9 changes: 9 additions & 0 deletions app/Draft/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ protected function validateTiles(): void {
protected function validateFactions(): void
{
$factions = array_reduce($this->factionSets, fn ($sum, Edition $e) => $sum += $e->factionCount(), 0);
// if POK is included and TE isn't, then keleres could add 1 extra
if (
in_array(Edition::PROPHECY_OF_KINGS, $this->factionSets) &&
$this->includeCouncilKeleresFaction &&
! in_array(Edition::THUNDERS_EDGE, $this->factionSets)
) {
$factions++;
}

if ($factions < $this->numberOfFactions) {
throw InvalidDraftSettingsException::notEnoughFactionsInSet($factions);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/RequestHandlers/HandleGenerateDraftRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function settingsFromRequest(): Settings
$this->tileSetsFromRequest(),
$this->factionSetsFromRequest(),
$this->request->get('include_keleres') == 'on',
$this->request->get('wormholes', 0) == 1,
$this->request->get('wormholes') == 'on',
$this->request->get('max_wormhole') == 'on',
(int) $this->request->get('min_legendaries'),
(float) $this->request->get('min_inf'),
Expand Down
8 changes: 8 additions & 0 deletions app/Http/RequestHandlers/HandleGenerateDraftRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ public static function settingsPayload()
'expected' => 1,
'expectedWhenNotSet' => 0,
];
yield 'Minimum 2 wormholes' => [
'postData' => [
'wormholes' => 'on',
],
'field' => 'minimumTwoAlphaAndBetaWormholes',
'expected' => true,
'expectedWhenNotSet' => false,
];
yield 'Minimum optimal Influence' => [
'postData' => [
'min_inf' => '4.5',
Expand Down
2 changes: 1 addition & 1 deletion app/TwilightImperium/Edition.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function factionCount(): int
return match($this) {
Edition::BASE_GAME => 17,
Edition::PROPHECY_OF_KINGS => 7,
Edition::THUNDERS_EDGE => 5,
Edition::THUNDERS_EDGE => 6,
Edition::DISCORDANT_STARS => 24,
Edition::DISCORDANT_STARS_PLUS => 10,
};
Expand Down
2 changes: 1 addition & 1 deletion app/TwilightImperium/EditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function itReturnsTheCorrectNumbersForThundersEdge(): void
$this->assertSame(15, Edition::THUNDERS_EDGE->blueTileCount());
$this->assertSame(5, Edition::THUNDERS_EDGE->redTileCount());
$this->assertSame(5, Edition::THUNDERS_EDGE->legendaryPlanetCount());
$this->assertSame(5, Edition::THUNDERS_EDGE->factionCount());
$this->assertSame(6, Edition::THUNDERS_EDGE->factionCount());
}

#[Test]
Expand Down
68 changes: 40 additions & 28 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ $(document).ready(function () {
toggleExpansion($(e.currentTarget))
});

// @todo initial check
// @todo disable DS/DSPlus when Pok is disabled

$('.draft-faction').on('change', faction_check);

$('#tabs nav a').on('click', function (e) {
e.preventDefault();
$('#tabs nav a, .tab').removeClass('active');
Expand Down Expand Up @@ -88,8 +83,6 @@ $(document).ready(function () {
request.onreadystatechange = function () {
if (request.readyState != 4) return;



let data = JSON.parse(request.responseText);

if (data.error) {
Expand Down Expand Up @@ -140,6 +133,44 @@ function enableExpansion(expansion) {
if (expansion == 'PoK') {
toggleDiscordantAvailability(true);
}

toggleKeleres();
}

function toggleKeleres() {
const POKIsEnabled = $('[data-toggle-expansion="PoK"]').is(':checked');
const TEIsEnabled = $('[data-toggle-expansion="TE"]').is(':checked');

let keleresIsAllowed = false;
let keleresIsRequired = false;

if (TEIsEnabled) {
// keleres is checked and disabled
$('[data-set="keleres"]')
.prop('disabled', true)
.prop('checked', true)
.parent().addClass('disabled')
} else {
if (POKIsEnabled) {
// keleres is optional and enabled
$('[data-set="keleres"]')
.prop('disabled', false)
.parent().removeClass('disabled')
} else {
// keleres is unavailable and disabled
$('[data-set="keleres"]')
.prop('disabled', true)
.prop('checked', false)
.parent().addClass('disabled')
}
}

if (keleresIsRequired) {
$('[data-set="keleres"]')
.prop('disabled', true)
.prop('checked', true)
.parent().addClass('disabled')
}
}

function toggleDiscordantAvailability(pokIsEnabled) {
Expand Down Expand Up @@ -168,6 +199,8 @@ function disableExpansion(expansion) {
if (expansion == 'PoK') {
toggleDiscordantAvailability(false);
}

toggleKeleres();
}

function update_alliance_mode() {
Expand Down Expand Up @@ -209,27 +242,6 @@ function loading(loading = true) {
}
}


function faction_check() {
let sets = [];
let max = 0;


$('.draft-faction').each(function (i, el) {
if ($(el).is(':checked')) {
max += parseInt($(el).data('num'));
$('.factions label[data-set="' + $(el).data('set') + '"]').removeClass('disabled');
$('.factions label[data-set="' + $(el).data('set') + '"] input').prop('disabled', false);
} else {
$('.factions label[data-set="' + $(el).data('set') + '"]').addClass('disabled');
$('.factions label[data-set="' + $(el).data('set') + '"] input').prop('disabled', true).prop('checked', false);
}
});


$('#num_factions').attr('max', max);
}

function init_player_count() {
$('#num_players').on('change', update_player_count);
$('#num_players').on('keyup', update_player_count);
Expand Down
5 changes: 3 additions & 2 deletions templates/factions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ function translateSet($set): string
'te' => \App\TwilightImperium\Edition::THUNDERS_EDGE->value,
'discordant' => \App\TwilightImperium\Edition::DISCORDANT_STARS->value,
'discordantexp' => \App\TwilightImperium\Edition::DISCORDANT_STARS_PLUS->value,
'keleres' => \App\TwilightImperium\Edition::THUNDERS_EDGE->value,
'keleres' => 'keleres',
};
}


foreach ($factions as $f) {
$fact = '<label data-expansion="' . translateSet($f['set']) . '" class="check" for="custom_f_' . $f['id'] . '"><input class="custom_faction" value="' . $f['name'] . '" type="checkbox" id="custom_f_' . $f['id'] . '" name="custom_factions[]" />';
$fact = '<label data-expansion="' . translateSet($f['set']) .'" class="check" for="custom_f_' . $f['id'] . '"><input class="custom_faction" value="' . $f['name'] . '" type="checkbox" id="custom_f_' . $f['id'] . '" name="custom_factions[]" />';
$fact .= '<img src="' . url('img/factions/ti_' . $f['id'] . '.png') . '" /> ' . $f['name'] . '</label>';
echo $fact;
}
3 changes: 1 addition & 2 deletions templates/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
Number of Factions
</label>

<input type="number" id="num_factions" name="num_factions" value="9" max="17" />
<input type="number" id="num_factions" name="num_factions" value="9" />
<span class="help">
Note: Less options means more competitive drafting.<br />
Number of players + 3 is kind of recommended, but this is all personal preference.
Expand Down Expand Up @@ -247,7 +247,6 @@
</label>
<span class="help">
The Council Keleres was introduced in <a target="_blank" href="https://images-cdn.fantasyflightgames.com/filer_public/35/e1/35e10f37-4b6d-4479-a117-4e2c571ddfa7/ti_codex_volume_3_vigil_v2_1-compressed.pdf">Codex III</a> and is included in Thunder's Edge.
(PoK or TE required). For simplicity's sake I'll leave it up to each group to decide how they want to handle things (including the very limited possibility of all 3 flavours also being picked). Just something to keep in mind.
</span>
<label for="factions_te" class="check" data-expansion="TE">
<input type="checkbox" class="draft-faction auto-enable" name="factionSets[TE]" id="factions_te" /> Thunder's Edge
Expand Down