public void Validate() { for (int x = 0; x < TilesWide; x++) { OnProgressChanged(this, new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World...")); for (int y = 0; y < TilesHigh; y++) { Tile curTile = Tiles[x, y]; if (curTile.Type == (int)TileType.IceByRod) { curTile.IsActive = false; } // TODO: Let Validate handle these //validate chest entry exists if (Tile.IsChest(curTile.Type)) { if (GetChestAtTile(x, y) == null) { Chests.Add(new Chest(x, y)); } } //validate sign entry exists else if (Tile.IsSign(curTile.Type)) { if (GetSignAtTile(x, y) == null) { Signs.Add(new Sign(x, y, string.Empty)); } } } } foreach (Chest chest in Chests.ToArray()) { bool removed = false; for (int x = chest.X; x < chest.X + 1; x++) { for (int y = chest.Y; y < chest.Y + 1; y++) { if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type)) { Chests.Remove(chest); removed = true; break; } } if (removed) { break; } } } foreach (Sign sign in Signs.ToArray()) { if (sign.Text == null) { Signs.Remove(sign); continue; } bool removed = false; for (int x = sign.X; x < sign.X + 1; x++) { for (int y = sign.Y; y < sign.Y + 1; y++) { if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type)) { Signs.Remove(sign); removed = true; break; } } if (removed) { break; } } } OnProgressChanged(this, new ProgressChangedEventArgs(0, "Validating Complete...")); if (Chests.Count > 1000) { throw new ArgumentOutOfRangeException(string.Format("Chest Count is {0} which is greater than 1000", Chests.Count)); } if (Signs.Count > 1000) { throw new ArgumentOutOfRangeException(string.Format("Sign Count is {0} which is greater than 1000", Signs.Count)); } }
public void Validate() { var t = TaskFactoryHelper.UiTaskFactory.StartNew(() => { for (int x = 0; x < TilesWide; x++) { OnProgressChanged(this, new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World...")); for (int y = 0; y < TilesHigh; y++) { Tile curTile = Tiles[x, y]; if (curTile.Type == (int)TileType.IceByRod) { curTile.IsActive = false; } ValSpecial(x, y); } } }); foreach (Chest chest in Chests.ToArray()) { bool removed = false; for (int x = chest.X; x < chest.X + 1; x++) { for (int y = chest.Y; y < chest.Y + 1; y++) { if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type)) { Chests.Remove(chest); removed = true; break; } } if (removed) { break; } } } foreach (Sign sign in Signs.ToArray()) { if (sign.Text == null) { Signs.Remove(sign); continue; } bool removed = false; for (int x = sign.X; x < sign.X + 1; x++) { for (int y = sign.Y; y < sign.Y + 1; y++) { if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type)) { Signs.Remove(sign); removed = true; break; } } if (removed) { break; } } } foreach (TileEntity tileEntity in TileEntities.ToArray()) { int x = tileEntity.PosX; int y = tileEntity.PosY; var anchor = GetAnchor(x, y); if (!Tiles[anchor.X, anchor.Y].IsActive || !Tile.IsTileEntity(Tiles[anchor.X, anchor.Y].Type)) { TaskFactoryHelper.ExecuteUiTask(() => TileEntities.Remove(tileEntity)); } } OnProgressChanged(this, new ProgressChangedEventArgs(0, "Validating Complete...")); if (Chests.Count > World.MaxChests) { throw new ArgumentOutOfRangeException($"Chest Count is {Chests.Count} which is greater than {World.MaxChests}."); } if (Signs.Count > World.MaxSigns) { throw new ArgumentOutOfRangeException($"Sign Count is {Signs.Count} which is greater than {World.MaxSigns}."); } }
public void Validate() { for (int x = 0; x < TilesWide; x++) { OnProgressChanged(this, new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "验证世界文件...")); for (int y = 0; y < TilesHigh; y++) { Tile curTile = Tiles[x, y]; if (curTile.Type == (int)TileType.IceByRod) { curTile.IsActive = false; } ValSpecial(x, y); } } foreach (Chest chest in Chests.ToArray()) { bool removed = false; for (int x = chest.X; x < chest.X + 1; x++) { for (int y = chest.Y; y < chest.Y + 1; y++) { if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type)) { Chests.Remove(chest); removed = true; break; } } if (removed) { break; } } } foreach (Sign sign in Signs.ToArray()) { if (sign.Text == null) { Signs.Remove(sign); continue; } bool removed = false; for (int x = sign.X; x < sign.X + 1; x++) { for (int y = sign.Y; y < sign.Y + 1; y++) { if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type)) { Signs.Remove(sign); removed = true; break; } } if (removed) { break; } } } foreach (TileEntity tileEntity in TileEntities.ToArray()) { int x = tileEntity.PosX; int y = tileEntity.PosY; if (!Tiles[x, y].IsActive || !Tile.IsTileEntity(Tiles[x, y].Type)) { TileEntities.Remove(tileEntity); } } OnProgressChanged(this, new ProgressChangedEventArgs(0, "验证完整性...")); if (Chests.Count > 1000) { throw new ArgumentOutOfRangeException(string.Format("宝箱数量为 {0} 且大于1000.", Chests.Count)); } if (Signs.Count > 1000) { throw new ArgumentOutOfRangeException(string.Format("标牌数量为 {0} 且大于1000.", Signs.Count)); } }
public void Validate() { for (int x = 0; x < TilesWide; x++) { OnProgressChanged(this, new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World...")); for (int y = 0; y < TilesHigh; y++) { Tile curTile = Tiles[x, y]; if (curTile.Type == 127) { curTile.IsActive = false; } // TODO: Let Validate handle these //validate chest entry exists if (curTile.Type == 21 || curTile.Type == 88) { if (GetChestAtTile(x, y) == null) { Chests.Add(new Chest(x, y)); } } //validate sign entry exists else if (curTile.Type == 55 || curTile.Type == 85) { if (GetSignAtTile(x, y) == null) { Signs.Add(new Sign(x, y, string.Empty)); } } } } foreach (Chest chest in Chests.ToArray()) { bool removed = false; for (int x = chest.X; x < chest.X + 1; x++) { for (int y = chest.Y; y < chest.Y + 1; y++) { if (!Tiles[x, y].IsActive || (Tiles[x, y].Type != 21 && Tiles[x, y].Type != 88)) { Chests.Remove(chest); removed = true; break; } } if (removed) { break; } } } foreach (Sign sign in Signs.ToArray()) { if (sign.Text == null) { Signs.Remove(sign); continue; } bool removed = false; for (int x = sign.X; x < sign.X + 1; x++) { for (int y = sign.Y; y < sign.Y + 1; y++) { if (!Tiles[x, y].IsActive || (Tiles[x, y].Type != 55 && Tiles[x, y].Type != 85)) { Signs.Remove(sign); removed = true; break; } } if (removed) { break; } } } }
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())); }