Factorio-Stdlib icon indicating copy to clipboard operation
Factorio-Stdlib copied to clipboard

data module

Open Choumiko opened this issue 8 years ago • 5 comments

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

Choumiko avatar May 01 '16 20:05 Choumiko

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 avatar May 03 '16 03:05 Afforess

@Choumiko FYI, I recently started on this. I went with a jquery selector ... inspired solution. Here's the commit: https://github.com/Afforess/Factorio-Stdlib/commit/bca9d7886b28137995133d90ba97a840d1ce143a

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 avatar Jul 24 '16 15:07 Afforess

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 avatar Jul 24 '16 15:07 Afforess

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

Afforess avatar Jul 31 '16 17:07 Afforess

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

boweiliu avatar Mar 03 '17 08:03 boweiliu