Skip to content

Field & Optional params#2

Open
oryxoik wants to merge 1 commit intomainfrom
field-and-optional-params
Open

Field & Optional params#2
oryxoik wants to merge 1 commit intomainfrom
field-and-optional-params

Conversation

@oryxoik
Copy link
Collaborator

@oryxoik oryxoik commented Mar 28, 2025

  • fields can be exposed with CLProperty attribute

  • methods can have a CLParams parameter after the required ones to allow optional params
    e.g. void SpawnEffect(string effectName, Vector3 position, Vector3 rotation, float scale, CLParams optionalParams)
    CLParams is just a wrapper around the original parameters array that is passed from the evaluator and all it does is index that array with an offset

      public readonly struct CLParams
      {
          private readonly int _offset;
          private readonly object[] _args;
    
          public CLParams(int offset, object[] args)
          {
              _offset = offset;
              _args = args;
          }
    
          public int Length => _args.Length - _offset;
          
          public object this[int index] => _args[_offset + index];
    
          public T Get<T>(int index) => CustomLogicEvaluator.ConvertTo<T>(this[index]);
    
          public bool TryGet<T>(int index, out T value)
          {
              if (_offset + index >= _args.Length)
              {
                  value = default;
                  return false;
              }
    
              value = CustomLogicEvaluator.ConvertTo<T>(_args[_offset + index]);
              return true;
          }
      }

    Example:

          private void SpawnEffect(string effect, Vector3 position, Vector3 rotation, float scale, CLParams optionalParams)
          {
              if (optionalParams.TryGet<Color>(0, out var tsExplodeColor))
              {
                  // do stuff
              }
          }

@oryxoik oryxoik requested a review from AutumnThyme March 28, 2025 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant