forked from actionk/Morpeh.Queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryHelper.cs
56 lines (47 loc) · 2.06 KB
/
QueryHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Linq;
using System.Reflection;
using Scellecs.Morpeh.Collections;
using Scellecs.Morpeh.Native;
using UnityEngine;
namespace Scellecs.Morpeh
{
internal static class QueryHelper
{
#region Validation
internal struct RequestedTypeInfo
{
public Type type;
public int typeId;
public RequestedTypeInfo(Type type) : this()
{
this.type = type;
}
public RequestedTypeInfo(Type type, int typeId)
{
this.type = type;
this.typeId = typeId;
}
}
internal static RequestedTypeInfo GetRequestedTypeInfo<T>() where T : struct, IComponent
{
return new RequestedTypeInfo(typeof(T), TypeIdentifier<T>.info.id);
}
internal static void ValidateRequest(QueryBuilder queryBuilder, Filter filter, params RequestedTypeInfo[] requestedTypeInfosToValidate)
{
var hasProblems = false;
foreach (var requestedTypeInfo in requestedTypeInfosToValidate)
{
if (!filter.includedTypeIds.Contains(requestedTypeInfo.typeId))
Debug.LogError(
$"You're expecting a component [<b>{requestedTypeInfo.type.Name}</b>] in your query in [<b>{queryBuilder.System.GetType().Name}</b>], but the query is <b>missing</b> this parameter. Please add it to the query first!");
if (filter.excludedTypeIds.Contains(requestedTypeInfo.typeId))
Debug.LogError(
$"You're expecting a component [<b>{requestedTypeInfo.type.Name}</b>] in your query in [<b>{queryBuilder.System.GetType().Name}</b>], but the query is <b>deliberately excluded</b> this parameter. Please remove it from the query or from the ForEach lambda!");
}
if (hasProblems)
throw new Exception($"There were problems when configuring a query for [<b>{queryBuilder.System.GetType().Name}</b>]. Please fix those first");
}
#endregion
}
}