-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block migrations to mitigate damage after block renames #1125
Add block migrations to mitigate damage after block renames #1125
Conversation
4b11aa7
to
8f57bbe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too complicated. A migration shouldn't have a type, or a name. And there should be only one file for it at the top level in the blocks/items/... directory, with a plain list of .@"old" = "new"
mappings.
Secondly I would like you to test renaming two files to the same id, this has happened in the past and will likely happen again (e.g. after #357).
And finally I wonder: Does this approach scale well? Do we now need to iterate through all player's inventories, through all chunks with chests in them? And from what I can tell you'd do that every time the world is loaded, not just once after an update.
Ok, I was thinking about it at it seems fine in most scenarios. Although it makes it so it is not possible to control order of migrations and this is strict many-to-one relation, so we can not reuse an ID we had before and handle this with migration. If I understand correctly, handling multiple renames of the block across multiple versions is possible, eg.: version 0:
version 1:
We just skip intermediate transitions. That is good for time complexity too.
You mean like when you merge two blocks into one? In theory it could work, but the result would be two numerical IDs mapping to same block name, I am not sure about the implications from game engine perspective, but you can't just shift palette to remove that gap.
It scales well as long as we use |
I have redesigned migrations to be an hash map loaded from @IntegratedQuantum please have look at this before I go and implement palette updates for items and biomes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate to do this, but this PR is too big which makes it difficult to review, I've had similarly sized PRs in the past and it always takes an eternity to review.
So please do the following:
- Move all the unrelated changes, such as reordering, reformatting and others into a separate PR
- Try to simplify your code if possible
- Try to split the functionality into smaller parts, e.g. here we could easily separate migration loading from applying the migrations.
Also somewhat related to that I'd suggest to read the contributing guidelines if you haven't already.
Well, I'm not sure about the implications either, that's why I want you to test it. |
02b43af
to
cd7e365
Compare
cd7e365
to
58d792d
Compare
There, I yeeted ~170 lines of unnecessary changes. I did read contribution guidelines. I am doing one feature, the feature is ID migrations. To implement and verify that I need to implement full flow at once. There was quite some unnecessary whitespace changes, I got rid of them. The rest I consider a necessary byproduct of my work, dictated by boy scout rule While reviewing you can mark files as Viewed (top right corner), so unless there are new changes / force pushes in those files, they will stay collapsed for consecutive reviews. There was a lot of changes since last review, but there was also significant shift in paradigm here. Sorry for doing the stupid thing first, I'm getting used to zig as I go. I don't agree with lack of style guidelines enforced by formatter, but I guess not my sandbox, not my rules. If you won't automate what is there to be automated you will always waste time disputing if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried this and I think there are 2 things that make it a bit awkward to use:
- The block always needs to be prefixed with
cubyz:
. This not only adds more noise, but also allows you to remap ids from another addon, which should be illegal in my opinion. - Having
source = destination
feels weird. I thinkdestination = source
is more natural, at least to me as a programmer. @ikabod-kee I'd like to hear your opinion on this.
I think that we should anticipate that migrations might be also useful for addons to alleviate their block changes. On top of that remapping vanilla blocks to custom blocks is also a feature, as this leaves an option to substitute stuff without rewriting all of the biome code. It's just that with great power comes great responsibility. |
Yeah, but the game re-adds all blocks that weren't found in the palette, so if an addon does this, then the palette grows with each launch. Now that I think about it, maybe we should only allow migrations if the source id isn't there anymore. That would prevent you from doing this accidentally. |
Oh but there is a problem with making it |
Also I don't agree it feels weird, as you are assigning Damn thinking about which side is source and which is destination makes me sick, you sure you don't want list of objects notation? 😝
|
Yeah, maybe the list of objects is the best approach to avoid any ambiguities. |
Back to (almost) initial implementation it is! (or rather will be :P) |
Yeah, on the user facing front it's pretty similar. |
fe21cec
to
199ed93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems good now, and it works, but there is still some work ahead:
- block migrations alone are not good enough without item migrations, these should be implemented before using block migrations for anything.
- allowing multiple block ids would be nice, this is also relevant if you accidentally opened the world after renaming, but before adding an entry to the migration table (in which case it has already created the new block with a separate id)
&tools, | ||
&biomes, | ||
&recipes, | ||
&models, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, how about adding a struct that stores all migrations and zon data, the struct could handle the init, deinit and clone operations, which would greatly simplify some of the code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is probably the way to go.
This pull request adds tracking mechanism for asset renaming / relocation. The name "migrations" was chosen because of similarity to database migrations produced by ORMs for chaning of table layout of exisiting databases.
TODO/CHANGELOG:
Usage
File
assets/cubyz/blocks/_migrations.zig.zon
allows to specify mapping from old ID to new ID. IDs do not include addon name, it is implied by location of_migrations.zig.zon
:progress towards #897