Skip to content

Commit

Permalink
Merge pull request #826 from PennyDreadfulMTG/restore-balance
Browse files Browse the repository at this point in the history
Deck visibility and other fixes
  • Loading branch information
bakert authored Nov 7, 2024
2 parents 6b2d232 + ddf82de commit 3d3d858
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 133 deletions.
25 changes: 9 additions & 16 deletions gatherling/Models/Deck.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,28 +339,21 @@ public function canEdit(string|false $username): bool

public function canView(string|false $username): bool
{
if ($username === false) {
return false;
}
$event = $this->getEvent();
$player = new Player($username);

if (($event->finalized && !$event->active) || $event->private_decks == 0) {
return true;
} elseif ($event->current_round > $event->mainrounds && !$event->private_finals) {
return true;
} else {
if (
$player->isSuper() ||
$event->isHost($username) ||
$event->isOrganizer($username) ||
strcasecmp($username, $this->playername) == 0
) {
return true;
}
} elseif ($username === false) {
return false;
}

return false;
$player = new Player($username);
return (
$player->isSuper() ||
$event->isHost($username) ||
$event->isOrganizer($username) ||
($this->playername !== null && strcasecmp($username, $this->playername) == 0)
);
}

public function isValid(): bool
Expand Down
58 changes: 28 additions & 30 deletions gatherling/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class Event
public ?string $cohost; // has one Player - cohost

// Subevents
public string|int $mainrounds;
public int $mainrounds;
public string $mainstruct;
public ?int $mainid; // Has one main subevent
public string|int $finalrounds;
public int $finalrounds;
public string $finalstruct;
public ?int $finalid; // Has one final subevent

Expand All @@ -64,9 +64,9 @@ public function __construct(int|string $name = '')
if ($name == '') {
$this->id = 0;
$this->name = '';
$this->mainrounds = '';
$this->mainrounds = 0;
$this->mainstruct = '';
$this->finalrounds = '';
$this->finalrounds = 0;
$this->finalstruct = '';
$this->host = null;
$this->cohost = null;
Expand Down Expand Up @@ -117,11 +117,12 @@ public function __construct(int|string $name = '')
}
}

// BAKERT remove all casts on mainrounds and finalrounds
$this->standing = new Standings($this->name, '0');

// Main rounds
$this->mainid = null;
$this->mainrounds = '';
$this->mainrounds = 0;
$this->mainstruct = '';
$sql = 'SELECT id AS mainid, rounds, type FROM subevents WHERE parent = :parent AND timing = 1';
$params = ['parent' => $this->name];
Expand All @@ -134,7 +135,7 @@ public function __construct(int|string $name = '')

// Final rounds
$this->finalid = null;
$this->finalrounds = '';
$this->finalrounds = 0;
$this->finalstruct = '';
$sql = 'SELECT id AS mainid, rounds, type FROM subevents WHERE parent = :parent AND timing = 2';
$params = ['parent' => $this->name];
Expand Down Expand Up @@ -179,9 +180,9 @@ public static function createEvent(
string $player_reportable,
string $late_entry_limit,
string $private,
string $mainrounds,
int $mainrounds,
string $mainstruct,
string $finalrounds,
int $finalrounds,
string $finalstruct,
string $client
): Event {
Expand Down Expand Up @@ -220,7 +221,7 @@ public static function createEvent(

$event->late_entry_limit = (int) $late_entry_limit;

if ($mainrounds == '') {
if ($mainrounds === 0) {
$mainrounds = 3;
}
if ($mainstruct == '') {
Expand Down Expand Up @@ -293,8 +294,8 @@ public function save(): void
];
db()->execute($sql, $params);

$this->newSubevent((int) $this->mainrounds, 1, $this->mainstruct);
$this->newSubevent((int) $this->finalrounds, 2, $this->finalstruct);
$this->newSubevent($this->mainrounds, 1, $this->mainstruct);
$this->newSubevent($this->finalrounds, 2, $this->finalstruct);
} else {
$sql = '
UPDATE
Expand Down Expand Up @@ -339,19 +340,19 @@ public function save(): void
db()->execute($sql, $params);

if ($this->mainid == null) {
$this->newSubevent((int) $this->mainrounds, 1, $this->mainstruct);
$this->newSubevent($this->mainrounds, 1, $this->mainstruct);
} else {
$main = new Subevent($this->mainid);
$main->rounds = (int) $this->mainrounds;
$main->rounds = $this->mainrounds;
$main->type = $this->mainstruct;
$main->save();
}

if ($this->finalid == null) {
$this->newSubevent((int) $this->finalrounds, 2, $this->finalstruct);
$this->newSubevent($this->finalrounds, 2, $this->finalstruct);
} else {
$final = new Subevent($this->finalid);
$final->rounds = (int) $this->finalrounds;
$final->rounds = $this->finalrounds;
$final->type = $this->finalstruct;
$final->save();
}
Expand Down Expand Up @@ -815,9 +816,9 @@ public function addMatch(Standings $playera, Standings $playerb, int $round = -9
$draws = 0;
$id = $this->mainid;

if ($round > (int) $this->mainrounds) {
if ($round > $this->mainrounds) {
$id = $this->finalid;
$round = $round - (int) $this->mainrounds;
$round = $round - $this->mainrounds;
}

if ($round == -99) {
Expand Down Expand Up @@ -845,9 +846,8 @@ public function assignTrophiesFromMatches(): void
$t4 = [];
$t8 = [];

// BAKERT redundant max here unless finalrounds can be negative XD
$finalRounds = (int) $this->finalrounds;
$totalRounds = (int) $this->mainrounds + $finalRounds;
$finalRounds = $this->finalrounds;
$totalRounds = $this->mainrounds + $finalRounds;

if ($finalRounds > 0) {
$finalMatches = $this->getRoundMatches($totalRounds);
Expand Down Expand Up @@ -876,8 +876,6 @@ public function assignTrophiesFromMatches(): void
}
}
}

print_r(['win' => $win, 'sec' => $sec, 't4' => $t4, 't8' => $t8]);
}

$this->setFinalists($win, $sec, $t4, $t8);
Expand Down Expand Up @@ -1064,9 +1062,9 @@ public static function trophySrc(string $eventname): string

public function isLeague(): bool
{
$test = (int) $this->current_round;
if ($test <= ((int) $this->finalrounds + (int) $this->mainrounds)) {
if ($test > (int) $this->mainrounds) {
$test = $this->current_round;
if ($test <= ($this->finalrounds + $this->mainrounds)) {
if ($test > $this->mainrounds) {
$structure = $this->finalstruct;
} else {
$structure = $this->mainstruct;
Expand All @@ -1091,9 +1089,9 @@ public function pairCurrentRound(bool $skip_invalid = false): void
//Check if all matches in the current round are finished
if (count($this->unfinishedMatches()) === 0) {
//Check to see if we are main rounds or final, get structure
$test = (int) $this->current_round;
if ($test < ((int) $this->finalrounds + (int) $this->mainrounds)) {
if ($test >= (int) $this->mainrounds) {
$test = $this->current_round;
if ($test < ($this->finalrounds + $this->mainrounds)) {
if ($test >= $this->mainrounds) {
// In the final rounds.
$structure = $this->finalstruct;
$subevent_id = $this->finalid;
Expand Down Expand Up @@ -1694,9 +1692,9 @@ public function startEvent(bool $precheck): void

public function structureSummary(): string
{
$ret = $this->toEnglish($this->mainstruct, (int) $this->mainrounds, false);
$ret = $this->toEnglish($this->mainstruct, $this->mainrounds, false);
if ($this->finalrounds > 0) {
$ret = $ret . ' followed by ' . $this->toEnglish($this->finalstruct, (int) $this->finalrounds, true);
$ret = $ret . ' followed by ' . $this->toEnglish($this->finalstruct, $this->finalrounds, true);
}
return $ret;
}
Expand Down
2 changes: 1 addition & 1 deletion gatherling/Models/EventSubeventDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
class EventSubeventDto extends Dto
{
public int $mainid;
public string $rounds;
public int $rounds;
public string $type;
}
2 changes: 1 addition & 1 deletion gatherling/Views/Components/RoundDropMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RoundDropMenu extends DropMenu
public function __construct(Event $event, int|string|null $selected, int $defaultValue = 0)
{
$options = [];
for ($r = 1; $r <= ((int) $event->mainrounds + (int) $event->finalrounds); $r++) {
for ($r = 1; $r <= ($event->mainrounds + $event->finalrounds); $r++) {
$star = $r > $event->mainrounds ? '*' : '';
$options[] = [
'isSelected' => $selected == $r,
Expand Down
4 changes: 2 additions & 2 deletions gatherling/api_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ function create_event(): array
argStr('player_reportable', ''),
argStr('late_entry_limit', ''),
argStr('private', ''),
argStr('mainrounds', ''),
(int) argStr('mainrounds', '0'),
argStr('mainstruct', ''),
argStr('finalrounds', ''),
(int) argStr('finalrounds', '0'),
argStr('finalstruct', ''),
argStr('client', '1')
);
Expand Down
2 changes: 1 addition & 1 deletion gatherling/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ Vue.use(Toasted);
});

var app = new Vue({
el: '#maincontainer',
el: 'body',
store
})
9 changes: 6 additions & 3 deletions gatherling/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ function insertEvent(): Event
post()->string('player_reportable'),
post()->string('late_entry_limit'),
post()->string('private'),
post()->string('mainrounds'),
post()->int('mainrounds'),
post()->string('mainstruct'),
post()->string('finalrounds'),
post()->int('finalrounds'),
post()->string('finalstruct'),
post()->string('client')
);
Expand Down Expand Up @@ -526,7 +526,10 @@ function updateMatches(): void
}
$rnd = post()->int('newmatchround');

if ($pA !== '' && $pB !== '' && $rnd) {
if ($pA !== '' && $pB !== '') {
if ($rnd === 0) {
throw new InvalidArgumentException('Cannot add match to round 0');
}
$playerA = new Standings($event->name, $pA);
$playerB = new Standings($event->name, $pB);
if ($res == 'P') {
Expand Down
6 changes: 6 additions & 0 deletions gatherling/gatherling.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ function formatDate(originalDate, start, timeZone, locale, short) {
} else {
formattedDate = date.toFormat('ccc, MMM d, yyyy');
}
if (formattedTime === 'midnight' && formattedDate === 'Today') {
formattedDate = 'This';
}
if (formattedTime === 'midnight') {
formattedDate += ' morning';
}

return `${formattedDate}${formattedTime}`;
}
Expand Down
Loading

0 comments on commit 3d3d858

Please sign in to comment.