Wolfram Research

Function Repository Resource:

ImportFactorioBlueprintString

Source Notebook

Import blueprint strings from the game Factorio

Contributed by: Sander Huisman

ResourceFunction["ImportFactorioBlueprintString"][str]

imports the Factorio blueprint string str.

ResourceFunction["ImportFactorioBlueprintString"][str,"Association"]

imports as a nested association.

Details

By default, the output is a list of rules.
Factorio is a construction and management simulation game developed by the Czech studio Wube Software.
This function Imports single blueprints or blueprint books from the game Factorio.
Blueprints can contain parts, connections and their settings that can then be used to fabricate in an automated fashion.

Examples

Basic Examples (1) 

Import a blueprint from the game Factorio:

In[1]:=
ResourceFunction[
 "ImportFactorioBlueprintString"]["0eNqdlt1ugzAMhd/\
F16wiDr95lWmaShtVkSCgEKahindfgG1CKx5priCQfBz72DJ3qOpBdkZpC+\
IO6tLqHsTrHXp10+d6fmbHToIAZWUDEehzM6+sOeu+\
a419qWRtYYpA6av8BMGm6PBw39XKWmk2x3B6i0Bqq6ySq4BlMb7roancTsEeT0fQtb070O\
r5Sw6Suk0jiKI8pdMs4w8CfRD8XwSnErCj5ZQuqNLduDivysjL+j7bASf+\
4PgHHO9rTANQbB+V/aIGZ5O5mdZdDwOOl4C/nW8H2w1zgTzAc3+\
dSOYSd8CFP5gfJKAMQBG2sPiZZOKTyWQsoDI5oRQDKoj7OMO4TwviSkRCXRJQN1SkaYC/\
3KefWRaQw4RQmQewUoJVBLV0sq1CpakiLJ+\
wlxCIcYAlFIsFsAgTEIPa1y9xyP2nW5kRAhP/8bYy3MRd5rLY/\
ANE8CFNvzZwwZK8xBzjnLEcp+kLwXup2A=="]
Out[1]=

Scope (1) 

Import a blueprint as nested Association expressions:

In[2]:=
blueprint = "0eNqdlt1ugzAMhd/\
F16wiDr95lWmaShtVkSCgEKahindfgG1CKx5priCQfBz72DJ3qOpBdkZpC+\
IO6tLqHsTrHXp10+d6fmbHToIAZWUDEehzM6+sOeu+\
a419qWRtYYpA6av8BMGm6PBw39XKWmk2x3B6i0Bqq6ySq4BlMb7roancTsEeT0fQtb070O\
r5Sw6Suk0jiKI8pdMs4w8CfRD8XwSnErCj5ZQuqNLduDivysjL+j7bASf+\
4PgHHO9rTANQbB+V/aIGZ5O5mdZdDwOOl4C/nW8H2w1zgTzAc3+\
dSOYSd8CFP5gfJKAMQBG2sPiZZOKTyWQsoDI5oRQDKoj7OMO4TwviSkRCXRJQN1SkaYC/\
3KefWRaQw4RQmQewUoJVBLV0sq1CpakiLJ+\
wlxCIcYAlFIsFsAgTEIPa1y9xyP2nW5kRAhP/8bYy3MRd5rLY/\
ANE8CFNvzZwwZK8xBzjnLEcp+kLwXup2A==";
ResourceFunction[
 "ImportFactorioBlueprintString"][blueprint, "Association"]
Out[3]=

Neat Examples (1) 

Import a blueprint and visualize a 4x4 belt balancer:

In[4]:=
ClearAll[DrawEntity, MyArrow]
MyArrow[p_List, size_] := Module[{d, pdir, pd, last = Last[p]},
  d = last - p[[-2]];
  pd = Cross[d];
  {Line[p], Line[{last, last - size d + 0.5 size pd, last - size d - 0.5 size pd, last}]}
  ]
DrawEntity[assoc_Association] := Module[{name, pos, dir, pdir, \[Delta] = 0.9, \[Sigma] = 0.25, type},
  pos = assoc["position"];
  pos = {pos["x"], -pos["y"]};
  If[! MissingQ[pos],
   dir = assoc["direction"];
   If[MissingQ[dir], dir = 0];
   dir = Switch[dir, 0, {0, 1}, 2, {1, 0}, 4, {0, -1}, 6, {-1, 0}, _, Missing[]];
   If[! MissingQ[dir],
    name = assoc["name"];
    If[! MissingQ[name],
     Switch[name,
      "transport-belt",
      MyArrow[{pos - \[Delta] dir/2, pos + \[Delta] dir/2}, \[Sigma]]
      ,
      "splitter",
      pdir = Cross[dir];
      {
       Style[Rectangle[pos - 0.5 dir + pdir, pos + 0.5 dir - pdir], FaceForm[], EdgeForm[Black]],
       MyArrow[{pos - \[Delta] 0.5 dir + \[Delta] 0.5 pdir, pos + \[Delta] 0.5 dir - \[Delta] 0.5 pdir}, \[Sigma]],
       MyArrow[{pos - \[Delta] 0.5 dir - \[Delta] 0.5 pdir, pos + \[Delta] 0.5 dir + \[Delta] 0.5 pdir}, \[Sigma]]
       }
      ,
      "underground-belt",
      type = assoc["type"];
      Switch[type,
       "input",
       Style[
        MyArrow[{pos - \[Delta] dir/2, pos + \[Delta] dir/2}, \[Sigma]], Blue],
       "output",
       Style[
        MyArrow[{pos - \[Delta] dir/2, pos + \[Delta] dir/2}, \[Sigma]], Darker@Red],
       _,
       {}
       ]
      ,
      _,
      {}
      ]
     ,
     {}
     ]
    ,
    {}
    ]
   ,
   {}
   ]
  ]
blueprint = "0eNqdlt1ugzAMhd/\
F16wiDr95lWmaShtVkSCgEKahindfgG1CKx5priCQfBz72DJ3qOpBdkZpC+\
IO6tLqHsTrHXp10+d6fmbHToIAZWUDEehzM6+sOeu+\
a419qWRtYYpA6av8BMGm6PBw39XKWmk2x3B6i0Bqq6ySq4BlMb7roancTsEeT0fQtb070O\
r5Sw6Suk0jiKI8pdMs4w8CfRD8XwSnErCj5ZQuqNLduDivysjL+j7bASf+\
4PgHHO9rTANQbB+V/aIGZ5O5mdZdDwOOl4C/nW8H2w1zgTzAc3+\
dSOYSd8CFP5gfJKAMQBG2sPiZZOKTyWQsoDI5oRQDKoj7OMO4TwviSkRCXRJQN1SkaYC/\
3KefWRaQw4RQmQewUoJVBLV0sq1CpakiLJ+\
wlxCIcYAlFIsFsAgTEIPa1y9xyP2nW5kRAhP/8bYy3MRd5rLY/\
ANE8CFNvzZwwZK8xBzjnLEcp+kLwXup2A==";
Graphics[DrawEntity /@ ResourceFunction["ImportFactorioBlueprintString"][blueprint, "Association"]["blueprint"]["entities"]]
Out[4]=

Resource History

Related Resources

License Information