private bool AddSign(Sign sign) { var index = -1; lock (_signLock) { for (var i = 0; i < _terrariaSigns.Length; ++i) { var terrariaSign = _terrariaSigns[i]; if (terrariaSign == null) { index = i; break; } var type = _terrariaTiles[terrariaSign.x, terrariaSign.y].type; if (type != TileID.Signs && type != TileID.Tombstones && type != TileID.AnnouncementBox) { index = i; break; } } if (index < 0) { return(false); } _terrariaSigns[index] = Adapt(sign); } return(true); }
private bool RemoveSign(Sign sign) { lock (_signLock) { var index = -1; for (var i = _terrariaSigns.Length - 1; i >= 0; --i) { var terrariaSign = _terrariaSigns[i]; if (terrariaSign != null && terrariaSign.x == sign.Position.X && terrariaSign.y == sign.Position.Y) { index = i; break; } } if (index < 0) { return(false); } _terrariaSigns[index] = null; } return(true); }
public void WriteRead() { var tiles = new Tile?[10, 10]; Main.tileFrameImportant[1] = true; var tile = new Tile { IsActive = true, BlockColor = 1, WallColor = 1, BlockId = 1, WallId = 1, Liquid = 255 }; for (var x = 0; x < 10; ++x) { for (var y = 0; y < 10; ++y) { tiles[x, y] = tile; } } var clipboard = new Clipboard(tiles); var items = new Item[40]; items[0] = new Item(1, 2, 3); var chest = new Chest(new Vector(0, 1), "Test", new Item[40]); var itemFrame = new ItemFrame(new Vector(3, 4), new Item(1, 2, 3)); var logicSensor = new LogicSensor(new Vector(2, 5), LogicSensorType.Day, true, 5); var sign = new Sign(new Vector(1, 0), "Test2"); var trainingDummy = new TrainingDummy(new Vector(4, 5), 21); clipboard.AddTileEntity(chest); clipboard.AddTileEntity(itemFrame); clipboard.AddTileEntity(logicSensor); clipboard.AddTileEntity(sign); clipboard.AddTileEntity(trainingDummy); var schematicFormat = new DefaultSchematicFormat(); Clipboard clipboard2; using (var stream = new MemoryStream()) { schematicFormat.Write(clipboard, stream); stream.Position = 0; clipboard2 = schematicFormat.Read(stream); Assert.That(clipboard2, Is.Not.Null); } for (var x = 0; x < 10; ++x) { for (var y = 0; y < 10; ++y) { Assert.That(clipboard2.GetTile(new Vector(x, y)), Is.EqualTo(tile)); } } foreach (var entity in clipboard2.GetTileEntities()) { if (entity is Chest chest2) { Assert.That(chest2.Position, Is.EqualTo(chest.Position)); Assert.That(chest2.Name, Is.EqualTo(chest.Name)); Assert.That(chest2.Items, Is.EquivalentTo(chest2.Items)); } else if (entity is ItemFrame itemFrame2) { Assert.That(itemFrame2.Position, Is.EqualTo(itemFrame.Position)); Assert.That(itemFrame2.Item, Is.EqualTo(itemFrame.Item)); } else if (entity is LogicSensor logicSensor2) { Assert.That(logicSensor2.Position, Is.EqualTo(logicSensor.Position)); Assert.That(logicSensor2.Type, Is.EqualTo(logicSensor.Type)); Assert.That(logicSensor2.IsEnabled, Is.EqualTo(logicSensor.IsEnabled)); Assert.That(logicSensor2.Data, Is.EqualTo(logicSensor.Data)); } else if (entity is Sign sign2) { Assert.That(sign2.Position, Is.EqualTo(sign.Position)); Assert.That(sign2.Text, Is.EqualTo(sign.Text)); } else if (entity is TrainingDummy trainingDummy2) { Assert.That(trainingDummy2.Position, Is.EqualTo(trainingDummy.Position)); Assert.That(trainingDummy2.NpcIndex, Is.EqualTo(trainingDummy.NpcIndex)); } } }
private static TerrariaSign Adapt(Sign sign) => new TerrariaSign { x = sign.Position.X, y = sign.Position.Y, text = sign.Text };