Exemplo n.º 1
0
        private void CreateContent()
        {
            IsLoading = true;

            // Create the player and add to the DynamicSprites.
            var playerSheet    = SpriteSheet.CreateNew(MainGame, "Temp/PirateGirlSheet", 1, 16);
            var playerAnimArgs = new AnimArgs(9, 1, 0.2f, AnimationState.None);

            Player          = new Player(MainGame, playerSheet, playerAnimArgs);
            Player.Altitude = 1;
            DynamicSprites.Add(Player);

            // Instantiate ghost marker with its default texture and add it to DynamicSprites. Image is null at this point, but will be set
            // by CubeDesignerViewModel.OnMainGameLoaded() as soon as SunbirdMBGame's constructor resolves.
            GhostMarker = new GhostMarker(MainGame, SpriteSheet.CreateNew(MainGame, "Temp/TopFaceSelectionMarker"))
            {
                DrawPriority = 1
            };
            DynamicSprites.Add(GhostMarker);

            ClickAnimation = new Sprite(MainGame, SpriteSheet.CreateNew(MainGame, "Temp/WalkTargetAnimation", 1, 7))
            {
                Alpha = 0.8f
            };
            DynamicSprites.Add(ClickAnimation);

            IsLoading             = false;
            MainGame.CurrentState = this;

            Peripherals.ScrollWheelUp   += Peripherals_ScrollWheelUp;
            Peripherals.ScrollWheelDown += Peripherals_ScrollWheelDown;
        }
Exemplo n.º 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;
        }