Exemplo n.º 1
0
        static void Example1()
        {
            const string fileName = "EGTUYgwUC9rpHmm4kJwZQXq4";

            var converters = Resources.GetConverters()
                             .Union(FigmaSharp.AppContext.Current.GetFigmaConverters())
                             .ToArray();

            fileProvider = new FigmaRemoteFileProvider();
            fileProvider.Load(fileName);

            var rendererService = new FigmaViewRendererService(fileProvider, converters);
            var rendererOptions = new FigmaViewRendererServiceOptions()
            {
                ScanChildrenFromFigmaInstances = false
            };

            rendererService.RenderInWindow(mainWindow, rendererOptions, "1.0. Bundle Figma Document");

            mainWindow.Resizable = false;
            mainWindow.Center();

            var urlTextField = rendererService.FindViewByName <TextBox>("FigmaUrlTextField");
            var bundleButton = rendererService.FindViewByName <Button>("BundleButton");
            var cancelButton = rendererService.FindViewByName <Button>("CancelButton");

            if (cancelButton != null)
            {
                cancelButton.Clicked += (s, e) =>
                {
                    if (urlTextField != null)
                    {
                        urlTextField.Text = "You pressed cancel";
                    }
                };
            }

            if (bundleButton != null)
            {
                bundleButton.Clicked += (s, e) =>
                {
                    if (urlTextField != null)
                    {
                        urlTextField.Text = "You pressed bundle";
                    }
                };
            }

            //We want know the background color of the figma camvas and apply to our scrollview
            var canvas = fileProvider.Nodes.OfType <FigmaCanvas>().FirstOrDefault();

            if (canvas != null)
            {
                mainWindow.BackgroundColor = canvas.backgroundColor;
            }
        }
Exemplo n.º 2
0
        public GameWindow(Rectangle rect) : base(rect)
        {
            Resizable = false;

            //in this case we want use a remote file provider (figma url from our document)
            var fileProvider = new FigmaRemoteFileProvider();

            fileProvider.Load("Jv8kwhoRsrmtJDsSHcTgWGYu");

            //we initialize our renderer service, this uses all the converters passed
            //and generate a collection of NodesProcessed which is basically contains <FigmaModel, IView, FigmaParentModel>

            var rendererService = new FigmaViewRendererService(fileProvider);

            //play background music
            backgroundMusic = new MusicPlayer("Background", "mp3");
            backgroundMusic.Play(-1);

            coinSound     = new MusicPlayer("Coin", "mp3");
            gameOverSound = new MusicPlayer("GameOver", "mp3");

            //we want load the entire level 1
            rendererService.RenderInWindow(this, "Level1");

            playerTile = rendererService.FindViewStartsWith <IImageView>("Player");

            startingPoint = playerTile.Allocation.Origin;

            pointsLabel = rendererService.FindViewByName <ILabel>("Points");
            gemsTiles   = rendererService.FindViewsStartsWith <IImageView>("Gem")
                          .ToList();
            wallTiles = rendererService.FindViewsStartsWith <IImageView>("Tile")
                        .ToArray();
            spikesTiles = rendererService.FindViewsStartsWith <IImageView>("Spikes")
                          .ToArray();
            heartTiles = rendererService.FindViewsStartsWith <IImageView>("Heart")
                         .OrderBy(s => s.Allocation.X)
                         .ToList();

            WorldUpdate();
        }