Example #1
0
        public CustomTerrainRenderer(World world)
        {
            map         = world.Map;
            terrainInfo = map.Rules.TerrainInfo as CustomTerrain;
            if (terrainInfo == null)
            {
                throw new InvalidDataException("CustomTerrainRenderer can only be used with the CustomTerrain parser");
            }

            tileCache = new CustomTileCache(terrainInfo);
        }
Example #2
0
        bool ITiledTerrainRendererInfo.ValidateTileSprites(ITemplatedTerrainInfo terrainInfo, Action <string> onError)
        {
            var missingImages = new HashSet <string>();
            var failed        = false;
            Action <uint, string> onMissingImage = (id, f) =>
            {
                onError("\tTemplate `{0}` references sprite `{1}` that does not exist.".F(id, f));
                missingImages.Add(f);
                failed = true;
            };

            var tileCache = new CustomTileCache((CustomTerrain)terrainInfo, onMissingImage);

            foreach (var t in terrainInfo.Templates)
            {
                var templateInfo = (CustomTerrainTemplateInfo)t.Value;
                for (var v = 0; v < templateInfo.Images.Length; v++)
                {
                    if (!missingImages.Contains(templateInfo.Images[v]))
                    {
                        for (var i = 0; i < t.Value.TilesCount; i++)
                        {
                            if (t.Value[i] == null || tileCache.HasTileSprite(new TerrainTile(t.Key, (byte)i), v))
                            {
                                continue;
                            }

                            onError("\tTemplate `{0}` references frame {1} that does not exist in sprite `{2}`.".F(t.Key, i, templateInfo.Images[v]));
                            failed = true;
                        }
                    }
                }
            }

            return(failed);
        }