public void Validate() { List <string> log = new List <string>(); IsUsingIo = true; var wb = Header.WorldBounds; short[,] deadSpace = new short[wb.Width, wb.Height]; for (int y = wb.Top; y <= wb.Bottom; y++) { OnProgressChanged(this, y, wb.Bottom, "Validating Tiles..."); for (int x = wb.Left; x <= wb.Right; x++) { // skip anything in the dead space if (deadSpace[x, y] > 0) { x += deadSpace[x, y] - 1; continue; } // TODO: Need Frames support // // (All tiles have the size/placement properties, but this may change in the future...) // var tile = Tiles[x, y]; if (!tile.IsActive) { continue; // immediate short-circuit } var type = tile.Type; var prop = WorldSettings.Tiles[type]; var place = prop.Placement; if (prop.AttachesTo.Count > 0) { continue; // can't really handle these yet... } if (!ValidatePlacement(new PointInt32(x, y), prop.Size, place)) // validation found a problem { log.Add(string.Format("Tile [{2}] at [{0},{1}] must be placed on {3} {4}", x, y, prop.Name, place.Has(FP.MustHaveAll) ? "all of:" : (place.IsSingular() ? "a" : "any of:"), place.Remove(FP.MustHaveAll))); } // validate chest/sign/NPC entries exist switch (type) { case 21: // Validate Chest if (GetChestAtTile(x, y) == null) { var c = new Chest(new PointInt32(x, y)); for (int i = 0; i < 20; i++) { c.Items.Add(new Item(0, "[empty]")); } Chests.Add(c); log.Add(string.Format("added empty chest content [{0},{1}]", x, y)); } break; case 55: case 85: // Validate Sign/Tombstone if (GetSignAtTile(x, y) == null) { Signs.Add(new Sign("", new PointInt32(x, y))); log.Add(string.Format("added blank sign text [{0},{1}]", x, y)); } break; } // TODO: validate the frame exists completely // // assuming the left-right scan, it should hit the top-left corner first // thus, we skip around the rest of the frame for the x-axis // y-axis is a little bit more difficult... (and it requires that x stay put for a bit) if (prop.Size.Y > 1) { for (int s = 1; s < prop.Size.Y; s++) { deadSpace[x, y + s] = prop.Size.X; } } if (prop.Size.X > 1) { x += prop.Size.X - 1; } } } var p = 0; OnProgressChanged(this, "Validating Chests..."); foreach (var chest in Chests.ToList()) { var loc = chest.Location; int locType = Tiles[loc.X, loc.Y].Type; if (locType != 21) { Chests.Remove(chest); log.Add(string.Format("removed missing chest {0}", loc)); } OnProgressChanged(this, ++p, Chests.Count); } p = 0; OnProgressChanged(this, "Validating Signs..."); foreach (var sign in Signs.ToList()) { var loc = sign.Location; int locType = Tiles[loc.X, loc.Y].Type; if (locType != 55 && locType != 85) { Signs.Remove(sign); log.Add(string.Format("removed missing sign {0}", loc)); } OnProgressChanged(this, ++p, Signs.Count); } foreach (NPC npc in Npcs) { // no validation yet... // (SS: Okay, this is now in the XML; just need to port that stuff over) } IsUsingIo = false; OnProgressChanged(this, 100, 100, "Validation Complete."); log.Add("FINISHED with Validation!"); ErrorLogging.Log(string.Join(Environment.NewLine, log.ToArray())); }