Skip to content

Commit

Permalink
alternations
Browse files Browse the repository at this point in the history
-  adds `getPlanetFieldMax` to planet service, so we can easily get the field_max value.

- Adds a getBuildingCount on the planet service, that sums the levels of the Building and Station Objects
- removes old building queue service changes ( no longer needed )
- Added building max / building count to overview and planet tool tips
- Adds tests
  • Loading branch information
jackbayliss committed Oct 14, 2024
1 parent 40f4b7e commit af3a4d3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/OverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function index(PlayerService $player, BuildingQueueService $building_queu
'user_honor_points' => 0, // @TODO
'build_active' => $build_active,
'building_count' => $player->planets->current()->getBuildingCount(),
'max_building_count' => $player->planets->current()->getPlanetFieldMax(),
'build_queue' => $build_queue,
'research_active' => $research_active,
'research_queue' => $research_queue,
Expand Down
18 changes: 0 additions & 18 deletions app/Services/BuildingQueueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,6 @@ public function activeBuildingQueueItemCount(PlanetService $planet, int $buildin
->count();
}

/**
* Get the processed buildings
* building.
*
* @param PlanetService $planet
* @return int
*/
public function processedBuildingItems(PlanetService $planet): int
{
// Fetch queue items that exist against the planet.
return BuildingQueue::where([
['planet_id', $planet->getPlanetId()],
['processed', 1],
['canceled', 0],
])->count();

}

/**
* Start building the next item in the queue (if available).
*
Expand Down
11 changes: 9 additions & 2 deletions app/Services/PlanetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ public function getPlanetImageType(): string
return (string)$type;
}

/**
* @return int
*/
public function getPlanetFieldMax(): int
{
return $this->planet->field_max;
}

/**
* Get planet metal production per second (decimal number).
*
Expand Down Expand Up @@ -1448,8 +1456,7 @@ public function isBuilding(): bool
*/
public function getBuildingCount(): int
{
$queue = resolve(BuildingQueueService::class);
return $queue->processedBuildingItems($this);
return collect($this->getBuildingArray())->sum();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/ingame/layouts/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ function initChatAsync() {
data-planet-id="{{ $planet->getPlanetId() }}" id="planet-{{ $key + 1 }}">
<a href="{{ $urlToCurrentWithUpdatedParam }}"
data-link="{{ $urlToCurrentWithUpdatedParam }}" title="<b>{{ $planet->getPlanetName() }} [{{ $planet->getPlanetCoordinates()->asString() }}]</b><br/>@lang('Lifeform'): Humans
<br/>12,800km (152/193)<br>20°C to 60°C<br/><a href=&quot;#TODO=ingame&amp;component=overview&amp;cp=33624092&quot;>@lang('Overview')</a><br/><a href=&quot;#TODO=ingame&amp;component=supplies&amp;cp=33624092&quot;>@lang('Resources')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=lfbuildings&amp;cp=33624092&quot;>@lang('Lifeform')</a><br/><a href=&quot;#TODOpage=ingame&amp;component=research&amp;cp=33624092&quot;>@lang('Research')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=facilities&amp;cp=33624092&quot;>@lang('Facilities')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=shipyard&amp;cp=33624092&quot;>@lang('Shipyard')</a><br/><a href=&quot;#TODO_component=defenses&amp;cp=33624092&quot;>@lang('Defense')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=fleetdispatch&amp;cp=33624092&quot;>@lang('Fleet')</a><br/><a href=&quot;#TODO_component=galaxy&amp;cp=33624092&amp;galaxy=2&amp;system=3&amp;position=6&quot;>@lang('Galaxy')</a>"
<br/>12,800km ({{ $planet->getBuildingCount() }}/{{ $planet->getPlanetFieldMax() }})<br>20°C to 60°C<br/><a href=&quot;#TODO=ingame&amp;component=overview&amp;cp=33624092&quot;>@lang('Overview')</a><br/><a href=&quot;#TODO=ingame&amp;component=supplies&amp;cp=33624092&quot;>@lang('Resources')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=lfbuildings&amp;cp=33624092&quot;>@lang('Lifeform')</a><br/><a href=&quot;#TODOpage=ingame&amp;component=research&amp;cp=33624092&quot;>@lang('Research')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=facilities&amp;cp=33624092&quot;>@lang('Facilities')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=shipyard&amp;cp=33624092&quot;>@lang('Shipyard')</a><br/><a href=&quot;#TODO_component=defenses&amp;cp=33624092&quot;>@lang('Defense')</a><br/><a href=&quot;#TODO_page=ingame&amp;component=fleetdispatch&amp;cp=33624092&quot;>@lang('Fleet')</a><br/><a href=&quot;#TODO_component=galaxy&amp;cp=33624092&amp;galaxy=2&amp;system=3&amp;position=6&quot;>@lang('Galaxy')</a>"
class="planetlink {{ ($planet->getPlanetId() === $currentPlanet->getPlanetId() && $currentPlayer->planets->count() > 1) ? 'active' : '' }} tooltipRight tooltipClose js_hideTipOnMobile ipiHintable"
data-ipi-hint="ipiPlanetHomeplanet">
<img class="planetPic js_replace2x" alt="{{ $planet->getPlanetName() }}"
Expand Down
2 changes: 1 addition & 1 deletion resources/views/ingame/overview/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script type="text/javascript">
var textContent = [];
textContent[0] = "@lang('Diameter'):";
textContent[1] = "{!! $planet_diameter !!}km (<span>{{ $building_count }}<\/span>\/<span>188<\/span>)";
textContent[1] = "{!! $planet_diameter !!}km (<span>{{ $building_count }}<\/span>\/<span>{{ $max_building_count }}<\/span>)";
textContent[2] = "@lang('Temperature'):";
textContent[3] = "{!! $planet_temp_min !!}\u00b0C to {!! $planet_temp_max !!}\u00b0C";
textContent[4] = "@lang('Position'):";
Expand Down
49 changes: 49 additions & 0 deletions tests/Unit/PlanetServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,53 @@ public function testAddValidResourceIndividually(): void
'deuterium' => $this->planetService->deuterium()->get(),
]);
}

/**
* Test that the field max function returns expected values
*/
public function testGetPlanetFieldMax(): void
{
$this->createAndSetPlanetModel([
'field_max' => 90,
]);
$this->assertEquals(90, $this->planetService->getPlanetFieldMax());


$this->createAndSetPlanetModel([
'field_max' => 14,
]);
$this->assertEquals(14, $this->planetService->getPlanetFieldMax());
}

/**
* Tests building count returns valid buildings, and specified levels.
*/
public function testGetPlanetBuildingCount(): void
{
$this->createAndSetPlanetModel([
'metal_mine' => 50,
'crystal_mine' => 20,
'small_cargo' => 10,
'destroyer' => 3,
'espionage_probe' => 2,
'rocket_launcher' => 1,
]);

// Should only return valid buildings, ( ie metal_mine and crystal_mine )
$this->assertEquals(70, $this->planetService->getBuildingCount());

// Do another test to ensure sum is correct.
$this->createAndSetPlanetModel([
'metal_mine' => 50,
'crystal_mine' => 50,
'solar_plant' => 50,
'destroyer' => 3,
'espionage_probe' => 2,
'rocket_launcher' => 44,
]);

// Should only return valid buildings, ( ie metal_mine crystal_mine, solar_plant )
$this->assertEquals(150, $this->planetService->getBuildingCount());

}
}

0 comments on commit af3a4d3

Please sign in to comment.