diff --git a/CHANGELOG.md b/CHANGELOG.md index b72a814..1c2bc67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/ +## [1.05.0] - [2020-08-13] +### Added +- Added logging, scoring actions are logged in the API, the data will be used later for multiple features. +### Changed +- Correct the title in the HTML. +- Removed the `canonical` header. +- Added our Twitter handle to the footer. +### Fixed +- Scratching Yahtzee disables the Yahtzee bonus inputs. +- The minimum score for Three of a kind, Four of a kind and Chance is 5, not 6. + ## [1.04.0] - [2022-08-10] ### Added - Added a registration email, sent after the first step of account creation, allows continuation of account creation (create password). diff --git a/app/Actions/Game/Log.php b/app/Actions/Game/Log.php new file mode 100644 index 0000000..91d3420 --- /dev/null +++ b/app/Actions/Game/Log.php @@ -0,0 +1,39 @@ + + * @copyright Dean Blackborough (Costs to Expect) 2018-2022 + * https://github.com/costs-to-expect/yahtzee/blob/main/LICENSE + */ +class Log extends Action +{ + public function __invoke( + Service $api, + string $resource_type_id, + string $resource_id, + string $game_id, + string $message, + array $parameters = [] + ): int + { + $create_message_response = $api->createGameLogMessage( + $resource_type_id, + $resource_id, + $game_id, + $message, + $parameters + ); + + if ($create_message_response['status'] === 201) { + return 201; + } + + return $create_message_response['status']; + } +} diff --git a/app/Api/Service.php b/app/Api/Service.php index 8bfa1ea..9f3711e 100644 --- a/app/Api/Service.php +++ b/app/Api/Service.php @@ -119,6 +119,26 @@ public function createGame( ); } + #[ArrayShape(['status' => "integer", 'content' => "array", 'fields' => "array"])] + public function createGameLogMessage( + string $resource_type_id, + string $resource_id, + string $game_id, + string $message, + array $parameters = [] + ): array + { + $uri = Uri::gameLog($resource_type_id, $resource_id, $game_id); + + return $this->http->post( + $uri['uri'], + [ + 'message' => $message, + 'parameters' => json_encode($parameters, JSON_THROW_ON_ERROR) + ] + ); + } + #[ArrayShape(['status' => "integer", 'content' => "array", 'fields' => "array"])] public function createPlayer(string $resource_type_id, string $name, string $description): array { diff --git a/app/Api/Uri.php b/app/Api/Uri.php index 6610f07..640e0a9 100644 --- a/app/Api/Uri.php +++ b/app/Api/Uri.php @@ -59,6 +59,22 @@ public static function game(string $resource_type_id, string $resource_id, strin ]; } + #[ArrayShape(['uri' => "string", 'name' => "string"])] + public static function gameLog( + string $resource_type_id, + string $resource_id, + string $game_id + ): array + { + $uri = '/' . self::VERSION . '/resource-types/' . $resource_type_id . + '/resources/' . $resource_id . '/items/' . $game_id . '/log'; + + return [ + 'uri' => $uri, + 'name' => 'Game log' + ]; + } + #[ArrayShape(['uri' => "string", 'name' => "string"])] public static function assignedGamePlayer( string $resource_type_id, diff --git a/app/Http/Controllers/Game.php b/app/Http/Controllers/Game.php index 7d6f221..5880bf5 100644 --- a/app/Http/Controllers/Game.php +++ b/app/Http/Controllers/Game.php @@ -8,6 +8,7 @@ use App\Actions\Game\Create; use App\Actions\Game\Delete; use App\Actions\Game\DeletePlayer; +use App\Actions\Game\Log; use App\Models\ShareToken; use Illuminate\Http\Request; @@ -536,6 +537,25 @@ public function scoreUpper(Request $request) $score_sheet['score']['bonus'] = $score_bonus; $score_sheet['score']['total'] = $score_sheet['score']['lower'] + $score_upper + $score_bonus; + $log_action = new Log(); + $log_action_result = $log_action( + $this->api, + $this->resource_type_id, + $this->resource_id, + $request->input('game_id'), + 'Scored ' . $request->input('score') . ' in their ' . ucfirst($request->input('dice')), + [ + 'player' => $request->input('player_id'), + 'section' => 'upper', + 'dice' => $request->input('dice'), + 'score' => $request->input('score'), + ] + ); + + if ($log_action_result !== 201) { + // @todo - Log an error + } + return $this->score( $this->api, $this->resource_type_id, @@ -557,13 +577,16 @@ public function scoreLower(Request $request) $request->input('player_id') ); + $combo = $request->input('combo'); + $score = $request->input('score'); + if ($score_sheet['status'] !== 200) { return response()->json(['message' => 'Unable to fetch your score sheet'], $score_sheet['status']); } $score_sheet = $score_sheet['content']['value']; - $score_sheet['lower-section'][$request->input('combo')] = $request->input('score'); + $score_sheet['lower-section'][$combo] = $score; $score_lower = 0; foreach ($score_sheet['lower-section'] as $value) { $score_lower += $value; @@ -572,6 +595,32 @@ public function scoreLower(Request $request) $score_sheet['score']['lower'] = $score_lower; $score_sheet['score']['total'] = $score_sheet['score']['upper'] + $score_sheet['score']['bonus'] + $score_lower; + $message = match ($combo) { + 'three_of_a_kind', 'four_of_a_kind', 'chance' => 'Scored ' . $score . ' in ' . ucfirst( + str_replace('_', '', $combo) + ), + default => 'Scored their ' . ucfirst(str_replace('_', ' ', $combo)) . ', scoring ' . $score, + }; + + $log_action = new Log(); + $log_action_result = $log_action( + $this->api, + $this->resource_type_id, + $this->resource_id, + $request->input('game_id'), + $message, + [ + 'player' => $request->input('player_id'), + 'section' => 'lower', + 'combo' => $request->input('combo'), + 'score' => $request->input('score'), + ] + ); + + if ($log_action_result !== 201) { + // @todo - Log an error + } + return $this->score( $this->api, $this->resource_type_id, diff --git a/app/Http/Controllers/Share.php b/app/Http/Controllers/Share.php index 7d6f00d..d459eaf 100644 --- a/app/Http/Controllers/Share.php +++ b/app/Http/Controllers/Share.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; +use App\Actions\Game\Log; use App\Api\Service; use App\Models\ShareToken; use Illuminate\Http\Request; @@ -163,6 +164,25 @@ public function scoreUpper(Request $request, $token) $score_sheet['score']['bonus'] = $score_bonus; $score_sheet['score']['total'] = $score_sheet['score']['lower'] + $score_upper + $score_bonus; + $log_action = new Log(); + $log_action_result = $log_action( + $api, + $parameters['resource_type_id'], + $parameters['resource_id'], + $parameters['game_id'], + 'Scored ' . $request->input('score') . ' in their ' . ucfirst($request->input('dice')), + [ + 'player' => $parameters['player_id'], + 'section' => 'upper', + 'dice' => $request->input('dice'), + 'score' => $request->input('score'), + ] + ); + + if ($log_action_result !== 201) { + // @todo - Log an error + } + return $this->score( $api, $parameters['resource_type_id'], @@ -181,7 +201,10 @@ public function scoreLower(Request $request, $token) $score_sheet = $this->getScoreSheet($api, $parameters); - $score_sheet['lower-section'][$request->input('combo')] = $request->input('score'); + $combo = $request->input('combo'); + $score = $request->input('score'); + + $score_sheet['lower-section'][$combo] = $score; $score_lower = 0; foreach ($score_sheet['lower-section'] as $value) { $score_lower += $value; @@ -190,6 +213,32 @@ public function scoreLower(Request $request, $token) $score_sheet['score']['lower'] = $score_lower; $score_sheet['score']['total'] = $score_sheet['score']['upper'] + $score_sheet['score']['bonus'] + $score_lower; + $message = match ($combo) { + 'three_of_a_kind', 'four_of_a_kind', 'chance' => 'Scored ' . $score . ' in ' . ucfirst( + str_replace('_', '', $combo) + ), + default => 'Scored their ' . ucfirst(str_replace('_', ' ', $combo)) . ', scoring ' . $score, + }; + + $log_action = new Log(); + $log_action_result = $log_action( + $api, + $parameters['resource_type_id'], + $parameters['resource_id'], + $parameters['game_id'], + $message, + [ + 'player' => $parameters['player_id'], + 'section' => 'lower', + 'combo' => $request->input('combo'), + 'score' => $request->input('score'), + ] + ); + + if ($log_action_result !== 201) { + // @todo - Log an error + } + return $this->score( $api, $parameters['resource_type_id'], diff --git a/config/app/config.php b/config/app/config.php index 6fa9c5e..0fd4e9b 100644 --- a/config/app/config.php +++ b/config/app/config.php @@ -10,6 +10,6 @@ 'item_subtype_id' => env('ITEM_SUBTYPE_ID'), 'cookie_user' => env('SESSION_NAME_USER'), 'cookie_bearer' => env('SESSION_NAME_BEARER'), - 'version' => '1.04.0', - 'release_date' => '10th August 2022' + 'version' => '1.05.0', + 'release_date' => '14th August 2022' ]; diff --git a/public/js/functions.js b/public/js/functions.js index 9f9cea2..5a87568 100644 --- a/public/js/functions.js +++ b/public/js/functions.js @@ -34,3 +34,18 @@ export function disable_yahtzee_bonus_if_game_over(turns) { display_selected_toast('done'); } } + +export function disable_yahtzee_bonus() { + let bonus_one = document.querySelector('input[type="checkbox"]#yahtzee_bonus_one.active'); + if (bonus_one !== null) { + bonus_one.disabled = true; + } + let bonus_two = document.querySelector('input[type="checkbox"]#yahtzee_bonus_two.active'); + if (bonus_two !== null) { + bonus_two.disabled = true; + } + let bonus_three = document.querySelector('input[type="checkbox"]#yahtzee_bonus_three.active'); + if (bonus_three !== null) { + bonus_three.disabled = true; + } +} diff --git a/public/js/score-sheet.js b/public/js/score-sheet.js index 8b6ab84..94887f4 100644 --- a/public/js/score-sheet.js +++ b/public/js/score-sheet.js @@ -1,4 +1,4 @@ -import { display_selected_toast, disable_yahtzee_bonus_if_game_over } from './functions.js'; +import {display_selected_toast, disable_yahtzee_bonus_if_game_over, disable_yahtzee_bonus} from './functions.js'; (function (axios) { 'use strict' @@ -150,7 +150,7 @@ import { display_selected_toast, disable_yahtzee_bonus_if_game_over } from './fu let score_lower_combination = function(element, show_toast = 'none') { let score = parseInt(element.value); - if (score >= 6 && score <= 30) { + if (score >= 5 && score <= 30) { clearTimeout(timeout); @@ -288,6 +288,10 @@ import { display_selected_toast, disable_yahtzee_bonus_if_game_over } from './fu disable_yahtzee_bonus_if_game_over(response.data.turns); + if (payload.combo === 'yahtzee') { + disable_yahtzee_bonus(); + } + display_selected_toast(show_toast); document.querySelectorAll('p.' + element.id.toString().replace('scratch_', '') + '_dice svg').forEach(dice => diff --git a/resources/views/add-players-to-game.blade.php b/resources/views/add-players-to-game.blade.php index ec4818a..f5e2593 100644 --- a/resources/views/add-players-to-game.blade.php +++ b/resources/views/add-players-to-game.blade.php @@ -3,7 +3,7 @@ - + Yahtzee Game Scorer: Add Players to Game diff --git a/resources/views/components/footer.blade.php b/resources/views/components/footer.blade.php index 5ba1fc9..c1bfbd8 100644 --- a/resources/views/components/footer.blade.php +++ b/resources/views/components/footer.blade.php @@ -3,6 +3,12 @@
© 2022 v{{ $version }} - {{ $release_date }} + + + + + Follow us on Twitter © +
Powered by our API
diff --git a/resources/views/create-password.blade.php b/resources/views/create-password.blade.php index 404384d..494ab36 100644 --- a/resources/views/create-password.blade.php +++ b/resources/views/create-password.blade.php @@ -3,7 +3,7 @@ - + Yahtzee Game Scorer: Register diff --git a/resources/views/game.blade.php b/resources/views/game.blade.php index 5ce0d33..33382f9 100644 --- a/resources/views/game.blade.php +++ b/resources/views/game.blade.php @@ -3,7 +3,7 @@ - + Yahtzee Game Scorer: Game diff --git a/resources/views/games.blade.php b/resources/views/games.blade.php index e4979c7..cc04f01 100644 --- a/resources/views/games.blade.php +++ b/resources/views/games.blade.php @@ -3,7 +3,7 @@ - + Yahtzee Game Scorer: Games diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 17954b1..3463c34 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -3,7 +3,7 @@ - + Yahtzee Game Scorer: Home diff --git a/resources/views/landing.blade.php b/resources/views/landing.blade.php index 5ad4386..5f97a00 100644 --- a/resources/views/landing.blade.php +++ b/resources/views/landing.blade.php @@ -3,14 +3,13 @@ - + Yahtzee: Game Scorer -