Skip to content

Commit f9b3a4e

Browse files
committed
code improvement
1 parent c37447c commit f9b3a4e

10 files changed

+60
-52
lines changed

src/Component/Map/Effects/Type/CloakUnuseableEffectHandler.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, Inform
2727
#[Override]
2828
public function addFlightInformation(LocationInterface $location, MessageCollectionInterface $messages): void
2929
{
30-
$messages->addInformation(
31-
sprintf(
32-
"[color=yellow]Ionische Dispersion durch %s stört die Phasenmodulation von Tarnsystemen in Sektor %s[/color]",
33-
$location->getFieldType()->getName(),
34-
$location->getSectorString()
35-
)
30+
$messages->addInformationf(
31+
"[color=yellow]Ionische Dispersion durch %s stört die Phasenmodulation von Tarnsystemen in Sektor %s[/color]",
32+
$location->getFieldType()->getName(),
33+
$location->getSectorString()
3634
);
3735
}
3836

@@ -44,10 +42,10 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
4442

4543
$this->spacecraftSystemManager->deactivate($wrapper, SpacecraftSystemTypeEnum::CLOAK, true);
4644

47-
$messages->addInformation(
45+
$messages->addMessageBy(
4846
sprintf("%s: [color=yellow]Tarnsystem ausgefallen[/color]", $spacecraft->getName()),
4947
$wrapper->get()->getUser()->getId()
5048
);
5149
}
5250
}
53-
}
51+
}

src/Component/Map/Effects/Type/EpsLeakEffectHandler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, Inform
2424
#[Override]
2525
public function addFlightInformation(LocationInterface $location, MessageCollectionInterface $messages): void
2626
{
27-
$messages->addInformation(
28-
sprintf(
29-
"[color=yellow]Energetische Disruption durch %s in Sektor %s kann den Plasmastrom von EPS-Systemen absorbieren[/color]",
30-
$location->getFieldType()->getName(),
31-
$location->getSectorString()
32-
)
27+
$messages->addInformationf(
28+
"[color=yellow]Energetische Disruption durch %s in Sektor %s kann den Plasmastrom von EPS-Systemen absorbieren[/color]",
29+
$location->getFieldType()->getName(),
30+
$location->getSectorString()
3331
);
3432
}
3533

@@ -58,7 +56,7 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
5856

5957
$epsSystemData->lowerEps($loss)->update();
6058

61-
$messages->addInformation(
59+
$messages->addMessageBy(
6260
sprintf(
6361
"%s: [color=yellow]%d Energie wird abgeleitet[/color]",
6462
$spacecraft->getName(),

src/Component/Map/Effects/Type/NfsMalfunctionCooldownEffectHandler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, Inform
3434
#[Override]
3535
public function addFlightInformation(LocationInterface $location, MessageCollectionInterface $messages): void
3636
{
37-
$messages->addInformation(
38-
sprintf(
39-
"[color=yellow]Subraumverzerrungen durch %s induzieren Rückkopplung in den Nahbereichsensoren in Sektor %s[/color]",
40-
$location->getFieldType()->getName(),
41-
$location->getSectorString()
42-
)
37+
$messages->addInformationf(
38+
"[color=yellow]Subraumverzerrungen durch %s induzieren Rückkopplung in den Nahbereichsensoren in Sektor %s[/color]",
39+
$location->getFieldType()->getName(),
40+
$location->getSectorString()
4341
);
4442
}
4543

@@ -64,7 +62,7 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
6462
$shutdownText = 'ausgefallen und ';
6563
}
6664

67-
$messages->addInformation(
65+
$messages->addMessageBy(
6866
sprintf(
6967
"%s: [color=yellow]%s %sin Rekalibrierungsphase[/color]",
7068
$spacecraft->getName(),

src/Component/Map/Effects/Type/ReactorLeakEffectHandler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, Inform
2424
#[Override]
2525
public function addFlightInformation(LocationInterface $location, MessageCollectionInterface $messages): void
2626
{
27-
$messages->addInformation(
28-
sprintf(
29-
"[color=yellow]Partikelanomalie durch %s kann in Sektor %s hochenergetische Reaktor-Plasmaströme aus der Reaktorkernmatrix extrahieren[/color]",
30-
$location->getFieldType()->getName(),
31-
$location->getSectorString()
32-
)
27+
$messages->addInformationf(
28+
"[color=yellow]Partikelanomalie durch %s kann in Sektor %s hochenergetische Reaktor-Plasmaströme aus der Reaktorkernmatrix extrahieren[/color]",
29+
$location->getFieldType()->getName(),
30+
$location->getSectorString()
3331
);
3432
}
3533

@@ -58,7 +56,7 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
5856

5957
$reactorWrapper->changeLoad(-$loss);
6058

61-
$messages->addInformation(
59+
$messages->addMessageBy(
6260
sprintf(
6361
"%s: [color=yellow]Reaktorladung sinkt signifikant um %d Einheiten[/color]",
6462
$spacecraft->getName(),

src/Component/Map/Effects/Type/ShieldMalfunctionEffectHandler.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, Inform
3333
#[Override]
3434
public function addFlightInformation(LocationInterface $location, MessageCollectionInterface $messages): void
3535
{
36-
$messages->addInformation(
37-
sprintf(
38-
"[color=yellow]Partikelinterferenz durch %s in Sektor %s sorgt für Destabilisierung des Schildgitters[/color]",
39-
$location->getFieldType()->getName(),
40-
$location->getSectorString()
41-
)
36+
$messages->addInformationf(
37+
"[color=yellow]Partikelinterferenz durch %s in Sektor %s sorgt für Destabilisierung des Schildgitters[/color]",
38+
$location->getFieldType()->getName(),
39+
$location->getSectorString()
4240
);
4341
}
4442

@@ -60,7 +58,7 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
6058
return;
6159
}
6260

63-
$messages->addInformation(
61+
$messages->addMessageBy(
6462
sprintf(
6563
"%s: [color=yellow]%s[/color]",
6664
$spacecraft->getName(),

src/Component/Map/Effects/Type/WarpdriveLeakEffectHandler.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, Inform
2121
#[Override]
2222
public function addFlightInformation(LocationInterface $location, MessageCollectionInterface $messages): void
2323
{
24-
$messages->addInformation(
25-
sprintf(
26-
"[color=yellow]Fluktuationen im Warpplasmaleitungssystem durch %s in Sektor %s festgestellt[/color]",
27-
$location->getFieldType()->getName(),
28-
$location->getSectorString()
29-
)
24+
$messages->addInformationf(
25+
"[color=yellow]Fluktuationen im Warpplasmaleitungssystem durch %s in Sektor %s festgestellt[/color]",
26+
$location->getFieldType()->getName(),
27+
$location->getSectorString()
3028
);
3129
}
3230

@@ -50,7 +48,7 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
5048

5149
$warpdrive->lowerWarpDrive($loss)->update();
5250

53-
$messages->addInformation(
51+
$messages->addMessageBy(
5452
sprintf(
5553
"%s: [color=yellow]Warpantriebs-Leckage verursacht Kapazitätsverlust von %s Cochrane[/color]",
5654
$spacecraft->getName(),
@@ -59,4 +57,4 @@ public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, Me
5957
$wrapper->get()->getUser()->getId()
6058
);
6159
}
62-
}
60+
}

src/Module/Spacecraft/Lib/Message/MessageCollection.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Stu\Module\Spacecraft\Lib\Message;
66

77
use Override;
8+
use Stu\Lib\Information\InformationInterface;
89
use Stu\Lib\Information\InformationWrapper;
910
use Stu\Module\PlayerSetting\Lib\UserEnum;
1011

@@ -22,7 +23,7 @@ public function add(MessageInterface $msg): void
2223
}
2324

2425
#[Override]
25-
public function addInformation(string $text, ?int $recipient = null): MessageInterface
26+
public function addMessageBy(string $text, ?int $recipient = null): MessageInterface
2627
{
2728
$message = $this->messageFactory->createMessage(
2829
UserEnum::USER_NOONE,
@@ -35,6 +36,24 @@ public function addInformation(string $text, ?int $recipient = null): MessageInt
3536
return $message;
3637
}
3738

39+
#[Override]
40+
public function addInformation(?string $information): InformationInterface
41+
{
42+
if ($information !== null) {
43+
$this->addMessageBy($information);
44+
}
45+
46+
return $this;
47+
}
48+
49+
#[Override]
50+
public function addInformationf(string $information, ...$args): InformationInterface
51+
{
52+
$this->addMessageBy(vsprintf($information, $args));
53+
54+
return $this;
55+
}
56+
3857
#[Override]
3958
public function getRecipientIds(): array
4059
{

src/Module/Spacecraft/Lib/Message/MessageCollectionInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace Stu\Module\Spacecraft\Lib\Message;
44

5+
use Stu\Lib\Information\InformationInterface;
56
use Stu\Lib\Information\InformationWrapper;
67

7-
interface MessageCollectionInterface
8+
interface MessageCollectionInterface extends InformationInterface
89
{
910
public function add(MessageInterface $msg): void;
1011

11-
public function addInformation(
12+
public function addMessageBy(
1213
string $text,
1314
?int $recipient = null
1415
): MessageInterface;

src/Module/Spacecraft/Lib/Movement/ShipMovementInformationAdder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function reachedDestination(
8989
$fieldType = $spacecraft->getLocation()->getFieldType();
9090
$flightDestinationInfo = $effect->getFlightDestinationInfo($fieldType);
9191
if ($flightDestinationInfo !== null) {
92-
$messages->addInformation(
92+
$messages->addMessageBy(
9393
sprintf("[color=yellow]%s[/color]", $flightDestinationInfo),
9494
$spacecraft->getUser()->getId()
9595
);

src/Module/Spacecraft/Lib/Movement/ShipMover.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private function leaveFleet(SpacecraftInterface $ship, MessageCollectionInterfac
254254
{
255255
if ($ship instanceof ShipInterface) {
256256
if ($this->leaveFleet->leaveFleet($ship)) {
257-
$messages->addInformation(sprintf('Die %s hat die Flotte verlassen', $ship->getName()));
257+
$messages->addInformationf('Die %s hat die Flotte verlassen', $ship->getName());
258258
}
259259
}
260260
}
@@ -328,14 +328,14 @@ private function postFlightInformations(
328328

329329
//add info about anomalies
330330
foreach ($finalDestination->getAnomalies() as $anomaly) {
331-
$messages->addInformation(sprintf(
331+
$messages->addInformationf(
332332
'[b][color=yellow]In diesem Sektor befindet sich eine %s-Anomalie[/color][/b]',
333333
$anomaly->getAnomalyType()->getName()
334-
));
334+
);
335335
}
336336
// add info about buyos
337337
foreach ($finalDestination->getBuoys() as $buoy) {
338-
$messages->addInformation(sprintf('[b][color=yellow]Boje entdeckt: [/color][/b]%s', $buoy->getText()));
338+
$messages->addInformationf('[b][color=yellow]Boje entdeckt: [/color][/b]%s', $buoy->getText());
339339
}
340340
}
341341

0 commit comments

Comments
 (0)