-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create new Model project and transfer over Grynt code generator
- Loading branch information
1 parent
8eccb0d
commit adf1d1f
Showing
57 changed files
with
4,026 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="..\Ozzyria.Model\Ozzyria.Model.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Grynt.Generators.Decorators; | ||
using Grynt.Generators.Fields; | ||
using Grynt.Generators; | ||
using Grynt.Model.Packages; | ||
using Grynt.Model.Definitions; | ||
|
||
namespace Ozzyria.Grynt | ||
{ | ||
internal class Program | ||
{ | ||
public static string OzzyriaModelRoot() | ||
{ | ||
return Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName, "Ozzyria.Model"); | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
var targetNamespace = "Ozzyria.Model"; | ||
var modelRoot = OzzyriaModelRoot(); | ||
|
||
System.Console.WriteLine("---- TYPES ----"); | ||
|
||
var typePackage = TypePackage.Load(Path.Combine(modelRoot, "CodeGen", "Files", "type_defs.json")); | ||
var basicFieldGenerator = new FieldsGenerator(typePackage); | ||
var typeClassGenerator = new ClassGenerator(targetNamespace, "Types", [ | ||
new FieldsDecorator(basicFieldGenerator), | ||
new SerializableDecorator(typePackage), | ||
new HydrateableDecorator(typePackage) | ||
]); | ||
var typeGenerator = new TypeGenerator(targetNamespace, typePackage, typeClassGenerator); | ||
foreach (var type in typePackage.Definitions.Values) | ||
{ | ||
var code = typeGenerator.Generate(type); | ||
System.Console.WriteLine(code); | ||
if (type.Type != TypeDefinition.TYPE_ASSUMED) | ||
{ | ||
File.WriteAllText(Path.Combine(modelRoot, "Types", type.Name + ".cs"), code); | ||
} | ||
} | ||
|
||
|
||
System.Console.WriteLine("---- COMPONENTS ----"); | ||
|
||
var componentPackage = ComponentPackage.Load(Path.Combine(modelRoot, "CodeGen", "Files", "component_defs.json")); | ||
var componentClassGenerator = new ComponentGenerator(targetNamespace, typePackage); | ||
foreach (var component in componentPackage.Definitions.Values) | ||
{ | ||
var code = componentClassGenerator.Generate(component); | ||
System.Console.WriteLine(code); | ||
File.WriteAllText(Path.Combine(modelRoot, "Components", component.Name + ".cs"), code); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using Ozzyria.Model.Types; | ||
|
||
namespace Grynt.Model.Definitions | ||
{ | ||
public class ComponentDefinition | ||
{ | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("is_pooled")] | ||
public bool IsPooled { get; set; } | ||
|
||
[JsonPropertyName("fields")] | ||
public Dictionary<string, FieldDefinition> Fields { get; set; } | ||
|
||
[JsonPropertyName("defaults")] | ||
public ValuePacket Defaults { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Grynt.Model.Definitions | ||
{ | ||
public class FieldDefinition | ||
{ | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("type")] | ||
public string TypeId { get; set; } | ||
|
||
[JsonPropertyName("exclude_from_serialize")] | ||
public bool ExcludeFromSerialize { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using Ozzyria.Model.Types; | ||
|
||
namespace Grynt.Model.Definitions | ||
{ | ||
public class PrefabDefinition | ||
{ | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("components")] | ||
public List<string> Components { get; set; } | ||
|
||
[JsonPropertyName("defaults")] | ||
public ValuePacket Defaults { get; set; } | ||
|
||
[JsonPropertyName("exposed")] | ||
public List<string> Exposed { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
using Ozzyria.Model.Types; | ||
|
||
namespace Grynt.Model.Definitions | ||
{ | ||
public class TypeDefinition | ||
{ | ||
public const string TYPE_ASSUMED = "assumed"; | ||
public const string TYPE_ENUM = "enum"; | ||
public const string TYPE_CLASS = "class"; | ||
|
||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("type")] | ||
public string Type { get; set; } | ||
|
||
[JsonPropertyName("values")] | ||
public List<string> EnumValues { get; set; } | ||
|
||
[JsonPropertyName("fields")] | ||
public Dictionary<string, FieldDefinition> ClassFields { get; set; } | ||
|
||
[JsonPropertyName("defaults")] | ||
public ValuePacket ClassDefaults { get; set; } | ||
} | ||
} |
Oops, something went wrong.