blueprintable
Contains the Blueprintable
class, an abstract class that implements a number of common properties and methods shared across all blueprintable objects.
More specifically, a “Blueprintable” object is a JSON dict that can be parsed as a blueprint string by Factorio.
- class Blueprintable(root_item: str, item: str, init_data: str | dict = None)
An abstract base class representing “blueprint-like” objects, such as
Blueprint
,DeconstructionPlanner
,UpgradePlanner
, andBlueprintBook
.All attributes default to keys in the
self._root
object, but can (and are) overwritten in select circumstances.- load_from_string(string: str) None
Load the
Blueprintable
with the contents ofstring
.Raises
DraftsmanWarning
if there are any unrecognized keywords in the blueprint string for this particular blueprintable.- Parameters:
string – Factorio-encoded blueprint string.
- Raises:
MalformedBlueprintStringError – If the input string is not decodable to a JSON object.
IncorrectBlueprintTypeError – If the input string is of a different type than the base class.
- abstract setup() None
Setup the Blueprintable’s parameters with the input keywords as values. Primarily used by the constructor, but can be used at any time to set a large number of keys all at once.
Raises
DraftsmanWarning
if any of the input keywords are unrecognized.- Parameters:
kwargs – The dict of all keywords to set in the blueprint.
Note
Calling
setup
only sets the specified keys to their values, and everything else to either their defaults orNone
. In other words, the effect of calling setup multiple times is not cumulative, but rather set to the keys in the last call.- Example:
>>> from draftsman.blueprintable import Blueprint >>> blueprint = Blueprint() >>> blueprint.setup(label="test") >>> assert blueprint.label == "test" >>> test_dict = {"description": "testing..."} >>> blueprint.setup(**test_dict) >>> assert blueprint.description == "testing..." >>> assert blueprint.label == None # Gone!
- abstract to_dict() dict
Returns the blueprintable as a dictionary. Intended for getting the precursor to a Factorio blueprint string before encoding and compression takes place.
- Returns:
The
dict
representation of theBlueprintable
.
- to_string() str
Returns this object as an encoded Factorio blueprint string.
- Returns:
The zlib-compressed, base-64 encoded string.
- Example:
>>> from draftsman.blueprintable import ( ... Blueprint, DeconstructionPlanner, UpgradePlanner, BlueprintBook ... ) >>> Blueprint({"version": (1, 0)}).to_string() '0eNqrVkrKKU0tKMrMK1GyqlbKLEnNVbJCEtNRKkstKs7Mz1OyMrIwNDE3sTQ3Mzc0MDM1q60FAHmVE1M=' >>> DeconstructionPlanner({"version": (1, 0)}).to_string() '0eNpdy0EKgCAQAMC/7Nkgw7T8TIQtIdga7tol/HtdunQdmBs2DJlYSg0SMy1nWomwgL+BUSTSzuCppqQgCh7gf6H7goILC78Cfpi0cWZ21unejra1B7C2I9M=' >>> UpgradePlanner({"version": (1, 0)}).to_string() '0eNo1yksKgCAUBdC93LFBhmm5mRB6iGAv8dNE3Hsjz/h0tOSzu+lK0TFThu0oVGtgX2C5xSgQKj2wcy5zCnyUS3gZdjukMuo02shV73qMH4ZxHbs=' >>> BlueprintBook({"version": (1, 0)}).to_string() '0eNqrVkrKKU0tKMrMK4lPys/PVrKqVsosSc1VskJI6IIldJQSk0syy1LjM/NSUiuUrAx0lMpSi4oz8/OUrIwsDE3MTSzNzcwNDcxMzWprAVWGHQI='
- version_string() str
Returns the version of the
Blueprintable
in human-readable string.- Returns:
a
str
of 4 version numbers joined by a ‘.’ character.- Example:
>>> from draftsman.blueprintable import Blueprint >>> blueprint = Blueprint({"version": (1, 2, 3)}) >>> blueprint.version_string() '1.2.3.0'
- version_tuple()
Returns the version of the
Blueprintable
as a 4-length tuple.- Returns:
A 4 length tuple in the format
(major, minor, patch, dev_ver)
.- Example:
>>> from draftsman.blueprintable import Blueprint >>> blueprint = Blueprint({"version": 281474976710656}) >>> blueprint.version_tuple() (1, 0, 0, 0)
- property description: str
The description of the blueprintable. Visible when hovering over it when inside someone’s inventory.
- Getter:
Gets the description, or
None
if not set.- Setter:
Sets the description of the object. Removes the attribute if set to
None
.- Type:
str
- Raises:
TypeError – If setting to anything other than a
str
orNone
.
- property icons: list
The visible icons of the blueprintable, shown in as the objects icon.
Stored as a list of
ICON
objects, which are dicts that contain aSIGNAL_ID
and anindex
key. Icons can be specified in this format, or they can be specified more succinctly with a simple list of signal names as strings.All signal entries must be a valid signal ID. If the input format is a list of strings, the index of each item will be it’s place in the list + 1. A max of 4 icons are permitted.
- Getter:
Gets the list if icons, or
None
if not set.- Setter:
Sets the icons of the Blueprint. Removes the attribute if set to
None
.- Type:
{"index": int, "signal": {"name": str, "type": str}}
- Raises:
DataFormatError – If the set value does not match either of the specifications above.
- Example:
>>> from draftsman.blueprintable import Blueprint >>> blueprint = Blueprint() >>> blueprint.icons = ["transport-belt"] >>> blueprint.icons [{'index': 1, 'signal': {'name': 'transport-belt', 'type': 'item'}}]
- property item: str
Always the name of the corresponding Factorio item to this blueprintable instance. Read only.
- Type:
str
- Example:
>>> from draftsman.blueprintable import ( ... Blueprint, DeconstructionPlanner, UpgradePlanner, BlueprintBook ... ) >>> Blueprint().item 'blueprint' >>> DeconstructionPlanner().item 'deconstruction-planner' >>> UpgradePlanner().item 'upgrade-planner' >>> BlueprintBook().item 'blueprint-book'
- property label: str
The user given name (title) of the blueprintable.
- Getter:
Gets the label, or
None
if not set.- Setter:
Sets the label of this object.
- Type:
str
- Raises:
TypeError – When setting
label
to something other thanstr
orNone
.
- property version: int
The version of Factorio the Blueprint was created in/intended for.
The Blueprint
version
is a 64-bit integer, which is a bitwise-OR of four 16-bit numbers. You can interpret this number more clearly by decoding it withdraftsman.utils.decode_version()
, or you can use the functionsversion_tuple()
orversion_string()
which will give you a more readable output. This version number defaults to the version of Factorio that Draftsman is currently initialized with.The version can be set either as said 64-bit int, or a sequence of ints, usually a list or tuple, which is then encoded into the combined representation. The sequence is defined as:
[major_version, minor_version, patch, development_release]
withpatch
anddevelopment_release
defaulting to 0.- Getter:
Gets the version, or
None
if not set.- Setter:
Sets the version of the Blueprint. Removes the attribute if set to
None
.- Type:
int
- Raises:
TypeError – If set to anything other than an
int
, sequence ofints
, orNone
.- Example:
>>> from draftsman.blueprintable import Blueprint >>> blueprint = Blueprint() >>> blueprint.version = (1, 0) # version 1.0.0.0 >>> assert blueprint.version == 281474976710656 >>> assert blueprint.version_tuple() == (1, 0, 0, 0) >>> assert blueprint.version_string() == "1.0.0.0"