Пример #1
0
        // Prosessoi kaikki layerit.
        private void ProcessLayers(List <Tuple <string, int> > drawOrderPairs, IEnumerable <BaseSerializedLayer> serializedLayers)
        {
            LayerFactory layerFactory = new LayerFactory(game, map.TileEngine);
            SheetFactory sheetFactory = new SheetFactory();

            foreach (BaseSerializedLayer serializedLayer in serializedLayers)
            {
                // alustaa layerin
                Size   size  = new Size(serializedLayer.Width, serializedLayer.Height);
                ILayer layer = layerFactory.MakeNew(serializedLayer);

                // alustaa tilejen parametrit ja indeksoi ne
                TileParameters tileParameters = GetRightTileParameters(serializedLayer, map.TileEngine);

                // jos layeri on tilayeri, tehdään sille tile sheetti
                if (serializedLayer is SerializedTileLayer)
                {
                    SerializedTileLayer tileLayer = serializedLayer as SerializedTileLayer;
                    layer.Sheet = sheetFactory.MakeNew(layer.GetType(), new object[]
                    {
                        tileLayer.SheetPath, contentManager, map.TileEngine
                    });
                }
                // jos layeri on animaatio layeri, tehdään sille animaatio sheetti
                else if (serializedLayer is SerializedAnimationLayer)
                {
                    SerializedAnimationLayer animationLayer = serializedLayer as SerializedAnimationLayer;
                    layer.Sheet = sheetFactory.MakeNew(layer.GetType(), new object[]
                    {
                        animationLayer.SheetPath, contentManager, map.TileEngine,
                        new AnimationManager(animationLayer.AnimationManager.FrameCount, animationLayer.AnimationManager.FrameTime)
                    });
                }

                // alustaa layerin ja sen tilet
                layer.Initialize(tileParameters);
                // lisää layerin managerille
                map.LayerManager.AddLayer(layer);

                // jos layeri ei ole rule, otetaan sen draworder huomioon
                if (!(layer is Layer <RuleTile>))
                {
                    AddDrawOrder(drawOrderPairs, serializedLayer);
                }
                // prosessoidaan objectit jos layeri sisältää objecti tilejä
                if (layer is Layer <ObjectTile> )
                {
                    ProcessMapObjects(serializedLayer, layer);
                }

                // rakennetaan componentit layerille lopuksi
                ComponentBuilder componentBuilder = new ComponentBuilder(game);
                layer.Components.AddComponents(componentBuilder.BuildComponents(layer));
            }
        }