A simple parser for Factorio blueprints.
- PHP 7.4
composer require zhukovsergei/factorio-blueprint-parser
make test
- Prase Blueprints
- Parse Books
- Convert to JSON
- Convert to an array
$blueprint = '0eNqllNuOgjAQht9lrqmxLejKq2zMhsNomkDbtMVoDO++LbjoKhvAvaIH5vv/mbZzhbxqUBshHaRXEIWSFtLPK1hxlFkV1txFI6QgHNYQgczqMMsx879CG4GQJZ4hpW00GWRUrrQy7iGMtfsIUDrhBPbC3eTyJZs6R+O5QzRWWDgjCnJojMwK9FytrA/0Pryih5E4gkv4BL5XtmFdG1U2hRMnTyW1H1dIeBAOhp/E2BIx+k8x/lqXFxG2SnoVvkrGGPHAOGTWESEtGuc3/iwN825LYXxy3V48wkxmM+ls5uZe2LM2aC1xJpM2JE1yrEYyJ7fE6W84G4Fvn2/lK4x3MPp4VFYjllNn9LHcdzzb9245nM+G0/VkVdZvFoXS5cbZfONsOZ3+0Md4fLIQ794Oen9+uTiSoWdoVY01DH57zHF4y/teLIQODTiCExrbRWz5mu42jPLtpm2/ARxU4FE=';
$bpp = new \App\BlueprintParser($blueprint);
\App\BlueprintParser::isValid($blueprint); // bool(true)
$bpp->getIsBook(); // bool(false)
$parsed = $bpp->summary()->asArray();
...array(8) {
["electric-furnace"]=>
int(2)
["roboport"]=>
int(1)
["fast-inserter"]=>
int(2)
["express-transport-belt"]=>
int(5)
["beacon"]=>
int(3)
["big-electric-pole"]=>
int(1)
["productivity-module-3"]=>
int(4)
["speed-module-3"]=>
int(6)
}
$parsed = $bpp->summary()->asJson();
{"electric-furnace":2,"roboport":1,"fast-inserter":2,"express-transport-belt":5,"beacon":3,"big-electric-pole":1,"productivity-module-3":4,"speed-module-3":6}
Get an array with label and icons. On single blueprint user can pick the icons, or it will pick automatically. This is extra icons basically represent the whole recipe.
$parsed = $bpp->getBlueprintExtra();
...array(2) {
["icons"]=>
string(21) "["beacon","roboport"]"
["label"]=>
string(15) "Some label here"
}