Beispiel #1
0
        private static void LoadWorldObjectsLayer(this Layout layout, string spawnPoint, List <OgmoEntity> entities)
        {
            // Filter out any spawn points that don't need to exist.
            if (HasManySpawnPoints(entities))
            {
                // If there are many spawn points and no default was given, just choose the first one.
                if (string.IsNullOrEmpty(spawnPoint))
                {
                    var firstSpawnPoint = entities.First(e => e.Name == "OverworldPlayerSpawnPoint");
                    entities.RemoveAll(e => e.Name == "OverworldPlayerSpawnPoint" && e != firstSpawnPoint);
                }
                else
                {
                    entities.RemoveAll(e => e.Name == "OverworldPlayerSpawnPoint" && spawnPoint != e.Values.SpawnPointName);
                }
            }

            var definitions = DefinitionList.GetDefinitions();

            foreach (var entity in entities)
            {
                var definition  = definitions.Get(entity.Name);
                var worldObject = layout.Objects.Create(definition, new Vector2(entity.X, entity.Y));

                // Default properties for every world object.
                worldObject.IsMirrored = entity.FlippedX;

                Loaders.Load(definition.Guid, worldObject, entity);
            }
        }
Beispiel #2
0
        public static DefinitionList GetDefinitions()
        {
            var definitionList = new DefinitionList();

            var definitionMethods = typeof(DefinitionList).Assembly.GetTypes()
                                    .SelectMany(type => type.GetMethods())
                                    .Where(m => m.GetCustomAttributes(typeof(RequiredByLayoutLoadAttribute), false).Length > 0);

            foreach (var method in definitionMethods)
            {
                definitionList._definitions.Add(method.DeclaringType.Name, (WorldObjectDefinition)method.Invoke(null, null));
            }

            return(definitionList);
        }