Exemplo n.º 1
0
        bool TryGetEntityFlowNodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var nodeRegistrationParams = new EntityFlowNodeRegistrationParams();

            var curEntityType = type.GetGenericArguments(typeof(EntityFlowNode <>)).ElementAt(0);

            nodeRegistrationParams.entityName = curEntityType.Name;

            var entType = typeof(EntityBase);

            // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality.
            while (curEntityType != entType)
            {
                EntityAttribute entAttribute;
                if (curEntityType.TryGetAttribute(out entAttribute))
                {
                    // don't override if the type before this (or earlier) changed it.
                    if (nodeRegistrationParams.entityName == null)
                    {
                        nodeRegistrationParams.entityName = entAttribute.Name;
                    }
                }

                curEntityType = curEntityType.BaseType;
            }

            var inputs  = new Dictionary <InputPortConfig, MethodInfo>();
            var outputs = new Dictionary <OutputPortConfig, MemberInfo>();

            var nodeType = type;

            while (nodeType != typeof(FlowNode))
            {
                TryGetFlowNodePorts(nodeType, ref inputs, ref outputs);

                nodeType = nodeType.BaseType;
            }

            if (inputs.Count == 0 && outputs.Count == 0)
            {
                return(false);
            }

            nodeRegistrationParams.InputPorts  = inputs.Keys.ToArray();
            nodeRegistrationParams.OutputPorts = outputs.Keys.ToArray();

            nodeRegistrationParams.InputMethods  = inputs.Values.ToArray();
            nodeRegistrationParams.OutputMembers = outputs.Values.ToArray();

            registrationParams = nodeRegistrationParams;

            return(true);
        }
Exemplo n.º 2
0
        bool TryGetGamemodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var gamemodeRegistrationParams = new GameRulesRegistrationParams();

            GameRulesAttribute gamemodeAttribute;

            if (type.TryGetAttribute(out gamemodeAttribute))
            {
                if (!string.IsNullOrEmpty(gamemodeAttribute.Name))
                {
                    gamemodeRegistrationParams.name = gamemodeAttribute.Name;
                }

                gamemodeRegistrationParams.defaultGamemode = gamemodeAttribute.Default;
            }

            registrationParams = gamemodeRegistrationParams;

            return(true);
        }
Exemplo n.º 3
0
        public IScriptRegistrationParams GetRegistrationParams(ScriptType scriptType, Type type)
        {
            IScriptRegistrationParams registrationParams = null;

            if ((scriptType & ScriptType.Actor) == ScriptType.Actor)
            {
                registrationParams = TryGetActorParams(type, scriptType);
            }
            else if ((scriptType & ScriptType.GameRules) == ScriptType.GameRules)
            {
                registrationParams = TryGetGamemodeParams(type);
            }
            else if ((scriptType & ScriptType.Entity) == ScriptType.Entity)
            {
                registrationParams = TryGetEntityParams(type);
            }
            else if ((scriptType & ScriptType.EntityFlowNode) == ScriptType.EntityFlowNode)
            {
                registrationParams = TryGetEntityFlowNodeParams(type);
            }
            else if ((scriptType & ScriptType.FlowNode) == ScriptType.FlowNode)
            {
                registrationParams = TryGetFlowNodeParams(type);
            }

            if ((scriptType & ScriptType.CryScriptInstance) == ScriptType.CryScriptInstance)
            {
                foreach (var member in type.GetMethods(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public))
                {
                    ConsoleCommandAttribute attribute;
                    if (member.TryGetAttribute(out attribute))
                    {
                        ConsoleCommand.Register(attribute.Name ?? member.Name, Delegate.CreateDelegate(typeof(ConsoleCommandDelegate), member) as ConsoleCommandDelegate, attribute.Comment, attribute.Flags);
                    }
                }
            }

            return(registrationParams);
        }
Exemplo n.º 4
0
        bool TryGetGamemodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var gamemodeRegistrationParams = new GameRulesRegistrationParams();

            GameRulesAttribute gamemodeAttribute;
            if (type.TryGetAttribute(out gamemodeAttribute))
            {
                if (!string.IsNullOrEmpty(gamemodeAttribute.Name))
                    gamemodeRegistrationParams.name = gamemodeAttribute.Name;

                gamemodeRegistrationParams.defaultGamemode = gamemodeAttribute.Default;
            }

            registrationParams = gamemodeRegistrationParams;

            return true;
        }
Exemplo n.º 5
0
        bool TryGetFlowNodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            if (!type.GetMembers().Any(member => member.ContainsAttribute<PortAttribute>()))
                return false;

            var nodeRegistrationParams = new FlowNodeRegistrationParams();

            FlowNodeAttribute nodeInfo;
            if (type.TryGetAttribute(out nodeInfo))
            {
                if (!string.IsNullOrEmpty(nodeInfo.UICategory))
                    nodeRegistrationParams.category = nodeInfo.UICategory;

                if (!string.IsNullOrEmpty(nodeInfo.Name))
                    nodeRegistrationParams.name = nodeInfo.Name;
            }

            registrationParams = nodeRegistrationParams;

            return true;
        }
Exemplo n.º 6
0
        bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var entityRegistrationParams = new EntityRegistrationParams();

            //LoadFlowNode(ref script, true);

            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var folders = type.GetNestedTypes(flags).Where(x => x.ContainsAttribute<EditorPropertyFolderAttribute>());
            var members = type.GetMembers(flags);
            var entityProperties = new List<object>();

            EntityProperty property;
            members.ForEach(member =>
                {
                    if (TryGetProperty(member, out property))
                        entityProperties.Add(property);
                });

            folders.ForEach(folder =>
                {
                    folder.GetMembers().ForEach(member =>
                        {
                            if (TryGetProperty(member, out property))
                            {
                                property.folder = folder.Name;
                                entityProperties.Add(property);
                            }
                        });
                });

            entityRegistrationParams.properties = entityProperties.ToArray();

            EntityAttribute entAttribute;
            if (type.TryGetAttribute(out entAttribute))
            {
                entityRegistrationParams.name = entAttribute.Name;

                var curType = type;

                var entType = typeof(Entity);
                while (curType != entType)
                {
                    if (type.TryGetAttribute(out entAttribute))
                    {
                        // don't override if the type before this (or earlier) changed it.
                        if(entityRegistrationParams.category == null)
                            entityRegistrationParams.category = entAttribute.Category;
                        if(entityRegistrationParams.editorHelper == null)
                            entityRegistrationParams.editorHelper = entAttribute.EditorHelper;
                        if(entityRegistrationParams.editorIcon  == null)
                            entityRegistrationParams.editorIcon = entAttribute.Icon;
                        if(entityRegistrationParams.flags == EntityClassFlags.Default)
                            entityRegistrationParams.flags = entAttribute.Flags;
                    }

                    curType = curType.BaseType;

                }
            }

            registrationParams = entityRegistrationParams;

            return true;
        }
Exemplo n.º 7
0
        bool TryGetActorParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var actorRegistrationParams = new ActorRegistrationParams();

            registrationParams = actorRegistrationParams;

            return true;
        }
Exemplo n.º 8
0
        bool TryGetFlowNodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var nodeRegistrationParams = new FlowNodeRegistrationParams();

            var inputs = new Dictionary<InputPortConfig, MethodInfo>();
            var outputs = new Dictionary<OutputPortConfig, MemberInfo>();

            var setFilter = false;
            var setTargetEntity = false;
            var setType = false;

            var nodeType = type;
            while (nodeType != typeof(FlowNode))
            {
                FlowNodeAttribute nodeAttribute;
                if (nodeType.TryGetAttribute(out nodeAttribute))
                {
                    if(nodeRegistrationParams.category == null)
                        nodeRegistrationParams.category = nodeAttribute.Category;
                    if (nodeRegistrationParams.name == null)
                        nodeRegistrationParams.name = nodeAttribute.Name;
                    if (nodeRegistrationParams.description == null)
                        nodeRegistrationParams.description = nodeAttribute.Description;

                    if (!setFilter)
                    {
                        nodeRegistrationParams.filter = nodeAttribute.Filter;
                        setFilter = true;
                    }
                    if (!setTargetEntity)
                    {
                        nodeRegistrationParams.hasTargetEntity = nodeAttribute.TargetsEntity;
                        setTargetEntity = true;
                    }
                    if (!setType)
                    {
                        nodeRegistrationParams.type = nodeAttribute.Type;
                        setType = true;
                    }
                }

                TryGetFlowNodePorts(nodeType, ref inputs, ref outputs);

                nodeType = nodeType.BaseType;
            }

            if (inputs.Count == 0 && outputs.Count == 0)
                return false;

            nodeRegistrationParams.InputPorts = inputs.Keys.ToArray();
            nodeRegistrationParams.OutputPorts = outputs.Keys.ToArray();

            nodeRegistrationParams.InputMethods = inputs.Values.ToArray();
            nodeRegistrationParams.OutputMembers = outputs.Values.ToArray();

            registrationParams = nodeRegistrationParams;

            return true;
        }
Exemplo n.º 9
0
        bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var entityRegistrationParams = new EntityRegistrationParams();

            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var members = type.GetMembers(flags);
            var entityProperties = new Dictionary<string, List<EditorProperty>>();

            members.ForEach(member => TryGetEntityProperty(member, ref entityProperties));

            int numProperties = entityProperties.Count;
            if (numProperties > 0)
            {
                var folders = new EditorPropertyFolder[numProperties];

                for (int i = 0; i < numProperties; i++)
                {
                    var folderPair = entityProperties.ElementAt(i);
                    var folder = new EditorPropertyFolder();

                    folder.name = folderPair.Key;
                    folder.properties = folderPair.Value.Cast<object>().ToArray();

                    folders[i] = folder;
                }

                entityRegistrationParams.propertyFolders = folders.Cast<object>().ToArray();
            }

            var curType = type;

            bool changedFlags = false;

            var entType = typeof(Entity);
            // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality.
            while (curType != entType)
            {
                EntityAttribute entAttribute;
                if (curType.TryGetAttribute(out entAttribute))
                {
                    // don't override if the type before this (or earlier) changed it.
                    if (entityRegistrationParams.name == null)
                        entityRegistrationParams.name = entAttribute.Name;
                    if (entityRegistrationParams.category == null)
                        entityRegistrationParams.category = entAttribute.Category;
                    if (entityRegistrationParams.editorHelper == null)
                        entityRegistrationParams.editorHelper = entAttribute.EditorHelper;
                    if (entityRegistrationParams.editorIcon == null)
                        entityRegistrationParams.editorIcon = entAttribute.Icon;
                    if (!changedFlags)
                    {
                        entityRegistrationParams.flags = entAttribute.Flags;
                        changedFlags = true;
                    }
                }

                curType = curType.BaseType;
            }

            registrationParams = entityRegistrationParams;

            return true;
        }
Exemplo n.º 10
0
        bool TryGetEntityFlowNodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var nodeRegistrationParams = new EntityFlowNodeRegistrationParams();

            var curEntityType = type.GetGenericArguments(typeof(EntityFlowNode<>)).ElementAt(0);
            nodeRegistrationParams.entityName = curEntityType.Name;

            var entType = typeof(EntityBase);

            // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality.
            while (curEntityType != entType)
            {
                EntityAttribute entAttribute;
                if (curEntityType.TryGetAttribute(out entAttribute))
                {
                    // don't override if the type before this (or earlier) changed it.
                    if (nodeRegistrationParams.entityName == null)
                        nodeRegistrationParams.entityName = entAttribute.Name;
                }

                curEntityType = curEntityType.BaseType;
            }

            var inputs = new Dictionary<InputPortConfig, MethodInfo>();
            var outputs = new Dictionary<OutputPortConfig, MemberInfo>();

            var nodeType = type;
            while (nodeType != typeof(FlowNode))
            {
                TryGetFlowNodePorts(nodeType, ref inputs, ref outputs);

                nodeType = nodeType.BaseType;
            }

            if (inputs.Count == 0 && outputs.Count == 0)
                return false;

            nodeRegistrationParams.InputPorts = inputs.Keys.ToArray();
            nodeRegistrationParams.OutputPorts = outputs.Keys.ToArray();

            nodeRegistrationParams.InputMethods = inputs.Values.ToArray();
            nodeRegistrationParams.OutputMembers = outputs.Values.ToArray();

            registrationParams = nodeRegistrationParams;

            return true;
        }
Exemplo n.º 11
0
        bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var entityRegistrationParams = new EntityRegistrationParams();

            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var folders = type.GetNestedTypes(flags).Where(x => x.ContainsAttribute<EditorPropertyFolderAttribute>());
            var members = type.GetMembers(flags);
            var entityProperties = new List<object>();

            EntityProperty property;
            members.ForEach(member =>
                {
                    if (TryGetEntityProperty(member, out property))
                        entityProperties.Add(property);
                });

            folders.ForEach(folder =>
                {
                    folder.GetMembers().ForEach(member =>
                        {
                            if (TryGetEntityProperty(member, out property))
                            {
                                property.folder = folder.Name;
                                entityProperties.Add(property);
                            }
                        });
                });

            entityRegistrationParams.properties = entityProperties.ToArray();

            var curType = type;

            bool changedFlags = false;

            var entType = typeof(Entity);
            // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality.
            while (curType != entType)
            {
                EntityAttribute entAttribute;
                if (curType.TryGetAttribute(out entAttribute))
                {
                    // don't override if the type before this (or earlier) changed it.
                    if (entityRegistrationParams.name == null)
                        entityRegistrationParams.name = entAttribute.Name;
                    if (entityRegistrationParams.category == null)
                        entityRegistrationParams.category = entAttribute.Category;
                    if (entityRegistrationParams.editorHelper == null)
                        entityRegistrationParams.editorHelper = entAttribute.EditorHelper;
                    if (entityRegistrationParams.editorIcon == null)
                        entityRegistrationParams.editorIcon = entAttribute.Icon;
                    if (!changedFlags)
                    {
                        entityRegistrationParams.flags = entAttribute.Flags;
                        changedFlags = true;
                    }
                }

                curType = curType.BaseType;
            }

            registrationParams = entityRegistrationParams;

            return true;
        }
Exemplo n.º 12
0
        IEnumerable <CryScript> ProcessAssembly(Assembly assembly)
        {
            if (assembly == null)
            {
                yield break;
            }

            foreach (var type in assembly.GetTypes())
            {
                IScriptRegistrationParams registrationParams = null;

                CryScript script;
                if (!type.ContainsAttribute <ExcludeFromCompilationAttribute>() && CryScript.TryCreate(type, out script))
                {
                    if (script.ScriptType.ContainsFlag(ScriptType.Actor))
                    {
                        TryGetActorParams(ref registrationParams, script.Type);
                    }
                    else if (script.ScriptType.ContainsFlag(ScriptType.GameRules))
                    {
                        TryGetGamemodeParams(ref registrationParams, script.Type);
                    }
                    else if (script.ScriptType.ContainsFlag(ScriptType.Entity))
                    {
                        TryGetEntityParams(ref registrationParams, script.Type);
                    }
                    else if (script.ScriptType.ContainsFlag(ScriptType.EntityFlowNode))
                    {
                        if (!TryGetEntityFlowNodeParams(ref registrationParams, script.Type))
                        {
                            continue;
                        }
                    }
                    else if (script.ScriptType.ContainsFlag(ScriptType.FlowNode))
                    {
                        if (!TryGetFlowNodeParams(ref registrationParams, script.Type))
                        {
                            continue;
                        }
                    }

                    if (script.ScriptType.ContainsFlag(ScriptType.CryScriptInstance))
                    {
                        foreach (var member in type.GetMethods(BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.Public))
                        {
                            ConsoleCommandAttribute attribute;
                            if (member.TryGetAttribute(out attribute))
                            {
                                ConsoleCommand.Register(attribute.Name ?? member.Name, Delegate.CreateDelegate(typeof(ConsoleCommandDelegate), member as MethodInfo) as ConsoleCommandDelegate, attribute.Comment, attribute.Flags);
                            }
                        }
                    }

                    script.RegistrationParams = registrationParams;

                    yield return(script);
                }

                if (type.ContainsAttribute <TestCollectionAttribute>())
                {
                    var ctor = type.GetConstructor(Type.EmptyTypes);
                    if (ctor != null)
                    {
                        var collection = new TestCollection
                        {
                            Instance = ctor.Invoke(Type.EmptyTypes),
                            Tests    = from method in type.GetMethods()
                                       where method.ContainsAttribute <TestAttribute>() &&
                                       method.GetParameters().Length == 0
                                       select method
                        };

                        TestManager.TestCollections.Add(collection);
                    }
                }
            }
        }
Exemplo n.º 13
0
        bool TryGetFlowNodeParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var nodeRegistrationParams = new FlowNodeRegistrationParams();

            var inputs  = new Dictionary <InputPortConfig, MethodInfo>();
            var outputs = new Dictionary <OutputPortConfig, MemberInfo>();

            var setFilter       = false;
            var setTargetEntity = false;
            var setType         = false;

            var nodeType = type;

            while (nodeType != typeof(FlowNode))
            {
                FlowNodeAttribute nodeAttribute;
                if (nodeType.TryGetAttribute(out nodeAttribute))
                {
                    if (nodeRegistrationParams.category == null)
                    {
                        nodeRegistrationParams.category = nodeAttribute.Category;
                    }
                    if (nodeRegistrationParams.name == null)
                    {
                        nodeRegistrationParams.name = nodeAttribute.Name;
                    }
                    if (nodeRegistrationParams.description == null)
                    {
                        nodeRegistrationParams.description = nodeAttribute.Description;
                    }

                    if (!setFilter)
                    {
                        nodeRegistrationParams.filter = nodeAttribute.Filter;
                        setFilter = true;
                    }
                    if (!setTargetEntity)
                    {
                        nodeRegistrationParams.hasTargetEntity = nodeAttribute.TargetsEntity;
                        setTargetEntity = true;
                    }
                    if (!setType)
                    {
                        nodeRegistrationParams.type = nodeAttribute.Type;
                        setType = true;
                    }
                }

                TryGetFlowNodePorts(nodeType, ref inputs, ref outputs);

                nodeType = nodeType.BaseType;
            }

            if (inputs.Count == 0 && outputs.Count == 0)
            {
                return(false);
            }

            nodeRegistrationParams.InputPorts  = inputs.Keys.ToArray();
            nodeRegistrationParams.OutputPorts = outputs.Keys.ToArray();

            nodeRegistrationParams.InputMethods  = inputs.Values.ToArray();
            nodeRegistrationParams.OutputMembers = outputs.Values.ToArray();

            registrationParams = nodeRegistrationParams;

            return(true);
        }
Exemplo n.º 14
0
        bool TryGetEntityParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            var entityRegistrationParams = new EntityRegistrationParams();

            BindingFlags flags            = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            var          members          = type.GetMembers(flags);
            var          entityProperties = new Dictionary <string, List <EditorProperty> >();

            members.ForEach(member => TryGetEntityProperty(member, ref entityProperties));

            int numProperties = entityProperties.Count;

            if (numProperties > 0)
            {
                var folders = new EditorPropertyFolder[numProperties];

                for (int i = 0; i < numProperties; i++)
                {
                    var folderPair = entityProperties.ElementAt(i);
                    var folder     = new EditorPropertyFolder();

                    folder.name       = folderPair.Key;
                    folder.properties = folderPair.Value.Cast <object>().ToArray();

                    folders[i] = folder;
                }

                entityRegistrationParams.propertyFolders = folders.Cast <object>().ToArray();
            }

            var curType = type;

            bool changedFlags = false;

            var entType = typeof(Entity);

            // This should not be specific to entities, all scripts should be able to utilize this parent class attribute functionality.
            while (curType != entType)
            {
                EntityAttribute entAttribute;
                if (curType.TryGetAttribute(out entAttribute))
                {
                    // don't override if the type before this (or earlier) changed it.
                    if (entityRegistrationParams.name == null)
                    {
                        entityRegistrationParams.name = entAttribute.Name;
                    }
                    if (entityRegistrationParams.category == null)
                    {
                        entityRegistrationParams.category = entAttribute.Category;
                    }
                    if (entityRegistrationParams.editorHelper == null)
                    {
                        entityRegistrationParams.editorHelper = entAttribute.EditorHelper;
                    }
                    if (entityRegistrationParams.editorIcon == null)
                    {
                        entityRegistrationParams.editorIcon = entAttribute.Icon;
                    }
                    if (!changedFlags)
                    {
                        entityRegistrationParams.flags = entAttribute.Flags;
                        changedFlags = true;
                    }
                }

                curType = curType.BaseType;
            }

            registrationParams = entityRegistrationParams;

            return(true);
        }
Exemplo n.º 15
0
        bool TryGetActorParams(ref IScriptRegistrationParams registrationParams, Type type)
        {
            registrationParams = new ActorRegistrationParams();

            return(true);
        }