Entitas  0.35.0
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
BlueprintsGenerator.cs
1 using System.Linq;
2 
3 namespace Entitas.CodeGenerator {
4 
6 
7  const string CLASS_FORMAT = @"using Entitas.Serialization.Blueprints;
8 
9 namespace Entitas.Unity.Serialization.Blueprints {{
10 
11  public partial class Blueprints {{
12 
13 {0}
14  }}
15 }}
16 ";
17  const string GETTER_FORMAT = " public Blueprint {0} {{ get {{ return GetBlueprint(\"{1}\"); }} }}";
18 
19  public CodeGenFile[] Generate(string[] blueprintNames) {
20  if(blueprintNames.Length == 0) {
21  return new CodeGenFile[0];
22  }
23 
24  var orderedBlueprintNames = blueprintNames.OrderBy(name => name).ToArray();
25  var blueprints = string.Format(CLASS_FORMAT, generateBlueprintGetters(orderedBlueprintNames));
26  return new [] { new CodeGenFile(
27  "BlueprintsGeneratedExtension",
28  blueprints,
29  GetType().FullName) };
30  }
31 
32  string generateBlueprintGetters(string[] blueprintNames) {
33  return string.Join("\n", blueprintNames
34  .Select(name => string.Format(GETTER_FORMAT, validPropertyName(name), name)).ToArray());
35  }
36 
37  static string validPropertyName(string name) {
38  return name
39  .Replace(" ", string.Empty)
40  .Replace("-", string.Empty)
41  .Replace("(", string.Empty)
42  .Replace(")", string.Empty);
43  }
44  }
45 }