Skip to content

Commit

Permalink
Merge pull request #28 from deanblackborough/main
Browse files Browse the repository at this point in the history
v0.16.0
  • Loading branch information
deanblackborough authored Aug 1, 2022
2 parents 08d8546 + c986a3d commit 8c6dead
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 90 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [0.16.0] - [2022-08-01]
### Added
- Added ability to remove a player from an open game, deletes the score sheet, share token and assignment.
- Upon scoring or scratching the background color for dice is updated to highlight what has been scored.

## [0.15.0] - [2022-08-01]
### Added
- Open games can be deleted.
Expand Down
88 changes: 88 additions & 0 deletions app/Actions/Game/DeletePlayer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);

namespace App\Actions\Game;

use App\Actions\Action;
use App\Api\Service;
use App\Models\ShareToken;

/**
* @author Dean Blackborough <[email protected]>
* @copyright Dean Blackborough (Costs to Expect) 2018-2022
* https://github.com/costs-to-expect/yahtzee/blob/main/LICENSE
*/
class DeletePlayer extends Action
{
public function __invoke(
Service $api,
string $resource_type_id,
string $resource_id,
string $game_id,
string $player_id
): int
{
// Delete the score sheet if it exists for the player
$score_sheet_response = $api->getPlayerScoreSheet(
$resource_type_id,
$resource_id,
$game_id,
$player_id
);

if ($score_sheet_response['status'] === 200) {

$response = $api->deletePlayerScoreSheet(
$resource_type_id,
$resource_id,
$game_id,
$score_sheet_response['content']['key']
);

if ($response['status'] !== 204) {
throw new \RuntimeException('Unable to delete score sheet for player with id ' .
$score_sheet_response['content']['key'] . ', error ' . $response['content']);
}
}

// Delete the player from the assignments
// We need all the players to work out which id to delete
$assigned_players_response = $api->getAssignedGamePlayers(
$resource_type_id,
$resource_id,
$game_id
);

if ($assigned_players_response['status'] !== 200) {
throw new \RuntimeException('Unable to fetch the assigned game players');
}

foreach($assigned_players_response['content'] as $player) {

if ($player['category']['id'] === $player_id) {
$response = $api->deleteAssignedGamePlayer(
$resource_type_id,
$resource_id,
$game_id,
$player['id']
);

if ($response['status'] !== 204) {
throw new \RuntimeException(
'Unable to delete player with id ' . $player['id'] . ', error ' .
$response['content']
);
}

break;
}
}

ShareToken::query()
->where('game_id', $game_id)
->where('player_id', $player_id)
->delete();

return 204;
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Actions\Game\Complete;
use App\Actions\Game\Create;
use App\Actions\Game\Delete;
use App\Actions\Game\DeletePlayer;
use App\Models\ShareToken;
use Illuminate\Http\Request;

Expand Down Expand Up @@ -348,6 +349,30 @@ public function deleteGame(Request $request, string $game_id)
abort(500, 'Unable to delete the game, unknown error');
}

public function deleteGamePlayer(Request $request, string $game_id, string $player_id)
{
$this->boostrap($request);

$action = new DeletePlayer();
try {
$result = $action(
$this->api,
$this->resource_type_id,
$this->resource_id,
$game_id,
$player_id
);

if ($result === 204) {
return redirect()->route('home');
}
} catch (\Exception $e) {
abort(500, $e->getMessage());
}

abort(500, 'Unable to delete the player from the game, unknown error');
}

public function playerBonus(Request $request, string $game_id, string $player_id)
{
$this->boostrap($request);
Expand Down
2 changes: 1 addition & 1 deletion config/app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
'item_subtype_id' => env('ITEM_SUBTYPE_ID'),
'cookie_user' => env('SESSION_NAME_USER'),
'cookie_bearer' => env('SESSION_NAME_BEARER'),
'version' => '0.15.0',
'version' => '0.16.0',
'release_date' => '1st August 2022'
];
5 changes: 5 additions & 0 deletions public/css/theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/css/theme.css.map

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions public/js/public-score-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
upper.disabled = true;

disable_yahtzee_bonus(response.data.turns);

document.querySelectorAll('label[for="' + this.value + '"] svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -94,6 +98,10 @@
total_score.innerText = response.data.score.upper + response.data.score.bonus + response.data.score.lower;

disable_yahtzee_bonus(response.data.turns);

document.querySelectorAll('label[for="' + this.id + '"] svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -287,6 +295,10 @@
disable_yahtzee_bonus(response.data.turns);

display_toast(show_toast);

document.querySelectorAll('p.' + element.id + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -319,6 +331,10 @@
disable_yahtzee_bonus(response.data.turns);

display_toast(show_toast);

document.querySelectorAll('p.' + element.id + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -352,6 +368,10 @@
disable_yahtzee_bonus(response.data.turns);

display_toast(show_toast);

document.querySelectorAll('p.' + element.id.toString().replace('scratch_', '') + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -381,6 +401,10 @@
lower.disabled = true;

disable_yahtzee_bonus(response.data.turns);

document.querySelectorAll('p.' + element.id.toString().replace('scratch_', '') + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down
24 changes: 24 additions & 0 deletions public/js/score-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@
disable_yahtzee_bonus_if_game_over(response.data.turns);

display_selected_toast(show_toast);

document.querySelectorAll('p.' + element.id + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -246,6 +250,10 @@
disable_yahtzee_bonus_if_game_over(response.data.turns);

display_selected_toast(show_toast);

document.querySelectorAll('p.' + element.id + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -280,6 +288,10 @@
disable_yahtzee_bonus_if_game_over(response.data.turns);

display_selected_toast(show_toast);

document.querySelectorAll('p.' + element.id.toString().replace('scratch_', '') + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -313,6 +325,10 @@
display_selected_toast(show_toast);

disable_yahtzee_bonus_if_game_over(response.data.turns);

document.querySelectorAll('p.' + element.id.toString().replace('scratch_', '') + '_dice svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -366,6 +382,10 @@
display_selected_toast(show_toast);

disable_yahtzee_bonus_if_game_over(response.data.turns);

document.querySelectorAll('label[for="' + element.id + '"] svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down Expand Up @@ -403,6 +423,10 @@
display_selected_toast(show_toast);

disable_yahtzee_bonus_if_game_over(response.data.turns);

document.querySelectorAll('label[for="' + element.value + '"] svg').forEach(dice =>
dice.classList.add('scored')
);
})
.catch(error => {
console.log(error);
Expand Down
5 changes: 5 additions & 0 deletions resources/scss/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ a.nav-link.active {
div.bonus-message p {
margin-top: 1rem;
border: 1px solid rgba(137, 43, 124, 1);
}

svg.scored {
border-radius: 0.3rem;
background-image: linear-gradient(55deg, rgba(137, 43, 124, 0.8), rgba(137, 43, 124, 0.4), rgba(137, 43, 124, 0.1));
}
1 change: 1 addition & 0 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
@if (array_key_exists($__open_game['id'], $share_tokens) && array_key_exists($__player['id'], $share_tokens[$__open_game['id']]))
<li class="list-inline-item"><a href="{{ route('public.score-sheet', ['token' => $share_tokens[$__open_game['id']][$__player['id']]]) }}">[Share]</a></li>
@endif
<li class="list-inline-item"><a href="{{ route('game.player.delete', ['game_id' => $__open_game['id'], 'player_id' => $__player['id']]) }}">[Remove]</a></li>
</ul>
</li>
@endforeach
Expand Down
Loading

0 comments on commit 8c6dead

Please sign in to comment.