Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creature: Is Dead #945

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/Datagrids/Bulks/CreatureBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class CreatureBulk extends Bulk
'tags',
'private_choice',
'extinct_choice',
'dead_choice',
'entity_image',
'entity_header',
];

protected $booleans = [
'is_extinct'
'is_extinct',
'is_dead',
];
}
1 change: 1 addition & 0 deletions app/Datagrids/Filters/CreatureFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function build()
])
->location()
->add('is_extinct')
->add('is_dead')
->isPrivate()
->template()
->hasImage()
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/CreatureResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public function toArray($request)
return $this->entity([
'type' => $model->type,
'creature_id' => $model->creature_id,
'is_extinct' => (bool) $model->is_extinct,
'is_extinct' => $model->isExtinct(),
'is_dead' => $model->isDead(),
'locations' => $locationIDs
]);
}
Expand Down
18 changes: 16 additions & 2 deletions app/Models/Creature.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* @property ?int $creature_id
* @property bool|int $is_extinct
* @property bool|int $is_dead
*/
class Creature extends MiscModel
{
Expand All @@ -50,6 +51,7 @@ class Creature extends MiscModel
'is_private',
'creature_id',
'is_extinct',
'is_dead',
];

/**
Expand All @@ -59,6 +61,7 @@ class Creature extends MiscModel

protected array $sortableColumns = [
'is_extinct',
'is_dead',
];

protected string $locationPivot = 'creature_location';
Expand All @@ -69,6 +72,7 @@ class Creature extends MiscModel
'type',
'parent.name',
'is_extinct',
'is_dead',
];

/**
Expand All @@ -89,9 +93,10 @@ class Creature extends MiscModel
protected array $exportFields = [
'base',
'is_extinct',
'is_dead',
];

protected array $exploreGridFields = ['is_extinct'];
protected array $exploreGridFields = ['is_extinct', 'is_dead'];

protected array $sanitizable = [
'name',
Expand Down Expand Up @@ -139,7 +144,7 @@ public function scopePreparedWith(Builder $query): Builder
*/
public function datagridSelectFields(): array
{
return ['creature_id', 'is_extinct'];
return ['creature_id', 'is_extinct', 'is_dead'];
}

/**
Expand All @@ -160,6 +165,7 @@ public function filterableColumns(): array
'creature_id',
'location_id',
'is_extinct',
'is_dead',
];
}

Expand Down Expand Up @@ -188,6 +194,14 @@ public function isExtinct(): bool
return (bool) $this->is_extinct;
}

/**
* Determine if the model is dead.
*/
public function isDead(): bool
{
return (bool) $this->is_dead;
}

/**
* Detach children when moving this entity from one campaign to another
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('creatures', function (Blueprint $table) {
$table->boolean('is_dead')->default(0);
$table->index('is_dead');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('creatures', function (Blueprint $table) {
$table->dropIndex('is_dead');
$table->dropColumn('is_dead');
});
}
};
1 change: 1 addition & 0 deletions lang/en/creatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
],
'hints' => [
'is_extinct' => 'This creature is extinct.',
'is_dead' => 'This creature is dead.',
],
'placeholders' => [
'type' => 'Herbivore, Aquatic, Mythical',
Expand Down
3 changes: 3 additions & 0 deletions resources/api-docs/1.0/creatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The list of returned entities can be filtered. The available filters are [availa
"creature_id": null,
"type": "Bird",
"is_extinct": true,
"is_dead": true,
"locations": [
67,
66,
Expand Down Expand Up @@ -87,6 +88,7 @@ To get the details of a single creature, use the following endpoint.
"creature_id": null,
"type": "Bird",
"is_extinct": true,
"is_dead": true,
"locations": [
67,
66,
Expand Down Expand Up @@ -118,6 +120,7 @@ To create a creature, use the following endpoint.
| `tags` | `array` | Array of tag ids |
| `locations` | `array` | Array of location ids |
| `is_extinct` | `boolean` | If the creature is extinct |
| `is_dead` | `boolean` | If the creature is dead |
| `entity_image_uuid` | `string` | Gallery image UUID for the entity image |
| `entity_header_uuid` | `string` | Gallery image UUID for the entity header (limited to premium campaigns) |
| `is_private` | `boolean` | If the creature is only visible to `admin` members of the campaign |
Expand Down
11 changes: 11 additions & 0 deletions resources/views/creatures/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@
},
'class' => 'icon'
],
[
'label' => '<i class="ra ra-skull" title="' . __('characters.fields.is_dead') . '"></i>',
'field' => 'is_dead',
'render' => function($model) {
if ($model->isDead()) {
return '<i class="ra ra-skull" title="' . __('characters.fields.is_dead') . '"></i>';
}
return '';
},
'class' => 'icon'
],
[
'type' => 'is_private',
]
Expand Down
9 changes: 9 additions & 0 deletions resources/views/creatures/form/_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
</x-checkbox>
</x-forms.field>

<x-forms.field
field="dead"
:label="__('characters.fields.is_dead')">
<input type="hidden" name="is_dead" value="0" />
<x-checkbox :text="__('creatures.hints.is_dead')">
<input type="checkbox" name="is_dead" value="1" @if (old('is_dead', $source->is_dead ?? $model->is_dead ?? false)) checked="checked" @endif />
</x-checkbox>
</x-forms.field>

@include('cruds.fields.tags')
@include('cruds.fields.image')

Expand Down
6 changes: 6 additions & 0 deletions resources/views/entities/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@
<span class="sr-only">{{ __('creatures.hints.is_extinct') }}</span>
</span>
@endif
@if ($model instanceof \App\Models\Creature && $model->isDead())
<span class="entity-name-icon entity-cre-dead cursor-pointer text-2xl" data-toggle="tooltip" data-title="{{ __('creatures.hints.is_dead') }}">
<x-icon class="ra ra-skull entity-icons " />
<span class="sr-only">{{ __('creatures.hints.is_dead') }}</span>
</span>
@endif
@if (auth()->check() && auth()->user()->isAdmin())
<span role="button" tabindex="0" class="entity-privacy-icon" data-toggle="dialog" data-url="{{ route('entities.quick-privacy', [$campaign, $model->entity]) }}" data-target="primary-dialog" aria-haspopup="dialog">
<i class="fa-solid fa-lock entity-icons text-2xl" data-title="{{ __('entities/permissions.quick.title') }}" data-toggle="tooltip" aria-hidden="true"></i>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/entities/pages/print/markdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@if ($model instanceof \App\Models\Creature && $model->isExtinct())
{{ __('creatures.hints.is_extinct') }}
@endif
@if ($model instanceof \App\Models\Creature && $model->isDead())
{{ __('creatures.hints.is_dead') }}
@endif

@if ($model instanceof \App\Models\Character && !empty($model->title))
{{ $model->title }}
Expand Down
Loading