public TemplateItem(string name, T value, TemplateValueType type) : base(name, type) { Value = value; }
public static TemplateValue MakeFromString(string input) { // string // float // int // bool // reference: basically just any plain old word // list(TemplateValueType) // map(TemplateValueType -> TemplateValueType) TemplateValueType type = TemplateValueType.TVT_Invalid; if (input == "string") { type = TemplateValueType.TVT_String; } else if (input == "float") { type = TemplateValueType.TVT_Float; } else if (input == "int") { type = TemplateValueType.TVT_Int; } else if (input == "bool") { type = TemplateValueType.TVT_Bool; } else if (ReferenceRegex.IsMatch(input)) { type = TemplateValueType.TVT_Reference; } else if (ListRegex.IsMatch(input)) { type = TemplateValueType.TVT_List; } else if (MapRegex.IsMatch(input)) { type = TemplateValueType.TVT_Map; } else { return(null); } string referencedType = null; TemplateValue keyType = null; TemplateValue valueType = null; switch (type) { case TemplateValueType.TVT_String: case TemplateValueType.TVT_Float: case TemplateValueType.TVT_Int: case TemplateValueType.TVT_Bool: break; case TemplateValueType.TVT_Reference: { referencedType = input; break; } case TemplateValueType.TVT_List: { int leftParenIndex = input.IndexOf('('); int rightParenIndex = input.LastIndexOf(')'); string rawListType = input.Substring(leftParenIndex, rightParenIndex - leftParenIndex); valueType = MakeFromString(rawListType); break; } case TemplateValueType.TVT_Map: { int leftParenIndex = input.IndexOf('('); int arrowIndex = input.IndexOf("->"); int rightParenIndex = input.LastIndexOf(')'); string rawMapKeyType = input.Substring(leftParenIndex, arrowIndex - leftParenIndex).Trim(); keyType = MakeFromString(rawMapKeyType); string rawMapValueType = input.Substring(arrowIndex + 2, rightParenIndex - (arrowIndex + 2)).Trim(); valueType = MakeFromString(rawMapValueType); break; } default: Debug.LogError("Invalid template value type."); return(null); } TemplateValue value = new TemplateValue(); value.Type = type; value.ReferencedType = referencedType; value.KeyType = keyType; value.ValueType = valueType; return(value); }
public TemplateItemBase(string name, TemplateValueType type) { Name = name; Type = type; }