Esempio n. 1
0
        public Entity Generate(EntityDefinition entityDescription)
        {
            Entity result = new Entity();

            // add type
            result.Type = (!String.IsNullOrEmpty(entityDescription.Type)) ? entityDescription.Type : "";

            // add classes
            result.Classes = (entityDescription.Classes != null && entityDescription.Classes.Length > 0)?entityDescription.Classes:new string[] {};


            // add material if available
            if (entityDescription.Material != null)
            {
                result.Material = this.materialFabricators[entityDescription.Material.Get <string>(EntityDefinition.JSON_TYPE)](entityDescription.Material);
            }

            //add Mesh if available
            if (entityDescription.Mesh != null) // entityDescription.hasProperty("test")
            {
                result.Mesh = this.meshFabricators[entityDescription.Mesh.Get <string>(EntityDefinition.JSON_TYPE)](entityDescription.Mesh, entityDescription.X, entityDescription.Y, entityDescription.Rotation);
            }

            //add attributes
            if (entityDescription.Attributes != null && entityDescription.Attributes.Length > 0)
            {
                foreach (Dictionary <string, object> s in entityDescription.Attributes)
                {
                    result.AddAttribute(this.attributeFabricators[s.Get <string>(EntityDefinition.JSON_TYPE)](s));
                }
            }

            //add Behaviours if available
            if (entityDescription.Behaviours != null && entityDescription.Behaviours.Length > 0)
            {
                foreach (string s in entityDescription.Behaviours)
                {
                    result.AddBehaviour(this.behaviourFabricators[s]());
                }
            }

            // finally add children recursively
            if (entityDescription.Children != null && entityDescription.Children.Length > 0)
            {
                foreach (EntityDefinition s in entityDescription.Children)
                {
                    result += this.Generate(s);
                }
            }

            return(result);
        }
Esempio n. 2
0
        /*public string Serialize(Entity e)
         * {
         *  //serializes with type
         *  var jsonSerializerSettings = new JsonSerializerSettings()
         *  {
         *      TypeNameHandling = TypeNameHandling.All
         *  };
         *
         *  return JsonConvert.SerializeObject(e, jsonSerializerSettings);
         * }*/

        //TODO: keine dynamic mehr, dafür festes oject
        //[Obsolete]
        //public Entity GenerateDynamical(dynamic entityDescription)
        //{
        //    Entity result = new Entity();

        //    // add type
        //    if (DoesPropertyExist(entityDescription, "Type"))
        //    {
        //        result.Type = entityDescription.Type;
        //    }

        //    // add classes
        //    if (DoesPropertyExist(entityDescription, "Classes"))
        //    {
        //        result.Classes = entityDescription.Classes;
        //    }

        //    // add material if available
        //    if (DoesPropertyExist(entityDescription, "Material"))
        //    {
        //        result.Material = this.materialFabricators[entityDescription.Material.Type]((IDictionary<string, object>)entityDescription.Material);
        //    }

        //    //add Mesh if available
        //    if (DoesPropertyExist(entityDescription, "Mesh")) // entityDescription.hasProperty("test")
        //    {
        //        result.Mesh = this.meshFabricators[entityDescription.Mesh.Type](entityDescription.Mesh, entityDescription.X, entityDescription.Y, entityDescription.Rotation);
        //    }

        //    //add attributes
        //    if (DoesPropertyExist(entityDescription, "Attributes"))
        //    {
        //        foreach (dynamic s in entityDescription.Attributes)
        //        {
        //            result.AddAttribute(this.attributeFabricators[s.Type](s));
        //        }
        //    }

        //    //add Behaviours if available
        //    if (DoesPropertyExist(entityDescription, "Behaviours"))
        //    {
        //        foreach (string s in entityDescription.Behaviours)
        //        {
        //            result.AddBehaviour(this.behaviourFabricators[s]());
        //        }
        //    }

        //    // finally add children recursively
        //    if (DoesPropertyExist(entityDescription, "Children"))
        //    {
        //        foreach (dynamic s in entityDescription.Children)
        //        {
        //            result += EntityFactory.GenerateDynamical(s);
        //        }
        //    }

        //    return result;
        //}

        public Entity GenerateByName(string entityName, float x = 0, float y = 0, float rotation = 0)
        {
            EntityDefinition ed = this.prefabs[entityName];

            /*  float xold = ed.X;
             * float yold = ed.Y;
             * float rotold = ed.Rotation;*/
            ed.X        = x;
            ed.Y        = y;
            ed.Rotation = rotation;

            Entity result = this.Generate(ed);

            /* ed.X = xold;
             * ed.Y = yold;
             * ed.Rotation = rotold;*/

            ed.X        = 0;
            ed.Y        = 0;
            ed.Rotation = 0;

            return(result);
        }
Esempio n. 3
0
 public void AddPrefab(string name, EntityDefinition ed)
 {
     this.prefabs.Add(name, ed);
 }