From c57d646229340fd2cfd04db1394501c231bc9d71 Mon Sep 17 00:00:00 2001 From: indifferentketchup Date: Thu, 30 Apr 2026 21:48:31 +0000 Subject: [PATCH] Wire ProjectZomboidAdminLog default analyser --- .../ProjectZomboid/ProjectZomboidAdminLog.php | 14 ++++- .../Analyser/AdminLogAnalysisTest.php | 53 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 test/tests/Games/ProjectZomboid/Analyser/AdminLogAnalysisTest.php diff --git a/src/Log/ProjectZomboid/ProjectZomboidAdminLog.php b/src/Log/ProjectZomboid/ProjectZomboidAdminLog.php index 0e9b986..5b8dc73 100644 --- a/src/Log/ProjectZomboid/ProjectZomboidAdminLog.php +++ b/src/Log/ProjectZomboid/ProjectZomboidAdminLog.php @@ -4,6 +4,12 @@ namespace IndifferentKetchup\Codex\Log\ProjectZomboid; use IndifferentKetchup\Codex\Analyser\AnalyserInterface; use IndifferentKetchup\Codex\Analyser\PatternAnalyser; +use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedItemInformation; +use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedXpInformation; +use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminChangedOptionInformation; +use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminGrantedAccessInformation; +use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminReloadedOptionsInformation; +use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminTeleportedInformation; use IndifferentKetchup\Codex\Detective\FilenameDetector; use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector; use IndifferentKetchup\Codex\Parser\ParserInterface; @@ -22,7 +28,13 @@ class ProjectZomboidAdminLog extends ProjectZomboidEventLog public static function getDefaultAnalyser(): AnalyserInterface { - return new PatternAnalyser(); + return (new PatternAnalyser()) + ->addPossibleInsightClass(AdminAddedItemInformation::class) + ->addPossibleInsightClass(AdminAddedXpInformation::class) + ->addPossibleInsightClass(AdminGrantedAccessInformation::class) + ->addPossibleInsightClass(AdminChangedOptionInformation::class) + ->addPossibleInsightClass(AdminReloadedOptionsInformation::class) + ->addPossibleInsightClass(AdminTeleportedInformation::class); } public static function getDetectors(): array diff --git a/test/tests/Games/ProjectZomboid/Analyser/AdminLogAnalysisTest.php b/test/tests/Games/ProjectZomboid/Analyser/AdminLogAnalysisTest.php new file mode 100644 index 0000000..658f12b --- /dev/null +++ b/test/tests/Games/ProjectZomboid/Analyser/AdminLogAnalysisTest.php @@ -0,0 +1,53 @@ +setLogFile(new PathLogFile($this->fixturePath())); + $log->parse(); + $analysis = $log->analyse(); + + $this->assertCount(2, $analysis->getFilteredInsights(AdminAddedItemInformation::class)); + $this->assertCount(2, $analysis->getFilteredInsights(AdminAddedXpInformation::class)); + $this->assertCount(2, $analysis->getFilteredInsights(AdminGrantedAccessInformation::class)); + $this->assertCount(2, $analysis->getFilteredInsights(AdminChangedOptionInformation::class)); + $this->assertCount(1, $analysis->getFilteredInsights(AdminReloadedOptionsInformation::class)); + $this->assertCount(2, $analysis->getFilteredInsights(AdminTeleportedInformation::class)); + } + + public function testIdenticalAddedItemEventsAreCoalesced(): void + { + $log = (new ProjectZomboidAdminLog())->setLogFile(new PathLogFile($this->fixturePath())); + $log->parse(); + $analysis = $log->analyse(); + + $shotgunInsight = null; + foreach ($analysis->getFilteredInsights(AdminAddedItemInformation::class) as $insight) { + if (str_contains($insight->getValue(), 'Base.ShotgunShells')) { + $shotgunInsight = $insight; + break; + } + } + + $this->assertNotNull($shotgunInsight); + $this->assertSame(2, $shotgunInsight->getCounterValue()); + } +}