Skip to content

Commit bba614d

Browse files
authored
Merge pull request #11 from semihcelek/bugfix/composition-revision
Aspects can't generate to a read-only directory bug is solved.
2 parents 1270071 + 478a037 commit bba614d

File tree

11 files changed

+73
-27
lines changed

11 files changed

+73
-27
lines changed

Gum.Composer/AspectType.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
3+
namespace Gum.Composer
4+
{
5+
public readonly struct AspectType : IEquatable<AspectType>
6+
{
7+
public readonly int Value;
8+
9+
public AspectType(int value)
10+
{
11+
Value = value;
12+
}
13+
14+
public bool Equals(AspectType other)
15+
{
16+
return Value == other.Value;
17+
}
18+
19+
public override bool Equals(object obj)
20+
{
21+
return obj is AspectType other && Equals(other);
22+
}
23+
24+
public override int GetHashCode()
25+
{
26+
return Value;
27+
}
28+
29+
public static implicit operator int(AspectType aspectType) => aspectType.Value;
30+
31+
public static implicit operator AspectType(int value) => new AspectType(value);
32+
}
33+
}

Gum.Composer/CodeGen/CompositionCodeGenerator.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ public static class CompositionCodeGenerator
3737
TAB + TAB + LINE + CTOR_CONTENT +
3838
LINE + TAB + TAB + "}";
3939
private const string ASPECT_TYPE_TEMPLATE =
40-
TAB + TAB + "public const " + ASPECT_TYPE + " ASPECT_TYPE = " + ASPECT_TYPE + "." + OBJECT_NAME + ";" +
40+
TAB + TAB + "public static readonly " + NAMESPACE + "." + ASPECT_TYPE + " ASPECT_TYPE = " + "(int)" + ASPECT_TYPE + "." + OBJECT_NAME + ";" +
4141
LINE + LINE +
42-
TAB + TAB + "public " + ASPECT_TYPE + " Type => ASPECT_TYPE;" + LINE + LINE;
42+
TAB + TAB + "public " + NAMESPACE + "." + ASPECT_TYPE + " Type => ASPECT_TYPE;" + LINE + LINE;
4343
private const string FIELD_TEMPLATE =
4444
TAB + TAB + "public readonly " + TYPE + " " + FIELD_NAME + ";" + LINE + LINE;
4545

@@ -57,15 +57,18 @@ public static void Run()
5757
{
5858
string aspectName = aspectPrototype.Name;
5959
bodyStringBuilder.Append(ASPECT_TYPE_TEMPLATE
60-
.Replace(OBJECT_NAME, aspectName));
60+
.Replace(OBJECT_NAME, aspectName)
61+
.Replace(NAMESPACE, UserConfig.NAMESPACE));
62+
6163
int argCounter = 0;
6264
foreach (KeyValuePair<string, string> kvp in aspectPrototype.Fields)
6365
{
6466
string fieldName = kvp.Key;
6567
string type = kvp.Value;
6668
bodyStringBuilder.Append(FIELD_TEMPLATE
6769
.Replace(TYPE, type)
68-
.Replace(FIELD_NAME, fieldName));
70+
.Replace(FIELD_NAME, fieldName)
71+
.Replace(NAMESPACE, UserConfig.NAMESPACE));
6972

7073
string argName = $"arg{argCounter}";
7174
argsStringBuilder.Append($"{type} {argName}, ");

Gum.Composer/Composition.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Runtime.CompilerServices;
66
using Gum.Composer.Exception;
7-
using Gum.Composer.Generated;
87
using Gum.Composer.Internal;
98
using Gum.Pooling;
109
using Gum.Pooling.Collections;

Gum.Composer/Generated/AspectType.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

Gum.Composer/Generated/Aspects.cs

Whitespace-only changes.

Gum.Composer/Generated/Types.gum

Lines changed: 0 additions & 1 deletion
This file was deleted.

Gum.Composer/IAspect.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Gum.Composer.Generated;
2-
3-
namespace Gum.Composer
1+
namespace Gum.Composer
42
{
53
public interface IAspect
64
{

Gum.Composer/Internal/AspectDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4-
using Gum.Composer.Generated;
54
using Gum.Core.Utility;
5+
using Gum.Composer;
66

77
namespace Gum.Composer.Internal
88
{

Gum.Composer/Unity/Editor/AspectCreationEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void AddNewType()
125125
TypeNameValidationResult typeNameValidationResult = ValidateTypeName(out string fullName);
126126
if (typeNameValidationResult != TypeNameValidationResult.Success)
127127
{
128-
Debug.LogError(
128+
Debug.LogError(
129129
$"Error while trying to add type: {_typeName} Error code: {typeNameValidationResult}");
130130
return;
131131
}

Gum.Composer/UserConfig.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
using System;
2-
using System.IO;
1+
using System.IO;
32
using Gum.Core.Assert;
43

54
namespace Gum.Composer
65
{
76
public static class UserConfig
87
{
98
private static readonly string ProjectDirectory = GetProjectDirectory(Directory.GetCurrentDirectory());
10-
public static readonly string AspectsDirectoryPath = $@"{ProjectDirectory}\Aspects";
11-
public static readonly string OutputDirectoryPath = $@"{ProjectDirectory}\Generated";
9+
public static readonly string AspectsDirectoryPath = $@"{ProjectDirectory}\{OUTPUT_FOLDER_NAME_PATTERN}\{ASPECT_FOLDER_NAME_PATTERN}";
10+
public static readonly string OutputDirectoryPath = $@"{ProjectDirectory}\{OUTPUT_FOLDER_NAME_PATTERN}";
1211

1312
public const string NAMESPACE = @"Gum.Composer";
14-
public const string FOLDER_SEARCH_PATTERN = "Gum.Composer";
13+
public const string FOLDER_SEARCH_PATTERN = "Assets";
14+
private const string OUTPUT_FOLDER_NAME_PATTERN = @"Gum\Composer\Generated";
15+
private const string ASPECT_FOLDER_NAME_PATTERN = "Aspects";
1516

1617
private static string GetProjectDirectory(string directory)
1718
{
1819
if (TryGetProjectDirectory(directory, out string foundDirectory))
1920
{
21+
CreateRequiredFoldersIfNotExist(foundDirectory);
22+
2023
return foundDirectory;
2124
}
2225

@@ -42,6 +45,24 @@ private static bool TryGetProjectDirectory(string directory, out string foundDir
4245
}
4346

4447
return false;
48+
49+
}
50+
51+
private static void CreateRequiredFoldersIfNotExist(string foundDirectory)
52+
{
53+
string[] directories;
54+
55+
try
56+
{
57+
directories = Directory.GetDirectories(foundDirectory, OUTPUT_FOLDER_NAME_PATTERN, SearchOption.AllDirectories);
58+
}
59+
catch (DirectoryNotFoundException directoryNotFoundException)
60+
{
61+
string outputFolderNamePattern = $@"{foundDirectory}\{OUTPUT_FOLDER_NAME_PATTERN}";
62+
63+
Directory.CreateDirectory(outputFolderNamePattern);
64+
Directory.CreateDirectory($@"{outputFolderNamePattern}\{ASPECT_FOLDER_NAME_PATTERN}");
65+
}
4566
}
4667
}
4768
}

0 commit comments

Comments
 (0)