Skip to content

Commit fb823ad

Browse files
authored
Merge pull request #16 from moorestech/revert-15-feature/code-revert
Revert "全部のコードをrevertしてみる"
2 parents 0fd8865 + 5bd3e54 commit fb823ad

80 files changed

Lines changed: 4091 additions & 212 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/settings.local.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(find:*)",
5+
"Bash(dotnet test:*)"
6+
]
7+
},
8+
"enableAllProjectMcpServers": false
9+
}

.github/workflows/nuget_push.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: NugetPush
22
on:
33
workflow_dispatch: {}
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
48

59
jobs:
610
push:

CLAUDE.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
CommandForgeGenerator is a C# Source Generator that converts YAML-based command definitions (commands.yaml) from CommandForgeEditor into strongly-typed C# code. It generates type-safe command classes from game scripting definitions.
8+
9+
## Build and Development Commands
10+
11+
### Building the Project
12+
```bash
13+
# Build entire solution
14+
dotnet build
15+
16+
# Build specific project
17+
dotnet build CommandForgeGenerator/CommandForgeGenerator.csproj
18+
19+
# Build in Release mode
20+
dotnet build -c Release
21+
22+
# Create NuGet package
23+
dotnet pack CommandForgeGenerator/CommandForgeGenerator.csproj -c Release
24+
```
25+
26+
### Running Tests
27+
```bash
28+
# Run all tests
29+
dotnet test
30+
31+
# Run tests with detailed output
32+
dotnet test --logger "console;verbosity=detailed"
33+
```
34+
35+
## Architecture Overview
36+
37+
### Source Generator Pipeline
38+
1. **Entry Point**: `CommandForgeGeneratorSourceGenerator` (CommandForgeGenerator.cs:9) - Implements `IIncrementalGenerator`
39+
2. **YAML Processing**: `CommandSemanticsLoader` (Semantic/CommandSemanticsLoader.cs) - Parses commands.yaml files
40+
3. **Code Generation**: `CodeGenerator` (CodeGenerate/CodeGenerator.cs) - Generates C# classes from parsed semantics
41+
42+
### Key Components
43+
44+
**YAML to Semantics Flow**:
45+
- YAML files are converted to JSON using embedded YamlDotNet
46+
- JSON is parsed using custom parser (`Json/JsonParser.cs`)
47+
- Semantics are extracted into `CommandsSemantics` data structures
48+
49+
**Generated Code Structure**:
50+
- `ICommandForgeCommand.g.cs` - Base interface for all commands
51+
- `CommandId.g.cs` - Enum for command identifiers
52+
- `[CommandName].g.cs` - Individual command classes with typed properties
53+
- `CommandForgeLoader.g.cs` - Loader that deserializes JSON into command objects
54+
55+
**Property Type Mapping**:
56+
- `string`, `int`, `float`, `bool` - Basic types
57+
- `enum``string`
58+
- `command``CommandId`
59+
- `vector2/3/4``UnityEngine.Vector2/3/4`
60+
- `vector2/3int``UnityEngine.Vector2/3Int`
61+
62+
### Important Implementation Details
63+
64+
1. **Conditional Compilation**: All generated code is wrapped in `#if ENABLE_COMMAND_FORGE_GENERATOR`
65+
2. **Newtonsoft.Json Dependency**: Generated code requires Newtonsoft.Json for deserialization
66+
3. **Unity Integration**: Vector types use global::UnityEngine namespace
67+
4. **Error Handling**: Exceptions during generation create an Error.g.cs file with diagnostics
68+
69+
## Testing Approach
70+
71+
Tests use xUnit and Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit for verifying generated code. Test projects reference the generator as an Analyzer.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#if ENABLE_COMMAND_FORGE_GENERATOR
2+
namespace CommandForgeGenerator.Command
3+
{
4+
public partial class TextCommand : ICommandForgeCommand
5+
{
6+
public const string Type = "text";
7+
public readonly CommandId CommandId;
8+
9+
public readonly string CharacterId;
10+
public readonly bool IsOverrideCharacterName;
11+
public readonly string? OverrideCharacterName;
12+
public readonly string Body;
13+
14+
15+
public static TextCommand Create(int commandId, global::Newtonsoft.Json.Linq.JToken json)
16+
{
17+
18+
var CharacterId = (string)json["characterId"];
19+
var IsOverrideCharacterName = (bool)json["isOverrideCharacterName"];
20+
var OverrideCharacterName = json["overrideCharacterName"] == null ? null : (string)json["overrideCharacterName"];
21+
var Body = (string)json["body"];
22+
23+
24+
return new TextCommand(commandId, CharacterId, IsOverrideCharacterName, OverrideCharacterName, Body);
25+
}
26+
27+
public TextCommand(int commandId, string CharacterId, bool IsOverrideCharacterName, string? OverrideCharacterName, string Body)
28+
{
29+
CommandId = (CommandId)commandId;
30+
31+
this.CharacterId = CharacterId;
32+
this.IsOverrideCharacterName = IsOverrideCharacterName;
33+
this.OverrideCharacterName = OverrideCharacterName;
34+
this.Body = Body;
35+
36+
}
37+
}
38+
}
39+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace CommandForgeGenerator.Command;
2+
3+
// 他の生成結果サンプルコマンドをコンパイルエラーにしないためのコード
4+
5+
public interface ICommandForgeCommand { }
6+
public enum CommandId{}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.IO;
2+
3+
namespace CommandForgeGenerator.Tests;
4+
5+
public class GenerateTestCode
6+
{
7+
// プロジェクトファイルに存在する GenerateSampleTextCommand.cs を取得する
8+
public static string TextCommandStr => File.ReadAllText("../../../GenerateSampleTextCommand.cs");
9+
public static string YamlFileStr => File.ReadAllText("../../../sampleCommands.yaml");
10+
}
Lines changed: 7 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.IO;
3+
using System.Linq;
24
using CommandForgeGenerator.Generator.CodeGenerate;
35
using CommandForgeGenerator.Generator.Json;
46
using CommandForgeGenerator.Generator.Semantic;
@@ -59,184 +61,16 @@ public void JsonParserTest()
5961
[Fact]
6062
public void GenerateTest()
6163
{
62-
var yaml = GetSampleYaml();
64+
var yaml = GenerateTestCode.YamlFileStr;
6365
var commandsSchema = CommandSemanticsLoader.GetCommandSemantics(yaml);
6466
var codeFiles = CodeGenerator.Generate(commandsSchema);
6567

66-
Assert.Equal(16, codeFiles.Count);
68+
var file = codeFiles.FirstOrDefault(c => c.FileName == "TextCommand.g.cs").Code;
6769

68-
#region Internal
70+
//File.WriteAllText("/Users/katsumi.sato/Desktop/a/TextCommand.g.cs", file);
6971

70-
string GetSampleYaml()
71-
{
72-
return """
73-
version: 1
74-
commands:
75-
- id: text
76-
label: テキスト
77-
description: 台詞を表示
78-
commandListLabelFormat: "{character}「{body}」"
79-
properties:
80-
character:
81-
type: enum
82-
options: ["キャラA", "キャラB", "キャラC", "キャラD", "先生", "店員"]
83-
required: true
84-
body:
85-
type: string
86-
multiline: true
87-
required: true
88-
89-
- id: emote
90-
label: エモート
91-
description: 立ち絵・表情切替
92-
commandListLabelFormat: "EMOTE: {character}, {emotion}"
93-
properties:
94-
character:
95-
type: enum
96-
options: ["キャラA", "キャラB", "キャラC", "キャラD", "先生", "店員"]
97-
required: true
98-
emotion:
99-
type: enum
100-
options: ["通常", "笑顔", "驚き", "怒り", "悲しみ", "困惑", "照れ", "恐怖", "喜び", "真剣"]
101-
required: true
102-
103-
- id: wait
104-
label: 待機
105-
description: 指定秒数だけウェイト
106-
commandListLabelFormat: "WAIT: {seconds}"
107-
defaultBackgroundColor: '#57e317'
108-
properties:
109-
seconds:
110-
type: number
111-
default: 0.5
112-
constraints:
113-
min: 0
114-
115-
- id: bgm
116-
label: BGM
117-
description: 背景音楽を変更
118-
commandListLabelFormat: "BGM: {track}, volume={volume}"
119-
properties:
120-
track:
121-
type: enum
122-
options: ["なし", "日常", "緊張", "悲しい", "楽しい", "神秘的", "アクション", "ロマンティック", "エンディング"]
123-
required: true
124-
volume:
125-
type: number
126-
default: 1.0
127-
constraints:
128-
min: 0
129-
max: 1.0
130-
131-
- id: sound
132-
label: 効果音
133-
description: 効果音を再生
134-
commandListLabelFormat: "SOUND: {effect}, volume={volume}"
135-
properties:
136-
effect:
137-
type: enum
138-
options: ["ドア", "足音", "衝撃", "爆発", "鐘", "拍手", "警報", "雨", "雷", "風"]
139-
required: true
140-
volume:
141-
type: number
142-
default: 1.0
143-
constraints:
144-
min: 0
145-
max: 1.0
146-
147-
- id: background
148-
label: 背景
149-
description: 背景画像を変更
150-
commandListLabelFormat: "BG: {scene}, effect={transition}"
151-
properties:
152-
scene:
153-
type: enum
154-
options: ["教室", "廊下", "体育館", "屋上", "公園", "駅", "カフェ", "自宅", "図書館", "商店街"]
155-
required: true
156-
transition:
157-
type: enum
158-
options: ["なし", "フェード", "ワイプ", "クロスフェード", "フラッシュ"]
159-
default: "なし"
160-
161-
- id: camera
162-
label: カメラ
163-
description: カメラワークを指定
164-
commandListLabelFormat: "CAMERA: {action}, target={target}"
165-
properties:
166-
action:
167-
type: enum
168-
options: ["ズームイン", "ズームアウト", "パン左", "パン右", "シェイク", "フォーカス", "リセット"]
169-
required: true
170-
target:
171-
type: enum
172-
options: ["全体", "キャラA", "キャラB", "キャラC", "キャラD", "先生", "店員", "背景"]
173-
default: "全体"
174-
175-
- id: choice
176-
label: 選択肢
177-
description: 選択肢を表示
178-
commandListLabelFormat: "CHOICE: {options}"
179-
properties:
180-
options:
181-
type: string
182-
multiline: true
183-
description: "選択肢を1行に1つずつ記述"
184-
required: true
185-
timeout:
186-
type: number
187-
default: 0
188-
description: "自動選択までの秒数(0で無制限)"
189-
190-
- id: action
191-
label: アクション
192-
description: キャラクターのアクションを実行
193-
commandListLabelFormat: "ACTION: {character}, {action}"
194-
properties:
195-
character:
196-
type: enum
197-
options: ["キャラA", "キャラB", "キャラC", "キャラD", "先生", "店員"]
198-
required: true
199-
action:
200-
type: enum
201-
options: ["歩く", "走る", "座る", "立つ", "ジャンプ", "踊る", "倒れる", "手を振る", "指さす", "抱きしめる"]
202-
required: true
203-
direction:
204-
type: enum
205-
options: ["左", "右", "上", "下", "中央"]
206-
default: "中央"
207-
208-
- id: narration
209-
label: ナレーション
210-
description: ナレーションテキストを表示
211-
commandListLabelFormat: "NARRATION: {text}"
212-
properties:
213-
text:
214-
type: string
215-
multiline: true
216-
required: true
217-
style:
218-
type: enum
219-
options: ["通常", "強調", "小さく", "斜体", "点滅"]
220-
default: "通常"
221-
222-
- id: branch
223-
label: 分岐
224-
description: 他のコマンドを参照する分岐
225-
commandListLabelFormat: "BRANCH: Target {targetCommand}"
226-
defaultBackgroundColor: "#f9f0ff"
227-
properties:
228-
targetCommand:
229-
type: command
230-
required: true
231-
commandTypes: ["text", "narration"] # Only allow text and narration commands
232-
condition:
233-
type: string
234-
required: true
235-
multiline: true
236-
""";
237-
}
23872

239-
#endregion
240-
73+
Assert.Equal(17, codeFiles.Count);
74+
Assert.Equal(GenerateTestCode.TextCommandStr, codeFiles.FirstOrDefault(c => c.FileName == "TextCommand.g.cs").Code);
24175
}
24276
}

0 commit comments

Comments
 (0)