AsherGlick / ResourceCalculator

A Video Game Resource Calculator
https://resourcecalculator.com
GNU General Public License v3.0
56 stars 30 forks source link

[ResourceRevamp] Item Name Field #78

Open AsherGlick opened 1 year ago

AsherGlick commented 1 year ago

Right now we have an awkward ordered dictionary of items in the resource list. This works purely because yaml, as a serialized data structure, is ordered. As a result we can parse it into code in an ordered manner. However if some other application parsed the file and then wrote the output, it may re-order the elements. Which is completely within-spec for the yaml file.

Additionally, searching for a particular item is very difficult in the current schema. If I am trying to find the Stone element I might search for Stone:, but that will return all the instances where stone is being used as a requirement Stone: -1. Even searching for two leading spaces will cause the same elements to be found. The only way to guarantee finding the item is by searching for the beginning of a line as well

r/$  Stone:/

Instead of using Stone as the key for a dictionary it should instead be a field within the element and the container should become an ordered array.

resources:
  Stone:
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Smelting
      requirements:
        Cobblestone: -1
        Fuel: -1

  Granite:
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Crafting
      requirements:
        Diorite: -1
        Nether Quartz: -1

Becomes

resources:
  - name: Stone
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Smelting
      requirements:
        Cobblestone: -1
        Fuel: -1

  - name: Granite
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Crafting
      requirements:
        Diorite: -1
        Nether Quartz: -1

This allows us to preserve the order of the items regardless of what parser is being used, and it gives us a much simpler way of finding the item we are looking for by searching for name: Stone