Add AdminAddedXpInformation insight
This commit is contained in:
27
src/Analysis/ProjectZomboid/AdminAddedXpInformation.php
Normal file
27
src/Analysis/ProjectZomboid/AdminAddedXpInformation.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Analysis\Information;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
|
||||||
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||||
|
|
||||||
|
class AdminAddedXpInformation extends Information implements PatternInsightInterface
|
||||||
|
{
|
||||||
|
public static function getPatterns(): array
|
||||||
|
{
|
||||||
|
return [AdminPattern::ADDED_XP_ENTRY];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMatches(array $matches, mixed $patternKey): void
|
||||||
|
{
|
||||||
|
$this->setLabel('Admin added xp');
|
||||||
|
$this->setValue(sprintf(
|
||||||
|
'%s added %s %s xp to %s',
|
||||||
|
$matches['admin'],
|
||||||
|
$matches['amount'],
|
||||||
|
$matches['skill'],
|
||||||
|
$matches['target']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,4 +34,6 @@ class AdminPattern
|
|||||||
* matching.
|
* matching.
|
||||||
*/
|
*/
|
||||||
public const string ADDED_ITEM_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added item (?<item>Base\.\S+) in (?<target>.+?)\'s inventory\.?$/';
|
public const string ADDED_ITEM_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added item (?<item>Base\.\S+) in (?<target>.+?)\'s inventory\.?$/';
|
||||||
|
|
||||||
|
public const string ADDED_XP_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added (?<amount>[\d.]+) (?<skill>\S+) xp\'s to (?<target>.+?)\.?$/';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminAddedXpInformation;
|
||||||
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AdminAddedXpInformationTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetPatternsReturnsEntryRegex(): void
|
||||||
|
{
|
||||||
|
$this->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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user