diff --git a/src/Analysis/ProjectZomboid/AdminAddedItemInformation.php b/src/Analysis/ProjectZomboid/AdminAddedItemInformation.php new file mode 100644 index 0000000..fe63508 --- /dev/null +++ b/src/Analysis/ProjectZomboid/AdminAddedItemInformation.php @@ -0,0 +1,26 @@ +setLabel('Admin added item'); + $this->setValue(sprintf( + '%s added %s to %s', + $matches['admin'], + $matches['item'], + $matches['target'] + )); + } +} diff --git a/src/Pattern/ProjectZomboid/AdminPattern.php b/src/Pattern/ProjectZomboid/AdminPattern.php index ee206d9..8b34c06 100644 --- a/src/Pattern/ProjectZomboid/AdminPattern.php +++ b/src/Pattern/ProjectZomboid/AdminPattern.php @@ -25,4 +25,12 @@ class AdminPattern public const string RELOADED_OPTIONS = '/^(?.+?) reloaded options$/'; public const string TELEPORTED = '/^(?.+?) teleported (?.+?) to (?\d+),(?\d+),(?-?\d+)$/'; -} + + /** + * Entry-anchored variants for analyser use. PatternAnalyser passes the + * full Entry text (including the [time] prefix) to preg_match_all, so + * these include the timestamp prefix and are anchored at start/end of + * the line. The body-only constants above are kept for direct-message + * 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\.?$/'; diff --git a/test/tests/Games/ProjectZomboid/Analysis/AdminAddedItemInformationTest.php b/test/tests/Games/ProjectZomboid/Analysis/AdminAddedItemInformationTest.php new file mode 100644 index 0000000..197298e --- /dev/null +++ b/test/tests/Games/ProjectZomboid/Analysis/AdminAddedItemInformationTest.php @@ -0,0 +1,48 @@ +assertSame([AdminPattern::ADDED_ITEM_ENTRY], AdminAddedItemInformation::getPatterns()); + } + + public function testEntryRegexMatchesFullLine(): void + { + $line = "[16-04-26 18:33:34.289] AdminUser added item Base.ShotgunShells in Player1's inventory."; + $this->assertSame(1, preg_match(AdminPattern::ADDED_ITEM_ENTRY, $line, $m)); + + $insight = new AdminAddedItemInformation(); + $insight->setMatches($m, 0); + + $this->assertSame('Admin added item', $insight->getLabel()); + $this->assertSame('AdminUser added Base.ShotgunShells to Player1', $insight->getValue()); + } + + public function testIsEqualCoalescesIdenticalAddedItem(): void + { + $a = $this->insightFor('AdminUser', 'Base.X', 'Player1'); + $b = $this->insightFor('AdminUser', 'Base.X', 'Player1'); + $c = $this->insightFor('AdminUser', 'Base.Y', 'Player1'); + + $this->assertTrue($a->isEqual($b)); + $this->assertFalse($a->isEqual($c)); + } + + private function insightFor(string $admin, string $item, string $target): AdminAddedItemInformation + { + $insight = new AdminAddedItemInformation(); + $insight->setMatches([ + 'admin' => $admin, + 'item' => $item, + 'target' => $target, + ], 0); + return $insight; + } +}