Skip to content

Commit

Permalink
Merge pull request #17 from JochenHeckl/unity_ci
Browse files Browse the repository at this point in the history
Unity ci
  • Loading branch information
JochenHeckl authored Feb 2, 2024
2 parents 791f5b9 + b3f7f84 commit d132021
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 72 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Actions

on: [push, pull_request]

jobs:
run_test:
name: Run Tests

permissions:
checks: write

strategy:
matrix:
unityVersion:
- 2023.2.7f1
- 2023.1.20f1
- 2022.3.19f1
- 2021.3.34f1
os:
- ubuntu-latest
# - windows-latest

runs-on: ${{ matrix.os }}

steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: false

# Test
- name: run tests
uses: game-ci/unity-test-runner@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
packageMode: true
unityVersion: ${{ matrix.unityVersion }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
Expand Down Expand Up @@ -77,4 +78,5 @@ crashlytics-build.properties
# End of https://www.toptal.com/developers/gitignore/api/unity

.vscode
.idea
.idea
.vs
96 changes: 49 additions & 47 deletions Editor/Scripts/ViewEditorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ namespace de.JochenHeckl.Unity.DataBinding.Editor
{
public class ViewEditorBase : UnityEditor.Editor
{
public static readonly IDataBindingEditorDisplayText EditorDisplayText =
internal static readonly IDataBindingEditorDisplayText EditorDisplayText =
new DataBindingEditorDisplayText();

public VisualElement EditorRootElement { get; set; }
public Type[] ValidDataSources { get; set; }
protected VisualElement EditorRootElement { get; private set; }

public ViewEditorBase() { }
protected Type[] ValidDataSources { get; private set; }

public virtual void OnEnable()
{
if (ValidDataSources == null)
{
ValidDataSources = GetValidDataSourceTypes();
}
ValidDataSources ??= GetValidDataSourceTypes();
}

public void InitDatabindingEditorRootElement()
protected void InitDatabindingEditorRootElement()
{
if (EditorRootElement == null)
{
Expand All @@ -50,7 +46,7 @@ public void InitDatabindingEditorRootElement()
}
}

public VisualElement MakeErrorReport(Exception exception)
protected static VisualElement MakeErrorReport(Exception exception)
{
var errorReport = new VisualElement();

Expand All @@ -76,7 +72,7 @@ private static void HandleReportError(Exception exception)
Application.OpenURL(link);
}

public VisualElement MakeDataSourceSection(
protected VisualElement MakeDataSourceSection(
SerializableType currentDataSourceType,
Action<Type> handleDataSourceTypeChanged
)
Expand All @@ -103,11 +99,11 @@ Action<Type> handleDataSourceTypeChanged
}
}

public static VisualElement MakeBindingSection<BindingType>(
protected static VisualElement MakeBindingSection<BindingType>(
string sectionHeaderText,
Action handleAddBinding,
IEnumerable<BindingType> bindings,
Func<BindingType, VisualElement> MakeEditorVisualElement
Func<BindingType, VisualElement> makeEditorVisualElement
)
{
var sectionRoot = new VisualElement();
Expand All @@ -120,8 +116,8 @@ Func<BindingType, VisualElement> MakeEditorVisualElement
headerLabel.AddToClassList(DataBindingEditorStyles.bindingGroupLabel);
header.Add(headerLabel);

var addBindingButton = new Button(handleAddBinding);
addBindingButton.text = "Add Binding";
var addBindingButton = new Button(handleAddBinding) { text = "Add Binding" };

addBindingButton.AddToClassList(DataBindingEditorStyles.addBindingActionButton);
header.Add(addBindingButton);

Expand All @@ -130,24 +126,22 @@ Func<BindingType, VisualElement> MakeEditorVisualElement
var bindingsGroup = new VisualElement();
bindingsGroup.AddToClassList(DataBindingEditorStyles.bindingGroupList);

if (!bindings.Any())
foreach (var binding in bindings)
{
bindingsGroup.Add(new Label($"There are no bindings in this secion."));
bindingsGroup.Add(makeEditorVisualElement(binding));
}
else

if (!bindingsGroup.Children().Any())
{
foreach (var binding in bindings)
{
bindingsGroup.Add(MakeEditorVisualElement(binding));
}
bindingsGroup.Add(new Label($"There are no bindings in this section."));
}

sectionRoot.Add(bindingsGroup);

return sectionRoot;
}

public static IEnumerable<ElementType> MoveElementUp<ElementType>(
protected static IEnumerable<ElementType> MoveElementUp<ElementType>(
IEnumerable<ElementType> sequence,
ElementType element
)
Expand All @@ -156,44 +150,53 @@ ElementType element
return MoveElementDown(sequence.Reverse(), element).Reverse();
}

public static IEnumerable<ElementType> MoveElementDown<ElementType>(
protected static IEnumerable<ElementType> MoveElementDown<ElementType>(
IEnumerable<ElementType> sequence,
ElementType element
)
where ElementType : class
{
for (var elementIndex = 0; elementIndex < sequence.Count(); ++elementIndex)
if (sequence == null)
{
var currentElement = sequence.ElementAt(elementIndex);
throw new ArgumentNullException(nameof(sequence));
}

var rearrangedSequence = sequence as ElementType[] ?? sequence.ToArray();

if (currentElement == element)
for (var elementIndex = 0; elementIndex < rearrangedSequence.Length; ++elementIndex)
{
if (rearrangedSequence[elementIndex] == element)
{
if (currentElement != sequence.Last())
if (elementIndex < (rearrangedSequence.Length - 1))
{
yield return sequence.ElementAt(elementIndex + 1);
++elementIndex;
(rearrangedSequence[elementIndex], rearrangedSequence[elementIndex + 1]) = (
rearrangedSequence[elementIndex + 1],
rearrangedSequence[elementIndex]
);

break;
}
}

yield return currentElement;
}

return rearrangedSequence;
}

public static Type[] GetValidDataSourceTypes()
private static Type[] GetValidDataSourceTypes()
{
var assemblies = AppDomain.CurrentDomain.GetAssemblies();

Func<Type, bool> dataSourceFilterFunc = (x) =>
!x.IsAbstract
&& !x.IsGenericType
&& !x.IsInterface
&& x.InheritsOrImplements(typeof(INotifyDataSourceChanged));

return assemblies
.Where(x => !x.IsDynamic)
.SelectMany(x => x.ExportedTypes)
.Where(dataSourceFilterFunc)
.Where(DataSourceFilterFunc)
.ToArray();

bool DataSourceFilterFunc(Type x) =>
!x.IsAbstract
&& !x.IsGenericType
&& !x.IsInterface
&& x.InheritsOrImplements(typeof(INotifyDataSourceChanged));
}

private VisualElement MakeDataSourceDropDown(
Expand Down Expand Up @@ -223,7 +226,7 @@ Action<Type> handleDataSourceTypeChanged
return dataSourceDropDown;
}

public static Type GuessDataSourceTypeName(string viewName, Type[] validDataSources)
protected static Type GuessDataSourceTypeName(string viewName, Type[] validDataSources)
{
return validDataSources
.Select(x => new { x, distance = viewName.DamerauLevenshteinDistance(x.Name) })
Expand Down Expand Up @@ -259,12 +262,11 @@ private static VisualElement MakeOpenDataSourceButton(SerializableType dataSourc
{
var dataSourceSourceFile = FindDataSourceSourceFile(dataSourceType.Type);

var button = new UnityEngine.UIElements.Button(
() => OpenDataSourceEditor(dataSourceSourceFile)
);

button.text = EditorDisplayText.EditSourceText;
button.tooltip = EditorDisplayText.NoSourceCodeAvailableToolTip;
var button = new Button(() => OpenDataSourceEditor(dataSourceSourceFile))
{
text = EditorDisplayText.EditSourceText,
tooltip = EditorDisplayText.NoSourceCodeAvailableToolTip
};

button.SetEnabled(dataSourceSourceFile != null);
return button;
Expand Down
46 changes: 23 additions & 23 deletions Tests/Editor/de.JochenHeckl.Unity.DataBinding.Editor.Tests.asmdef
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "de.JochenHeckl.Unity.DataBinding.Editor.Tests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"de.Jochenheckl.Unity.DataBinding"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
{
"name": "de.JochenHeckl.Unity.DataBinding.Editor.Tests",
"rootNamespace": "de.JochenHeckl.Unity.DataBinding.Editor.Tests",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"de.Jochenheckl.Unity.DataBinding"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
},
"licensesUrl": "https://raw.githubusercontent.com/JochenHeckl/DataBinding/main/LICENSE.md",
"dependencies": {
"com.unity.test-framework": "1.1.11"
"com.unity.test-framework": "1.4.3"
},
"testtables": [
"de.jochenheckl.unity.databinding"
],
"samples": [
{
"displayName": "MyFirstDataBoundView (Getting Started Tutorial)",
Expand Down

0 comments on commit d132021

Please sign in to comment.