コード例 #1
0
        /// <summary>Gets definitions suitable as start pages.</summary>
        /// <returns>An enumeration of item definitions.</returns>
        public IEnumerable <ItemDefinition> GetStartDefinitions()
        {
            ICollection <ItemDefinition> preferred = new List <ItemDefinition>();
            ICollection <ItemDefinition> fallback  = new List <ItemDefinition>();

            foreach (ItemDefinition d in definitions.GetDefinitions())
            {
                InstallerHint hint = d.Installer;

                if (Is(hint, InstallerHint.PreferredStartPage))
                {
                    preferred.Add(d);
                }
                if (!Is(hint, InstallerHint.NeverStartPage))
                {
                    fallback.Add(d);
                }
            }

            if (preferred.Count == 0)
            {
                preferred = fallback;
            }

            return(preferred);
        }
コード例 #2
0
		public ControllerMapper(ITypeFinder typeFinder, IDefinitionManager definitionManager)
		{
			IList<ControlsAttribute> controllerDefinitions = FindControllers(typeFinder);
			foreach (ItemDefinition id in definitionManager.GetDefinitions())
			{
				IAdapterDescriptor controllerDefinition = GetControllerFor(id, controllerDefinitions);
				if(controllerDefinition != null)
				{
					ControllerMap[id.ItemType] = controllerDefinition.ControllerName;

					// interacting with static context is tricky, here I made the assumtion that the last
					// finder is the most relevat and takes the place of previous ones, this makes a few 
					// tests pass and doesn't seem to be called in production
					foreach (var finder in PathDictionary.GetFinders(id.ItemType).Where(f => f is ActionResolver))
						PathDictionary.RemoveFinder(id.ItemType, finder);

					// Use MVC's ReflectedControllerDescriptor to find all actions on the Controller
					var methods = new ReflectedControllerDescriptor(controllerDefinition.AdapterType)
						.GetCanonicalActions()
						.Select(m => m.ActionName).ToArray();
					var actionResolver = new ActionResolver(this, methods);

					_controllerActionMap[controllerDefinition.ControllerName] = methods;

					PathDictionary.PrependFinder(id.ItemType, actionResolver);
				}
			}
		}
コード例 #3
0
        public virtual IEnumerable <T> Find <T>(ContentItem root) where T : class
        {
            if (root is T)
            {
                yield return(root as T);
            }

            foreach (ItemDefinition definition in definitions.GetDefinitions())
            {
                if (typeof(T).IsAssignableFrom(definition.ItemType))
                {
                    foreach (var item in finder
                             .Where.Type.Eq(definition.ItemType)
                             .And.AncestralTrail.Like(Utility.GetTrail(root) + "%")
                             .Select())
                    {
                        if (N2.Find.EnumerateParents(item).Any(i => i is ITrashCan))
                        {
                            continue;
                        }

                        yield return(item as T);
                    }
                }
            }
        }
コード例 #4
0
ファイル: MagicLocation.cs プロジェクト: brianmatic/n2cms
 public virtual ItemDefinition GetDefinition(IDefinitionManager definitions)
 {
     foreach (ItemDefinition definition in definitions.GetDefinitions())
         if (definition.Discriminator == ItemDiscriminator)
             return definition;
     return null;
 }
コード例 #5
0
        public ControllerMapper(ITypeFinder typeFinder, IDefinitionManager definitionManager)
        {
            IList <ControlsAttribute> controllerDefinitions = FindControllers(typeFinder);

            foreach (ItemDefinition id in definitionManager.GetDefinitions())
            {
                IAdapterDescriptor controllerDefinition = GetControllerFor(id, controllerDefinitions);
                if (controllerDefinition != null)
                {
                    ControllerMap[id.ItemType] = controllerDefinition.ControllerName;

                    // interacting with static context is tricky, here I made the assumtion that the last
                    // finder is the most relevat and takes the place of previous ones, this makes a few
                    // tests pass and doesn't seem to be called in production
                    foreach (var finder in PathDictionary.GetFinders(id.ItemType).Where(f => f is ActionResolver))
                    {
                        PathDictionary.RemoveFinder(id.ItemType, finder);
                    }

                    // Use MVC's ReflectedControllerDescriptor to find all actions on the Controller
                    var methods = new ReflectedControllerDescriptor(controllerDefinition.AdapterType)
                                  .GetCanonicalActions()
                                  .Select(m => m.ActionName).ToArray();
                    var actionResolver = new ActionResolver(this, methods);

                    _controllerActionMap[controllerDefinition.ControllerName] = methods;

                    PathDictionary.PrependFinder(id.ItemType, actionResolver);
                }
            }
        }
コード例 #6
0
        public override void Deserialize(BinaryReader reader, IDefinitionManager definitionManager)
        {
            base.Deserialize(reader, definitionManager);

            var count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                string name       = reader.ReadString();
                var    definition = definitionManager.GetDefinitions().FirstOrDefault(d => d.GetType().FullName == name);
                var    amount     = reader.ReadDecimal();

                if (definition == null || !(definition is IInventoryableDefinition))
                {
                    continue;
                }

                var slot = new InventorySlot()
                {
                    Amount     = amount,
                    Definition = (IInventoryableDefinition)definition,
                };

                Inventory.Add(slot);
            }
        }
コード例 #7
0
        public override void Populate(IDefinitionManager definitionManager, IPlanet planet, IChunkColumn column00, IChunkColumn column10, IChunkColumn column01, IChunkColumn column11)
        {
            // Tree Definitions initialisieren
            if (treeDefinitions == null)
            {
                treeDefinitions = definitionManager.GetDefinitions<ITreeDefinition>().OrderBy(d => d.Order).ToArray();
                foreach (var treeDefinition in treeDefinitions)
                    treeDefinition.Init(definitionManager);
            }

            int salt = (column00.Index.X & 0xffff) + ((column00.Index.Y & 0xffff) << 16);
            Random random = new Random(planet.Seed + salt);

            Index3 sample = new Index3(column00.Index.X * Chunk.CHUNKSIZE_X, column00.Index.Y * Chunk.CHUNKSIZE_Y, column00.Heights[0, 0]);
            foreach (var treeDefinition in treeDefinitions)
            {
                int density = treeDefinition.GetDensity(planet, sample);
                if (density <= 0) continue;

                for (int i = 0; i < density; i++)
                {
                    int x = random.Next(Chunk.CHUNKSIZE_X / 2, Chunk.CHUNKSIZE_X * 3 / 2);
                    int y = random.Next(Chunk.CHUNKSIZE_Y / 2, Chunk.CHUNKSIZE_Y * 3 / 2);
                    int z = LocalBuilder.GetSurfaceHeight(column00, column10, column01, column11, x, y);

                    LocalBuilder builder = new LocalBuilder(x, y, z + 1, column00, column10, column01, column11);
                    treeDefinition.PlantTree(definitionManager, planet, new Index3(x, y, z), builder, random.Next(int.MaxValue));
                }
            }
        }
コード例 #8
0
        public void Start()
        {
            foreach (var definition in definitions.GetDefinitions())
            {
                if (typeof(IRootPage).IsAssignableFrom(definition.ItemType))
                {
                    if (!definition.Containers.Any(c => c.Name == "Collaboration"))
                    {
                        definition.Add(new TabContainerAttribute("Collaboration", "Collaboration", 130)
                        {
                            ContainerName = definition.Containers.Any(c => c.Name == "RootSettings")
                                                                ? "RootSettings"
                                                                : null
                        });
                    }

                    if (!definition.Editables.Any(e => e.Name == "Messages"))
                    {
                        definition.Add(new EditableChildrenAttribute("Messages", "Collaboration", "Messages", 100)
                        {
                            ContainerName = "Collaboration", MinimumTypeName = typeof(Items.ICollaborationPart).AssemblyQualifiedName
                        });
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>Generates subclasses nhibernate xml configuration as an alternative to NHibernate definition file and adds them to the configuration.</summary>
        /// <param name="cfg">The nhibernate configuration to build.</param>
        protected virtual void GenerateMappings(NHibernate.Cfg.Configuration cfg)
        {
            Debug.Write("Adding");
            StringBuilder mappings = new StringBuilder(mappingStartTag);

            var allTypes = definitions.GetDefinitions()
                           .Select(d => d.ItemType)
                           .SelectMany(t => Utility.GetBaseTypesAndSelf(t))
                           .Distinct()
                           .OrderBy(t => Utility.GetBaseTypes(t).Count())
                           .Where(t => t.IsSubclassOf(typeof(ContentItem)))
                           .ToList();

            foreach (var type in allTypes)
            {
                string discriminator = type.Name;
                var    definition    = definitions.GetDefinition(type);
                if (definition != null)
                {
                    discriminator = definition.Discriminator ?? discriminator;
                }

                string classMapping = generator.GetMapping(type, type.BaseType, discriminator);
                mappings.Append(classMapping);
            }

            mappings.Append(mappingEndTag);
            cfg.AddXml(FormatMapping(mappings.ToString()));
        }
コード例 #10
0
        public override void Execute()
        {
            this.definitions = Engine.Resolve<IDefinitionManager>();
            this.finder = Engine.Resolve<IItemFinder>();

            foreach (var definition in definitions.GetDefinitions())
            {
                definition.NumberOfItems = finder.Where.Type.Eq(definition.ItemType).Count();
            }
        }
コード例 #11
0
        public override void Execute()
        {
            this.definitions = Engine.Resolve <IDefinitionManager>();
            this.finder      = Engine.Resolve <IItemFinder>();

            foreach (var definition in definitions.GetDefinitions())
            {
                definition.NumberOfItems = finder.Where.Type.Eq(definition.ItemType).Count();
            }
        }
コード例 #12
0
ファイル: MagicLocation.cs プロジェクト: xychb/n2cms
 public virtual ItemDefinition GetDefinition(IDefinitionManager definitions)
 {
     foreach (ItemDefinition definition in definitions.GetDefinitions())
     {
         if (definition.Discriminator == ItemDiscriminator)
         {
             return(definition);
         }
     }
     return(null);
 }
コード例 #13
0
        public override void Execute()
        {
            var root           = repository.Get(host.CurrentSite.RootItemID);
            var discriminators = repository.FindDescendantDiscriminators(root).ToDictionary(d => d.Discriminator, d => d.Count);

            foreach (var definition in definitions.GetDefinitions())
            {
                int numberOfItems;
                discriminators.TryGetValue(definition.Discriminator, out numberOfItems);
                definition.NumberOfItems = numberOfItems;
            }
        }
コード例 #14
0
        public void Start()
        {
            foreach (ItemDefinition definition in definitions.GetDefinitions())
            {
                if (IsPage(definition))
                {
                    TabContainerAttribute seoTab = new TabContainerAttribute("seo", SeoTabTitle, 30);
                    definition.Add(seoTab);

                    AddEditableText(definition, TitleTitle, SeoConcern.HeadTitle, 151, 200);
                    AddEditableText(definition, MetaKeywordsTitle, SeoConcern.MetaKeywords, 152, 400);
                    AddEditableText(definition, MetaDescriptionTitle, SeoConcern.MetaDescription, 153, 1000);
                }
            }
        }
コード例 #15
0
        public void Start()
        {
            foreach (ItemDefinition definition in definitions.GetDefinitions())
            {
                if (typeof(ISyndicatable).IsAssignableFrom(definition.ItemType))
                {
                    EditableCheckBoxAttribute ecb = new EditableCheckBoxAttribute(CheckBoxText, 10);
                    ecb.Name          = SyndicatableDetailName;
                    ecb.ContainerName = ContainerName;
                    ecb.SortOrder     = SortOrder;

                    definition.Add(ecb);
                }
            }
        }
コード例 #16
0
 private void InitializeDependencyProviders()
 {
     foreach (var definition in definitions.GetDefinitions())
     {
         foreach (var interfaceType in definition.ItemType.GetInterfaces())
         {
             if (interfaceType.IsGenericType && typeof(IInjectable <>) == interfaceType.GetGenericTypeDefinition())
             {
                 Type genericType  = interfaceType.GetGenericArguments()[0];
                 Type providerType = typeof(EntityDependencySetter <>).MakeGenericType(genericType);
                 var  injector     = services.Resolve(providerType) as IDependencySetter;
                 AddSetters(definition.ItemType, injector);
             }
         }
     }
 }
コード例 #17
0
 public void Start()
 {
     foreach (ItemDefinition definition in _definitionManager.GetDefinitions())
     {
         if (typeof(ModelBase).IsAssignableFrom(definition.ItemType) && !definition.IsPage)
         {
             var ecb = new EditableCheckBoxAttribute
             {
                 Title         = "",
                 CheckBoxText  = "Wrap with container",
                 Name          = "UseContainer",
                 DefaultValue  = true,
                 ContainerName = Defaults.Containers.Metadata
             };
             definition.Add(ecb);
         }
     }
 }
コード例 #18
0
        public override void Populate(IDefinitionManager definitionManager, IPlanet planet, IChunkColumn column00, IChunkColumn column10, IChunkColumn column01, IChunkColumn column11)
        {
            // Tree Definitions initialisieren
            if (treeDefinitions == null)
            {
                treeDefinitions = definitionManager.GetDefinitions <ITreeDefinition>().OrderBy(d => d.Order).ToArray();
                foreach (var treeDefinition in treeDefinitions)
                {
                    treeDefinition.Init(definitionManager);
                }
            }

            int    salt   = (column00.Index.X & 0xffff) + ((column00.Index.Y & 0xffff) << 16);
            Random random = new Random(planet.Seed + salt);

            Index3 sample = new Index3(column00.Index.X * Chunk.CHUNKSIZE_X, column00.Index.Y * Chunk.CHUNKSIZE_Y, column00.Heights[0, 0]);

            foreach (var treeDefinition in treeDefinitions)
            {
                int density = treeDefinition.GetDensity(planet, sample);
                if (density <= 0)
                {
                    continue;
                }

                for (int i = 0; i < density; i++)
                {
                    int x = random.Next(Chunk.CHUNKSIZE_X / 2, Chunk.CHUNKSIZE_X * 3 / 2);
                    int y = random.Next(Chunk.CHUNKSIZE_Y / 2, Chunk.CHUNKSIZE_Y * 3 / 2);
                    int z = LocalBuilder.GetSurfaceHeight(column00, column10, column01, column11, x, y);

                    float blocktemp = planet.ClimateMap.GetTemperature(new Index3(column00.Index.X * Chunk.CHUNKSIZE_X,
                                                                                  column00.Index.Y * Chunk.CHUNKSIZE_X, z));

                    if (blocktemp > treeDefinition.MaxTemperature || blocktemp < treeDefinition.MinTemperature)
                    {
                        continue;
                    }

                    LocalBuilder builder = new LocalBuilder(x, y, z + 1, column00, column10, column01, column11);
                    treeDefinition.PlantTree(definitionManager, planet, new Index3(x, y, z), builder, random.Next(int.MaxValue));
                }
            }
        }
コード例 #19
0
        public void Start()
        {
            foreach (ItemDefinition definition in definitions.GetDefinitions())
            {
                if (IsPage(definition))
                {
                    SeparatorAttribute separator = new SeparatorAttribute("seo", SortIndex);
                    separator.ContainerName = Tabs.Details;
                    definition.Add(separator);

                    var titleEditor = AddEditableText(definition, TitleTitle, SeoConcern.HeadTitle, SortIndex + 3, 200);
                    titleEditor.HelpTitle = "This text is displayed in the browser's title bar and in search engine result lists, when this value is empty the page title is used.";
                    var keywordsEditor = AddEditableText(definition, MetaKeywordsTitle, SeoConcern.MetaKeywords, SortIndex + 6, 400);
                    keywordsEditor.HelpTitle = "Keywords that may be used by search engines to pinpoint whe subject of this page. Text content and incoming links also affect this.";
                    var descriptionEditor = AddEditableText(definition, MetaDescriptionTitle, SeoConcern.MetaDescription, SortIndex + 9, 1000);
                    descriptionEditor.HelpTitle = "A text that can be used by search engines to describe this page when displaying it in search results.";
                }
            }
        }
コード例 #20
0
        public IChunkColumn GenerateColumn(IDefinitionManager definitionManager, IPlanet planet, Index2 index)
        {
            IDefinition[] definitions = definitionManager.GetDefinitions().ToArray();

            IBlockDefinition sandDefinition = definitions.OfType <SandBlockDefinition>().First();
            ushort           sandIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), sandDefinition) + 1);

            IChunk[] result = new IChunk[planet.Size.Z];

            ChunkColumn column = new ChunkColumn(result, planet.Id, index);


            for (int layer = 0; layer < planet.Size.Z; layer++)
            {
                result[layer] = new Chunk(new Index3(index.X, index.Y, layer), planet.Id);
            }

            int part = (planet.Size.Z * Chunk.CHUNKSIZE_Z) / 4;

            for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++)
            {
                float heightY = (float)Math.Sin((float)(y * Math.PI) / 15f);
                for (int x = 0; x < Chunk.CHUNKSIZE_X; x++)
                {
                    float heightX = (float)Math.Sin((float)(x * Math.PI) / 18f);

                    float height = ((heightX + heightY + 2) / 4) * (2 * part);
                    for (int z = 0; z < planet.Size.Z * Chunk.CHUNKSIZE_Z; z++)
                    {
                        if (z < (int)(height + part))
                        {
                            int block = z % (Chunk.CHUNKSIZE_Z);
                            int layer = z / Chunk.CHUNKSIZE_Z;
                            result[layer].SetBlock(x, y, block, sandIndex);
                        }
                    }
                }
            }

            column.CalculateHeights();
            return(column);
        }
コード例 #21
0
        /// <summary>Gets or sets additional child types allowed below this item.</summary>
        public IEnumerable <ItemDefinition> GetAllowedChildren(IDefinitionManager definitions, ContentItem parentItem)
        {
            IEnumerable <ItemDefinition> all = definitions.GetDefinitions().ToList();

            foreach (var d in all)
            {
                var ctx = new AllowedDefinitionQuery {
                    Parent = parentItem, ParentDefinition = this, ChildDefinition = d, Definitions = definitions
                };
                var filters = AllowedChildFilters.Union(d.AllowedParentFilters).ToList();
                if (filters.Any(f => f.IsAllowed(ctx) == AllowedDefinitionResult.Allow))
                {
                    yield return(d);
                }
                else if (!filters.Any(f => f.IsAllowed(ctx) == AllowedDefinitionResult.Deny))
                {
                    yield return(d);
                }
            }
        }
コード例 #22
0
        public virtual IEnumerable <T> Find <T>(ContentItem root) where T : class
        {
            if (root is T)
            {
                yield return(root as T);
            }

            foreach (ItemDefinition definition in definitions.GetDefinitions())
            {
                if (typeof(T).IsAssignableFrom(definition.ItemType))
                {
                    foreach (var item in repository.FindDescendants(root, definition.Discriminator))
                    {
                        if (N2.Find.EnumerateParents(item).Any(i => i is ITrashCan))
                        {
                            continue;
                        }

                        yield return(item as T);
                    }
                }
            }
        }
コード例 #23
0
 public override bool IsApplicable(DatabaseStatus status)
 {
     return(definitions.GetDefinitions().SelectMany(d => d.Properties.Values).Any(p => p.PropertyType.IsEnum));
 }
コード例 #24
0
ファイル: ChunkColumn.cs プロジェクト: fnawratil/octoawesome
        /// <summary>
        /// Deserialisiert die Chunksäule aus dem angegebenen Stream.
        /// </summary>
        /// <param name="stream">Quellstream</param>
        /// <param name="definitionManager">Der verwendete DefinitionManager</param>
        /// <param name="columnIndex">Die Position der Säule</param>
        /// <param name="planetId">Der Index des Planeten</param>
        public void Deserialize(BinaryReader reader, IDefinitionManager definitionManager)
        {
            bool longIndex = reader.ReadByte() > 0;

            // Phase 1 (Column Meta: Heightmap, populated, chunkcount)
            Chunks = new Chunk[reader.ReadByte()]; // Chunk Count

            Populated = reader.ReadBoolean();      // Populated

            Index  = new Index2(reader.ReadInt32(), reader.ReadInt32());
            Planet = reader.ReadInt32();

            for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++) // Heightmap
            {
                for (int x = 0; x < Chunk.CHUNKSIZE_X; x++)
                {
                    Heights[x, y] = reader.ReadUInt16();
                }
            }

            int[] counter = new int[Chunks.Length];

            for (int i = 0; i < Chunks.Length; i++) // ChangeCounter
            {
                counter[i] = reader.ReadInt32();
            }

            // Phase 2 (Block Definitionen)
            List <IDefinition>          types = new List <IDefinition>();
            Dictionary <ushort, ushort> map   = new Dictionary <ushort, ushort>();

            int typecount = longIndex ? reader.ReadUInt16() : reader.ReadByte();

            for (int i = 0; i < typecount; i++)
            {
                string        typeName        = reader.ReadString();
                IDefinition[] definitions     = definitionManager.GetDefinitions().ToArray();
                var           blockDefinition = definitions.FirstOrDefault(d => d.GetType().FullName == typeName);
                types.Add(blockDefinition);

                map.Add((ushort)types.Count, (ushort)(Array.IndexOf(definitions, blockDefinition) + 1));
            }

            // Phase 3 (Chunk Infos)
            for (int c = 0; c < Chunks.Length; c++)
            {
                IChunk chunk = Chunks[c] = new Chunk(new Index3(Index, c), Planet);
                chunk.Changed += OnChunkChanged;
                chunk.SetColumn(this);

                for (int i = 0; i < chunk.Blocks.Length; i++)
                {
                    ushort typeIndex = longIndex ? reader.ReadUInt16() : reader.ReadByte();
                    chunk.MetaData[i] = 0;
                    if (typeIndex > 0)
                    {
                        chunk.Blocks[i] = map[typeIndex];

                        var definition = (IBlockDefinition)definitionManager.GetDefinitionByIndex(map[typeIndex]);

                        if (definition.HasMetaData)
                        {
                            chunk.MetaData[i] = reader.ReadInt32();
                        }
                    }
                }
                chunk.ChangeCounter = counter[c];
            }

            //Entities lesen
            var count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                var name   = reader.ReadString();
                var length = reader.ReadInt32();

                byte[] buffer = new byte[length];
                reader.Read(buffer, 0, length);

                try
                {
                    var type = Type.GetType(name);

                    if (type == null)
                    {
                        continue;
                    }

                    Entity entity = (Entity)Activator.CreateInstance(type);

                    using (MemoryStream memorystream = new MemoryStream(buffer))
                    {
                        using (BinaryReader componentbinarystream = new BinaryReader(memorystream))
                        {
                            entity.Deserialize(componentbinarystream, definitionManager);
                        }
                    }

                    Entities.Add(entity);
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #25
0
 private bool DefinitionsContainsUrlSources()
 {
     return(definitions.GetDefinitions().Any(d => typeof(IUrlSource).IsAssignableFrom(d.ItemType)));
 }
コード例 #26
0
        public IChunkColumn GenerateColumn(IDefinitionManager definitionManager, IPlanet planet, Index2 index)
        {
            IDefinition[] definitions = definitionManager.GetDefinitions().ToArray();
            //TODO More Generic, überdenken der Planetgeneration im allgemeinen (Heapmap + Highmap + Biome + Modding)
            IBlockDefinition sandDefinition = definitions.OfType <SandBlockDefinition>().FirstOrDefault();
            ushort           sandIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), sandDefinition) + 1);

            IBlockDefinition snowDefinition = definitions.OfType <SnowBlockDefinition>().FirstOrDefault();
            ushort           snowIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), snowDefinition) + 1);

            IBlockDefinition groundDefinition = definitions.OfType <GroundBlockDefinition>().FirstOrDefault();
            ushort           groundIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), groundDefinition) + 1);

            IBlockDefinition stoneDefinition = definitions.OfType <StoneBlockDefinition>().FirstOrDefault();
            ushort           stoneIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), stoneDefinition) + 1);

            IBlockDefinition waterDefinition = definitions.OfType <WaterBlockDefinition>().FirstOrDefault();
            ushort           waterIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), waterDefinition) + 1);

            IBlockDefinition grassDefinition = definitions.OfType <GrassBlockDefinition>().FirstOrDefault();
            ushort           grassIndex      = (ushort)(Array.IndexOf(definitions.ToArray(), grassDefinition) + 1);

            if (!(planet is ComplexPlanet))
            {
                throw new ArgumentException("planet is not a Type of ComplexPlanet");
            }

            ComplexPlanet localPlanet = (ComplexPlanet)planet;

            float[,] localHeightmap = localPlanet.BiomeGenerator.GetHeightmap(index);

            IChunk[] chunks = new IChunk[planet.Size.Z];
            for (int i = 0; i < planet.Size.Z; i++)
            {
                chunks[i] = new Chunk(new Index3(index, i), planet.Id);
            }

            int  obersteSchicht;
            bool surfaceBlock;
            bool ozeanSurface;

            for (int x = 0; x < Chunk.CHUNKSIZE_X; x++)
            {
                for (int y = 0; y < Chunk.CHUNKSIZE_Y; y++)
                {
                    obersteSchicht = 5;
                    surfaceBlock   = true;
                    ozeanSurface   = false;

                    for (int i = chunks.Length - 1; i >= 0; i--)
                    {
                        for (int z = Chunk.CHUNKSIZE_Z - 1; z >= 0; z--)
                        {
                            int absoluteZ = (z + (i * Chunk.CHUNKSIZE_Z));

                            if (absoluteZ <= localHeightmap[x, y] * localPlanet.Size.Z * Chunk.CHUNKSIZE_Z)
                            {
                                if (obersteSchicht > 0)
                                {
                                    float temp = localPlanet.ClimateMap.GetTemperature(new Index3(index.X * Chunk.CHUNKSIZE_X + x, index.Y * Chunk.CHUNKSIZE_Y + y, i * Chunk.CHUNKSIZE_Z + z));

                                    if ((ozeanSurface || surfaceBlock) && (absoluteZ <= (localPlanet.BiomeGenerator.SeaLevel + 2)) && (absoluteZ >= (localPlanet.BiomeGenerator.SeaLevel - 2)))
                                    {
                                        chunks[i].SetBlock(x, y, z, sandIndex);
                                    }
                                    else if (temp >= 35)
                                    {
                                        chunks[i].SetBlock(x, y, z, sandIndex);
                                    }
                                    else if (absoluteZ >= localPlanet.Size.Z * Chunk.CHUNKSIZE_Z * 0.6f)
                                    {
                                        if (temp > 12)
                                        {
                                            chunks[i].SetBlock(x, y, z, groundIndex);
                                        }
                                        else
                                        {
                                            chunks[i].SetBlock(x, y, z, stoneIndex);
                                        }
                                    }
                                    else if (temp >= 8)
                                    {
                                        if (surfaceBlock && !ozeanSurface)
                                        {
                                            chunks[i].SetBlock(x, y, z, grassIndex);
                                            surfaceBlock = false;
                                        }
                                        else
                                        {
                                            chunks[i].SetBlock(x, y, z, groundIndex);
                                        }
                                    }
                                    else if (temp <= 0)
                                    {
                                        if (surfaceBlock && !ozeanSurface)
                                        {
                                            chunks[i].SetBlock(x, y, z, snowIndex);
                                            surfaceBlock = false;
                                        }
                                        else
                                        {
                                            chunks[i].SetBlock(x, y, z, groundIndex);
                                        }
                                    }
                                    else
                                    {
                                        chunks[i].SetBlock(x, y, z, groundIndex);
                                    }
                                    obersteSchicht--;
                                }
                                else
                                {
                                    chunks[i].SetBlock(x, y, z, stoneIndex);
                                }
                            }
                            else if ((z + (i * Chunk.CHUNKSIZE_Z)) <= localPlanet.BiomeGenerator.SeaLevel)
                            {
                                chunks[i].SetBlock(x, y, z, waterIndex);
                                ozeanSurface = true;
                            }
                        }
                    }
                }
            }

            ChunkColumn column = new ChunkColumn(chunks, planet.Id, index);

            column.CalculateHeights();
            return(column);
        }
コード例 #27
0
        public override MigrationResult Migrate(DatabaseStatus preSchemaUpdateStatus)
        {
            int updatedItems = 0;

            using (var transaction = repository.BeginTransaction())
            {
                var nonNullZoneNameParts = repository.Find(Parameter.IsNull("ZoneName") & Parameter.TypeIn(definitions.GetDefinitions().Where(d => !d.IsPage).Select(d => d.Discriminator).ToArray()));
                foreach (var item in nonNullZoneNameParts)
                {
                    item.ZoneName = "";
                    repository.SaveOrUpdate(item);
                    updatedItems++;
                }

                transaction.Commit();
            }

            return(new MigrationResult(this)
            {
                UpdatedItems = updatedItems
            });
        }
コード例 #28
0
ファイル: ItemDefinition.cs プロジェクト: tenniskit/n2cms
 // Fixes #614 pages marked with RestrictCardinality cannot be sorted
 /// <summary>Gets or sets additional child types allowed below this item.</summary>
 public IEnumerable <ItemDefinition> GetAllowedChildren(IDefinitionManager definitions, ContentItem parentItem, ContentItem childItem)
 {
     return(definitions.GetDefinitions().AllowedBelow(this, parentItem, childItem, definitions));
 }
コード例 #29
0
 private IEnumerable <ItemDefinition> DefinitionWithPopularityAttribute()
 {
     return(definitions.GetDefinitions().Where(d => d.GetCustomAttributes <SortChildrenAttribute>().Any(sc => sc.CustomSorterType == typeof(PopularityChildrenSorter))));
 }
コード例 #30
0
 public override bool IsApplicable(DatabaseStatus status)
 {
     return(status.NeedsUpgrade || definitions.GetDefinitions().Any(d => d.Properties.Any(p => p.Value.Editable is EditableItemAttribute)));
 }