Suppose we have the following list:

createInstance = {import:create-instance-plugin}

person
  name = [this.nameList]
  nameList
    Salman
    Manny
    Rhian
  age = {31-49}
  child = [this.child_obj]
  child_obj
    name = [this.nameList]
    nameList
      Anne
      Arram
      Amelia
    age = {3-17}

If we output:

[p = createInstance(person, "deep"), p.name] [p.age] [p.name] [p.age]

We can see that it has fixed the name and the age property on the instance. However, if we output:

[p = createInstance(person, "deep"), p.child.name] [p.child.age] [p.child.name] [p.child.age]

It would throw undefined. Now looking at similar list:

person
  name = {Salman|Manny|Rhian}
  age = {31-49}
  child = [this.child_obj]
  child_obj
    name = {Anne|Arram|Amelia}
    age = {3-17}

output
  [p = createInstance(person, "deep"), p.child.name] [p.child.age] [p.child.name] [p.child.age]

This would have the values fixed and working.

Looking at the code of the create-instance-plugin, it would only allow the ‘deep’ fixing of properties if there isn’t any items/lists in it. What that means is the following:

child_obj
  name = [this.nameList]
  nameList
    Anne
    Arram
    Amelia
  age = {3-17}

This object/list, has a list ( nameList) within it as well as properties (name and age), while:

child_obj
  name = {Anne|Arram|Amelia}
  age = {3-17}

Only has properties. and based on Line 22 of the create-instance-plugin:

...
} else if(propValue.getPropertyKeys && propValue.getPropertyKeys.length > 0 && propValue.getLength === 0) {
...

If the list to be fixed has a list within it other than the properties i.e. propValue.getLength is not zero, then it wouldn’t fix the properties within it.

The first child_obj has a nameList with it, and upon calling propValue.getLength it would have 1 while the second child_obj will return a propValue.getLength of 0 since it doesn’t have any lists.

Thus, the solution for the problem is just removing the propValue.getLength === 0 check OR create another check without it.


TLDR; propValue.getLength === 0 at Line 22 of the create-instance-plugin can be removed to allow properties that rely on same level lists to be fixed. Here is the demo of the problem with a ‘remixed’ create instance plugin with the fix.

  • perchance@lemmy.worldM
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    6 months ago

    Hmm, I think I misunderstood some stuff with my earlier comments. With the caveat that this is frying my brain a little, I think there are cases that this change would break - e.g. https://perchance.org/bm1vp6py5a#edit Try swapping the plugin import to see the behavior change.

    If it turns out it isn’t really possible to fix this issue, then it may be time for me to make a new plugin which fixes this issue and some others, and perhaps introduces some handy features that people tend to need. Let me know if you have any requests in that department - e.g. everything gets fixed by default, but if a property name begins with * (or something), like *foo, then character.foo would be a random property, instead of being fixed/resolved. And another thing I think is to call evaluateItem after selectOne if the selected item has no children. Not sure though - would definitely need feedback on this from people who use the plugin extensively.

    Another alternative is to just add an extra “mode” to create-instance-plugin (like the existing "deep" one), which fixes all the issues and makes everything intuitive, but that might make it a bit more complicated and cumbersome, since the behavior would vary so much, which could be confusing to newbies.

    • VioneT@lemmy.worldOPM
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      6 months ago

      Okay, might be too crazy now but, if the list has a list propValue.getLength > 0, we can do a .selectOne to it, then re-apply the previous properties to it. Meaning, it would have one ‘list’ value, but it would still have the previous properties.

      You can check the code here: https://perchance.org/hxoknecflu

      But if that might break more generators, then probably a new instance plugin might be good XDDDDD.

      Edit: it might still be breaking generators, since if the item that was .selectOneed is a list, then it would still randomize and not be fixed: See the [p.child.testing] in this generator: https://perchance.org/vnm320e3k6#edit