Esempio n. 1
0
        public RawMapEntity CreateEntity(MapObjectSpawnDescriptor fromDescriptor)
        {
            MapEntityDataDescriptor template = m_editorCore.Templates.MapEntityDataDescriptors.Find(x => x.FourCC == fromDescriptor.FourCC);

            RawMapEntity obj = new RawMapEntity();
            obj.FourCC = fromDescriptor.FourCC;
            obj.Fields = new PropertyCollection();

            // stupid copy paste

            // See if our template list has a complex version of this file, otherwise grab the default.
            MapObjectDataDescriptor complexDescriptor = m_editorCore.Templates.MapObjectDataDescriptors.Find(x => x.FourCC == fromDescriptor.FourCC && x.TechnicalName == fromDescriptor.TechnicalName);
            if (complexDescriptor == null)
                complexDescriptor = m_editorCore.Templates.DefaultMapObjectDataDescriptor;

            // Determine which field we need to remove, and then insert in the other fields (in order) where it used to be.
            foreach (var fieldToReplace in complexDescriptor.DataOverrides)
            {
                for (int k = 0; k < template.Fields.Count; k++)
                {
                    if (template.Fields[k].FieldName == fieldToReplace.ParameterName)
                    {
                        // Remove the old field.
                        template.Fields.RemoveAt(k);

                        // Now insert the new fields starting at the location of the one we just replaced.
                        template.Fields.InsertRange(k, fieldToReplace.Values);
                        break;
                    }
                }
            }

            // Finally initialize the fields using default values.
            for (int i = 0; i < template.Fields.Count; i++)
            {
                var templateProperty = template.Fields[i];
                string propertyName = templateProperty.FieldName;
                PropertyType type = templateProperty.FieldType;
                object value = GetDefaultValue(templateProperty);

                if (propertyName == "Name")
                    value = fromDescriptor.TechnicalName;

                obj.Fields.Properties.Add(new Property(propertyName, type, value));
            }

            return obj;
        }
Esempio n. 2
0
        public void SpawnEntityInWorld(MapObjectSpawnDescriptor dragData)
        {
            WLog.Info(LogCategory.EditorCore, null, "Caught object to be spawned {0} in scene: {1}", dragData, SelectedScene);

            // Meh.
            MapEntityLoader loader = new MapEntityLoader(m_editorCore, Map);

            // We can skip post-processing the entities via MapEntityLoader b/c that just does reference fixups, and
            // because this is a new entity there's no references so no point in trying to fix them up.
            var newEnt = loader.CreateEntity(dragData);

            if (SelectedScene is Stage)
                MapLoader.PostProcessStage((Stage)SelectedScene, new List<MapEntityLoader.RawMapEntity>(new[] { newEnt }));

            if(SelectedScene is Room)
                MapLoader.PostProcessRoom((Room)SelectedScene, new List<MapEntityLoader.RawMapEntity>(new[] { newEnt }));

            // meh more hacks.
            foreach (var ent in SelectedScene.Entities)
                ent.World = this;
        }