tile¶
- class Tile(name: ~typing.Annotated[str, <function conditional.<locals>.decorator.<locals>.attr_validator at 0x7e1ce6927400>], position: ~draftsman.classes.vector.Vector | tuple[int | float, int | float] = NOTHING, *, extra_keys: dict[str, ~typing.Any] | None = None)¶
Bases:
SpatialLike,ExportableTile class. Used for keeping track of tiles in Blueprints.
- property collision_mask : set | None¶
A set of strings representing the collision layers that this object collides with.
- property collision_set : CollisionSet¶
Set of
CollisionShapewhere the Entity’s position acts as their origin.
- 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_keysafter 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.
- property global_position : Vector¶
Position of the object, expressed in global space (world space). The sum position of this object and all of its parent’s positions combined.
- name : attr_validator at 0x7e1ce6927400>]¶
The name of the Tile.
Must be a string representing the name of a valid Factorio tile. If the name is not recognized in
draftsman.data.tiles.raw, thenTile().validate()will return errors.
- classmethod from_dict( ) 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_VERSIONif unable to read the current environment.
- get_world_bounding_box() AABB | None¶
Gets the world-space coordinates AABB that completely encompasses the
collision_setof thisSpatialLike. ReturnsNoneif the collision set of the target object is unknown.
- get_world_collision_set() CollisionSet¶
Get’s the world-space coordinate
CollisionSetof the object, AKA the collection of all shapes that this EntityLike interacts with.- Returns:
A copy of this objects
CollisionSetwith the correct world-space location.
- mergable_with(other: Tile) bool¶
Determines if two entities are mergeable, or that they can be combined into a single tile. Two tiles are considered mergable if they have the same
nameand exist at the sameposition
- merge(other: Tile)¶
Merges this tile with another one. Due to the simplicity of tiles, this does nothing as long as the merged tiles are of the same name. Allows you to overlap areas of concrete and landfill without issuing
OverlappingObjectsWarnings.
- to_dict(
- version: tuple[int, ...] | None =
None, - exclude_none: bool =
True, - exclude_defaults: bool =
True, 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_VERSIONif unable to read the current environment.- exclude_none: bool =
True¶ Whether or not
Noneproperties 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 ifNone.- 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.
- version: tuple[int, ...] | None =
- validate(
- mode: ValidationMode =
ValidationMode.STRICT, 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.
- mode: ValidationMode =
- Returns:
A
ValidationResultobject, which contains all errors and warnings from the validation pass.