AsherGlick / ResourceCalculator

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

[ResourceRevamp] Disallow Native Comments #80

Open AsherGlick opened 1 year ago

AsherGlick commented 1 year ago

Several resource files contain native yaml comments in them. While having comments is great, they are not normally parsed by machines. This means that if a program were to consume and export this file all of the comments would be stripped out. #75 Intends to do just this. Additionally those comments could not be displayed to the users of the GUI. For the most part these comments are used in three situations:

There are likely other use cases, however these are the three that will be addressed now and others will be address ad-hoc.

The best solution is to convert these comments into fields that can be parsed and displayed to the GUI users. #78 is intending to replace the resources: dictionary with an array so we will assume this work has already been completed for the following examples.

# A recipe list for craftmine, not to be confused with another popular game.
resources:
  # Rocky Resources
  - name: Stone
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Smelting
      requirements:
        Cobblestone: -1
        Fuel: -1

  # Granite-y resources
  # Granite says it is made by crafting here, but really it is Ethereal Smelting. Which is not yet supported
  - name: Granite
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Crafting
      requirements:
        Diorite: -1
        Nether Quartz: -1

becomes

comment: A recipe list for craftmine, not to be confused with another popular game.
resources:
  - comment: Rocky Resources
  - name: Stone
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Smelting
      requirements:
        Cobblestone: -1
        Fuel: -1

  - comment: Granite-y resources
  - name: Granite
    comment: Granite says it is made by crafting here, but really it is Ethereal Smelting. Which is not yet supported
    recipes:
    - recipe_type: Raw Resource
    - output: 1
      recipe_type: Crafting
      requirements:
        Diorite: -1
        Nether Quartz: -1

While a little less visually distinct from the native comments we have now increased compatibility with machine parsers, allowed this datum to be translated to json and back, and allowed the future GUI Editor to benefit from comments.

Using - comment: in the resources list was decided over using a recursing - group: style syntax because this method was simpler and made less assumptions about how the resources file should be structured.

After this change the linter will begin to print warnings when it discovers a native comment (if possible).