Skip to content

Commit 9bfeb71

Browse files
committed
サンプルのcommands.yamlを使うように修正
1 parent c529cc9 commit 9bfeb71

4 files changed

Lines changed: 204 additions & 187 deletions

File tree

CommandForgeGenerator.Tests/GenerateSampleTextCommand.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@ public partial class TextCommand : ICommandForgeCommand
66
public const string Type = "text";
77
public readonly CommandId CommandId;
88

9-
public readonly string Character;
10-
public readonly string? Body;
11-
public readonly string? VoiceId;
9+
public readonly string CharacterId;
10+
public readonly bool IsOverrideCharacterName;
11+
public readonly string? OverrideCharacterName;
12+
public readonly string Body;
1213

1314

1415
public static TextCommand Create(int commandId, global::Newtonsoft.Json.Linq.JToken json)
1516
{
1617

17-
var Character = (string)json["character"];
18-
var Body = json["body"] == null ? null : (string)json["body"];
19-
var VoiceId = json["voiceId"] == null ? null : (string)json["voiceId"];
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"];
2022

2123

22-
return new TextCommand(commandId, Character, Body, VoiceId);
24+
return new TextCommand(commandId, CharacterId, IsOverrideCharacterName, OverrideCharacterName, Body);
2325
}
2426

25-
public TextCommand(int commandId, string Character, string? Body, string? VoiceId)
27+
public TextCommand(int commandId, string CharacterId, bool IsOverrideCharacterName, string? OverrideCharacterName, string Body)
2628
{
2729
CommandId = (CommandId)commandId;
2830

29-
this.Character = Character;
31+
this.CharacterId = CharacterId;
32+
this.IsOverrideCharacterName = IsOverrideCharacterName;
33+
this.OverrideCharacterName = OverrideCharacterName;
3034
this.Body = Body;
31-
this.VoiceId = VoiceId;
3235

3336
}
3437
}

CommandForgeGenerator.Tests/GenerateTestCode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ public class GenerateTestCode
66
{
77
// プロジェクトファイルに存在する GenerateSampleTextCommand.cs を取得する
88
public static string TextCommandStr => File.ReadAllText("../../../GenerateSampleTextCommand.cs");
9+
public static string YamlFileStr => File.ReadAllText("../../../sampleCommands.yaml");
910
}
Lines changed: 6 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.IO;
23
using System.Linq;
34
using CommandForgeGenerator.Generator.CodeGenerate;
@@ -60,188 +61,16 @@ public void JsonParserTest()
6061
[Fact]
6162
public void GenerateTest()
6263
{
63-
var yaml = GetSampleYaml();
64+
var yaml = GenerateTestCode.YamlFileStr;
6465
var commandsSchema = CommandSemanticsLoader.GetCommandSemantics(yaml);
6566
var codeFiles = CodeGenerator.Generate(commandsSchema);
6667

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

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

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

244-
#endregion
245-
73+
Assert.Equal(17, codeFiles.Count);
74+
Assert.Equal(GenerateTestCode.TextCommandStr, codeFiles.FirstOrDefault(c => c.FileName == "TextCommand.g.cs").Code);
24675
}
24776
}

0 commit comments

Comments
 (0)