Add ProjectZomboidItemLog (item.txt)
Per-line item gain/loss event log. Parser captures only the timestamp; analysers decompose location/delta/item via ItemPattern::FIELDS. Detectors: filename match plus content signature on the container/floor/inventory location verbs paired with a signed delta.
This commit is contained in:
10
test/src/Games/ProjectZomboid/fixtures/item-minimal.txt
Normal file
10
test/src/Games/ProjectZomboid/fixtures/item-minimal.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
[16-04-26 19:01:00.277] 76561198000000001 "Player1" container -1 0,0,0 [Base.LouisvilleMap5].
|
||||
[16-04-26 19:07:58.669] 76561198000000001 "Player1" floor +1 1000,2000,0 [Base.Dung_Sheep].
|
||||
[16-04-26 19:10:52.112] 76561198000000001 "Player1" floor +1 1001,2001,0 [Base.Dung_Cow].
|
||||
[16-04-26 19:28:34.852] 76561198000000002 "Player2" floor +1 1010,2010,0 [Base.Dung_Pig].
|
||||
[16-04-26 19:28:34.856] 76561198000000002 "Player2" floor +1 1010,2010,0 [Base.Dung_Cow].
|
||||
[16-04-26 19:30:01.100] 76561198000000003 "AdminUser" inventory +1 1020,2020,0 [Base.Hammer].
|
||||
[16-04-26 19:31:15.221] 76561198000000003 "AdminUser" inventory -1 1020,2020,0 [Base.Hammer].
|
||||
[16-04-26 19:35:42.812] 76561198000000001 "Player1" container -1 1002,2002,0 [Base.WaterBottleFull].
|
||||
[16-04-26 19:40:00.514] 76561198000000002 "Player2" floor +1 1011,2011,0 [Base.Bandage].
|
||||
[16-04-26 19:42:25.223] 76561198000000002 "Player2" inventory +5 1011,2011,0 [Base.Bullets9mm].
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
|
||||
|
||||
use IndifferentKetchup\Codex\Detective\Detective;
|
||||
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidItemLog;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\ItemPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProjectZomboidItemLogTest extends TestCase
|
||||
{
|
||||
private function fixturePath(): string
|
||||
{
|
||||
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/item-minimal.txt';
|
||||
}
|
||||
|
||||
public function testParsesEachLineAsAnEntry(): void
|
||||
{
|
||||
$log = (new ProjectZomboidItemLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||
$log->parse();
|
||||
|
||||
$this->assertCount(10, $log->getEntries());
|
||||
}
|
||||
|
||||
public function testFieldsRegexExtractsItemAndDelta(): void
|
||||
{
|
||||
$line = '[16-04-26 19:42:25.223] 76561198000000002 "Player2" inventory +5 1011,2011,0 [Base.Bullets9mm].';
|
||||
$this->assertSame(1, preg_match(ItemPattern::FIELDS, $line, $m));
|
||||
$this->assertSame('Player2', $m['player']);
|
||||
$this->assertSame('inventory', $m['location']);
|
||||
$this->assertSame('+5', $m['delta']);
|
||||
$this->assertSame('Base.Bullets9mm', $m['item']);
|
||||
}
|
||||
|
||||
public function testDetectiveDispatchesByContent(): void
|
||||
{
|
||||
$detective = (new Detective())
|
||||
->setLogFile(new PathLogFile($this->fixturePath()))
|
||||
->addPossibleLogClass(ProjectZomboidItemLog::class);
|
||||
|
||||
$this->assertInstanceOf(ProjectZomboidItemLog::class, $detective->detect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user