static ImaginaryObject CreateImaginaryObject(Type type)
            {
                if (type.IsEditable())
                {
                    EditorData editorData = EditorData.GetEmpty();
                    EditableSystem.OpenEditor(type, ref editorData);
                    return(new ImaginaryEditableObject(type, editorData));
                }

                if (type.IsEnum)
                {
                    return(new ImaginaryEnum(type, SelectItem(Enum.GetNames(type))));
                }

                if (type.QualifiesAsPrimitive())
                {
                    return(new ImaginaryPrimitive(Convert.ChangeType(Console.ReadLine(), type)));
                }

                if (type.GetConstructors().Length > 0)
                {
                    return(new ImaginaryConstructableObject(type, GetConstructorParameters(type)));
                }

                return(new ImaginaryConstructableObject(type));
            }
            static ImaginaryScript CreateImaginaryScript(Type type)
            {
                if (type.IsEditable())
                {
                    EditorData editorData = EditorData.GetEmpty();
                    EditableSystem.OpenEditor(type, ref editorData);
                    return(new ImaginaryScript(new ImaginaryEditableObject(type, editorData)));
                }

                if (type.GetConstructors().Length > 0)
                {
                    return(new ImaginaryScript(new ImaginaryConstructableObject(type, GetConstructorParameters(type))));
                }

                return(new ImaginaryScript(new ImaginaryConstructableObject(type)));
            }
            static ImaginaryHierarchyObject CreateImaginaryHierarchyObject(ref ImaginaryHierarchyObject currentSelectedHierarchyObject, Type ofType)
            {
                if (ofType.IsEditable())
                {
                    EditorData editorData = EditorData.GetEmpty();
                    EditableSystem.OpenEditor(ofType, ref editorData);
                    return(new ImaginaryHierarchyObject(currentSelectedHierarchyObject,
                                                        new ImaginaryEditableObject(ofType, editorData)));
                }

                if (ofType.GetConstructors().Length > 0)
                {
                    return(new ImaginaryHierarchyObject(currentSelectedHierarchyObject,
                                                        new ImaginaryConstructableObject(ofType, GetConstructorParameters(ofType))));
                }

                return(new ImaginaryHierarchyObject(currentSelectedHierarchyObject,
                                                    new ImaginaryConstructableObject(ofType)));
            }
#pragma warning restore CA1031 // Do not catch general exception types
#endif
            static void Modify(ref ImaginaryHierarchyObject currentSelectedHierarchyObject, string toModify = null)
            {
                ImaginaryHierarchyObject hierarchyObjectToModify;

                if (string.IsNullOrEmpty(toModify))
                {
                    hierarchyObjectToModify = currentSelectedHierarchyObject;
                }
                else
                {
                    if (!currentSelectedHierarchyObject.LocalHierarchy.ContainsKey(toModify))
                    {
                        Output.ErrorLog($"command error: no HierarchyObject named {toModify} can be found!");
                        return;
                    }

                    hierarchyObjectToModify = currentSelectedHierarchyObject.LocalHierarchy[toModify];
                }

                if (AskYOrNQuestion(
                        $"Do you want to change the name of the HierarchyObject? Name = {GetName(hierarchyObjectToModify)}"))
                {
                    SetName(hierarchyObjectToModify, AskQuestion("Write the new name"));
                }

                if (hierarchyObjectToModify.ImaginaryObjectBase is ImaginaryEditableObject imaginaryEditableObject)
                {
                    EditableSystem.OpenEditor(imaginaryEditableObject.TypeData.GetConstructionType(),
                                              ref ((ImaginaryEditableObject)hierarchyObjectToModify.ImaginaryObjectBase).EditorData);
                }
                else if (hierarchyObjectToModify.ImaginaryObjectBase is ImaginaryConstructableObject
                         imaginaryConstructableObject)
                {
                    imaginaryConstructableObject.ImaginaryConstructionParameters =
                        GetConstructorParameters(imaginaryConstructableObject.TypeData.GetConstructionType());
                }
                else
                {
                    Output.ErrorLog(
                        $"{hierarchyObjectToModify.ImaginaryObjectBase.GetType()} cannot be modified using this tool.");
                }
            }
Example #5
0
 public override object CreateInstance() => EditableSystem.Create(TypeData.GetConstructionType(), EditorData);