Version 3.0 Release #189
Pinned
redruin1
announced in
Announcements
Replies: 1 comment 4 replies
-
|
What is the current status of the update script? Can't get it to work with any mods, no mention of compatibility in changelogs or docs. Couldn't get it to work draftsman 2.0 either. Just wondering if it is still WIP or something wrong with my setup? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
3.0 Release
Draftsman 3.0 is now released. Along with it come numerous improvements, fixes, and breaking changes that may affect your scripts.
Blueprint Versioning
Draftsman 3.0 can now read/write different kinds of blueprint string JSON, corresponding to Factorio versions 1.X and 2.X:
Draftsman will automatically attempt to read the version of the blueprint from it's
versionkey, and will default back to the Factorio version of the current environment if absent.While a nice quality of life feature for interacting with different Factorio versions, an excellent side effect of this functionality is the logical separation between the serialized external format(s) and the internal Python format:
Because conversions between different formats are now guaranteed anyway, it permits the internal Python representation to severely diverge from the exported dictionaries - which means that they can be structured in ways that are more natural or convenient to use, or even in a manner that is more performant. For example, just because the serialized form has to be a
list, doesn't mean that we couldn't use adictfor faster lookups on Draftsman's side during blueprint creation/manipulation. Converting from adictto alistincurs some additional cost when creating the final blueprint string, sure - but this usually only ever happens once, while manipulating the blueprint prior can happen thousands, or even millions of times. Clearly, this will be an active source of potential optimizations once said optimization pass happens in the (hopefully) near future.Due to this design pattern shift however, the syntax for importing has changed - made clearer and more intuitive, but changed nonetheless. Instead of using the constructor, you now use
from_string()andfrom_dict()when importing from a external format:This now enlists a separate function for each distinct operation, rather than cramming importing and instance construction into the same syntactic spot:
For select circumstances, you may still be able to get away with the old
Entity(**json_dict)syntax, but since the Python structure is now logically separated from the external forms this has no guarantee of continuing to work in the future.Using
attrsinstead ofpydanticUnsatisfied with
pydanticas a validation solution, Draftsman 3.0 usesattrsandcattrs, a far simpler and sensical solution to handling the format conversions mentioned above. In addition, because everything is in readily apparent pure-python functions, altering the desired behavior is far more straightforward than the hackery needed to get Pydantic to behave. In addition, it's also likely that this switch introduced no performance regression, despite not having the Rust backend that Pydantic utilizes.Global Validation
Before, validation of certain Draftsman objects could be enabled/disabled via a pair of arguments passed to it's constructor:
Already this is confusing - what is the difference between
validateandvalidate_assignment? Why are they both provided to the constructor, but onlyvalidate_assignmentis available after construction? When does the conversion from a string literal to aValidationModetake place?And that is just considering the specification of the behavior - now consider the question of whether validation should recurse through a Draftsman object's children:
You can "cheat" and give each component their own validation 'flag', but then you now have to resolve between them:
After many conceptual headaches, I came to the conclusion that the only reasonable solution was to massively reduce complexity. No longer is validation specific to certain Draftsman objects - now, it is a single global flag which affects all Draftsman behavior:
This is far simpler and easier to intuit, while largely retaining almost all of the flexibility of the old system. You can use
validators.get_mode()to query the current validation value, andset_mode()can be used as a context manager to temporarily change the validation mode for a specific code block:If more flexibility is needed, expanding this system will be far easier than fixing the old one.
Removed
__factorio_version__and__factorio_version_info__Instead, users should use
draftsman.data.mods.versions["base"], which is guaranteed to update when the environment updates during script execution. If this value is not present due to a missing or corrupted environment, users can fallback todraftsman.DEFAULT_FACTORIO_VERSION.tilesis now added toGroupUsers can now add tiles to Groups in the same way as entities, which are ultimately flattened to a 1-dimensional structure when exporting. In order to resolve this change, the
entitiesarray is no longer the place to storeGroupinstances - instead, users should use thegroupsattribute:This makes the tree structure more explicit, and prevents users from having to access nested tiles like
blueprint.entities[...].tiles[...], which would be rather confusing.However, while the nested accessing is gone from
EntityList, you can still use tuples ofint/strto represent entity "paths" for things likeadd_circuit_connection()and similar:Additional Minor Features/Fixes
InventoryTypeenumeration for specifying item requests to specific inventory spots.Beta Was this translation helpful? Give feedback.
All reactions