Repository: 4ian/GDevelop
File: newIDE/app/src/PropertiesEditor/PropertiesMapToSchema.js (JavaScript)

Code before:
      name,
      valueType: 'textarea',
      getValue: (instance: Instance): string => {
        return getProperties(instance)
          .get(name)
          .getValue();
      },
      setValue: (instance: Instance, newValue: string) => {
        onUpdateProperty(instance, name, newValue);
      },
      getLabel,
      getDescription,
    };
  } else if(valueType ==='animationname')
    {
      function getChoices()
    {
      if(!object)
      { return [{value:"Object is not valid !", label:"Object is not valid !"}] }

      let animationArray = [];
      for(let i = 0; i < object.getConfiguration().getAnimationsCount(); i++ )
      {
          animationArray.push(object.getConfiguration().getAnimationName(i));
      }
        return animationArray.map(value => ({ value, label: value }));
   
    }
      return {
        name,
        valueType: 'string',
        getValue: (instance: Instance): string => {
          return getProperties(instance)
            .get(name)
            .getValue();
        },
        setValue: (instance: Instance, newValue: string) => {
          console.log(instance, name, newValue);
          onUpdateProperty(instance, name, newValue);
        },
        getLabel,
        getDescription,
        getChoices,
      }
    } 
    
  else {
    console.error(
      `A property with type=${valueType} could not be mapped to a field. Ensure that this type is correct and understood by the IDE.`
    );
    return null;

Review comment (suggestion):
You can use the `mapFor` fonction to shorten the code a bit.
The empty string should be added to the list.

Code after:
      name,
      valueType: 'textarea',
      getValue: (instance: Instance): string => {
        return getProperties(instance)
          .get(name)
          .getValue();
      },
      setValue: (instance: Instance, newValue: string) => {
        onUpdateProperty(instance, name, newValue);
      },
      getLabel,
      getDescription,
    };
  } else if (valueType === 'animationname') {
    return {
      getChoices: () => {
        if (!object) {
          return [];
        }
        const animationArray = mapFor(
          0,
          object.getConfiguration().getAnimationsCount(),
          i => {
            const animationName = object.getConfiguration().getAnimationName(i);
            if (animationName === '') {
              return null;
            }
            return {
              value: animationName,
              label: animationName,
            };
          }
        ).filter(Boolean);
        animationArray.push({ value: '', label: '(no animation)' });
        return animationArray;
      },
      name,
      valueType: 'string',
      getValue: (instance: Instance): string => {
        return getProperties(instance)
          .get(name)
          .getValue();
      },
      setValue: (instance: Instance, newValue: string) => {
        onUpdateProperty(instance, name, newValue);
      },
      getLabel,
    };
  } else {
    console.error(
      `A property with type=${valueType} could not be mapped to a field. Ensure that this type is correct and understood by the IDE.`