Skip to content

Commit cace39f

Browse files
committed
Reading ecsact runtime builder json
1 parent bff4476 commit cace39f

File tree

2 files changed

+142
-11
lines changed

2 files changed

+142
-11
lines changed

Editor/EcsactRuntimeBuilder.cs

Lines changed: 142 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,53 @@
55
using System.Collections.Generic;
66
using Ecsact.Editor;
77

8+
[System.Serializable]
9+
struct MessageBase {
10+
public string type;
11+
}
12+
13+
[System.Serializable]
14+
struct AlertMessage {
15+
public const string type = "alert";
16+
public string content;
17+
}
18+
19+
[System.Serializable]
20+
struct InfoMessage {
21+
public const string type = "info";
22+
public string content;
23+
}
24+
25+
[System.Serializable]
26+
struct ErrorMessage {
27+
public const string type = "error";
28+
public string content;
29+
}
30+
31+
[System.Serializable]
32+
struct WarningMessage {
33+
public const string type = "warning";
34+
public string content;
35+
}
36+
37+
[System.Serializable]
38+
struct SuccessMessage {
39+
public const string type = "success";
40+
public string content;
41+
}
42+
43+
[System.Serializable]
44+
struct ModuleMethodsMessage {
45+
[System.Serializable]
46+
public struct MethodInfo {
47+
public bool available;
48+
}
49+
50+
public const string type = "module_methods";
51+
public string module_name;
52+
public Dictionary<string, MethodInfo> methods;
53+
}
54+
855
public static class EcsactRuntimeBuilder {
956

1057
public struct Options {
@@ -56,16 +103,50 @@ public static void Build
56103
proc.OutputDataReceived += (_, ev) => {
57104
var line = ev.Data;
58105
if(!string.IsNullOrWhiteSpace(line)) {
59-
Progress.SetDescription(progressId, line);
60-
UnityEngine.Debug.Log(line);
106+
var baseMessage = JsonUtility.FromJson<MessageBase>(line);
107+
switch(baseMessage.type) {
108+
case AlertMessage.type:
109+
ReceiveMessage(
110+
progressId,
111+
JsonUtility.FromJson<AlertMessage>(line)
112+
);
113+
break;
114+
case InfoMessage.type:
115+
ReceiveMessage(
116+
progressId,
117+
JsonUtility.FromJson<InfoMessage>(line)
118+
);
119+
break;
120+
case ErrorMessage.type:
121+
ReceiveMessage(
122+
progressId,
123+
JsonUtility.FromJson<ErrorMessage>(line)
124+
);
125+
break;
126+
case WarningMessage.type:
127+
ReceiveMessage(
128+
progressId,
129+
JsonUtility.FromJson<WarningMessage>(line)
130+
);
131+
break;
132+
case SuccessMessage.type:
133+
ReceiveMessage(
134+
progressId,
135+
JsonUtility.FromJson<SuccessMessage>(line)
136+
);
137+
break;
138+
case ModuleMethodsMessage.type:
139+
ReceiveMessage(
140+
progressId,
141+
JsonUtility.FromJson<ModuleMethodsMessage>(line)
142+
);
143+
break;
144+
}
61145
}
62146
};
63147

64148
proc.Exited += (_, _) => {
65149
if(proc.ExitCode != 0) {
66-
UnityEngine.Debug.LogError(
67-
$"ecsact_rtb exited with code {proc.ExitCode}"
68-
);
69150
Progress.Finish(progressId, Progress.Status.Failed);
70151
} else {
71152
Progress.Finish(progressId, Progress.Status.Succeeded);
@@ -104,13 +185,65 @@ public static void Build
104185
FileUtil.GetUniqueTempPathInProject()
105186
);
106187

107-
UnityEngine.Debug.Log(proc.StartInfo.FileName);
108-
UnityEngine.Debug.Log(proc.StartInfo.Arguments);
109-
UnityEngine.Debug.Log($"CWD: {System.IO.Directory.GetCurrentDirectory()}");
110-
111188
Progress.Report(progressId, 0.1f);
112189
proc.Start();
113190
proc.BeginOutputReadLine();
114191
proc.BeginErrorReadLine();
115192
}
193+
194+
private static void ReceiveMessage
195+
( int progressId
196+
, AlertMessage message
197+
)
198+
{
199+
EditorUtility.DisplayDialog(
200+
title: "Ecsact Runtime Builder",
201+
message: message.content,
202+
ok: "ok"
203+
);
204+
}
205+
206+
private static void ReceiveMessage
207+
( int progressId
208+
, InfoMessage message
209+
)
210+
{
211+
Progress.SetDescription(progressId, message.content);
212+
UnityEngine.Debug.Log(message.content);
213+
}
214+
215+
private static void ReceiveMessage
216+
( int progressId
217+
, ErrorMessage message
218+
)
219+
{
220+
Progress.SetDescription(progressId, message.content);
221+
UnityEngine.Debug.LogError(message.content);
222+
}
223+
224+
private static void ReceiveMessage
225+
( int progressId
226+
, WarningMessage message
227+
)
228+
{
229+
Progress.SetDescription(progressId, message.content);
230+
UnityEngine.Debug.LogWarning(message.content);
231+
}
232+
233+
private static void ReceiveMessage
234+
( int progressId
235+
, SuccessMessage message
236+
)
237+
{
238+
Progress.SetDescription(progressId, message.content);
239+
UnityEngine.Debug.Log(message.content);
240+
}
241+
242+
private static void ReceiveMessage
243+
( int progressId
244+
, ModuleMethodsMessage message
245+
)
246+
{
247+
248+
}
116249
}

Editor/Importer/EcsactImporter.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public override void OnImportAsset(AssetImportContext ctx) {
7777
return;
7878
}
7979

80-
UnityEngine.Debug.Log(pkgJsonStr);
81-
8280
var pkgJson = JsonUtility.FromJson<PkgInfoJson>(pkgJsonStr);
8381
var pkg = (EcsactPackage)ScriptableObject.CreateInstance(
8482
typeof(EcsactPackage)

0 commit comments

Comments
 (0)