Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Commit

Permalink
Add more options for the Godot version compatibility field
Browse files Browse the repository at this point in the history
This includes an "Any" choice which is suitable for many
non-code assets.
  • Loading branch information
Calinou committed Dec 25, 2019
1 parent bb8225d commit 6584d3c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 24 deletions.
11 changes: 0 additions & 11 deletions app/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions app/AssetVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Requests/SubmitAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion database/factories/AssetVersionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
];
});
11 changes: 6 additions & 5 deletions resources/views/asset/create.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@extends('layouts.app')
@inject('assetClass', 'App\Asset')
@inject('assetVersionClass', 'App\AssetVersion')

@if ($editing)
@section('title', __('Edit “:asset”', ['asset' => $asset->title]))
Expand Down Expand Up @@ -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
</div>

<div class="-mt-4 mb-8 text-sm text-gray-600">
{{ __('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.') }}
</div>
@endif

@component('components/form-input', [
Expand Down
2 changes: 1 addition & 1 deletion resources/views/asset/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class="cursor-pointer text-gray-600 dark:text-gray-500 leading-relaxed mb-4 ml-2
</a>
</td>
<td class="border px-3 py-1">@include('includes/date-relative', ['date' => \Carbon\Carbon::parse($version->created_at)])</td>
<td class="border px-3 py-1">Godot {{ $version->godot_version }}.x</td>
<td class="border px-3 py-1">Godot {{ $version->godot_version }}</td>
</tr>
@endforeach
</tbody>
Expand Down
8 changes: 3 additions & 5 deletions resources/views/asset/version-form.blade.php
Original file line number Diff line number Diff line change
@@ -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`).
Expand Down Expand Up @@ -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
</div>
Expand Down

0 comments on commit 6584d3c

Please sign in to comment.