Skip to content

Commit 609c0ed

Browse files
committed
Support runtime builder subcommands
1 parent cace39f commit 609c0ed

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Editor/EcsactRuntimeBuilder.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,30 @@ public struct MethodInfo {
5252
public Dictionary<string, MethodInfo> methods;
5353
}
5454

55+
[System.Serializable]
56+
struct SubcommandStartMessage {
57+
public const string type = "subcommand_start";
58+
public long id;
59+
public string executable;
60+
public List<string> arguments;
61+
}
62+
63+
[System.Serializable]
64+
struct SubcommandProgressMessage {
65+
public const string type = "subcommand_progress";
66+
public long id;
67+
public string description;
68+
}
69+
70+
[System.Serializable]
71+
struct SubcommandEndMessage {
72+
public const string type = "subcommand_end";
73+
public long id;
74+
public int exit_code;
75+
}
76+
5577
public static class EcsactRuntimeBuilder {
78+
private static Dictionary<long, int> _subcommandProgressIds = new();
5679

5780
public struct Options {
5881
public List<string> ecsactFiles;
@@ -141,6 +164,24 @@ public static void Build
141164
JsonUtility.FromJson<ModuleMethodsMessage>(line)
142165
);
143166
break;
167+
case SubcommandStartMessage.type:
168+
ReceiveMessage(
169+
progressId,
170+
JsonUtility.FromJson<SubcommandStartMessage>(line)
171+
);
172+
break;
173+
case SubcommandProgressMessage.type:
174+
ReceiveMessage(
175+
progressId,
176+
JsonUtility.FromJson<SubcommandProgressMessage>(line)
177+
);
178+
break;
179+
case SubcommandEndMessage.type:
180+
ReceiveMessage(
181+
progressId,
182+
JsonUtility.FromJson<SubcommandEndMessage>(line)
183+
);
184+
break;
144185
}
145186
}
146187
};
@@ -246,4 +287,39 @@ private static void ReceiveMessage
246287
{
247288

248289
}
290+
291+
private static void ReceiveMessage
292+
( int progressId
293+
, SubcommandStartMessage message
294+
)
295+
{
296+
var subcommandProgressId = Progress.Start(
297+
name: System.IO.Path.GetFileName(message.executable),
298+
description: string.Join(" ", message.arguments),
299+
parentId: progressId
300+
);
301+
_subcommandProgressIds.Add(message.id, subcommandProgressId);
302+
}
303+
304+
private static void ReceiveMessage
305+
( int progressId
306+
, SubcommandProgressMessage message
307+
)
308+
{
309+
var subcommandProgressId = _subcommandProgressIds[message.id];
310+
Progress.SetDescription(subcommandProgressId, message.description);
311+
}
312+
313+
private static void ReceiveMessage
314+
( int progressId
315+
, SubcommandEndMessage message
316+
)
317+
{
318+
var subcommandProgressId = _subcommandProgressIds[message.id];
319+
if(message.exit_code == 0) {
320+
Progress.Finish(subcommandProgressId, Progress.Status.Succeeded);
321+
} else {
322+
Progress.Finish(subcommandProgressId, Progress.Status.Failed);
323+
}
324+
}
249325
}

0 commit comments

Comments
 (0)