Skip to content
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

data module #9

Open
Choumiko opened this issue May 1, 2016 · 5 comments
Open

data module #9

Choumiko opened this issue May 1, 2016 · 5 comments

Comments

@Choumiko
Copy link
Contributor

Choumiko commented May 1, 2016

A module to allow easier data.raw manipulation:

 -- creates a new pole named my-op-pole based on big pole, changing mining result name as well
local op_pole = Data.copy("electric-pole", "big-electric-pole", "my-op-pole")
op_pole.wire_distance = 9001

local recipe = Data.copy("recipe", "big.electric-pole", "my-op-pole")
local item = Data.copy("item", "big.electric-pole", "my-op-pole")
-- could perform some checks, e.g. duplicate name
Data.extend{op_pole, recipe, item}
Data.add_unlock_to_tech("some-tech", recipe) -- or Data.add_unlock_to_tech("some-tech", "my-op-pole")

-- remove all 'references' to the item from data.raw
Data.remove("item", "name-to-remove")
--replace all 'references' to itemA with itemB
Data.replace("item", "itemA", "itemB")

Last 2 seem like edge cases

@Afforess
Copy link
Owner

Afforess commented May 3, 2016

Yes, definitely. I've written a few things like this before for Marathon. Data manipulation is often a pain, and it would be nice to have easy functions for.

@Afforess
Copy link
Owner

Afforess commented Jul 24, 2016

@Choumiko FYI, I recently started on this. I went with a jquery selector ... inspired solution. Here's the commit: bca9d78

Example:
Data.select("recipe:copper.*) -- selects all recipes matching copper.*
Recipe.select("copper.*) -- selects all recipes matching copper.*
Recipe.select("copper.*:ingredients:copper.*") -- selects all ingredients whose name matches 'copper.*' in recipes matching copper.*

@Afforess
Copy link
Owner

Afforess commented Jul 24, 2016

I also wrote a metatable that is dynamically assigned to the recipe fields 'ingredients' and 'results', which detects the layout of the item, and emulates the 'amount' and 'name' fields when the item object is an array, or emulates the '1' and '2' fields if the item is a table. This should allow modders to stop trying to write code for either way and detecting, and just use the named fields when accessing, but write the shorthand array when updating recipes.

@Afforess
Copy link
Owner

The very basics of this was added to 0.6.0, but more work needs to be done to support specific data structures.

https://github.com/Afforess/Factorio-Stdlib/releases/tag/0.6.0

@boweiliu
Copy link

boweiliu commented Mar 3, 2017

What's our progress so far? What remains to be done on this issue?

@Afforess Afforess added this to the Future Direction milestone May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants