Resolve WES-127-Refactor_Themelist
This commit is contained in:
committed by
Jelle De Geest
parent
564ec209c7
commit
ea13788199
11
Assets/Common/Interfaces/ModelIndex.cs
Normal file
11
Assets/Common/Interfaces/ModelIndex.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// This enum is used to identify each of the SignLanguage models
|
||||
/// </summary>
|
||||
public enum ModelIndex
|
||||
{
|
||||
FINGERSPELLING,
|
||||
NONE
|
||||
}
|
||||
11
Assets/Common/Interfaces/ModelIndex.cs.meta
Normal file
11
Assets/Common/Interfaces/ModelIndex.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dbd5e1100bc81648b52206df369d0a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Common/Interfaces/ModelList.cs
Normal file
57
Assets/Common/Interfaces/ModelList.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Barracuda;
|
||||
/// <summary>
|
||||
/// This scriptable will hold tupples of Courseindices and models
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/ModelList")]
|
||||
public class ModelList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Small class to link a model to a courseIndex irrespective of its position in a list
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ModelTuple
|
||||
{
|
||||
/// <summary>
|
||||
/// ModelIndex to which the model corresponds
|
||||
/// </summary>
|
||||
public ModelIndex index;
|
||||
/// <summary>
|
||||
/// The model itself
|
||||
/// </summary>
|
||||
public NNModel model;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Index of the currently active model
|
||||
/// </summary>
|
||||
public int currentModelIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A list of all the models
|
||||
/// </summary>
|
||||
public List<ModelTuple> models = new List<ModelTuple>();
|
||||
|
||||
/// <summary>
|
||||
/// Get a model by modelindex
|
||||
/// </summary>
|
||||
/// <param name="modelIndex">ModelIndex of the model</param>
|
||||
/// <returns>Model associated with this index, null if no model was found</returns>
|
||||
public NNModel GetCurrentModel()
|
||||
{
|
||||
return models.Find(x => x.model == models[currentModelIndex].model)?.model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function to find a model-index in the list based on its index
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
public void SetCurrentModel(ModelIndex index)
|
||||
{
|
||||
currentModelIndex = models.FindIndex((m) => m.index == index);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Interfaces/ModelList.cs.meta
Normal file
11
Assets/Common/Interfaces/ModelList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a3f61c93a08c04496c49ffd10b9021
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Barracuda;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -24,9 +23,9 @@ public class Theme : ScriptableObject
|
||||
public ThemeIndex index;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the model used in the SignPredictor
|
||||
/// The index of the model you want to use
|
||||
/// </summary>
|
||||
public NNModel model;
|
||||
public ModelIndex modelIndex;
|
||||
|
||||
/// <summary>
|
||||
/// List of all learnable words/letters
|
||||
|
||||
@@ -16,6 +16,7 @@ MonoBehaviour:
|
||||
description: Van vis tot leeuw
|
||||
index: 2
|
||||
model: {fileID: 0}
|
||||
modelIndex: 1
|
||||
learnables:
|
||||
- name: Walvis
|
||||
image: {fileID: 21300000, guid: 2b01165a5836ab14593d7a5862bd6793, type: 3}
|
||||
|
||||
@@ -15,6 +15,8 @@ MonoBehaviour:
|
||||
title: Kleren en Kleuren
|
||||
description: Van rok tot sok
|
||||
index: 1
|
||||
model: {fileID: 0}
|
||||
modelIndex: 1
|
||||
learnables:
|
||||
- name: Blauw
|
||||
image: {fileID: 21300000, guid: 182fb89eba9c64041bef31ca35c4bcd8, type: 3}
|
||||
|
||||
@@ -15,6 +15,8 @@ MonoBehaviour:
|
||||
title: Familie
|
||||
description: Van generatie tot generatie
|
||||
index: 6
|
||||
model: {fileID: 0}
|
||||
modelIndex: 1
|
||||
learnables:
|
||||
- name: Broer
|
||||
image: {fileID: 21300000, guid: eecf67266f150f1489717049489cf16d, type: 3}
|
||||
|
||||
@@ -16,6 +16,7 @@ MonoBehaviour:
|
||||
description: Van kers tot pompoen
|
||||
index: 3
|
||||
model: {fileID: 0}
|
||||
modelIndex: 1
|
||||
learnables:
|
||||
- name: Aardappel
|
||||
image: {fileID: 21300000, guid: 2610cdbc24a125f43ada7fed67d8f51b, type: 3}
|
||||
|
||||
@@ -15,6 +15,8 @@ MonoBehaviour:
|
||||
title: Hobbies
|
||||
description: Van schilderen tot reizen
|
||||
index: 4
|
||||
model: {fileID: 0}
|
||||
modelIndex: 1
|
||||
learnables:
|
||||
- name: Dansen
|
||||
image: {fileID: 21300000, guid: 6d405f607ae817744b49f921f0611088, type: 3}
|
||||
|
||||
@@ -15,6 +15,8 @@ MonoBehaviour:
|
||||
title: Huis beschrijven
|
||||
description: Van zetel tot villa
|
||||
index: 5
|
||||
model: {fileID: 0}
|
||||
modelIndex: 1
|
||||
learnables:
|
||||
- name: Keuken
|
||||
image: {fileID: 21300000, guid: b17ce5bf59092b847b084d3400e7a1b4, type: 3}
|
||||
|
||||
@@ -56,8 +56,8 @@ public class CourseActivityScreen : MonoBehaviour
|
||||
Course course = courseList.courses[index];
|
||||
|
||||
// vvv TEMPORARY STUFF vvv
|
||||
playButton.SetActive(course.theme.model != null);
|
||||
previewButton.SetActive(course.theme.model == null);
|
||||
playButton.SetActive(course.theme.modelIndex != ModelIndex.NONE);
|
||||
previewButton.SetActive(course.theme.modelIndex == ModelIndex.NONE);
|
||||
// ^^^ TEMPORARY STUFF ^^^
|
||||
|
||||
title.text = course.title;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"CommonScripts",
|
||||
"InterfacesScripts"
|
||||
"InterfacesScripts",
|
||||
"Unity.Barracuda",
|
||||
"SignPredictor"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
80
Assets/Common/Tests/ModelListTest.cs
Normal file
80
Assets/Common/Tests/ModelListTest.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using NUnit.Framework;
|
||||
using Unity.Barracuda;
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// Test the ModelList class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ModelListTest
|
||||
{
|
||||
private ModelList modelList;
|
||||
|
||||
/// <summary>
|
||||
/// Setup a ModelList with all possible Models in the enum
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup_Model()
|
||||
{
|
||||
modelList = ScriptableObject.CreateInstance<ModelList>();
|
||||
|
||||
// Add a Model for each index in the enum
|
||||
|
||||
// Dumb way to access each index in the enum, couldn't find a different way to do it though
|
||||
foreach (var field in typeof(ModelIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
ModelIndex value = (ModelIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
ModelList.ModelTuple model = new ModelList.ModelTuple();
|
||||
// This is all we will need to distinguish
|
||||
model.index = value;
|
||||
|
||||
// Insert in front to guarantee that ModelIndex will not line up with listIndex
|
||||
modelList.models.Insert(0, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Check if current model can be correctly gotten as current via GetCurrentModel
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetCurrentModel()
|
||||
{
|
||||
System.Random random = new System.Random();
|
||||
ModelIndex value = (ModelIndex)random.Next(modelList.models.Count);
|
||||
modelList.SetCurrentModel(value);
|
||||
|
||||
Assert.AreEqual(modelList.models[modelList.currentModelIndex].model, modelList.GetCurrentModel());
|
||||
|
||||
// Check if empty model fails gracefully (returns null)
|
||||
Assert.IsNull(ScriptableObject.CreateInstance<ModelList>().GetCurrentModel());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if all models can be correctly set as current via SetCurrentModel
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetCurrentModel()
|
||||
{
|
||||
foreach (var field in typeof(ModelIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
ModelIndex value = (ModelIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
modelList.SetCurrentModel(value);
|
||||
|
||||
// Fetch the current model and check if its name is the same as the one we made into the current one
|
||||
ModelList.ModelTuple m = modelList.models[modelList.currentModelIndex];
|
||||
|
||||
Assert.AreEqual(m.index, value);
|
||||
Assert.IsTrue(m.model is NNModel || m.model is null);
|
||||
}
|
||||
}
|
||||
ModelList emptyList = ScriptableObject.CreateInstance<ModelList>();
|
||||
emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING);
|
||||
|
||||
Assert.IsTrue(emptyList.currentModelIndex == -1);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/ModelListTest.cs.meta
Normal file
11
Assets/Common/Tests/ModelListTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1313e0cc80244354eb6e2d0c1e891941
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user