Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: main

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
Build:
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true

- name: Restore packages
run: nuget restore
working-directory: ./Source

- name: Setup build
uses: microsoft/setup-msbuild@v2

- name: Build targets
run: msbuild /t:ExplorerCommand /t:glTF /t:Tests /p:Configuration=Release /p:Platform=x64
working-directory: ./Source

- name: Run tests
run: dotnet test ./Build/Tests/bin/Release/AnyCPU/Tests.dll -s ./Source/.runsettings -v n
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Build

# published files end up here
/Source/glTF/bin

# launc settings
/Source/glTF/Properties/launchSettings.json
6 changes: 6 additions & 0 deletions Source/.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<ResultsDirectory>..\Build\Tests\Results</ResultsDirectory>
</RunConfiguration>
</RunSettings>
File renamed without changes.
10 changes: 10 additions & 0 deletions Source/Core/Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>glTF</RootNamespace>
</PropertyGroup>

</Project>
79 changes: 79 additions & 0 deletions Source/Core/Extensions/JsonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Text.Json;
using System.Text.Json.Nodes;

namespace glTF
{
internal static class JsonExtensions
{
public static JsonArray? GetArray(this JsonNode node, string propertyName, JsonArray? defaultValue = null)
{
var propertyNode = node[propertyName];
if (propertyNode == null || propertyNode.GetValueKind() != JsonValueKind.Array)
{
return defaultValue;
}

return propertyNode.AsArray();
}

public static int GetInt(this JsonNode node, string propertyName, int defaultValue = -1)
{
var propertyNode = node[propertyName];
if (propertyNode == null || propertyNode.GetValueKind() != JsonValueKind.Number)
{
return defaultValue;
}

return propertyNode.GetValue<int>();
}

public static string? GetString(this JsonNode node, string propertyName, string? defaultValue = null)
{
var propertyNode = node[propertyName];
if (propertyNode == null || propertyNode.GetValueKind() != JsonValueKind.String)
{
return defaultValue;
}

return propertyNode.GetValue<string>();
}

public static string? GetLocalPath(this JsonNode node, string propertyName, Uri baseUri, string? defaultValue = null)
{
var uriString = node.GetString(propertyName);
if (uriString == null)
{
return defaultValue;
}

if (!Uri.TryCreate(baseUri, uriString, out var uri) || !uri.IsFile)
{
return defaultValue;
}

return uri.LocalPath;
}

public static void SetInt(this JsonNode jsonNode, string propertyName, int value, int defaultValue)
{
if (value == defaultValue)
{
jsonNode.AsObject().Remove(propertyName);
}
else
{
jsonNode[propertyName] = JsonValue.Create(value);
}
}

public static bool Remove(this JsonNode node, string propertyName)
{
if (node.GetValueKind() != JsonValueKind.Object)
{
return false;
}

return node.AsObject().Remove(propertyName);
}
}
}
47 changes: 47 additions & 0 deletions Source/Core/MimeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace glTF
{
internal class MimeType
{
public static string ToFileExtension(string? mimeType)
{
switch (mimeType)
{
case "image/png":
return ".png";
case "image/jpeg":
return ".jpg";
case "image/vnd-ms.dds":
return ".dds";
case "image/ktx2":
return ".ktx2";
case "image/webp":
return ".webp";
}

return ".bin";
}

public static string FromFileExtension(string? fileExtension)
{
if (fileExtension != null)
{
switch (fileExtension.ToLower())
{
case ".png":
return "image/png";
case ".jpg":
case ".jpeg":
return "image/jpeg";
case ".dds":
return "image/vnd-ms.dds";
case ".ktx2":
return "image/ktx2";
case ".webp":
return "image/webp";
}
}

return "application/octet-stream";
}
}
}
Loading