public void SaveAndLoad_ShouldSaveSceneToFileAndThenLoadItFromFile_GivenSceneWithEntityWithTextRenderer() { // Arrange var scene = SystemUnderTest.SceneFactory.Create(); var entityWithTextRenderer = CreateNewEntityWithRandomName(); entityWithTextRenderer.AddComponent(new TextRendererComponent { Text = Utils.Random.GetString(), FontSize = FontSize.FromPoints(Utils.Random.Next()), Color = Color.FromArgb(Utils.Random.Next()), Visible = Utils.Random.NextBool(), SortingLayerName = Utils.Random.GetString(), OrderInLayer = Utils.Random.Next() }); scene.AddEntity(entityWithTextRenderer); // Act SystemUnderTest.SceneLoader.Save(scene, _sceneFilePath); var loadedScene = SystemUnderTest.SceneLoader.Load(_sceneFilePath); // Assert AssertScenesAreEqual(loadedScene, scene); AssertEntitiesAreEqual(loadedScene.RootEntities.Single(), entityWithTextRenderer); var textRenderer = entityWithTextRenderer.GetComponent <TextRendererComponent>(); var loadedTextRenderer = loadedScene.RootEntities.Single().GetComponent <TextRendererComponent>(); Assert.That(loadedTextRenderer.Text, Is.EqualTo(textRenderer.Text)); Assert.That(loadedTextRenderer.FontSize, Is.EqualTo(textRenderer.FontSize)); Assert.That(loadedTextRenderer.Color, Is.EqualTo(textRenderer.Color)); Assert.That(loadedTextRenderer.Visible, Is.EqualTo(textRenderer.Visible)); Assert.That(loadedTextRenderer.SortingLayerName, Is.EqualTo(textRenderer.SortingLayerName)); Assert.That(loadedTextRenderer.OrderInLayer, Is.EqualTo(textRenderer.OrderInLayer)); }
protected internal override void Deserialize(IComponentDataReader reader, IAssetStore assetStore) { base.Deserialize(reader, assetStore); Text = reader.ReadString("Text") ?? throw new InvalidOperationException("Text cannot be null."); FontSize = FontSize.FromPoints(reader.ReadDouble("FontSize")); Color = reader.ReadColor("Color"); }
public void FromPoints_ShouldReturnInstanceWithCorrectPointsAndDips(double expectedPoints, double expectedDips) { // Arrange // Act var actual = FontSize.FromPoints(expectedPoints); // Assert Assert.That(actual.Points, Is.EqualTo(expectedPoints)); Assert.That(actual.Dips, Is.EqualTo(expectedDips)); }
public void ToString_Test(double points, string expected) { // Arrange var fontSize = FontSize.FromPoints(points); // Act var actual = fontSize.ToString(); // Assert Assert.That(actual, Is.EqualTo(expected)); }
public void EqualityMembers_ShouldEqualFontSize_WhenPointsAreEqual(double points1, double points2, bool expectedIsEqual) { // Arrange var fontSize1 = FontSize.FromPoints(points1); var fontSize2 = FontSize.FromPoints(points2); // Act // Assert AssertEqualityMembers .ForValues(fontSize1, fontSize2) .UsingEqualityOperator((x, y) => x == y) .UsingInequalityOperator((x, y) => x != y) .EqualityIsExpectedToBe(expectedIsEqual); }
public override void OnFixedUpdate() { var time = (_ticks / 60.0) * Rate; Debug.Assert(Entity != null, nameof(Entity) + " != null"); var textRenderer = Entity.GetComponent <TextRendererComponent>(); //var transform = Entity.GetComponent<Transform2DComponent>(); textRenderer.FontSize = FontSize.FromPoints((Math.Sin(time * 2) + 1.1) * 40); //transform.Scale = new Vector2((Math.Sin(time) + 1.1) * 10, (Math.Sin(time) + 1.1) * 10); _ticks++; }
public Entity AddText() { var entity = new Entity(); entity.AddComponent(RandomTransform2DComponent()); entity.AddComponent(new TextRendererComponent { Text = Utils.Random.GetString(), FontSize = FontSize.FromPoints(Utils.Random.NextDouble()), Color = Color.FromArgb(Utils.Random.Next()) }); _scene.AddEntity(entity); return(entity); }
public void SerializeAndDeserialize() { // Arrange var component = new TextRendererComponent { Visible = false, SortingLayerName = "Some sorting layer", OrderInLayer = 2, Text = "some text", FontSize = FontSize.FromPoints(12.34), Color = Color.FromArgb(1, 2, 3, 4) }; // Act var actual = SerializeAndDeserialize(component); // Assert Assert.That(actual.Visible, Is.EqualTo(component.Visible)); Assert.That(actual.SortingLayerName, Is.EqualTo(component.SortingLayerName)); Assert.That(actual.OrderInLayer, Is.EqualTo(component.OrderInLayer)); Assert.That(actual.Text, Is.EqualTo(component.Text)); Assert.That(actual.FontSize, Is.EqualTo(component.FontSize)); Assert.That(actual.Color, Is.EqualTo(component.Color)); }
private void CreateRotatingText() { var text = new Entity(); text.AddComponent(Transform2DComponent.CreateDefault()); text.AddComponent(new TextRendererComponent { Text = "I am Text!", Color = Color.FromArgb(255, 0, 255, 0), FontSize = FontSize.FromPoints(16) }); text.AddComponent(new FollowEllipseComponent { Velocity = 1, Width = 300, Height = 300 }); text.AddComponent(new RotateComponent()); text.AddComponent(new DoMagicWithTextComponent()); Scene.AddEntity(text); }