Skip to content

Commit

Permalink
Populate shipyard queue on resources page
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed Nov 22, 2024
1 parent a2160b0 commit 17fda90
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function addBuildRequest(Request $request, PlayerService $player): JsonRe
{
// If the technology is a solar satellite, execute the addBuildRequest method in ShipyardController.
if ($request->input('technologyId') === '212') {
resolve(ShipyardController::class)->addBuildRequest($request, $player);
return resolve(ShipyardController::class)->addBuildRequest($request, $player);
}

// Explicitly verify CSRF token because this request supports both POST and GET.
Expand Down
23 changes: 22 additions & 1 deletion app/Http/Controllers/ResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use OGame\Http\Controllers\Abstracts\AbstractBuildingsController;
use OGame\Models\Resources;
use OGame\Services\BuildingQueueService;
use OGame\Services\UnitQueueService;
use OGame\Services\ObjectService;
use OGame\Services\PlayerService;
use Carbon\Carbon;

class ResourcesController extends AbstractBuildingsController
{
Expand All @@ -36,6 +38,7 @@ public function __construct(BuildingQueueService $queue)
public function index(Request $request, PlayerService $player): View
{
$this->setBodyId('resources');
$this->planet = $player->planets->current();

// Prepare custom properties
$this->header_filename_objects = [1, 2, 3, 4]; // Building ID's that make up the header filename.
Expand All @@ -44,7 +47,25 @@ public function index(Request $request, PlayerService $player): View
];
$this->view_name = 'ingame.resources.index';

return parent::index($request, $player);
// Parse shipyard queue for this planet because the resources page
// shows both the building queue (handled by parent) but also the shipyard queue.
$unitQueue = resolve(UnitQueueService::class);
$unit_full_queue = $unitQueue->retrieveQueue($this->planet);
$unit_build_active = $unit_full_queue->getCurrentlyBuildingFromQueue();
$unit_build_queue = $unit_full_queue->getQueuedFromQueue();

// Get total time of all items in unit queue.
$unit_queue_time_end = $unitQueue->retrieveQueueTimeEnd($this->planet);
$unit_queue_time_countdown = 0;
if ($unit_queue_time_end > 0) {
$unit_queue_time_countdown = $unit_queue_time_end - (int)Carbon::now()->timestamp;
}

return parent::index($request, $player)->with([
'unit_build_active' => $unit_build_active,
'unit_build_queue' => $unit_build_queue,
'unit_queue_time_countdown' => $unit_queue_time_countdown,
]);
}

/**
Expand Down
19 changes: 4 additions & 15 deletions resources/views/ingame/resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,17 @@ class="productionboxbuilding injectedComponent parent supplies">
</div>
</div>
<div class="productionBoxShips boxColumn ship">

<div id="productionboxshipyardcomponent"
class="productionboxshipyard injectedComponent parent supplies">
<div class="content-box-s">
<div class="header">
<h3>Shipyard</h3>
</div>
<div class="content">
<table cellspacing="0" cellpadding="0" class="construction active">
<tbody>
<tr>
<td colspan="2" class="idle">
<a class="tooltip js_hideTipOnMobile tpd-hideOnClickOutside" title=""
href="#TODO_page=ingame&amp;component=shipyard">
No ships/defense in construction.
<br>
(To shipyard)
</a>
</td>
</tr>
</tbody>
</table>
{{-- Unit is actively being built. --}}
@include ('ingame.shared.buildqueue.unit-active', ['build_active' => $unit_build_active, 'build_queue_countdown' => $unit_queue_time_countdown])
{{-- Unit queue has items. --}}
@include ('ingame.shared.buildqueue.unit-queue', ['build_queue' => $unit_build_queue])
</div>
<div class="footer"></div>
</div>
Expand Down

0 comments on commit 17fda90

Please sign in to comment.