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); } }
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); } }
private static Rememberer InterpretRememberCode(int id, string code) { if (SplitOnOperator(id, code, out var split, '=', '-', '+', '*', '/')) { if (split.Source == StateSource.Custom) { return(CustomRemember(code)); } var source = split.Source; var key = split.Key; var value = split.Value; var op = split.Operator; if (op == '=' && value == "true" || value == "false") { // Bool assignment. return(SetBool(split, source)); } else if (value.Contains('.')) { // Check for a number // Any value containing a decimal is a float manipulation. return(SetFloat(split, source)); } else if (value.All(char.IsDigit)) { // A value containing all digits is an int manipulation. return(SetInt(split, source)); } else if (op == '=') { // String assignment. return((query) => Rememberers.Set(query, split.Key, split.Value, source)); } } Debug.LogError($"Failed to interpret criteria: {code}."); return(null); }
private static Rememberer SetBool(RuleSplit split, StateSource source) { var @bool = bool.Parse(split.Value); return((query) => Rememberers.Set(query, split.Key, @bool, source)); }