From 6584d3cc822e893b48c979aafb8fb2c72cc1deb5 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 25 Dec 2019 01:12:36 +0100 Subject: [PATCH] Add more options for the Godot version compatibility field This includes an "Any" choice which is suitable for many non-code assets. --- app/Asset.php | 11 ----------- app/AssetVersion.php | 20 ++++++++++++++++++++ app/Http/Requests/SubmitAsset.php | 3 ++- database/factories/AssetVersionFactory.php | 3 ++- resources/views/asset/create.blade.php | 11 ++++++----- resources/views/asset/show.blade.php | 2 +- resources/views/asset/version-form.blade.php | 8 +++----- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/app/Asset.php b/app/Asset.php index 45346132..a46b79ac 100644 --- a/app/Asset.php +++ b/app/Asset.php @@ -133,17 +133,6 @@ class Asset extends Model 'MPL-2.0' => 'MPLv2', ]; - /** - * The available Godot versions. - * - * TODO: Replace this with a system based on semantic versioning range strings? - */ - public const GODOT_VERSIONS = [ - '3.0', - '3.1', - '3.2', - ]; - /** * The primary key associated with the table. * This value has been changed from the default for compatibility with the diff --git a/app/AssetVersion.php b/app/AssetVersion.php index 9c9351d6..adbd689b 100644 --- a/app/AssetVersion.php +++ b/app/AssetVersion.php @@ -19,6 +19,26 @@ */ class AssetVersion extends Model { + /** + * The available Godot versions for declaring the compatibility range. + */ + public const GODOT_VERSIONS = [ + // Any version (should only be used for non-code assets) + '*' => 'Any', + + // Any version in the Godot 3 series + '3.x.x' => 'Godot 3.x.x', + + '3.0.x' => 'Godot 3.0.x', + '3.1.x' => 'Godot 3.1.x', + '3.2.x' => 'Godot 3.2.x', + + // Any version in the Godot 4 series + '4.x.x' => 'Godot 4.x.x', + + '4.0.x' => 'Godot 4.0.x', + ]; + /** * The key used to store the last modification date and time. * This value has been changed from the default for consistency with Asset. diff --git a/app/Http/Requests/SubmitAsset.php b/app/Http/Requests/SubmitAsset.php index cba2a5dd..2ce065c7 100644 --- a/app/Http/Requests/SubmitAsset.php +++ b/app/Http/Requests/SubmitAsset.php @@ -6,6 +6,7 @@ use App\Asset; use App\AssetPreview; +use App\AssetVersion; use App\Rules\SuccessRespondingUrl; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Validation\Rule; @@ -94,7 +95,7 @@ function ($attribute, $value, $fail) { 'versions' => 'required|array|min:1', 'versions.*.id' => 'nullable|integer|gte:1', 'versions.*.version_string' => 'required|string|max:50', - 'versions.*.godot_version' => ['required', Rule::in(Asset::GODOT_VERSIONS)], + 'versions.*.godot_version' => ['required', Rule::in(array_keys(AssetVersion::GODOT_VERSIONS))], 'versions.*.download_url' => [ 'nullable', 'bail', diff --git a/database/factories/AssetVersionFactory.php b/database/factories/AssetVersionFactory.php index d28e0af9..cadfbd0b 100644 --- a/database/factories/AssetVersionFactory.php +++ b/database/factories/AssetVersionFactory.php @@ -3,12 +3,13 @@ declare(strict_types=1); /* @var \Illuminate\Database\Eloquent\Factory $factory */ + use App\AssetVersion; use Faker\Generator as Faker; $factory->define(AssetVersion::class, function (Faker $faker) { return [ 'version_string' => $faker->regexify('[0-2]\.[0-9]\.[0-2]'), - 'godot_version' => $faker->regexify('3\.[0-2]'), + 'godot_version' => $faker->randomElement(array_keys(AssetVersion::GODOT_VERSIONS)), ]; }); diff --git a/resources/views/asset/create.blade.php b/resources/views/asset/create.blade.php index 4e180867..bf6d481f 100644 --- a/resources/views/asset/create.blade.php +++ b/resources/views/asset/create.blade.php @@ -1,5 +1,6 @@ @extends('layouts.app') @inject('assetClass', 'App\Asset') +@inject('assetVersionClass', 'App\AssetVersion') @if ($editing) @section('title', __('Edit “:asset”', ['asset' => $asset->title])) @@ -142,14 +143,14 @@ class="link" 'label' => __('Godot version'), 'placeholder' => __('Select a Godot version'), 'required' => true, - 'choices' => [ - '3.2' => 'Godot 3.2.x', - '3.1' => 'Godot 3.1.x', - '3.0' => 'Godot 3.0.x', - ], + 'choices' => $assetVersionClass::GODOT_VERSIONS, ]) @endcomponent + +
+ {{ __('The "Any" version should only be used for assets that do not contain code (such as engine-agnostic art assets). If in doubt, choose the minor Godot version used to develop the asset.') }} +
@endif @component('components/form-input', [ diff --git a/resources/views/asset/show.blade.php b/resources/views/asset/show.blade.php index fca79777..e08426de 100644 --- a/resources/views/asset/show.blade.php +++ b/resources/views/asset/show.blade.php @@ -106,7 +106,7 @@ class="cursor-pointer text-gray-600 dark:text-gray-500 leading-relaxed mb-4 ml-2 @include('includes/date-relative', ['date' => \Carbon\Carbon::parse($version->created_at)]) - Godot {{ $version->godot_version }}.x + Godot {{ $version->godot_version }} @endforeach diff --git a/resources/views/asset/version-form.blade.php b/resources/views/asset/version-form.blade.php index e6534a0a..8381a458 100644 --- a/resources/views/asset/version-form.blade.php +++ b/resources/views/asset/version-form.blade.php @@ -1,3 +1,5 @@ +@inject('assetVersionClass', 'App\AssetVersion') + @php // If `$prototype` is `true`, the array index will be replaced with // a placeholder value that must be replaced with JavaScript (see `$index`). @@ -38,11 +40,7 @@ 'label' => __('Godot version'), 'placeholder' => __('Select a Godot version'), 'required' => true, - 'choices' => [ - '3.2' => 'Godot 3.2.x', - '3.1' => 'Godot 3.1.x', - '3.0' => 'Godot 3.0.x', - ], + 'choices' => $assetVersionClass::GODOT_VERSIONS, ]) @endcomponent