Giter Club home page Giter Club logo

factorio-draftsman's Introduction

factorio-draftsman

A logo generated with 'examples/draftsman_logo.py'

Documentation Status codecov Code style: black

A 'draftsman' is a kind of artist that specializes in creating technical drawings across many engineering disciplines, including architectural, mechanical, and electrical. Similarly, factorio-draftsman is a Python module for creating and editing blueprints for the game Factorio.

from draftsman.blueprintable import Blueprint, BlueprintBook
from draftsman.constants import Direction
from draftsman.entity import ConstantCombinator

blueprint = Blueprint()
blueprint.label = "Example"
blueprint.description = "A blueprint for the readme."
blueprint.version = (1, 0)  # 1.0

# Create a alt-mode combinator string
test_string = "testing"
for i, c in enumerate(test_string):
    constant_combinator = ConstantCombinator()
    constant_combinator.tile_position = (i, 0)
    letter_signal = "signal-{}".format(c.upper())
    constant_combinator.set_signal(index=0, signal=letter_signal, count=0)
    blueprint.entities.append(constant_combinator)

# Create a simple clock and blinking light
constant = ConstantCombinator()
constant.tile_position = (-1, 3)
constant.direction = Direction.EAST
constant.set_signal(0, "signal-red", 1)
constant.id = "constant"
blueprint.entities.append(constant)

# Flexible ways to specify entities
blueprint.entities.append(
    "decider-combinator",
    id="clock",
    tile_position=[0, 3],
    direction=Direction.EAST,
    control_behavior={
        "decider_conditions": {
            "first_signal": "signal-red",
            "comparator": "<=",
            "constant": 60,
            "output_signal": "signal-red",
            "copy_count_from_input": True,
        }
    },
)

# Use IDs to keep track of complex blueprints
blueprint.entities.append("small-lamp", id="blinker", tile_position=(2, 3))
blinker = blueprint.entities["blinker"]
blinker.set_circuit_condition("signal-red", "=", 60)
blinker.use_colors = True

blueprint.add_circuit_connection("green", "constant", "clock")
blueprint.add_circuit_connection("red", "clock", "clock", 1, 2)
blueprint.add_circuit_connection("green", "clock", "blinker", 2, 1)

# Factorio API filter capabilities
ccs = blueprint.find_entities_filtered(name="constant-combinator")
assert len(ccs) == len(test_string) + 1

blueprint_book = BlueprintBook()
blueprint_book.blueprints = [blueprint]

print(blueprint_book)  # Pretty printing using json
print(blueprint_book.to_string())  # Blueprint string

Overview

Simply put, Draftsman attempts to provide a universal solution to the task of creating and manipulating Factorio blueprint strings, which are compressed text strings used by players to share their constructions easily with others. Draftsman allows users to programmatically create these strings via script, allowing for designs that would normally be too tedious to design by hand, such as combinator computer compilers, image-to-blueprint converters, pumpjack placers, as well as any other complex or repetitive design better suited for a computer's touch.

For more information on what exactly Draftsman is and does, as well as its intended purpose and philosophy, you can read the documentation here.

For more examples on what exactly you can do with draftsman, take a look at the examples folder.

Features

  • Compatible with the latest versions of Python 2 and 3
  • Compatible with the latest versions of Factorio (1.0+)
  • Compatible with Factorio mods(!)
  • Well documented
  • Intuitive and flexible API
  • Useful constructs for ease-of-use:
    • Give entities unique string IDs to make association between entities easier
    • Filter entities from blueprints by type, region and other parameters just like Factorio's own API
    • Entities are categorized and organized within draftsman.data for easy and flexible iteration
    • Group entities together and manipulate them all as one unit
  • Verbose Errors and Warnings ("Factorio-safety" and "Factorio-correctness")
  • Expansive and rigorous test suite

Usage

Installation:

To install the module from PyPI:

pip install factorio-draftsman

Then, to perform first time setup run

draftsman-update

Note that the draftsman-update command must be run at least once before use to ensure the module is properly setup. Currently I'm looking into solutions to have this command automatically run on install, but for now it must be manually run.


Testing with unittest:

python -m unittest discover

Coverage with coverage:

coverage run

Note that testing currently is only guaranteed to work with a vanilla install (no mods).


How to use mods:

  1. Navigate to the package's installation location
  2. Drop the mods you want into the factorio-mods folder
  3. Run draftsman-update to reflect any changes made

draftsman-update can also be called in script via the method draftsman.env:update() if you want to change the mod list on the fly:

# my_update_script.py
from draftsman.env import update
update() # equivalent to calling 'draftsman-update' from the command line

Both mod-info.json and mod-settings.dat are recognized by the script, so you can also just change the settings in either of those and the loading process will adjust as well.

TODO

  • Figure out exactly what determines if an Entity is flip-able or not
  • Most of the data extracted from data.raw is sorted, but not all of it
  • Split documentation from docstrings so that each function has a more readable example
  • RailPlanner (specify rail paths via turtle-like commands)
  • Custom data.raw extraction and formatting?
  • Maybe integrate defaults for more succinct blueprint strings?
  • Look into Lua bindings via backport to C

factorio-draftsman's People

Contributors

redruin1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.