示例#1
0
        private static Rememberer SetFloat(RuleSplit split, StateSource source)
        {
            var @float = float.Parse(split.Value);

            switch (split.Operator)
            {
            case '=':
                return((query) => Rememberers.Set(query, split.Key, @float, source));

            case '-':
                return((query) => Rememberers.SubtractFloat(query, split.Key, @float, source));

            case '+':
                return((query) => Rememberers.AddFloat(query, split.Key, @float, source));

            case '*':
                return((query) => Rememberers.MultiplyFloat(query, split.Key, @float, source));

            case '/':
                return((query) => Rememberers.DivideFloat(query, split.Key, @float, source));

            default:
                Debug.LogError($"Couldn't interpret criteria as float operation: {split}.");
                return(null);
            }
        }
示例#2
0
        private static Rememberer SetInt(RuleSplit split, StateSource source)
        {
            var @int = int.Parse(split.Value);

            switch (split.Operator)
            {
            case '=':
                return((query) => Rememberers.Set(query, split.Key, @int, source));

            case '-':
                return((query) => Rememberers.SubtractInt(query, split.Key, @int, source));

            case '+':
                return((query) => Rememberers.AddInt(query, split.Key, @int, source));

            case '*':
                Debug.LogError($"Integer multiplication not supported: {split}. Add a decimal.");
                return(null);

            case '/':
                Debug.LogError($"Integer division not supported: {split}. Add a decimal.");
                return(null);

            default:
                Debug.LogError($"Couldn't interpret criteria as int operation: {split}.");
                return(null);
            }
        }
示例#3
0
        private static Criterion IsFloat(RuleSplit split, StateSource source)
        {
            var f = float.Parse(split.Value);

            switch (split.Operator)
            {
            case '=':
                return((query) => Criteria.Equal(query, split.Key, f, source));

            case '>':
                return((query) => Criteria.GreaterThan(query, split.Key, f, source));

            case '<':
                return((query) => Criteria.LessThan(query, split.Key, f, source));

            case '!':
                return((query) => !Criteria.Equal(query, split.Key, f, source));

            default:
                Debug.LogError($"Couldn't interpret criteria as float operation: {split.Key}, {split.Operator}, {split.Value}.");
                return(null);
            }
        }
示例#4
0
        private static bool SplitOnOperator(int id, string raw, out RuleSplit split, params char[] operators)
        {
            var index = raw.IndexOfAny(operators);

            if (index == -1)
            {
                split = default;
                return(false);
            }

            var source = SourceCodes[raw[0]];
            var key    = raw.Substring(1, index - 1);
            var op     = raw[index];
            var value  = raw.Substring(index + 1);

            // Handle reserved words/characters
            {
                if (value.ToLowerInvariant() == "timestamp")
                {
                    value = Time.time.ToString();
                }
                else if (value.ToLowerInvariant() == "rule")
                {
                    value = id.ToString();
                }
            }

            split = new RuleSplit
            {
                Source   = source,
                Key      = key,
                Operator = op,
                Value    = value,
            };

            return(true);
        }
示例#5
0
        private static Rememberer SetBool(RuleSplit split, StateSource source)
        {
            var @bool = bool.Parse(split.Value);

            return((query) => Rememberers.Set(query, split.Key, @bool, source));
        }
示例#6
0
        private static Criterion IsBool(RuleSplit split, StateSource source)
        {
            var @bool = bool.Parse(split.Value);

            return((query) => Criteria.Equal(query, split.Key, @bool, source));
        }