Skip to content

Commit 2aa6000

Browse files
authored
Merge pull request #3 from moorestech/codex/jsonパース処理の生成
Add vector types parsing
2 parents 5790ae3 + bd47fc5 commit 2aa6000

7 files changed

Lines changed: 57 additions & 3 deletions

File tree

CommandForgeGenerator.SandBox/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ private static void Main(string[] args)
1212
var json = GetJson();
1313
var loader = CommandForgeLoader.LoadCommands(json);
1414

15-
if (loader.Count == 152)
15+
if (loader.Count == 12)
1616
{
17-
Console.WriteLine(loader.Count == 152 ? "OK" : "NG");
17+
Console.WriteLine("OK");
1818
}
1919
else
2020
{

CommandForgeGenerator.SandBox/SampleProject/commands.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ commands:
1414
multiline: true
1515
required: true
1616

17+
- id: characterPosition
18+
label: カメラ位置
19+
description: カメラ位置
20+
commandListLabelFormat: "カメラ移動 {position}"
21+
properties:
22+
position:
23+
type: vector3
24+
required: true
25+
1726
- id: emote
1827
label: エモート
1928
description: 立ち絵・表情切替

CommandForgeGenerator.SandBox/SampleProject/skits/sample_skit.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
"type": "wait",
7474
"seconds": 0.5,
7575
"backgroundColor": "#57e317"
76+
},
77+
{
78+
"id": 100,
79+
"type": "characterPosition",
80+
"position": [0, 10.5 , 0]
7681
}
7782
]
7883
}

CommandForgeGenerator/CodeGenerate/CodeGenerator.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ private static string GenerateCreateMethodTempVariables(List<CommandProperty> co
119119
{
120120
properties.AppendLine($"var {property.CodeProperty} = (CommandId)((int)json[\"{property.Name}\"]);");
121121
}
122+
else if (property.Type is CommandPropertyType.Vector2)
123+
{
124+
properties.AppendLine($"var {property.CodeProperty}Array = json[\"{property.Name}\"];");
125+
properties.AppendLine($"var {property.CodeProperty} = new global::UnityEngine.Vector2((float){property.CodeProperty}Array[0], (float){property.CodeProperty}Array[1]);");
126+
}
127+
else if (property.Type is CommandPropertyType.Vector3)
128+
{
129+
properties.AppendLine($"var {property.CodeProperty}Array = json[\"{property.Name}\"];");
130+
properties.AppendLine($"var {property.CodeProperty} = new global::UnityEngine.Vector3((float){property.CodeProperty}Array[0], (float){property.CodeProperty}Array[1], (float){property.CodeProperty}Array[2]);");
131+
}
132+
else if (property.Type is CommandPropertyType.Vector4)
133+
{
134+
properties.AppendLine($"var {property.CodeProperty}Array = json[\"{property.Name}\"];");
135+
properties.AppendLine($"var {property.CodeProperty} = new global::UnityEngine.Vector4((float){property.CodeProperty}Array[0], (float){property.CodeProperty}Array[1], (float){property.CodeProperty}Array[2], (float){property.CodeProperty}Array[3]);");
136+
}
137+
else if (property.Type is CommandPropertyType.Vector2Int)
138+
{
139+
properties.AppendLine($"var {property.CodeProperty}Array = json[\"{property.Name}\"];");
140+
properties.AppendLine($"var {property.CodeProperty} = new global::UnityEngine.Vector2Int((int){property.CodeProperty}Array[0], (int){property.CodeProperty}Array[1]);");
141+
}
142+
else if (property.Type is CommandPropertyType.Vector3Int)
143+
{
144+
properties.AppendLine($"var {property.CodeProperty}Array = json[\"{property.Name}\"];");
145+
properties.AppendLine($"var {property.CodeProperty} = new global::UnityEngine.Vector3Int((int){property.CodeProperty}Array[0], (int){property.CodeProperty}Array[1], (int){property.CodeProperty}Array[2]);");
146+
}
122147
else
123148
{
124149
properties.AppendLine($"var {property.CodeProperty} = ({type})json[\"{property.Name}\"];");
@@ -173,6 +198,11 @@ private static string GetTypeCode(CommandPropertyType type)
173198
CommandPropertyType.Float => "float",
174199
CommandPropertyType.Bool => "bool",
175200
CommandPropertyType.CommandId => "CommandId",
201+
CommandPropertyType.Vector2 => "global::UnityEngine.Vector2",
202+
CommandPropertyType.Vector3 => "global::UnityEngine.Vector3",
203+
CommandPropertyType.Vector4 => "global::UnityEngine.Vector4",
204+
CommandPropertyType.Vector2Int => "global::UnityEngine.Vector2Int",
205+
CommandPropertyType.Vector3Int => "global::UnityEngine.Vector3Int",
176206
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
177207
};
178208
}

CommandForgeGenerator/CommandForgeGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<!-- NuGet Package Metadata -->
1919
<Title>CommandForge Generator</Title>
2020
<Authors>Moorestech</Authors>
21-
<Version>1.0.2</Version>
21+
<Version>1.0.3</Version>
2222
<Description>CommandForgeEditorのcommands.yamlのC#コードを生成するSourceGenerator</Description>
2323
<PackageProjectUrl>https://github.com/moorestech/CommandForgeGenerator</PackageProjectUrl>
2424
<RepositoryUrl>https://github.com/moorestech/CommandForgeGenerator</RepositoryUrl>

CommandForgeGenerator/Semantic/CommandSemanticsLoader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ CommandsSemantics ParseCommandsSchema(JsonObject root)
8282
"boolean" => CommandPropertyType.Bool,
8383
"enum" => CommandPropertyType.String,
8484
"command" => CommandPropertyType.CommandId,
85+
"vector2" => CommandPropertyType.Vector2,
86+
"vector3" => CommandPropertyType.Vector3,
87+
"vector4" => CommandPropertyType.Vector4,
88+
"vector2int" => CommandPropertyType.Vector2Int,
89+
"vector3int" => CommandPropertyType.Vector3Int,
8590
_ => throw new Exception($"未知の property type \"{typeStr}\"")
8691
};
8792

CommandForgeGenerator/Semantic/CommandsSemantics.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public enum CommandPropertyType{
4545
Float,
4646
Bool,
4747
CommandId,
48+
Vector2,
49+
Vector3,
50+
Vector4,
51+
Vector2Int,
52+
Vector3Int,
4853
}

0 commit comments

Comments
 (0)