Esempio n. 1
0
        public void AddEntity(Entity entity)
        {
            // Made with a lot of help from stack overflow

            entities.Add(entity);
            nodesByEntity[entity] = new List <Node>();
            foreach (Type NodeType in nodeTypes)
            {
                Entity[] currentEntityList = { entity };
                if ((bool)NodeType.GetMethod("HasToBeCreated").Invoke(null, currentEntityList))
                {
                    Type[] constructorParameterTypes = { typeof(Entity) };
                    Node   node = (Node)NodeType.GetConstructor(constructorParameterTypes).Invoke(currentEntityList);
                    nodesByEntity[entity].Add(node);
                    nodesByType[NodeType].Add(node);
                }
            }
        }
Esempio n. 2
0
        public Node Activate(JankyNodeContext context, Dictionary <string, string> initProps)
        {
            var node = (Node)FormatterServices.GetUninitializedObject(NodeType);

            node.Children = new List <Node>();
            node.Context  = context;

            foreach (var kvp in _properties)
            {
                if (initProps == null || !initProps.TryGetValue(kvp.Key, out string value))
                {
                    value = kvp.Value.DefaultValue;
                }
                SetProperty(node, kvp.Key, value);
            }

            NodeType.GetConstructor(Type.EmptyTypes).Invoke(node, null);

            return(node);
        }