Add ProjectZomboidMapLog (map.txt)
Per-line world object placement/removal log. LINE pattern handles both integer and floating-point coordinates and both 'Base.X' and 'IsoObject (X)' object encodings. Detectors: filename match plus content signature on the added/removed verbs paired with Base./IsoObject prefix.
This commit is contained in:
10
test/src/Games/ProjectZomboid/fixtures/map-minimal.txt
Normal file
10
test/src/Games/ProjectZomboid/fixtures/map-minimal.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
[16-04-26 18:39:37.028] 76561198000000001 "Player1" added Base.Aerosolbomb at 1000,2000,0.
|
||||
[16-04-26 18:55:05.485] 76561198000000001 "Player1" added Base.Aerosolbomb at 1001,2001,0.
|
||||
[16-04-26 21:20:06.768] 76561198000000002 "Player2" added IsoObject (fencing_damaged_01_124) at 1010.0,2010.0,0.0.
|
||||
[16-04-26 22:02:43.043] 76561198000000001 "Player1" added Base.Aerosolbomb at 1002,2002,0.
|
||||
[16-04-26 22:03:31.620] 76561198000000001 "Player1" added Base.PipeBomb at 1003,2003,0.
|
||||
[16-04-26 22:10:00.100] 76561198000000003 "AdminUser" removed Base.Aerosolbomb at 1001,2001,0.
|
||||
[16-04-26 22:15:22.200] 76561198000000003 "AdminUser" removed IsoObject (fencing_damaged_01_124) at 1010.0,2010.0,0.0.
|
||||
[16-04-26 22:30:11.450] 76561198000000002 "Player2" added Base.Doorframe at 1011,2011,0.
|
||||
[16-04-26 22:35:00.812] 76561198000000002 "Player2" added IsoObject (window_01_01) at 1011.0,2011.0,0.0.
|
||||
[16-04-26 22:40:33.221] 76561198000000001 "Player1" added Base.Plank at 1004,2004,0.
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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\ProjectZomboidMapLog;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\MapPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProjectZomboidMapLogTest extends TestCase
|
||||
{
|
||||
private function fixturePath(): string
|
||||
{
|
||||
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/map-minimal.txt';
|
||||
}
|
||||
|
||||
public function testParsesEachLineAsAnEntry(): void
|
||||
{
|
||||
$log = (new ProjectZomboidMapLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||
$log->parse();
|
||||
|
||||
$this->assertCount(10, $log->getEntries());
|
||||
}
|
||||
|
||||
public function testFieldsRegexHandlesIntegerCoordinates(): void
|
||||
{
|
||||
$line = '[16-04-26 18:39:37.028] 76561198000000001 "Player1" added Base.Aerosolbomb at 1000,2000,0.';
|
||||
$this->assertSame(1, preg_match(MapPattern::FIELDS, $line, $m));
|
||||
$this->assertSame('added', $m['verb']);
|
||||
$this->assertSame('Base.Aerosolbomb', $m['object']);
|
||||
$this->assertSame('1000', $m['x']);
|
||||
}
|
||||
|
||||
public function testFieldsRegexHandlesFloatCoordinatesAndIsoObject(): void
|
||||
{
|
||||
$line = '[16-04-26 21:20:06.768] 76561198000000002 "Player2" added IsoObject (fencing_damaged_01_124) at 1010.0,2010.0,0.0.';
|
||||
$this->assertSame(1, preg_match(MapPattern::FIELDS, $line, $m));
|
||||
$this->assertSame('IsoObject (fencing_damaged_01_124)', $m['object']);
|
||||
$this->assertSame('1010.0', $m['x']);
|
||||
}
|
||||
|
||||
public function testDetectiveDispatchesByContent(): void
|
||||
{
|
||||
$detective = (new Detective())
|
||||
->setLogFile(new PathLogFile($this->fixturePath()))
|
||||
->addPossibleLogClass(ProjectZomboidMapLog::class);
|
||||
|
||||
$this->assertInstanceOf(ProjectZomboidMapLog::class, $detective->detect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user