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:
44
src/Log/ProjectZomboid/ProjectZomboidMapLog.php
Normal file
44
src/Log/ProjectZomboid/ProjectZomboidMapLog.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analyser\AnalyserInterface;
|
||||
use IndifferentKetchup\Codex\Analyser\PatternAnalyser;
|
||||
use IndifferentKetchup\Codex\Detective\FilenameDetector;
|
||||
use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector;
|
||||
use IndifferentKetchup\Codex\Parser\ParserInterface;
|
||||
use IndifferentKetchup\Codex\Parser\PatternParser;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\MapPattern;
|
||||
|
||||
class ProjectZomboidMapLog extends ProjectZomboidEventLog
|
||||
{
|
||||
public static function getDefaultParser(): ParserInterface
|
||||
{
|
||||
return static::makePatternParser(
|
||||
MapPattern::LINE,
|
||||
[PatternParser::TIME]
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDefaultAnalyser(): AnalyserInterface
|
||||
{
|
||||
return new PatternAnalyser();
|
||||
}
|
||||
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [
|
||||
(new FilenameDetector())
|
||||
->setPattern('/_map\.txt$/')
|
||||
->setWeight(0.95),
|
||||
(new WeightedSinglePatternDetector())
|
||||
->setPattern('/^\[[^\]]+\] \d{17} "[^"]+" (?:added|removed) (?:Base\.|IsoObject )/m')
|
||||
->setWeight(0.90),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Project Zomboid Map Log";
|
||||
}
|
||||
}
|
||||
18
src/Pattern/ProjectZomboid/MapPattern.php
Normal file
18
src/Pattern/ProjectZomboid/MapPattern.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Pattern\ProjectZomboid;
|
||||
|
||||
/**
|
||||
* Regex constants for the Project Zomboid map.txt format.
|
||||
*
|
||||
* [time] steamid "player" verb object at x,y,z.
|
||||
*
|
||||
* Coordinates may be integer or floating point; objects may be Base.X
|
||||
* tokens or 'IsoObject (X)' parenthesised forms.
|
||||
*/
|
||||
class MapPattern
|
||||
{
|
||||
public const string LINE = '/^\[(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\] \d{17} "[^"]+" \S+ .+ at [\d.]+,[\d.]+,[\d.]+\.$/';
|
||||
|
||||
public const string FIELDS = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<steamid>\d{17}) "(?<player>[^"]+)" (?<verb>\S+) (?<object>.+) at (?<x>[\d.]+),(?<y>[\d.]+),(?<z>[\d.]+)\.$/';
|
||||
}
|
||||
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