Closed elswindle closed 2 years ago
A quick addition to this, but this error is not limited to circuit connections, but power connections as well. That's probably a given, but better to be thorough.
Alright, this is finally fixed in 0.9.6
. The code you provided above is verified to work and produce the correct blueprint string. However, I've rewritten some of the code to highlight some potential syntactic improvements:
# Removed duplicate beacons from the string causing OverlappingObjectsWarnings
bp_str = "0eNqtldtugzAMht/F10lVApTC5V5jmiYOVhcNAktCNYR49yVtN9G1oyTaFQc73x87djxCUffYSS40ZCPwshUKsucRFD+IvLb/9NAhZMA1NkBA5I39KjA3rjAR4KLCT8iCiTxcVOfFbAWbXgig0FxzPGvO3Ah0rTIWo2FoxpsGm5jAYJZtYsswYGVNnWyrvtT8yPVAG/NeIw0t/MIeXkXfFCgvO7ze/q1KeFGJr1VUh1gt49ka/NYbH67AM296NKMrnZfvlAuFUhvb30FsTzK/SLEDaRG0m4Hq9sCV5iUt31BpKvGjN8/FzdG70MQLuszc++TOlrNBVVxiebZHN+DUI5VruMF2noV7zfbda7YdPJstcGkHunOu2IA5NIQPf03DUXZdGU4C0dpT8L/xYpcceYSwexQC/YdKSlzubZ+T3ttBdJpU2WwaEjiiVCcJtg+iJGVJxNI0TANiY0Uz5uDpx3uavgA9W1xx"
# unecessary to create two blueprints, the data is copied anyway
bp = Blueprint(bp_str)
# bp2 = Blueprint(bp_str)
new_id = 0
inserters = bp.find_entities_filtered(type='inserter')
for ins in inserters:
ins.id = str(new_id)
new_id += 1
base_pos = ins.position
pos1 = (base_pos['x'], base_pos['y']+1)
# I should probably write a function `find_entity_at_position``, or rewrite
# `find_entity` to have `name` as an optional parameter. Thoughts?
nb = bp.find_entities_filtered(position=pos1)
if(nb[0].type == 'logistic-container'):
nb[0].id = str(new_id)
new_id += 1
bp.add_circuit_connection('red', ins.id, nb[0].id)
# Im also not happy with having to extract and construct a new tuple for simple offsets
# like this; I should probably integrate some 2d vector library and convert everything to
# that
pos1 = (base_pos['x'], base_pos['y']-1)
nb = bp.find_entities_filtered(position=pos1)
if(nb[0].type == 'logistic-container'):
nb[0].id = str(new_id)
new_id += 1
bp.add_circuit_connection('green', ins.id, nb[0].id)
# also unecessary to create two groups, as we can simply modify one group
# If you still need the different IDs, you can set them in a loop similar to
# above
g1 = Group(entities=bp.entities)
# g2 = Group('g2', entities=bp.entities)
# for entity in g2.entities:
# entity.position['x'] += 9
final_bp = Blueprint()
final_bp.entities.append(g1) # copy at (0, 0)
# Setting a group's position automatically translates sub-entities on export
final_bp.position = (9, 0)
final_bp.entities.append(g1) # copy at (9, 0)
print(final_bp.to_string())
Perhaps I should make an optional constructor to initialize a Group from a blueprint string, which would eliminate the malarkey of creating a "scratch" Blueprint just to import it into a Group. Would that be useful?
Having a constructor for Group
that accepts a string would be nice since it'll save computation time converting from a blueprint to a group. That will be good considering my comment in #20.
Alright, I'll put it in now. What attributes would you like to acquire from a blueprint string? Should it just be the entities, or is there extra information that you would like to extract?
I think entities is all I should need. If not, I can just override the __init__
function and grab more data. I feel like the only other thing I might need is some location data, like local/absolute position. I haven't gotten to that point yet.
After adding circuit connections to entities within a group and adding that
Group
to aBlueprint
, when I try to convert the blueprint to a string, I get aValueError
that the connected entity is not in the list. More specifically, I load up a blueprint and add a few circuit connections (at this point, the blueprint is still good and can export to string with no issue). I then create aGroup
from the entities of the blueprint. I add theGroup
to a newBlueprint
and try to create the string from it, but it breaks. If I do not make the circuit connections, there's no problem and can import it to Factorio no problem. I've attached my code and the error code:Exception has occurred: ValueError <LogisticRequestContainer '5'>{'name': 'logistic-chest-requester', 'position': {'x': 43.5, 'y': -0.5}, 'connections': {'1': {'green': [{'entity_id': <Association to Inserter with id '0'>}], 'red': [{'entity_id': <Association to Inserter with id '4'>}]}}} is not in list