From 6387fb1c52545b954a7be6a4478b5540e4f9e395 Mon Sep 17 00:00:00 2001 From: indifferentketchup Date: Thu, 30 Apr 2026 20:37:50 +0000 Subject: [PATCH] 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. --- .../ProjectZomboid/ProjectZomboidMapLog.php | 44 ++++++++++++++++ src/Pattern/ProjectZomboid/MapPattern.php | 18 +++++++ .../ProjectZomboid/fixtures/map-minimal.txt | 10 ++++ .../Log/ProjectZomboidMapLogTest.php | 51 +++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 src/Log/ProjectZomboid/ProjectZomboidMapLog.php create mode 100644 src/Pattern/ProjectZomboid/MapPattern.php create mode 100644 test/src/Games/ProjectZomboid/fixtures/map-minimal.txt create mode 100644 test/tests/Games/ProjectZomboid/Log/ProjectZomboidMapLogTest.php diff --git a/src/Log/ProjectZomboid/ProjectZomboidMapLog.php b/src/Log/ProjectZomboid/ProjectZomboidMapLog.php new file mode 100644 index 0000000..38a72ab --- /dev/null +++ b/src/Log/ProjectZomboid/ProjectZomboidMapLog.php @@ -0,0 +1,44 @@ +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"; + } +} diff --git a/src/Pattern/ProjectZomboid/MapPattern.php b/src/Pattern/ProjectZomboid/MapPattern.php new file mode 100644 index 0000000..de120b9 --- /dev/null +++ b/src/Pattern/ProjectZomboid/MapPattern.php @@ -0,0 +1,18 @@ +\d{17}) "(?[^"]+)" (?\S+) (?.+) at (?[\d.]+),(?[\d.]+),(?[\d.]+)\.$/'; +} diff --git a/test/src/Games/ProjectZomboid/fixtures/map-minimal.txt b/test/src/Games/ProjectZomboid/fixtures/map-minimal.txt new file mode 100644 index 0000000..bae44ba --- /dev/null +++ b/test/src/Games/ProjectZomboid/fixtures/map-minimal.txt @@ -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. diff --git a/test/tests/Games/ProjectZomboid/Log/ProjectZomboidMapLogTest.php b/test/tests/Games/ProjectZomboid/Log/ProjectZomboidMapLogTest.php new file mode 100644 index 0000000..1925551 --- /dev/null +++ b/test/tests/Games/ProjectZomboid/Log/ProjectZomboidMapLogTest.php @@ -0,0 +1,51 @@ +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()); + } +}