Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: JSON Inheritance  (Read 2212 times)

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
JSON Inheritance
« on: July 28, 2017, 11:53:25 AM »

I'd like JSONS to be able to Inherit, rather than id.equals --> overwrite.  Basically, if id.equals, then use JSONObject.has() to check the fields / JSONArrays that are present, and overwrite only where there isn't a match with the existing data. 

This works for Settings.json, but it doesn't work for .wpn, .proj, .ship, .skin, .variant etc.- the engine crashes if all of the required fields aren't present.  A "inherits" Boolean might be the way here.

This issue with how the JSONs are not inheritable, even though the data in the game is inherently able to support it, keeps coming up for me, now that I'm not working on a TC where I can control all the data going in. 

Inheritance might produce weird results depending on load-order (something I've also had to work around, and honestly I think should get addressed, but it's a much bigger feature request) but I feel that it's preferable to the alternative, where Mod X wants to tweak Variable A but Mod Y wants to tweak Variable B, with no conflicts between them, other than the engine
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: JSON Inheritance
« Reply #1 on: July 28, 2017, 12:06:51 PM »

This works for Settings.json, but it doesn't work for .wpn, .proj, .ship, .skin, .variant etc.- the engine crashes if all of the required fields aren't present.

Are you sure? Taking a quick look at .wpn file loading, the game does the same thing as it does for settings and merges stuff. Same for skins and ships and variants.

Doesn't seem to for projectiles, though - fixed that up.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: JSON Inheritance
« Reply #2 on: July 28, 2017, 01:09:09 PM »

I just tried it for a .wpn here:

Code
{
"id":"annihilator",

"projectileSpecId":"annihilator_rocket2",

}

Game crashes; says that specClass can't be found.

This is basically what I'm looking for, btw; just altering the key lines, leaving the rest of the data at Vanilla values (partly future-proofing of the FX system where that's practical).
« Last Edit: July 28, 2017, 01:11:53 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: JSON Inheritance
« Reply #3 on: July 28, 2017, 01:39:16 PM »

Maybe it's complaining about annihilator_rocket2 not being found?

(If you could knock together a mini-mod to reproduce the crash, I'd love to take a look.)
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: JSON Inheritance
« Reply #4 on: July 29, 2017, 10:30:50 AM »

Definitely not that.  I'll put one together immediately :)
Logged
Please check out my SS projects :)
Xeno's Mod Pack

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: JSON Inheritance
« Reply #5 on: July 29, 2017, 12:44:42 PM »

OK, here's a mod that demonstrates this.  Causes a crash if loaded with just Vanilla here.
« Last Edit: July 29, 2017, 12:47:09 PM by xenoargh »
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: JSON Inheritance
« Reply #6 on: July 29, 2017, 01:29:41 PM »

Getting an http 500 trying to download it.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: JSON Inheritance
« Reply #7 on: July 30, 2017, 06:34:31 AM »

Oops.  Fixed!
Logged
Please check out my SS projects :)
Xeno's Mod Pack

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24114
    • View Profile
Re: JSON Inheritance
« Reply #8 on: July 30, 2017, 09:49:14 AM »

Aha, thank you! It was broken further up the line than I was looking - it was indeed trying to merge files, but was using absolute paths (rather than relative to mod location) and so was only finding one copy of said files. Fixed it up across the board - variants, hulls, skills, weapons, projectiles.
Logged

xenoargh

  • Admiral
  • *****
  • Posts: 5078
  • naively breaking things!
    • View Profile
Re: JSON Inheritance
« Reply #9 on: July 30, 2017, 12:37:32 PM »

Thank you!  That will mean I can get rid of a ton of hassles  ;)
Logged
Please check out my SS projects :)
Xeno's Mod Pack