anegostudios / VintageStory-Issues

Vintage Story's public issue tracker for reporting bugs, crashes and the like
46 stars 16 forks source link

Inserting into arrays using asset patching doesn't work #2

Closed copygirl closed 6 years ago

copygirl commented 6 years ago

According to RFC 6902 linked in the 1.5.2 release post, inserting into arrays should be possible. This is kind of important if the order matters, which can be the case for block behaviors, for example

  • If the target location specifies an array index, a new value is inserted into the array at the specified index.

Example patch

File: assets/carrycapacity/patches/carryable.json

[
  { file: "game:blocktypes/wood/generic/chest", op: "add", path: "/behaviors/0", value: {
    name: "Carryable",
    properties: {
      translation: [ 0.0625, 0, 0 ],
      rotation: [ 0, 180, 0 ],
    }
  } }
]

Workaround

Can replace the entire array for now:

[
  { file: "game:blocktypes/wood/generic/chest", op: "replace", path: "/behaviors", value: [
    { name: "Carryable", properties: {
      translation: [ 0.0625, 0, 0 ],
      rotation: [ 0, 180, 0 ],
    } },
    { name: "Container" },
    { name: "HorizontalOrientable" },
  ] }
]
tyronx commented 6 years ago

Feel like fixing that @copygirl? It's this lib: https://github.com/tavis-software/Tavis.JsonPatch

milochristiansen commented 6 years ago

It appears the "add" operator does not work at all. The following patch:

[
    { file: "game:blocktypes/clay/bowl", op: "replace", path: "/variantgroups/0/states", value: ["raw", "burned", "honey", "soup"] },
    { file: "game:blocktypes/clay/bowl", op: "add", path: "/shapeByType/*-soup", value: { base: "game:block/clay/bowl-ground" } },
    { file: "game:blocktypes/clay/bowl", op: "add", path: "/texturesByType/*-soup", value: { content: { base: "block/cauldron/cauldroninside" } } },
    { file: "game:blocktypes/clay/bowl", op: "add", path: "/nutritionPropsByType/*-soup", value: { 
        saturation: 400, 
        health: 1,
        eatenStack: { type: "block", code: "game:bowl-burned" }
    } },
]

produces the following errors:

21.3.2018 18:54:25 [Error] Patch cauldron:patches/bowl.json: Patching of file game:blocktypes/clay/bowl.json failed because supplied path /shapeByType/*-soup is invalid: Cannot traverse beyond depth 1. Token *-soup was not found
21.3.2018 18:54:25 [Error] Patch cauldron:patches/bowl.json: Patching of file game:blocktypes/clay/bowl.json failed because supplied path /texturesByType/*-soup is invalid: Cannot traverse beyond depth 1. Token *-soup was not found
21.3.2018 18:54:25 [Error] Patch cauldron:patches/bowl.json: Patching of file game:blocktypes/clay/bowl.json failed because supplied path /nutritionPropsByType/*-soup is invalid: Cannot traverse beyond depth 1. Token *-soup was not found
tyronx commented 6 years ago

Is this still an issue @copygirl?

copygirl commented 6 years ago

Nope, from what I know and have tested it should work now!