tile_list

class TileList(parent: Collection, initlist: list[Tile] | None = None)

Bases: Exportable, MutableSequence

A list which exclusively contains Factorio tiles.

extra_keys : dict[str, Any] | None

Serialized

This attribute is imported/exported from blueprint strings.

Any additional keys that are not recognized by Draftsman when loading from a raw JSON dictionary end up as keys in this attribute. Under normal circumstances, this field should always remain None, indicating that all fields provided were properly translated into the internal Python format.

If there are any values in extra_keys after being imported from a raw JSON dictionary, then (left alone) these values will also be exported back into an output JSON dictionary in order to keep import-export cycles stable. A side effect of this is that users can use this attribute to add additional fields that will end up in the output string, primarily for custom metadata that can be read by other tools:

>>> input_dict = {
...    "name": "wooden-chest",
...    "position": {"x": 0.5, "y": 0.5},
...    "unknown_key": "blah"
... }
>>> container = Container.from_dict(input_dict)
>>> container.extra_keys
{"unknown_key": "blah"}
>>> container.extra_keys["custom"] = "data"
>>> container.to_dict()
{
    "name": "wooden-chest",
    "position": {"x": 0.5, "y": 0.5},
    "unknown_key": "blah",
    "custom": "data"
}

The structure of input keys are preserved, meaning you may have to recurse through keys to find the unknown data:

>>> input_dict = {
...     "name": "wooden-chest",
...     "position": {"x": 0.5, "y": 0.5},
...     "nested": {
...         "dictionary": "value"
...     }
... }
>>> container = Container.from_dict(input_dict)
>>> container.extra_keys
{"nested": {"dictionary": "value"}}

Note

While Draftsman makes an effort to preserve keys that it doesn’t recognize, Factorio itself makes no such effort - so if you create a blueprint string with custom metadata and then import it into the game, that additional data will be stripped and cannot be retrieved when exporting a new string from the game.

append(
name: str | Tile,
copy: bool = True,
merge: bool = False,
**kwargs,
) Tile

Appends the Tile to the end of the sequence.

Parameters:
name: str | Tile

The string name of the tile, or an already existing Tile instance.

copy: bool = True

Whether or not to create a deepcopy of the given tile instance and add that to the list. If name was a string instead, then this parameter does nothing since a new tile instance is always created.

merge: bool = False

Whether or not tiles with the same name and position should combine into one entity. If not, Draftsman will issue OverlappingObjectWarning s in these cases.

**kwargs

Any other keyword arguments that should be passed to the newly created tile instance, if creating from a string name.

Returns:

The newly appended Tile.

clear() None -- remove all items from S
count(value) integer -- return number of occurrences of value
difference(
other: TileList,
) TileList

Calculate the set difference between this list and another TileList.

extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

classmethod from_dict(
d: dict,
version: tuple[int, ...] | None = None,
) Self

Attempts to construct a new instance of this class from a Python dictionary in JSON format.

Parameters:
d: dict

The dictionary to interpret.

version: tuple[int, ...] | None = None

The Factorio version that the input data is compliant with.

The given version tuple will automatically attempt to grab the closest applicable converter - meaning that specifying a version of (1, 1, 96) will use the 1.0 converter, and a version of (2, 0, 32) will use the 2.0 converter.

If no version is provided, it will default to current environment’s Factorio version, or to draftsman.DEFAULT_FACTORIO_VERSION if unable to read the current environment.

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(
idx: int,
name: str | Tile,
copy: bool = True,
merge: bool = False,
**kwargs,
) Tile

Inserts an element into the TileList.

Parameters:
idx: int

The numeric index to insert this tile into the parent list.

name: str | Tile

The string name of the tile, or an already existing Tile instance.

copy: bool = True

Whether or not to create a deepcopy of the given tile instance and add that to the list. If name was a string instead, then this parameter does nothing since a new tile instance is always created.

merge: bool = False

Whether or not tiles with the same name and position should combine into one entity. If not, Draftsman will issue OverlappingObjectWarning s in these cases.

**kwargs

Any other keyword arguments that should be passed to the newly created tile instance, if creating from a string name.

Returns:

The newly inserted Tile.

intersection(
other: TileList,
) TileList

Calculate the set intersection between this list and another TileList.

pop([index]) item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()

S.reverse() – reverse IN PLACE

to_dict(
version: tuple[int, ...] | None = None,
exclude_none: bool = True,
exclude_defaults: bool = True,
) dict

Export this object to a JSON dictionary, usually directly prior to encoding into the compressed blueprint string format.

Parameters:
version: tuple[int, ...] | None = None

Which Factorio version format this entity should be exported with. The same Draftsman object can be converted to many version-specific output dictionaries, each of which may have different structures.

The given version tuple will automatically attempt to grab the closest applicable converter - meaning that specifying a version of (1, 1, 96) will use the 1.0 converter, and a version of (2, 0, 32) will use the 2.0 converter.

If no version is provided, it will default to current environment’s Factorio version, or to draftsman.DEFAULT_FACTORIO_VERSION if unable to read the current environment.

exclude_none: bool = True

Whether or not None properties should be omitted from the output string. For certain properties this option has no effect, as they either must always be present or never be present if None.

exclude_defaults: bool = True

Whether or not to exclude properties that are equivalent to their default values. Including these values in the generated output is redundant as Factorio will populate them automatically, but it is useful to disable for debug/illustation purposes.

union(
other: TileList,
) TileList

Calculate the set union between this list and another TileList.

validate(
mode: ValidationMode = ValidationMode.STRICT,
) ValidationResult

Validates the called object against it’s known format.

Example:

>>> import draftsman
>>> from draftsman.constants import ValidationMode
>>> from draftsman.entity import Container
>>> from draftsman.error import DataFormatError
>>> c = Container("wooden-chest")
>>> with draftsman.validators.set_mode(ValidationMode.DISABLED):
...     c.bar = "incorrect"
>>> try:
...     c.validate().reissue_all()
... except DataFormatError as e:
...     print("wrong!")
wrong!
Parameters:
mode: ValidationMode = ValidationMode.STRICT

How strict to be when valiating the object, corresponding to the number and type of errors and warnings returned.

Returns:

A ValidationResult object, which contains all errors and warnings from the validation pass.