Skip to content

Commit 1e0327f

Browse files
arthurkehrwaldfreezy
authored andcommitted
Add machine folder validation
1 parent 34cd85e commit 1e0327f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Editor/Inspector/MpfGamelogicEngineInspector.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public override VisualElement CreateInspectorGUI()
6868
path = "./StreamingAssets/" + path.Split("StreamingAssets/")[1];
6969

7070
var machineFolderProp = serializedObject.FindProperty(
71-
$"_mpfStarter._machineFolder"
71+
$"_mpfWrangler._machineFolder"
7272
);
7373
machineFolderProp.stringValue = path;
7474
serializedObject.ApplyModifiedProperties();
@@ -195,6 +195,9 @@ ex is RpcException exception
195195
executableSourceProp,
196196
OnExecutableSourceChanged
197197
);
198+
199+
MachineFolderValidationBoxes(machineFolderField);
200+
198201
return root;
199202
}
200203

@@ -255,5 +258,44 @@ private void UpdateGameItemList(VisualElement parent, IEnumerable<string> itemId
255258
parent.Add(label);
256259
}
257260
}
261+
262+
private void MachineFolderValidationBoxes(VisualElement machineFolderField)
263+
{
264+
var machineFolderProp = serializedObject.FindProperty($"_mpfWrangler._machineFolder");
265+
var notAMachineFolderErrorBox = new HelpBox(
266+
"The machine folder is not valid. It must contain a folder called 'config' "
267+
+ "with at least one .yaml file inside.",
268+
HelpBoxMessageType.Error
269+
);
270+
var streamingAssetsWarnBox = new HelpBox(
271+
"The machine folder is not located in the 'StreamingAssets' folder. It will not be"
272+
+ " included in builds.",
273+
HelpBoxMessageType.Warning
274+
);
275+
streamingAssetsWarnBox.TrackPropertyValue(machineFolderProp, UpdateVisibility);
276+
var container = machineFolderField.parent;
277+
var index = container.IndexOf(machineFolderField);
278+
container.Insert(index, notAMachineFolderErrorBox);
279+
container.Insert(index + 1, streamingAssetsWarnBox);
280+
UpdateVisibility(machineFolderProp);
281+
282+
void UpdateVisibility(SerializedProperty _)
283+
{
284+
var machineFolder = _mpfEngine.MachineFolder;
285+
var isMachineFolderInStreamingAssets = machineFolder.StartsWith(
286+
Application.streamingAssetsPath
287+
);
288+
streamingAssetsWarnBox.style.display = isMachineFolderInStreamingAssets
289+
? DisplayStyle.None
290+
: DisplayStyle.Flex;
291+
292+
var configDir = Path.Combine(machineFolder, "config");
293+
var isValidMachineFolder =
294+
Directory.Exists(configDir) && Directory.GetFiles(configDir, "*.yaml").Any();
295+
notAMachineFolderErrorBox.style.display = isValidMachineFolder
296+
? DisplayStyle.None
297+
: DisplayStyle.Flex;
298+
}
299+
}
258300
}
259301
}

Runtime/MpfGamelogicEngine.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class MpfGamelogicEngine : MonoBehaviour, IGamelogicEngine
8181
public event EventHandler<SwitchEventArgs2> OnSwitchChanged;
8282
#pragma warning restore CS0067
8383

84+
public string MachineFolder => _mpfWrangler.MachineFolder;
85+
8486
#if UNITY_EDITOR
8587
public async Task QueryParseAndStoreMpfMachineDescription(CancellationToken ct)
8688
{

0 commit comments

Comments
 (0)