Esempio n. 1
0
        public int CountCycles(List <string> input)
        {
            var cube = CubeParser.Parse(input);

            var cycled = cube.Cycle();

            int active = cycled.Active;

            return(active);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is Action <string, byte[]> action && parameter is string filter)
            {
                return(new TransientCommand(() =>
                {
                    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                    dlg.Filter = filter;

                    if (dlg.ShowDialog() == true)
                    {
                        bool failed = false;
                        try
                        {
                            var bytes = File.ReadAllBytes(dlg.FileName);

                            if (Path.GetExtension(dlg.FileName)?.ToLower() == ".png")
                            {
                                BitmapImage biImg = new BitmapImage();
                                using MemoryStream ms = new MemoryStream(bytes);
                                biImg.BeginInit();
                                biImg.StreamSource = ms;
                                biImg.EndInit();

                                if (biImg.PixelWidth != 512 || biImg.PixelHeight != 512)
                                {
                                    throw new InvalidOperationException($"Wrong LUT size {biImg.PixelWidth}x{biImg.PixelHeight}");
                                }
                            }
                            else
                            {
                                var data = CubeParser.Read(bytes);
                                if (data == null)
                                {
                                    throw new InvalidOperationException("Bad cube format");
                                }
                            }

                            action(dlg.FileName, bytes);
                        }
                        catch (Exception e)
                        {
                            Log.Warning(e, $"Failed to open image file");
                            failed = true;
                        }
                        if (failed)
                        {
                            action(dlg.FileName, null);
                        }
                    }
                }));
            }

            return(null);
        }
Esempio n. 3
0
        public void FirstStarExample()
        {
            var input = new List <string>
            {
                ".#.",
                "..#",
                "###"
            };

            var cube = CubeParser.Parse(input);

            var cycled = cube.Cycle();

            int active = cycled.Active;

            Assert.Equal(112, active);
        }
Esempio n. 4
0
 public static IDirectXFilterStage Create(DirectXContext dx, byte[] buffer, SingleFrameType type, double amount)
 {
     if (type == SingleFrameType.Cube)
     {
         var cube = CubeParser.Read(buffer);
         if (cube != null)
         {
             var texture1 = cube.Is3D ? null : CreateTexture1D(dx, cube);
             var texture3 = cube.Is3D ? CreateTexture3D(dx, cube) : null;
             return(new DirectXFilterStageLUT(dx, texture1, texture3, amount, cube.Size, CreateConfig(cube.Is3D), cube.DomainMin, cube.DomainMax));
         }
     }
     else if (type == SingleFrameType.Png)
     {
         var texture = CreateTexture3D(dx, buffer);
         return(new DirectXFilterStageLUT(dx, null, texture, amount, 64, CreateConfig(true), new Vector3(0, 0, 0), new Vector3(1, 1, 1)));
     }
     return(null);
 }
Esempio n. 5
0
        public async void GeneratePacks(object sender, EventArgs args)
        {
            bool valid = Int32.TryParse(this.PackNumEntry.Text, out int packNum);

            if (!valid || packNum < 0)
            {
                await this.DisplayAlert("Invalid Pack Number", $"'{this.PackNumEntry.Text}' is not a valid number", "Okay");

                return;
            }

            CubeParser parser;

            try
            {
                parser = new CubeParser(this.CubeDefEditor.Text, ConfigurationManager.ActiveDeck);
            }
            catch (Exception exc)
            {
                await this.DisplayAlert("Failed to Compile", $"Error: ${exc.Message}", "Okay");

                return;
            }

            List <List <PackCard> > cards = new List <List <PackCard> >();

            try
            {
                for (int i = 0; i < packNum; i++)
                {
                    List <PackCard> pack = parser.MakePack();
                    cards.Add(pack);
                }
            }
            catch (Exception exc)
            {
                await this.DisplayAlert("Failed to Exectue", $"Error: ${exc.Message}", "Okay");

                return;
            }

            Deck generated = new Deck(false)
            {
                Name = "Generated Packs"
            };

            for (int i = 0; i < cards.Count; i++)
            {
                foreach (PackCard card in cards[i])
                {
                    generated.AddCard(card.Card, Deck.MASTER, !card.Foil);
                    generated.AddCard(card.Card, $"Pack {i+1}", !card.Foil);
                }
            }
            generated.RemoveBoard("Mainboard");
            generated.RemoveBoard("Sideboard");

            foreach (Deck.BoardInfo info in generated.BoardInfos)
            {
                info.Editable = info.Viewable = info.Name != Deck.MASTER;
            }

            await Navigation.PushAsync(new DeckPage(generated, false));
        }