Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator creates compilable code with type specific modifications #169

Merged
merged 37 commits into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ea9b803
Make Examples path check OS agnostic.
jrmacgill Jun 23, 2020
b0c018e
Examples path check OS agnostic.
jrmacgill Jun 23, 2020
c56c6d4
Update Runtime.cs
jrmacgill Jun 23, 2020
51879a2
Merge branch 'canary' of https://github.com/jmacgill/unity-atoms into…
jrmacgill Jun 23, 2020
22bb39e
Re-generate and patch back in type specific changes
jrmacgill Jun 23, 2020
1f7f944
Add missing UnityEngine using.
jrmacgill Jun 23, 2020
dd67da9
Marked as not sealed
jrmacgill Jun 23, 2020
dcb0f35
Support the current value type as a conditional.
jrmacgill Jun 24, 2020
b6847eb
Nested if blocks
jrmacgill Jun 24, 2020
25ebe39
Use next char instead of next linefeed.
jrmacgill Jun 24, 2020
394715c
Remove debug lines.
jrmacgill Jun 24, 2020
09adfc0
Keep Atom Base Variable sepecfic code.
jrmacgill Jun 24, 2020
143a93b
Fix position of endif
jrmacgill Jun 24, 2020
a9e69f1
Add Raise for void type
jrmacgill Jun 24, 2020
a7a1044
Add void and FSM specific logic
jrmacgill Jun 24, 2020
78cfe10
Add is numeric conditional
jrmacgill Jun 24, 2020
98f0330
Add more type specific logic
jrmacgill Jun 24, 2020
bc9c5b5
Add is Vector to generator.
jrmacgill Jun 24, 2020
91cdd4d
Add type specific logic
jrmacgill Jun 24, 2020
a4adf84
Add collider type
jrmacgill Jun 24, 2020
c86fa4d
Add color specific logic
jrmacgill Jun 24, 2020
4611a6d
Working on whitespace diffs
jrmacgill Jun 25, 2020
36d52d6
Working on whitespace diffs
jrmacgill Jun 25, 2020
8b077d8
remove unused test assembly
jrmacgill Jun 25, 2020
91c52a0
removed example nested if
jrmacgill Jun 25, 2020
e773596
test comment removed after regen
jrmacgill Jun 25, 2020
1a44211
missing ValueEquals
jrmacgill Jun 25, 2020
fd79ca7
missing ValueEquals on colliders
jrmacgill Jun 25, 2020
3dd4465
missing color speciifc code.
jrmacgill Jun 25, 2020
26a91aa
whitesapce cleanup
jrmacgill Jun 25, 2020
ccf2fa3
whitesapce cleanup
jrmacgill Jun 25, 2020
b9ce9f1
whitesapce cleanup
jrmacgill Jun 25, 2020
b7a53ac
whitesapce cleanup
jrmacgill Jun 25, 2020
d36d0e6
whitesapce cleanup
jrmacgill Jun 25, 2020
96ecdd1
whitesapce cleanup
jrmacgill Jun 25, 2020
07110db
remove temp debug
jrmacgill Jun 25, 2020
539f6d3
Generated events now follows editoconfig. + Inline conditionals now s…
AdamRamberg Jul 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class AtomBaseVariableEventReferenceUsage
public const int LIST_INSTANCER_ADDED_EVENT = 8;
public const int LIST_INSTANCER_REMOVED_EVENT = 9;
}

/// <summary>
/// Event Reference of type `AtomBaseVariable`. Inherits from `AtomBaseEventReference&lt;AtomBaseVariable, AtomBaseVariableEvent, AtomBaseVariableEventInstancer&gt;`.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class VoidBaseEventReferenceUsage
public const int COLLECTION_INSTANCER_CLEARED_EVENT = 4;
public const int LIST_INSTANCER_CLEARED_EVENT = 5;
}

/// <summary>
/// Event Reference of type `Void`. Inherits from `AtomBaseEventReference&lt;Void, VoidEvent, VoidEventInstancer&gt;`.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions Packages/BaseAtoms/Runtime/Events/VoidEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace UnityAtoms.BaseAtoms
/// </summary>
[EditorIcon("atom-icon-cherry")]
[CreateAssetMenu(menuName = "Unity Atoms/Events/Void", fileName = "VoidEvent")]
public sealed class VoidEvent : AtomEvent<Void>
{
public sealed class VoidEvent : AtomEvent<Void> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not valid based on our https://github.com/AdamRamberg/unity-atoms/blob/master/.editorconfig

make sure your IDE uses the editorconfig (vs code needs a plugin for that IIRC)

Copy link
Collaborator

@soraphis soraphis Jul 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid formatting results in many files touched unnecessary. please correct those.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I need to fix this in the generator mostly - not much point in having it generate code that does not need to be modified if it then relies on the IDE to fix the formatting anyway. I was having trouble getting linefeeds and whitespace to behave where blocks were removed.

Failing that, I could remove the generated files from the PR - I'll see if I can avoid that though. I'll take a run at it this weekend.

public override void Raise()
{
Raise(new Void());
Expand Down
11 changes: 11 additions & 0 deletions Packages/BaseAtoms/Runtime/References/ColorReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,16 @@ public sealed class ColorReference : EquatableAtomReference<
public ColorReference() : base() { }
public ColorReference(Color value) : base(value) { }
public bool Equals(ColorReference other) { return base.Equals(other); }
/// <summary>
/// Set Alpha of Color by value.
/// </summary>
/// <param name="value">New alpha value.</param>
public void SetAlpha(float value) => Value = new Color(Value.r, Value.g, Value.b, value);

/// <summary>
/// Set Alpha of Color by Variable value.
/// </summary>
/// <param name="variable">New alpha Variable value.</param>
public void SetAlpha(AtomBaseVariable<float> variable) => SetAlpha(variable.Value);
}
}
4 changes: 3 additions & 1 deletion Packages/BaseAtoms/Runtime/Variables/BoolVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ namespace UnityAtoms.BaseAtoms
/// </summary>
[EditorIcon("atom-icon-lush")]
[CreateAssetMenu(menuName = "Unity Atoms/Variables/Bool", fileName = "BoolVariable")]
public sealed class BoolVariable : EquatableAtomVariable<bool, BoolPair, BoolEvent, BoolPairEvent, BoolBoolFunction> { }
public sealed class BoolVariable : EquatableAtomVariable<bool, BoolPair, BoolEvent, BoolPairEvent, BoolBoolFunction>
{
}
}
4 changes: 3 additions & 1 deletion Packages/BaseAtoms/Runtime/Variables/StringVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ namespace UnityAtoms.BaseAtoms
/// </summary>
[EditorIcon("atom-icon-lush")]
[CreateAssetMenu(menuName = "Unity Atoms/Variables/String", fileName = "StringVariable")]
public class StringVariable : EquatableAtomVariable<string, StringPair, StringEvent, StringPairEvent, StringStringFunction> { }
public class StringVariable : EquatableAtomVariable<string, StringPair, StringEvent, StringPairEvent, StringStringFunction>
{
}
}
10 changes: 7 additions & 3 deletions Packages/Core/Editor/Generator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public static string[] GetTemplatePaths()
return Directory.GetFiles(templateSearchPath, "UA_Template*.txt", SearchOption.AllDirectories);
}

public static List<string> CreateTemplateConditions(bool isValueTypeEquatable, string valueTypeNamespace, string subUnityAtomsNamespace)
public static List<string> CreateTemplateConditions(bool isValueTypeEquatable, string valueTypeNamespace, string subUnityAtomsNamespace, string valueType)
{
var templateConditions = new List<string>();
templateConditions.Add("TYPE_IS_" + valueType.ToUpper());
if (valueType == "int" || valueType == "float") { templateConditions.Add("IS_NUMERIC");}
if (valueType == "Vector2" || valueType == "Vector3") { templateConditions.Add("IS_VECTOR");}
if (valueType == "Collider" || valueType == "Collider2D" || valueType == "Collider3D") { templateConditions.Add("IS_COLLIDER");}
if (isValueTypeEquatable) { templateConditions.Add("EQUATABLE"); }
if (!string.IsNullOrEmpty(valueTypeNamespace)) { templateConditions.Add("TYPE_HAS_NAMESPACE"); }
if (!string.IsNullOrEmpty(subUnityAtomsNamespace)) { templateConditions.Add("HAS_SUB_UA_NAMESPACE"); }
Expand Down Expand Up @@ -151,8 +155,8 @@ private static string RemoveDuplicateNamespaces(string template)
{
if (kvp.Value > 1)
{
var usingStr = $"using {kvp.Key};\n";
contentCopy = contentCopy.Remove(contentCopy.IndexOf(usingStr), usingStr.Length);
var usingStr = $"using {kvp.Key};";
contentCopy = contentCopy.Remove(contentCopy.IndexOf(usingStr), usingStr.Length+1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Packages/Core/Editor/Generator/GeneratorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void OnEnable()
var button2 = new Button(() =>
{
var templates = Generator.GetTemplatePaths();
var templateConditions = Generator.CreateTemplateConditions(_isValueTypeEquatable, _valueTypeNamespace, _subUnityAtomsNamespace);
var templateConditions = Generator.CreateTemplateConditions(_isValueTypeEquatable, _valueTypeNamespace, _subUnityAtomsNamespace, _valueType);
var templateVariables = Generator.CreateTemplateVariablesMap(_valueType, _valueTypeNamespace, _subUnityAtomsNamespace);
var capitalizedValueType = _valueType.Capitalize();

Expand Down
4 changes: 2 additions & 2 deletions Packages/Core/Editor/Generator/RegenerateAllAtoms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void Regenereate()
foreach (var item in itemsToRegenerate)
{
var templates = Generator.GetTemplatePaths();
var templateConditions = Generator.CreateTemplateConditions(item.IsValueEquatable, item.ValueTypeNamespace, item.SubUnityAtomsNamespace);
var templateConditions = Generator.CreateTemplateConditions(item.IsValueEquatable, item.ValueTypeNamespace, item.SubUnityAtomsNamespace, item.ValueType);
var templateVariables = Generator.CreateTemplateVariablesMap(item.ValueType, item.ValueTypeNamespace, item.SubUnityAtomsNamespace);
var capitalizedValueType = item.ValueType.Capitalize();

Expand All @@ -126,4 +126,4 @@ static void Regenereate()

}
}
#endif
#endif