upgrade_planner
{
"upgrade_planner": {
"item": "upgrade-planner", # The associated item with this structure
"label": str, # A user given name for this upgrade planner
"version": int, # The encoded version of Factorio this planner was created
# with/designed for (64 bits)
"settings": {
"mappers": [ # List of dicts, each one a "mapper"
{
"from": {
"name": str, # The name of a valid replacable entity/item
"type": "entity" or "item" # Depending on name
},
"to": {
"name": str, # The name of a different, corresponding entity/item
"type": "entity" or "item" # Depending on name
},
"index": int # in range [1, 24]
},
.. # Up to 24 mappers total
],
"description": str, # A user given description for this upgrade planner
"icons": [ # A set of signals to act as visual identification
{
"signal": {"name": str, "type": str}, # Name and type of signal
"index": int, # In range [1, 4], starting top-left and moving across
},
... # Up to 4 icons total
]
}
}
}
- class UpgradePlanner(upgrade_planner: str | dict = None)
Bases:
Blueprintable
A
Blueprintable
used to upgrade and downgrade entities and items.- 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.
- remove_mapping(from_obj, to_obj, index=None)
Removes an upgrade mapping occurence of an upgrade mapping. If
index
is specified, it will attempt to remove that specific mapping from that specific index, otherwise it will search for the first occurence of a matching mapping. No action is performed if no mapping matches the input arguments.
- set_mapping(from_obj: str | dict, to_obj: str | dict, index: int) None
Sets a single mapping in the
UpgradePlanner
.
- setup(**kwargs)
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!
- 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 mappers: list
The list of mappings of one entity or item type to the other entity or item type.
- Raises:
DataFormatError – If setting this attribute and any of the entries in the list do not match the format specified above.
- Getter:
- Setter:
- Type:
TODO
- 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"