Пример #1
0
        public void RemoveWorldObject(Coord2D mouseIsoFlatCoord, Coord2D mouseIsoCoord)
        {
            Coord3D mouseIsoCoord3D = new Coord3D(mouseIsoCoord, Altitude);

            if (BuildMode == BuildMode.Cube && LayerMap.ContainsKey(mouseIsoCoord3D))
            {
                var sprite = LayerMap[mouseIsoCoord3D];
                if (sprite is Cube)
                {
                    LayerMap.Remove(mouseIsoCoord3D);

                    foreach (var coord in mouseIsoCoord.AdjacentCoords())
                    {
                        WalkableTileTable.Remove(Altitude + 1, coord, mouseIsoCoord);
                    }

                    // If there is a cube below,
                    if (LayerMap.ContainsKey(new Coord3D(mouseIsoCoord, Altitude - 1)) && LayerMap[new Coord3D(mouseIsoCoord, Altitude - 1)] is Cube)
                    {
                        foreach (var coord in mouseIsoCoord.AdjacentCoords())
                        {
                            WalkableTileTable.Add(Altitude, coord, mouseIsoCoord);
                        }
                    }
                }
            }
            else if (BuildMode == BuildMode.Deco && LayerMap.ContainsKey(mouseIsoCoord3D))
            {
                var sprite = LayerMap[mouseIsoCoord3D];
                if (sprite is Deco deco)
                {
                    foreach (var coord in deco.OccupiedCoords)
                    {
                        LayerMap.Remove(coord);

                        // If there are cubes below,
                        var c = new Coord3D(new Coord2D(coord.X, coord.Y), Altitude - 1);
                        if (LayerMap.ContainsKey(c) && LayerMap[c] is Cube)
                        {
                            foreach (var _coord in new Coord2D(coord.X, coord.Y).AdjacentCoords())
                            {
                                WalkableTileTable.Add(Altitude, _coord, new Coord2D(coord.X, coord.Y));
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void LoadContentFromFile()
        {
            IsLoading = true;
            // Most time is spent here...
            var XmlData = Serializer.ReadXML <MapBuilder>(MapBuilderSerializer, saveFilePath);

            // Variable assignment here:
            Altitude          = XmlData.Altitude;
            WalkableTileTable = XmlData.WalkableTileTable;
            LayerMap          = XmlData.LayerMap;
            DynamicSprites    = XmlData.DynamicSprites;

            bool createNewGhostMarker = false;

            for (int i = 0; i < DynamicSprites.Count(); i++)
            {
                Sprite sprite = DynamicSprites[i];
                if (sprite is Player player)
                {
                    Player = player;
                }
                else if (sprite is GhostMarker ghostMarker)
                {
                    GhostMarker = ghostMarker;
                }
                else if (sprite.Animator?.SpriteSheet?.TexturePath == "Temp/WalkTargetAnimation")
                {
                    ClickAnimation = sprite;
                }

                // Load content can fail if the content file for the sprite no longer exists.
                try { sprite.LoadContent(MainGame); }
                catch (Exception e)
                {
                    e.Message.Log();
                    if (sprite is GhostMarker ghostMarker)
                    {
                        // If the content file was required for the ghost marker, remove the current ghost marker and get ready to make a new one.
                        createNewGhostMarker = true;
                        DynamicSprites.Remove(ghostMarker);
                    }
                    i--;
                }
            }

            if (createNewGhostMarker)
            {
                // The content file for the ghost marker was removed, so make a new one and add it to the layer map.
                GhostMarker = new GhostMarker(MainGame, SpriteSheet.CreateNew(MainGame, "Temp/TopFaceSelectionMarker"))
                {
                    DrawPriority = 1
                };
                DynamicSprites.Add(GhostMarker);
            }

            List <Coord3D> purgedSprites  = new List <Coord3D>();
            List <Coord3D> decoReferences = new List <Coord3D>();

            foreach (var layerMapItem in LayerMap)
            {
                var sprite = layerMapItem.Value;
                if (sprite is DecoReference)
                {
                    decoReferences.Add(layerMapItem.Key);
                }
                // Load content can fail if the content file for the sprite no longer exists.
                try { sprite.LoadContent(MainGame); }
                catch (Exception e)
                {
                    e.Message.Log();
                    if (sprite is Deco deco)
                    {
                        foreach (var coord in deco.OccupiedCoords)
                        {
                            purgedSprites.Add(coord);
                        }
                    }
                    else
                    {
                        purgedSprites.Add(layerMapItem.Key);
                    }
                }
            }
            foreach (var coord in purgedSprites)
            {
                LayerMap.Remove(coord);
            }
            foreach (var coord in decoReferences)
            {
                DecoReference decoReference = LayerMap[coord] as DecoReference;
                decoReference.Reference = (Deco)LayerMap[decoReference.ReferenceCoord];
            }

            IsLoading             = false;
            MainGame.CurrentState = this;

            Peripherals.ScrollWheelUp   += Peripherals_ScrollWheelUp;
            Peripherals.ScrollWheelDown += Peripherals_ScrollWheelDown;
        }