// TODO do some sort of caching: rendering these images every time probably sucks for performance.
        public IEnumerable <ComboOption> GetComboOptions(IDataModel model)
        {
            var defaultOptions = GetOptions(model)
                                 .Select((option, i) => new ComboOption(option, i))
                                 .Where(combo => combo.Text != null)
                                 .ToList();

            if (!(model.GetNextRun(model.GetAddressFromAnchor(new NoDataChangeDeltaModel(), -1, EnumName)) is ITableRun tableRun))
            {
                return(defaultOptions);
            }
            if (!(tableRun.ElementContent[0] is ArrayRunPointerSegment pointerSegment))
            {
                return(defaultOptions);
            }
            if (!LzSpriteRun.TryParseSpriteFormat(pointerSegment.InnerFormat, out var _) && !SpriteRun.TryParseSpriteFormat(pointerSegment.InnerFormat, out var _))
            {
                return(defaultOptions);
            }

            var imageOptions = new List <ComboOption>();

            for (int i = 0; i < tableRun.ElementCount; i++)
            {
                var destination = model.ReadPointer(tableRun.Start + tableRun.ElementLength * i);
                if (!(model.GetNextRun(destination) is ISpriteRun run))
                {
                    return(defaultOptions);
                }
                var sprite         = run.GetPixels(model, 0);
                var paletteAddress = SpriteTool.FindMatchingPalette(model, run, 0);
                var paletteRun     = model.GetNextRun(paletteAddress) as IPaletteRun;
                var palette        = paletteRun?.GetPalette(model, paletteRun.PaletteFormat.InitialBlankPages) ?? TileViewModel.CreateDefaultPalette(16);
                var image          = SpriteTool.Render(sprite, palette, paletteRun?.PaletteFormat.InitialBlankPages ?? default, 0);
                var option         = VisualComboOption.CreateFromSprite(defaultOptions[i].Text, image, sprite.GetLength(0), i);
                imageOptions.Add(option);
            }

            return(imageOptions);
        }
Example #2
0
        public static RunStrategy GetStrategy(string format)
        {
            RunStrategy strategy;

            if (format == PCSRun.SharedFormatString)
            {
                strategy = new PCSRunContentStrategy();
            }
            else if (format.StartsWith(AsciiRun.SharedFormatString))
            {
                strategy = new AsciiRunContentStrategy();
            }
            else if (format == EggMoveRun.SharedFormatString)
            {
                strategy = new EggRunContentStrategy();
            }
            else if (format == PIERun.SharedFormatString)
            {
                strategy = new PIERunContentStrategy();
            }
            else if (format == PLMRun.SharedFormatString)
            {
                strategy = new PLMRunContentStrategy();
            }
            else if (format == XSERun.SharedFormatString)
            {
                strategy = new XseRunContentStrategy();
            }
            else if (format == BSERun.SharedFormatString)
            {
                strategy = new BseRunContentStrategy();
            }
            else if (format == ASERun.SharedFormatString)
            {
                strategy = new AseRunContentStrategy();
            }
            else if (format.StartsWith(OverworldSpriteListRun.SharedFormatString.Substring(0, OverworldSpriteListRun.SharedFormatString.Length - 1)))
            {
                strategy = new OverworldSpriteListContentStrategy(format);
            }
            else if (format == TrainerPokemonTeamRun.SharedFormatString)
            {
                strategy = new TrainerPokemonTeamRunContentStrategy();
            }
            else if (LzSpriteRun.TryParseSpriteFormat(format, out var spriteFormat))
            {
                strategy = new LzSpriteRunContentStrategy(spriteFormat);
            }
            else if (LzPaletteRun.TryParsePaletteFormat(format, out var paletteFormat))
            {
                strategy = new LzPaletteRunContentStrategy(paletteFormat);
            }
            else if (TilesetRun.TryParseTilesetFormat(format, out var tilesetFormat))
            {
                strategy = new TilesetRunContentStrategy(tilesetFormat);
            }
            else if (LzTilesetRun.TryParseTilesetFormat(format, out var lzTilesetFormat))
            {
                strategy = new LzTilesetRunContentStrategy(lzTilesetFormat);
            }
            else if (LzTilemapRun.TryParseTilemapFormat(format, out var tilemapFormat))
            {
                strategy = new LzTilemapRunContentStrategy(tilemapFormat);
            }
            else if (TilemapRun.TryParseTilemapFormat(format, out var tilemapFormat1))
            {
                strategy = new TilemapRunContentStrategy(tilemapFormat1);
            }
            else if (SpriteRun.TryParseSpriteFormat(format, out var spriteFormat1))
            {
                strategy = new SpriteRunContentStrategy(spriteFormat1);
            }
            else if (PaletteRun.TryParsePaletteFormat(format, out var paletteFormat1))
            {
                strategy = new PaletteRunContentStrategy(paletteFormat1);
            }
            else if (format.IndexOf("[") >= 0 && format.IndexOf("[") < format.IndexOf("]"))
            {
                strategy = new TableStreamRunContentStrategy();
            }
            else
            {
                return(null);
            }

            strategy.Format = format;
            return(strategy);
        }