Modding Help What is the most efficient way to patch another mod?

Discussion in 'Starbound Modding' started by xaliber, Feb 10, 2017.

Tags:
  1. xaliber

    xaliber Scruffy Nerf-Herder

    Let's say there is a mod that adds a group of monster spawns with a .biome.patch, something like this

    Code:
    {
    "op":"add",
    "path":"/spawnProfile/groups/-",
    "value":{
            "select" : 5,
            "pool" : [
              [ 1, "monster1" ],
              [ 1, "monster2" ],
              [ 1, "monster3" ],
              [ 1, "monster4" ],
              [ 1, "monster5" ],
              [ 1, "monster6" ]
            ]
          }
    }
    
    I'd like to make a patch for that mod so monster4 won't appear.

    However, since the monsters are added into the array that way, I cannot know for sure in what array number those monster groups will appear. If the user is using another mod that also adds something into the groups array, this group can be the 5th in the array, or maybe the 7th, or who knows.

    I can't use

    Code:
    [ {
         "op": "remove",
         "path": "/spawnProfile/groups/5/pool/3"
    } ]
    
    Because I can't be certain if the monster group added by that mod is actually is the 5th order in the array.

    What would be the most efficient way to solve this problem, without making an exact copy of the mod (but without the monster4)?

    Can we use wildcard character (*) with the operation "test", to make the game search for any relevant value before applying the patch? So something like this:

    Code:
    [{
    "op": "test",
    "path": "/spawnProfile/groups/*/pool/3",
    "value": [ 01, "monster4" ]
    },{
    "op": "remove",
    "path": "/spawnProfile/groups/*/pool/3"
    }]
    
     
    Last edited: Feb 10, 2017
  2. bk3k

    bk3k Oxygen Tank

    I doubt a wildcard works, but by all means try it and report if * ? etc works. To my knowledge you can't do something like %value% either except in cases where scripts will replace %value% but not for patching purposes. Unfortunately with arrays I believe you'd need to do this.

    Code:
    [
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/0/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/0/pool/3"
        }
      ],
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/1/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/1/pool/3"
        }
      ],
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/2/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/2/pool/3"
        }
      ],
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/3/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/3/pool/3"
        }
      ],
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/4/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/4/pool/3"
        }
      ],
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/5/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/5/pool/3"
        }
      ],
      [
        {
        "op": "test",
        "path":"/spawnProfile/groups/6/pool/3/1",
        "value": "monster4"
        },
        {
        "op": "remove",
        "path": "/spawnProfile/groups/6/pool/3"
        }
      ]
    ]
    
    etc. At least patch batches allow you to attempt a copy/paste brute force assault. Not exactly "efficient" though.
    And alternatively to "remove" you could "replace" with the value you want.

    It would be cool if something like this was an option.

    Code:
      [
        {
        "op": "edit",
        "script":"/script/myMod/my_JSONeditor.lua",
        "arguments" : [ "/biomes/surface/alien.biome", "stupid_monster1" ]
        }
      ]
    Likely never going to happen as there is nothing in any JSON standard for this. And I suppose it would make more sense that if this option did exist, it would be js not lua.

    Anyhow you can read up on the patching here. Starbound does use an expansion to that which allows the batching I demonstrated. Namely nesting the patch array within another array such that any failure in the batch doesn't prevent the changes that other batches would apply. Also Starbound allows comments where in the official JSON standard foolishly removed them. Otherwise it should fallow that standard.
     
    Last edited: Feb 10, 2017
    xaliber and Cyel like this.
  3. xaliber

    xaliber Scruffy Nerf-Herder

    I've tested it, and as expected, wildcard doesn't seem to work. :/ That's a shame.

    The "brute force" method... not as efficient as needed, but at least it's a lot better than copying the entire mod folder just for a small patch haha. Thanks, bk3k!

    About performance though, do you know if that way will affect the game performance - since it test the value multiple times, would it make the game slower? I've tested around and played a while, generating one planet after another. It looked fine at a glance, but I'm not entirely sure how the game processes it...
     
  4. bk3k

    bk3k Oxygen Tank

    I don't think that would hurt performance aside from a very slight increase in initial load time.
     
    xaliber likes this.
  5. xaliber

    xaliber Scruffy Nerf-Herder

    Thanks very much then! This should suffice for the mean time. Kinda hoping the upcoming update also give more flexibility in modding haha.
     

Share This Page