Asset_Create_SpriteAnimation_ShouldRecreateSpriteAnimationAssetFileWithTheSameAssetId_WhenSpriteAnimationAssetFileAlreadyExists_GivenKeepAssetId()
        {
            // Arrange
            CopyAnimationFiles();

            var spriteAnimationAssetFilePath =
                Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension(new DirectoryInfo(_temporaryDirectory.Path).Name));

            RunGeishaCli($"asset create sprite-animation \"{_temporaryDirectory.Path}\"");

            var originalAssetData = AssetData.Load(spriteAnimationAssetFilePath);
            var modifiedAssetData = AssetData.CreateWithJsonContent(originalAssetData.AssetId, originalAssetData.AssetType, new SpriteAnimationAssetContent());

            modifiedAssetData.Save(spriteAnimationAssetFilePath);

            // Act
            RunGeishaCli($"asset create sprite-animation \"{_temporaryDirectory.Path}\" --keep-asset-id");

            // Assert
            var actualAssetData = AssetData.Load(spriteAnimationAssetFilePath);

            Assert.That(actualAssetData.AssetId, Is.EqualTo(originalAssetData.AssetId));
            Assert.That(actualAssetData.ReadJsonContent <SpriteAnimationAssetContent>().DurationTicks, Is.EqualTo(TimeSpan.FromSeconds(1).Ticks));
        }
        public void Asset_Create_InputMapping_ShouldCreateDefaultInputMappingAssetFileInCurrentDirectory()
        {
            // Arrange
            // Act
            RunGeishaCli("asset create input-mapping", _temporaryDirectory.Path);

            // Assert
            var inputMappingAssetFilePath = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("DefaultInputMapping"));

            Assert.That(File.Exists(inputMappingAssetFilePath), Is.True, "InputMapping asset file was not created.");

            var inputMappingAssetData = AssetData.Load(inputMappingAssetFilePath);

            Assert.That(inputMappingAssetData.AssetId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(inputMappingAssetData.AssetType, Is.EqualTo(InputAssetTypes.InputMapping));

            var inputMappingAssetContent = inputMappingAssetData.ReadJsonContent <InputMappingAssetContent>();

            Assert.That(inputMappingAssetContent.ActionMappings, Contains.Key("Jump"));
            Debug.Assert(inputMappingAssetContent.ActionMappings != null, "inputMappingAssetContent.ActionMappings != null");
            var jumpAction = inputMappingAssetContent.ActionMappings["Jump"];

            Assert.That(jumpAction, Has.Length.EqualTo(2));
            Assert.That(jumpAction[0].Key, Is.EqualTo(Key.Space));
            Assert.That(jumpAction[1].Key, Is.EqualTo(Key.Up));

            Assert.That(inputMappingAssetContent.AxisMappings, Contains.Key("MoveRight"));
            Debug.Assert(inputMappingAssetContent.AxisMappings != null, "inputMappingAssetContent.AxisMappings != null");
            var moveRightAxis = inputMappingAssetContent.AxisMappings["MoveRight"];

            Assert.That(moveRightAxis, Has.Length.EqualTo(2));
            Assert.That(moveRightAxis[0].Key, Is.EqualTo(Key.Right));
            Assert.That(moveRightAxis[0].Scale, Is.EqualTo(1.0));
            Assert.That(moveRightAxis[1].Key, Is.EqualTo(Key.Left));
            Assert.That(moveRightAxis[1].Scale, Is.EqualTo(-1.0));
        }
        public void Asset_Create_Sprite_ShouldCreateSpriteAssetFileInTheSameDirectoryAsTextureAssetFile_GivenTextureAssetFilePath()
        {
            // Arrange
            var pngFilePathToCopy    = Utils.GetPathUnderTestDirectory(@"Assets\TestTexture.png");
            var pngFilePathInTempDir = Path.Combine(_temporaryDirectory.Path, "TestTexture.png");

            File.Copy(pngFilePathToCopy, pngFilePathInTempDir);

            var textureAssetFilePathToCopy    = Utils.GetPathUnderTestDirectory(AssetFileUtils.AppendExtension(@"Assets\TestTexture"));
            var textureAssetFilePathInTempDir = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestTexture"));

            File.Copy(textureAssetFilePathToCopy, textureAssetFilePathInTempDir);

            // Act
            RunGeishaCli($"asset create sprite \"{textureAssetFilePathInTempDir}\"");

            // Assert
            var spriteAssetFilePath = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestTexture.sprite"));

            Assert.That(File.Exists(spriteAssetFilePath), Is.True, "Sprite asset file was not created.");

            var assetData = AssetData.Load(spriteAssetFilePath);

            Assert.That(assetData.AssetId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(assetData.AssetType, Is.EqualTo(RenderingAssetTypes.Sprite));
            var spriteAssetContent = assetData.ReadJsonContent <SpriteAssetContent>();

            Assert.That(spriteAssetContent.TextureAssetId, Is.EqualTo(AssetsIds.TestTexture.Value));
            Assert.That(spriteAssetContent.SourceUV.X, Is.Zero);
            Assert.That(spriteAssetContent.SourceUV.Y, Is.Zero);
            Assert.That(spriteAssetContent.SourceDimensions.X, Is.EqualTo(10));
            Assert.That(spriteAssetContent.SourceDimensions.Y, Is.EqualTo(10));
            Assert.That(spriteAssetContent.Pivot.X, Is.EqualTo(5));
            Assert.That(spriteAssetContent.Pivot.Y, Is.EqualTo(5));
            Assert.That(spriteAssetContent.PixelsPerUnit, Is.EqualTo(1));
        }
        public void Asset_Create_Sprite_ShouldCreateSpriteAssetFiles_GivenSpriteParameters(string parameters)
        {
            // Arrange
            var pngFilePathToCopy    = Utils.GetPathUnderTestDirectory(@"Assets\SpriteSheet\TestSpriteSheet.png");
            var pngFilePathInTempDir = Path.Combine(_temporaryDirectory.Path, "TestSpriteSheet.png");

            File.Copy(pngFilePathToCopy, pngFilePathInTempDir);

            var textureAssetFilePathToCopy    = Utils.GetPathUnderTestDirectory(AssetFileUtils.AppendExtension(@"Assets\SpriteSheet\TestSpriteSheet"));
            var textureAssetFilePathInTempDir = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestSpriteSheet"));

            File.Copy(textureAssetFilePathToCopy, textureAssetFilePathInTempDir);

            // Act
            RunGeishaCli($"asset create sprite \"{textureAssetFilePathInTempDir}\" {parameters}");

            // Assert
            var spriteAssetFilePath1 = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestSpriteSheet_0.sprite"));

            Assert.That(File.Exists(spriteAssetFilePath1), Is.True, "Sprite asset file was not created.");

            var assetData1 = AssetData.Load(spriteAssetFilePath1);

            Assert.That(assetData1.AssetId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(assetData1.AssetType, Is.EqualTo(RenderingAssetTypes.Sprite));
            var spriteAssetContent1 = assetData1.ReadJsonContent <SpriteAssetContent>();

            Assert.That(spriteAssetContent1.TextureAssetId, Is.EqualTo(AssetsIds.SpriteSheet.Texture.Value));
            Assert.That(spriteAssetContent1.SourceUV.X, Is.EqualTo(25));
            Assert.That(spriteAssetContent1.SourceUV.Y, Is.EqualTo(50));
            Assert.That(spriteAssetContent1.SourceDimensions.X, Is.EqualTo(25));
            Assert.That(spriteAssetContent1.SourceDimensions.Y, Is.EqualTo(25));
            Assert.That(spriteAssetContent1.Pivot.X, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent1.Pivot.Y, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent1.PixelsPerUnit, Is.EqualTo(1));

            var spriteAssetFilePath2 = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestSpriteSheet_1.sprite"));

            Assert.That(File.Exists(spriteAssetFilePath2), Is.True, "Sprite asset file was not created.");

            var assetData2 = AssetData.Load(spriteAssetFilePath2);

            Assert.That(assetData2.AssetId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(assetData2.AssetType, Is.EqualTo(RenderingAssetTypes.Sprite));
            var spriteAssetContent2 = assetData2.ReadJsonContent <SpriteAssetContent>();

            Assert.That(spriteAssetContent2.TextureAssetId, Is.EqualTo(AssetsIds.SpriteSheet.Texture.Value));
            Assert.That(spriteAssetContent2.SourceUV.X, Is.EqualTo(50));
            Assert.That(spriteAssetContent2.SourceUV.Y, Is.EqualTo(50));
            Assert.That(spriteAssetContent2.SourceDimensions.X, Is.EqualTo(25));
            Assert.That(spriteAssetContent2.SourceDimensions.Y, Is.EqualTo(25));
            Assert.That(spriteAssetContent2.Pivot.X, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent2.Pivot.Y, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent2.PixelsPerUnit, Is.EqualTo(1));

            var spriteAssetFilePath3 = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestSpriteSheet_2.sprite"));

            Assert.That(File.Exists(spriteAssetFilePath3), Is.True, "Sprite asset file was not created.");

            var assetData3 = AssetData.Load(spriteAssetFilePath3);

            Assert.That(assetData3.AssetId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(assetData3.AssetType, Is.EqualTo(RenderingAssetTypes.Sprite));
            var spriteAssetContent3 = assetData3.ReadJsonContent <SpriteAssetContent>();

            Assert.That(spriteAssetContent3.TextureAssetId, Is.EqualTo(AssetsIds.SpriteSheet.Texture.Value));
            Assert.That(spriteAssetContent3.SourceUV.X, Is.EqualTo(75));
            Assert.That(spriteAssetContent3.SourceUV.Y, Is.EqualTo(50));
            Assert.That(spriteAssetContent3.SourceDimensions.X, Is.EqualTo(25));
            Assert.That(spriteAssetContent3.SourceDimensions.Y, Is.EqualTo(25));
            Assert.That(spriteAssetContent3.Pivot.X, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent3.Pivot.Y, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent3.PixelsPerUnit, Is.EqualTo(1));

            var spriteAssetFilePath4 = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestSpriteSheet_3.sprite"));

            Assert.That(File.Exists(spriteAssetFilePath4), Is.True, "Sprite asset file was not created.");

            var assetData4 = AssetData.Load(spriteAssetFilePath4);

            Assert.That(assetData4.AssetId, Is.Not.EqualTo(Guid.Empty));
            Assert.That(assetData4.AssetType, Is.EqualTo(RenderingAssetTypes.Sprite));
            var spriteAssetContent4 = assetData4.ReadJsonContent <SpriteAssetContent>();

            Assert.That(spriteAssetContent4.TextureAssetId, Is.EqualTo(AssetsIds.SpriteSheet.Texture.Value));
            Assert.That(spriteAssetContent4.SourceUV.X, Is.EqualTo(0));
            Assert.That(spriteAssetContent4.SourceUV.Y, Is.EqualTo(75));
            Assert.That(spriteAssetContent4.SourceDimensions.X, Is.EqualTo(25));
            Assert.That(spriteAssetContent4.SourceDimensions.Y, Is.EqualTo(25));
            Assert.That(spriteAssetContent4.Pivot.X, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent4.Pivot.Y, Is.EqualTo(12.5));
            Assert.That(spriteAssetContent4.PixelsPerUnit, Is.EqualTo(1));
        }
        Asset_Create_Sprite_ShouldRecreateSpriteAssetFileWithTheSameAssetId_WhenSpriteAssetFileAlreadyExists_GivenTextureAssetFilePath_And_KeepAssetId()
        {
            // Arrange
            var pngFilePathToCopy    = Utils.GetPathUnderTestDirectory(@"Assets\TestTexture.png");
            var pngFilePathInTempDir = Path.Combine(_temporaryDirectory.Path, "TestTexture.png");

            File.Copy(pngFilePathToCopy, pngFilePathInTempDir);

            var textureAssetFilePathToCopy    = Utils.GetPathUnderTestDirectory(AssetFileUtils.AppendExtension(@"Assets\TestTexture"));
            var textureAssetFilePathInTempDir = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestTexture"));

            File.Copy(textureAssetFilePathToCopy, textureAssetFilePathInTempDir);

            var spriteAssetFilePath = Path.Combine(_temporaryDirectory.Path, AssetFileUtils.AppendExtension("TestTexture.sprite"));

            RunGeishaCli($"asset create sprite \"{textureAssetFilePathInTempDir}\"");

            var originalAssetData = AssetData.Load(spriteAssetFilePath);
            var modifiedAssetData = AssetData.CreateWithJsonContent(originalAssetData.AssetId, originalAssetData.AssetType, new SpriteAssetContent());

            modifiedAssetData.Save(spriteAssetFilePath);

            // Act
            RunGeishaCli($"asset create sprite \"{textureAssetFilePathInTempDir}\" --keep-asset-id");

            // Assert
            var actualAssetData = AssetData.Load(spriteAssetFilePath);

            Assert.That(actualAssetData.AssetId, Is.EqualTo(originalAssetData.AssetId));
            Assert.That(actualAssetData.ReadJsonContent <SpriteAssetContent>().TextureAssetId, Is.EqualTo(AssetsIds.TestTexture.Value));
        }
예제 #6
0
 private static AssetInfo CreateNewAssetInfo()
 {
     return(new AssetInfo(AssetId.CreateUnique(), new AssetType("AssetType.Object"), AssetFileUtils.AppendExtension("asset-file")));
 }