Skip to content

Commit

Permalink
feat: element updating on design updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Jul 12, 2024
1 parent e840d38 commit f41edb5
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 86 deletions.
14 changes: 14 additions & 0 deletions app/Services/DesignUpdateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\Species\Subtype;
use App\Models\User\User;
use App\Models\User\UserItem;
use App\Services\TypingManager;
use Carbon\Carbon;
use Config;
use DB;
Expand Down Expand Up @@ -332,6 +333,7 @@ public function saveRequestAddons($data, $request) {
$request->data = json_encode([
'user' => Arr::only(getDataReadyAssets($userAssets), ['user_items', 'currencies']),
'character' => Arr::only(getDataReadyAssets($characterAssets), ['currencies']),
'element_ids' => isset($requestData['element_ids']) ? $requestData['element_ids'] : null,
]);
$request->save();

Expand Down Expand Up @@ -404,6 +406,11 @@ public function saveRequestFeatures($data, $request) {
$feature = CharacterFeature::create(['character_image_id' => $request->id, 'feature_id' => $featureId, 'data' => $data['feature_data'][$key], 'character_type' => 'Update']);
}

if (isset($data['element_ids']) && $data['element_ids']) {
$data['element_ids'] = array_filter($data['element_ids']);
$request->data = array_merge($request->data, ['element_ids' => $data['element_ids']]);
}

// Update other stats
$request->species_id = $species->id;
$request->rarity_id = $rarity->id;
Expand Down Expand Up @@ -571,6 +578,13 @@ public function approveRequest($data, $request, $user) {
'sort' => 0,
]);

if (isset($request->data['element_ids']) && $request->data['element_ids']) {
$typingService = new TypingManager;
if (!$typingService->createTyping(get_class($image), $image->id, $request->data['element_ids'], false)) {
throw new \Exception('Failed to create typing.');
}
}

// Shift the image credits over to the new image
$request->designers()->update(['character_type' => 'Character', 'character_image_id' => $image->id]);
$request->artists()->update(['character_type' => 'Character', 'character_image_id' => $image->id]);
Expand Down
98 changes: 49 additions & 49 deletions composer.lock

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

46 changes: 46 additions & 0 deletions resources/views/character/design/features.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@
<a href="#" class="remove-feature btn btn-danger mb-2">×</a>
</div>
</div>

<h2>Elements</h2>
<p>Here you can update the elements of the character.</p>
@php
$type = \App\Models\Element\Typing::where('typing_model', 'App\Models\Character\CharacterImage')
->where('typing_id', $request->character->image->id)
->first();
$newType = $type ? clone $type : null;
if (isset($request->data['element_ids']) && $request->data['element_ids'] && $type) {
$newType->element_ids = json_encode($request->data['element_ids']);
}
@endphp
<p class="alert alert-info">Current Typing: {!! $type ? $type->elementNames : 'None' !!}</p>
@include('widgets._add_typing', ['object' => $request, 'type' => $newType ?? null, 'isStaff' => false])

<div class="text-right">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
</div>
Expand Down Expand Up @@ -136,6 +151,37 @@
</div>
@endforeach
</div>
@if (isset($request->data['element_ids']) && $request->data['element_ids'])
@php
$currentType = \App\Models\Element\Typing::where('typing_model', 'App\Models\Character\CharacterImage')
->where('typing_id', $request->character->image->id)
->first();
// make newtype a clone of current type not a reference
$newType = $currentType ? clone $currentType : null;
if ($currentType) {
$newType->element_ids = json_encode($request->data['element_ids']);
}
@endphp
<h4 class="mt-3">Elements</h4>
<div class="row">
<div class="row col-md-6 col-sm-12">
<div class="col-lg-4 col-md-6 col-4">
<h5>Current Typing</h5>
</div>
<div class="col-lg-8 col-md-6 col-8 row">
<h5>{!! $currentType?->displayElements !!}</h5>
</div>
</div>
<div class="row col-md-6 col-sm-12">
<div class="col-lg-4 col-md-6 col-4">
<h5>New Typing</h5>
</div>
<div class="col-lg-8 col-md-6 col-8 row">
<h5>{!! $newType?->displayElements !!}</h5>
</div>
</div>
</div>
@endif
@endif

@endsection
Expand Down
Loading

0 comments on commit f41edb5

Please sign in to comment.