From a2faa551a1c257c799adb545ca1dc0b16d91525c Mon Sep 17 00:00:00 2001 From: indifferentketchup Date: Thu, 30 Apr 2026 21:45:12 +0000 Subject: [PATCH] Add AdminAddedXpInformation insight --- .../AdminAddedXpInformation.php | 27 +++++++++++++++ src/Pattern/ProjectZomboid/AdminPattern.php | 2 ++ .../Analysis/AdminAddedXpInformationTest.php | 33 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/Analysis/ProjectZomboid/AdminAddedXpInformation.php create mode 100644 test/tests/Games/ProjectZomboid/Analysis/AdminAddedXpInformationTest.php diff --git a/src/Analysis/ProjectZomboid/AdminAddedXpInformation.php b/src/Analysis/ProjectZomboid/AdminAddedXpInformation.php new file mode 100644 index 0000000..57e5589 --- /dev/null +++ b/src/Analysis/ProjectZomboid/AdminAddedXpInformation.php @@ -0,0 +1,27 @@ +setLabel('Admin added xp'); + $this->setValue(sprintf( + '%s added %s %s xp to %s', + $matches['admin'], + $matches['amount'], + $matches['skill'], + $matches['target'] + )); + } +} diff --git a/src/Pattern/ProjectZomboid/AdminPattern.php b/src/Pattern/ProjectZomboid/AdminPattern.php index d3f6d34..5d778ff 100644 --- a/src/Pattern/ProjectZomboid/AdminPattern.php +++ b/src/Pattern/ProjectZomboid/AdminPattern.php @@ -34,4 +34,6 @@ class AdminPattern * matching. */ public const string ADDED_ITEM_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?.+?) added item (?Base\.\S+) in (?.+?)\'s inventory\.?$/'; + + public const string ADDED_XP_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?.+?) added (?[\d.]+) (?\S+) xp\'s to (?.+?)\.?$/'; } diff --git a/test/tests/Games/ProjectZomboid/Analysis/AdminAddedXpInformationTest.php b/test/tests/Games/ProjectZomboid/Analysis/AdminAddedXpInformationTest.php new file mode 100644 index 0000000..67b7170 --- /dev/null +++ b/test/tests/Games/ProjectZomboid/Analysis/AdminAddedXpInformationTest.php @@ -0,0 +1,33 @@ +assertSame([AdminPattern::ADDED_XP_ENTRY], AdminAddedXpInformation::getPatterns()); + } + + public function testEntryRegexMatchesFullLine(): void + { + $line = "[16-04-26 18:34:00.500] AdminUser added 750.0 Blunt xp's to Player1."; + $this->assertSame(1, preg_match(AdminPattern::ADDED_XP_ENTRY, $line, $m)); + + $insight = new AdminAddedXpInformation(); + $insight->setMatches($m, 0); + + $this->assertSame('Admin added xp', $insight->getLabel()); + $this->assertSame('AdminUser added 750.0 Blunt xp to Player1', $insight->getValue()); + } + + public function testEntryRegexDoesNotMatchAddedItemLine(): void + { + $line = "[16-04-26 18:33:34.289] AdminUser added item Base.ShotgunShells in Player1's inventory."; + $this->assertSame(0, preg_match(AdminPattern::ADDED_XP_ENTRY, $line)); + } +}