Open kryzeth opened 5 years ago
Data.Util.duplicate is old school code
See if this does what you want
Data(electric-mining-drill):copy('test-mining-drill)
No need to extend as Data handles all that
Keep in mind the Data Lib is still very much WIP (and looking for developers to assist!) and doesn't fully handle results in a lot of cases
Ah. That... completely changes how I have to do things. I wrote all of my current code on the assumption that I could edit the things before pushing them into the global table. At least I wasn't done yet, so rewriting everything won't be too bad, I suppose.
But yeah, Data.Util.duplicate was just the only thing I could find (and use) from the API. I still haven't figured out how to use the colon expressions, like the one you provided. Which also gives an error, but seems I just had to provide the data type (item, recipe, mining-drill, etc)
But it does seem to work as intended, setting the normal/expensive result properly.
Lua is just table references, Data.raw is nothing special just a table. data:extend is just a function with very limited error checking that puts your table into data.raw in the correct spot. You can push whatever you want to it. and as long as when you are finished pushing to it it has everything it needs you won't have a problem.
The colon is just a shortcut syntax it passes the table (Data or more realistly the table created by Data as its first argument)
Using what you are familiar with data:extend({my_entity})
is just a shortcut for data.extend(data, {my_entity})
local test_recipe = Data('electric-mining-drill', 'recipe'):copy('test-mining-drill')
-- Its created, and pushed but that doesn't mean we have to be done with it.
test_recipe.energy_required = 200
There are even shortcuts if needed (ps just examples not even sure if it supports everything I put here)
Data('electric-mining-drill', 'recipe'):copy('test-mining-drill'):set_field('energy_required', 200):add_flag('hidden').change_this = 2
Also Data can take a table in which case it doesnt need the second paramater as long as the table contains it (it also won't extend an already extended table, not that it matters)
Data(data.raw.recipe['electric-mining-drill']):copy('test-mining-drill') -- the copy will extend it.
Woah... that second example seems close to what I might need. So in that case, set_field is changing the value of 'energy_required', which is located within the newly created 'test-mining-drill' recipe? Hmm....
But wow, I never actually knew that. I just assumed data:extend({whatever}) was just the way Factorio added things. Thanks for the help! Also.. I also don't really use github, so not sure if I'm supposed to close this.. or something?
We can leave it open, I might actually update duplicate :P
Not sure if I'm not using it right, but when I try using duplicate on a recipe that has normal/expensive variants, the result of those normal/expensive recipes are not set to the new name, but kept as the old name.
However, when using duplicate on a simple recipe that does not have difficulty defined, it works as I think is intended, where the result is set to the new name. Example code below: