Skip to content

Commit

Permalink
Allowing publish by script
Browse files Browse the repository at this point in the history
  • Loading branch information
Delsin-Yu committed May 18, 2024
1 parent a1843cc commit a513beb
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 39 deletions.
14 changes: 14 additions & 0 deletions ApplicationPublisher/ApplicationPublisher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\JsonPowerInspector.Versioning\JsonPowerInspector.Versioning.csproj" />
</ItemGroup>

</Project>
35 changes: 35 additions & 0 deletions ApplicationPublisher/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// See https://aka.ms/new-console-template for more information

using System.Diagnostics;

var programVersion = JsonPowerInspector.Version.Current;

var repoDir = Path.Combine(Environment.CurrentDirectory, "..", "..", "..", "..");

var projectPath = Path.GetFullPath(Path.Combine(repoDir, "JsonPowerInspector"));
var publishDir = Path.GetFullPath(Path.Combine(repoDir, "Build", $"Json Power Inspector v{programVersion}"));
var publishPath = $"../Build/\"Json Power Inspector v{programVersion}\"/\"Json Power Inspector.exe\"";
var godotPath = args[0];

Console.WriteLine(
$"""
Publishing version: {programVersion},
Project Path: {projectPath},
Publish Path: {publishPath},
Godot Path: {args[0]}
"""
);

Directory.CreateDirectory(publishDir);


var processStartInfo = new ProcessStartInfo
{
WorkingDirectory = projectPath,
Arguments = $"--headless --export-release Win64 {publishPath}",
FileName = godotPath
};

await Process.Start(processStartInfo)!.WaitForExitAsync();

Console.WriteLine("Publish finish");
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

</Project>
11 changes: 11 additions & 0 deletions JsonPowerInspector.Versioning/Version.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace JsonPowerInspector;

public static class Version
{
public static string Current => _versions[^1];

private static readonly string[] _versions =
[
"0.0.1"
];
}
1 change: 1 addition & 0 deletions JsonPowerInspector/JsonPowerInspector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="GDTask" Version="*" />
<PackageReference Include="JsonPowerInspector.Template" Version="*" />
<ProjectReference Include="..\JsonPowerInspector.Versioning\JsonPowerInspector.Versioning.csproj" />
<TrimmerRootAssembly Include="GodotSharp" />
<TrimmerRootAssembly Include="$(TargetName)" />
</ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions JsonPowerInspector/JsonPowerInspector.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonPowerInspector.Template
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication", "..\TestApplication\TestApplication.csproj", "{EFA1A05A-2E6B-43C8-9129-289010440016}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApplicationPublisher", "..\ApplicationPublisher\ApplicationPublisher.csproj", "{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonPowerInspector.Versioning", "..\JsonPowerInspector.Versioning\JsonPowerInspector.Versioning.csproj", "{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -31,5 +35,17 @@ Global
{EFA1A05A-2E6B-43C8-9129-289010440016}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
{EFA1A05A-2E6B-43C8-9129-289010440016}.ExportRelease|Any CPU.ActiveCfg = Debug|Any CPU
{EFA1A05A-2E6B-43C8-9129-289010440016}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}.ExportDebug|Any CPU.ActiveCfg = Debug|Any CPU
{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}.ExportRelease|Any CPU.ActiveCfg = Debug|Any CPU
{6FD4CA97-9E5A-4962-A21F-DD287C2DD4F4}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}.ExportDebug|Any CPU.ActiveCfg = Debug|Any CPU
{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}.ExportDebug|Any CPU.Build.0 = Debug|Any CPU
{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}.ExportRelease|Any CPU.ActiveCfg = Debug|Any CPU
{325D9CC3-0CAC-4413-9C06-8CC7DD70F9BB}.ExportRelease|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
EndGlobal
9 changes: 0 additions & 9 deletions JsonPowerInspector/Scripts/Dialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

namespace JsonPowerInspector;

public static class Version
{
public static string Current => _versions[^1];

private static readonly string[] _versions =
[
"0.0.1"
];
}
public static class Dialogs
{
public static GDTask<bool> OpenDataLossDialog() =>
Expand Down
2 changes: 1 addition & 1 deletion JsonPowerInspector/Scripts/InspectionSessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ string dataPath
try
{
using var fileStream = File.OpenRead(templatePath);
setup = JsonSerializer.Deserialize(fileStream, Serialization.Default.PackedObjectDefinition);
setup = JsonSerializer.Deserialize(fileStream, PowerTemplateJsonContext.Default.PackedObjectDefinition);
}
catch (Exception e)
{
Expand Down
25 changes: 0 additions & 25 deletions JsonPowerInspector/Scripts/Serialization.cs

This file was deleted.

12 changes: 10 additions & 2 deletions JsonPowerInspector/Scripts/UserConfig.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using Godot;

namespace JsonPowerInspector;

public static partial class UserConfig
{
[JsonSerializable(typeof(ConfigData))]
[JsonSourceGenerationOptions(UseStringEnumConverter = true, WriteIndented = true)]
private partial class ConfigDataContext : JsonSerializerContext;

public static JsonTypeInfo<ConfigData> Context => ConfigDataContext.Default.ConfigData;

public class ConfigData
{
public record struct SerializableVector2(int X, int Y)
Expand All @@ -30,13 +38,13 @@ public static void LoadConfig()
}
using var access = FileAccess.Open(_configPath, FileAccess.ModeFlags.Read);
var jsonText = access.GetAsText(true);
Current = JsonSerializer.Deserialize(jsonText, Serialization.Default.ConfigData);
Current = JsonSerializer.Deserialize(jsonText, Context);
Current ??= new();
}

public static void SaveConfig()
{
var jsonText = JsonSerializer.Serialize(Current, Serialization.Default.ConfigData);
var jsonText = JsonSerializer.Serialize(Current, Context);
using var access = FileAccess.Open(_configPath, FileAccess.ModeFlags.WriteRead);
access.StoreLine(jsonText);
}
Expand Down
133 changes: 131 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,141 @@
<!-- markdownlint-disable MD033 -->
<!-- markdownlint-disable MD010 -->
# Json Power Inspector for Typed Programing Languauge

Json Power Inspector is a JSON editor that offers advanced GUI editing experience based on the serialization information created from a typed language.

## Using the application

1. [Create a `.jsontemplate` file from your data structure.](#create-a-jsontemplate-file-from-your-data-structure)
2. Download and unzip the application to a place where you can remember.
3. Launch the application.
4. Drag and drop your `.jsontemplate` file to the application window.
5. Start editing.

## Language Support
## Create a JsonTemplate file from your data structure

Before start using the application, it is required for the developers to serialize their data structure into a dedicated `.jsontemplate` file that contains type information.

We provide a serializer Nuget package for `C#/dotnet8` developers, you are more than welcome to create your version of the serializer for your language/environment.

<img width="824" alt="0883561077770b3cbfdc2db912200966" src="https://github.com/Delsin-Yu/Json-Power-Inspector/assets/71481700/d7be2410-3200-47a4-965c-2f6c80551e4b">
### Documentation for `JsonPowerInspector.Template` Nuget Package Users

#### Usage

- Install the [JsonPowerInspector.Template](https://www.nuget.org/packages/JsonPowerInspector.Template) Nuget package into the C# project that contains the data structure you wish to work with, for demonstration purpose, let's use this `MyItem` type as an example.

```csharp
public struct MyItem
{
public string Name { get; set; }
public string Description { get; set; }
public int Price { get; set; }
}
```

- Use the following line to serialize the model and save it into a jsontemlpate file.

```csharp
var definition = TemplateSerializer.CollectTypeDefinition<MyItem>();
var jsonTemplateString = TemplateSerializer.Serialize(definition);
File.WriteAllText("MyItem.jsontemplate", jsonTemplateString);
```

#### Supported features and restrictions

- The serializer collect type info for `instance` `Properties` that are `publicly` avaible and have both `get` and `set` accessor.
- The following types and features are supported by the serializer:

|Type info|Restrictions|Inspector Type|Customizable Display Name|Restrict the number range|Displays a dropdown instead of value editor|
|-|-|-|-|-|-|
|`T[]` or `List<T>`|Nested types are displayed with their corresponding inspector|`Array Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor header|Annotate the property with `NumberRangeAttribute` for the array element type, the type itself should be compatible with `NumberRange`.|Annotate the property with `DropdownAttribute` for the array element type, the type itself should be compatible with `Dropdown`|
|`Dictionary<TKey, TValue>`|`TKey` only support `Numbers` or `Strings` (.Net restrictions)|`Dictionary Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor header|Annotate the property with `KeyNumberRangeAttribute` for `TKey`<br/> and use `ValueNumberRangeAttribute` for `TValue`, <br/>the annotated type should be a `NumberRange` compatible type.|Annotate the property with `KeyDropdownAttribute` for `TKey`<br/> and use `ValueDropdownAttribute` for `TValue`, <br/>the annotated type should be a `Dropdown` compatible type, the correcponding types gets |
|`bool`|N/A|`Boolean Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor name|Not supported|Not supported|
|Primitive number types `byte`, `ushort`, `uint`, `ulong`, `sbyte`, `short`, `int`, `long`, `float`, and `double`|Integer types only support inputing integral values, where Float types support inputing values with decimal|`Number Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor name|Annotate the property with `NumberRangeAttribute` to customize the value range|Use `DropdownAttribute` to customize the dropdown data source and value resolver|
|`string`|N/A|`String Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor name|Not supported|Annotate the property with `DropdownAttribute` to customize the dropdown data source and value resolver|
|`enum`|Enum Flags are not supported curerntly|`Enum Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor name, or annotated the enum values with `InspectorNameAttribute` to customize the names shown in the dropdown|Not supported|Not supported|
|Other Non-Generic Types|Only `instance` `Properties` that are `publicly` avaible and have both `get` and `set` accessor are recorded.|`Object Inspector`|Annotate the property with `InspectorNameAttribute` to customize the name shown in the editor header|Not Supported|Not Supported|

##### Example

- The model use for serialization:

```csharp
public class MyDemoModel
{
/// <summary>
/// Displayed as "Int Array" in inspector.
/// Each array element have an input range clamps to -2 to 2.
/// </summary>
[InspectorName("Int Array"), NumberRange(-2, 2)]
public int[] MyIntArrayProperty { get; set; }

/// <summary>
/// Displayed as "Dictionary" in inspector.
/// When adding a dictionary element,
/// the input range for the key clamps to 0 to 10.
/// </summary>
[InspectorName("Dictionary"), KeyNumberRange(0, 10)]
public Dictionary<int, string> MyDictionaryProperty { get; set; }

/// <summary>
/// Displayed as "MyBool" in inspector.
/// </summary>
public bool MyBool { get; set; }

/// <summary>
/// Displayed as "Number Value" in inspector.
/// Have an input range clamps to -10 to 10.
/// </summary>
[InspectorName("Number Value"), NumberRange(-10, 10)]
public float MyFloat { get; set; }

/// <summary>
/// Displayed as "Number Value" in inspector.
/// Use a dropdown for selecting the values.
/// </summary>
[InspectorName("String Value"), Dropdown("StringSelection.tsv")]
public string MyString { get; set; }

/// <summary>
/// Displayed as "Time Type" in inspector.
/// Use a dropdown for selecting the enum values.
/// </summary>
[InspectorName("Time Type")]
public DateTimeKind MyDateTimeKind { get; set; }

/// <summary>
/// Displayed as "Nested Model" in inspector.
/// </summary>
[InspectorName("Nested Model")]
public MyDemoModel Nested { get; set; }
}
```

- The serialization code:

```csharp
var definition = TemplateSerializer.CollectTypeDefinition<MyDemoModel>();
var jsonText = TemplateSerializer.Serialize(definition);
File.WriteAllText("MyDemoModel.jsontemplate", jsonText, Encoding.UTF8);
```

- And the content for `StringSelection.tsv`, which should be placed int the same with `MyDemoModel.jsontemplate`.

```text
Value Display
Lorem String Value: Lorem
ipsum String Value: ipsum
dolor String Value: dolor
sit String Value: sit
amet String Value: amet
consectetur String Value: consectetur
adipiscing String Value: adipiscing
elit String Value: elit
```

- Here is a screenshot of the inspector after loading the `MyDemoModel.jsontemplate`.

### Documentation for creating your serializer and `jsontemlpate` file specification

WIP

0 comments on commit a513beb

Please sign in to comment.