Merge branch 'code-formatting-and-cleanup' into 'development'
Add formatting rules See merge request wesign/unity-application!26
This commit is contained in:
commit
594e95d7e1
228
.editorconfig
Normal file
228
.editorconfig
Normal file
@ -0,0 +1,228 @@
|
||||
# Remove the line below if you want to inherit .editorconfig settings from higher directories
|
||||
root = true
|
||||
|
||||
# C# files
|
||||
[*.cs]
|
||||
|
||||
#### Core EditorConfig Options ####
|
||||
|
||||
# Indentation and spacing
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
tab_width = 4
|
||||
|
||||
# New line preferences
|
||||
end_of_line = crlf
|
||||
insert_final_newline = false
|
||||
|
||||
#### .NET Coding Conventions ####
|
||||
|
||||
# Organize usings
|
||||
dotnet_separate_import_directive_groups = false
|
||||
dotnet_sort_system_directives_first = false
|
||||
file_header_template = unset
|
||||
|
||||
# this. and Me. preferences
|
||||
dotnet_style_qualification_for_event = false
|
||||
dotnet_style_qualification_for_field = false
|
||||
dotnet_style_qualification_for_method = false
|
||||
dotnet_style_qualification_for_property = false
|
||||
|
||||
# Language keywords vs BCL types preferences
|
||||
dotnet_style_predefined_type_for_locals_parameters_members = true
|
||||
dotnet_style_predefined_type_for_member_access = true
|
||||
|
||||
# Parentheses preferences
|
||||
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
|
||||
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
|
||||
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
|
||||
|
||||
# Modifier preferences
|
||||
dotnet_style_require_accessibility_modifiers = for_non_interface_members
|
||||
|
||||
# Expression-level preferences
|
||||
dotnet_style_coalesce_expression = true
|
||||
dotnet_style_collection_initializer = true
|
||||
dotnet_style_explicit_tuple_names = true
|
||||
dotnet_style_namespace_match_folder = true
|
||||
dotnet_style_null_propagation = true
|
||||
dotnet_style_object_initializer = true
|
||||
dotnet_style_operator_placement_when_wrapping = beginning_of_line
|
||||
dotnet_style_prefer_auto_properties = true
|
||||
dotnet_style_prefer_compound_assignment = true
|
||||
dotnet_style_prefer_conditional_expression_over_assignment = true
|
||||
dotnet_style_prefer_conditional_expression_over_return = true
|
||||
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
|
||||
dotnet_style_prefer_inferred_anonymous_type_member_names = true
|
||||
dotnet_style_prefer_inferred_tuple_names = true
|
||||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
|
||||
dotnet_style_prefer_simplified_boolean_expressions = true
|
||||
dotnet_style_prefer_simplified_interpolation = true
|
||||
|
||||
# Field preferences
|
||||
dotnet_style_readonly_field = true
|
||||
|
||||
# Parameter preferences
|
||||
dotnet_code_quality_unused_parameters = all
|
||||
|
||||
# Suppression preferences
|
||||
dotnet_remove_unnecessary_suppression_exclusions = none
|
||||
|
||||
# New line preferences
|
||||
dotnet_style_allow_multiple_blank_lines_experimental = true
|
||||
dotnet_style_allow_statement_immediately_after_block_experimental = true
|
||||
|
||||
#### C# Coding Conventions ####
|
||||
|
||||
# var preferences
|
||||
csharp_style_var_elsewhere = false
|
||||
csharp_style_var_for_built_in_types = false
|
||||
csharp_style_var_when_type_is_apparent = false
|
||||
|
||||
# Expression-bodied members
|
||||
csharp_style_expression_bodied_accessors = true
|
||||
csharp_style_expression_bodied_constructors = false
|
||||
csharp_style_expression_bodied_indexers = true
|
||||
csharp_style_expression_bodied_lambdas = true
|
||||
csharp_style_expression_bodied_local_functions = false
|
||||
csharp_style_expression_bodied_methods = false
|
||||
csharp_style_expression_bodied_operators = false
|
||||
csharp_style_expression_bodied_properties = true
|
||||
|
||||
# Pattern matching preferences
|
||||
csharp_style_pattern_matching_over_as_with_null_check = true
|
||||
csharp_style_pattern_matching_over_is_with_cast_check = true
|
||||
csharp_style_prefer_extended_property_pattern = true
|
||||
csharp_style_prefer_not_pattern = true
|
||||
csharp_style_prefer_pattern_matching = true
|
||||
csharp_style_prefer_switch_expression = true
|
||||
|
||||
# Null-checking preferences
|
||||
csharp_style_conditional_delegate_call = true
|
||||
|
||||
# Modifier preferences
|
||||
csharp_prefer_static_local_function = true
|
||||
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
|
||||
csharp_style_prefer_readonly_struct = true
|
||||
|
||||
# Code-block preferences
|
||||
csharp_prefer_braces = true
|
||||
csharp_prefer_simple_using_statement = true
|
||||
csharp_style_namespace_declarations = block_scoped
|
||||
csharp_style_prefer_method_group_conversion = true
|
||||
csharp_style_prefer_top_level_statements = true
|
||||
|
||||
# Expression-level preferences
|
||||
csharp_prefer_simple_default_expression = true
|
||||
csharp_style_deconstructed_variable_declaration = true
|
||||
csharp_style_implicit_object_creation_when_type_is_apparent = true
|
||||
csharp_style_inlined_variable_declaration = true
|
||||
csharp_style_prefer_index_operator = true
|
||||
csharp_style_prefer_local_over_anonymous_function = true
|
||||
csharp_style_prefer_null_check_over_type_check = true
|
||||
csharp_style_prefer_range_operator = true
|
||||
csharp_style_prefer_tuple_swap = true
|
||||
csharp_style_prefer_utf8_string_literals = true
|
||||
csharp_style_throw_expression = true
|
||||
csharp_style_unused_value_assignment_preference = discard_variable
|
||||
csharp_style_unused_value_expression_statement_preference = discard_variable
|
||||
|
||||
# 'using' directive preferences
|
||||
csharp_using_directive_placement = outside_namespace
|
||||
|
||||
# New line preferences
|
||||
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
|
||||
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
|
||||
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
|
||||
csharp_style_allow_embedded_statements_on_same_line_experimental = true
|
||||
|
||||
#### C# Formatting Rules ####
|
||||
|
||||
# New line preferences
|
||||
csharp_new_line_before_catch = true
|
||||
csharp_new_line_before_else = true
|
||||
csharp_new_line_before_finally = true
|
||||
csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = all
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
|
||||
# Indentation preferences
|
||||
csharp_indent_block_contents = true
|
||||
csharp_indent_braces = false
|
||||
csharp_indent_case_contents = true
|
||||
csharp_indent_case_contents_when_block = true
|
||||
csharp_indent_labels = one_less_than_current
|
||||
csharp_indent_switch_labels = true
|
||||
|
||||
# Space preferences
|
||||
csharp_space_after_cast = false
|
||||
csharp_space_after_colon_in_inheritance_clause = true
|
||||
csharp_space_after_comma = true
|
||||
csharp_space_after_dot = false
|
||||
csharp_space_after_keywords_in_control_flow_statements = true
|
||||
csharp_space_after_semicolon_in_for_statement = true
|
||||
csharp_space_around_binary_operators = before_and_after
|
||||
csharp_space_around_declaration_statements = false
|
||||
csharp_space_before_colon_in_inheritance_clause = true
|
||||
csharp_space_before_comma = false
|
||||
csharp_space_before_dot = false
|
||||
csharp_space_before_open_square_brackets = false
|
||||
csharp_space_before_semicolon_in_for_statement = false
|
||||
csharp_space_between_empty_square_brackets = false
|
||||
csharp_space_between_method_call_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_call_name_and_opening_parenthesis = false
|
||||
csharp_space_between_method_call_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
|
||||
csharp_space_between_method_declaration_name_and_open_parenthesis = false
|
||||
csharp_space_between_method_declaration_parameter_list_parentheses = false
|
||||
csharp_space_between_parentheses = false
|
||||
csharp_space_between_square_brackets = false
|
||||
|
||||
# Wrapping preferences
|
||||
csharp_preserve_single_line_blocks = true
|
||||
csharp_preserve_single_line_statements = true
|
||||
|
||||
#### Naming styles ####
|
||||
|
||||
# Naming rules
|
||||
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
|
||||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
|
||||
|
||||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
|
||||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
|
||||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
|
||||
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
|
||||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
|
||||
|
||||
# Symbol specifications
|
||||
|
||||
dotnet_naming_symbols.interface.applicable_kinds = interface
|
||||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.interface.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
|
||||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.types.required_modifiers =
|
||||
|
||||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
|
||||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
|
||||
dotnet_naming_symbols.non_field_members.required_modifiers =
|
||||
|
||||
# Naming styles
|
||||
|
||||
dotnet_naming_style.pascal_case.required_prefix =
|
||||
dotnet_naming_style.pascal_case.required_suffix =
|
||||
dotnet_naming_style.pascal_case.word_separator =
|
||||
dotnet_naming_style.pascal_case.capitalization = pascal_case
|
||||
|
||||
dotnet_naming_style.begins_with_i.required_prefix = I
|
||||
dotnet_naming_style.begins_with_i.required_suffix =
|
||||
dotnet_naming_style.begins_with_i.word_separator =
|
||||
dotnet_naming_style.begins_with_i.capitalization = pascal_case
|
||||
@ -4,15 +4,26 @@ using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// A class for holding all progress belonging to a user
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
// Can not be created from Editor
|
||||
public class Progress
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for handling the stored progress
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
// Helper class to serialize into byte[]
|
||||
protected class DataEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// The key, used to reference the data object
|
||||
/// </summary>
|
||||
public string key;
|
||||
|
||||
/// <summary>
|
||||
/// The object, representated as a list of byte (which can be serialized)
|
||||
/// </summary>
|
||||
public List<byte> bytes = new List<byte>();
|
||||
|
||||
public DataEntry(string key, byte[] data)
|
||||
@ -22,13 +33,21 @@ public class Progress
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Course or Minigame")]
|
||||
/// <summary>
|
||||
/// Entries in the <c>Progress</c> object
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
// values belonging to a certain key, in List (which can be serialized)
|
||||
private List<DataEntry> entries = new List<DataEntry>();
|
||||
|
||||
|
||||
// Add new `key` := `value`, returns `true` if successful
|
||||
/// <summary>
|
||||
/// Update the value of a certain key,
|
||||
/// or add a new value if the key was not present
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data to be added/updated</typeparam>
|
||||
/// <param name="key">The key, used for referencing the data</param>
|
||||
/// <param name="data">The object of type <typeparamref name="T"/></param>
|
||||
/// <returns><c>true</c> if successful, <c>false</c> otherwise</returns>
|
||||
public bool AddOrUpdate<T>(string key, T data)
|
||||
{
|
||||
if (data == null)
|
||||
@ -55,6 +74,13 @@ public class Progress
|
||||
}
|
||||
|
||||
// Get the value of type `T` belonging to `key`
|
||||
/// <summary>
|
||||
/// Get the data object of a certain key
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data object</typeparam>
|
||||
/// <param name="key">The key referencing the data object</param>
|
||||
/// <returns>The data, cast to a type <typeparamref name="T"/></returns>
|
||||
/// <exception cref="KeyNotFoundException"></exception>
|
||||
public T Get<T>(string key)
|
||||
{
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
|
||||
@ -2,29 +2,45 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// A class holding all information of a user
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class User
|
||||
{
|
||||
[Header("Personal data")]
|
||||
// User nickname
|
||||
/// <summary>
|
||||
/// User nickname
|
||||
/// </summary>
|
||||
public string username;
|
||||
// User avatar
|
||||
|
||||
/// <summary>
|
||||
/// The avatar of the user
|
||||
/// </summary>
|
||||
public Sprite avatar;
|
||||
|
||||
[Header("Personal settings")]
|
||||
// TODO: set personal settings and preferences
|
||||
|
||||
[Header("Progress")]
|
||||
// Total playtime
|
||||
/// <summary>
|
||||
/// The total playtime of the user
|
||||
/// </summary>
|
||||
/// <remarks>TODO: needs to be implemented</remarks>
|
||||
public double playtime;
|
||||
|
||||
/// <summary>
|
||||
/// List of courses a user started/completed
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
// List of courses a user started/completed
|
||||
public List<Progress> courses = new List<Progress>();
|
||||
|
||||
/// <summary>
|
||||
/// List of minigames a user played
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
// List of minigames a user played
|
||||
public List<Progress> minigames = new List<Progress>();
|
||||
|
||||
// Get a list of all recently started courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
|
||||
/// <summary>
|
||||
/// Get a list of all recently started courses
|
||||
/// </summary>
|
||||
/// <returns>A <c>List</c> of <c>Tuples</c>, containing the <c>CourseIndex</c>
|
||||
/// and a <c>float</c> holding the progress (value between 0 and 1) of the user in this course</returns>
|
||||
public List<Tuple<CourseIndex, float>> GetRecentCourses()
|
||||
{
|
||||
// TODO: return better results (for now only return all courses)
|
||||
@ -38,7 +54,11 @@ public class User
|
||||
return recentCourses;
|
||||
}
|
||||
|
||||
// Get a list of all recommended courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
|
||||
/// <summary>
|
||||
/// Get a list of all recommended courses
|
||||
/// </summary>
|
||||
/// <returns>A <c>List</c> of <c>Tuples</c>, containing the <c>CourseIndex</c>
|
||||
/// and a <c>float</c> holding the progress (value between 0 and 1) of the user in this course</returns>
|
||||
public List<Tuple<CourseIndex, float>> GetRecommendedCourses()
|
||||
{
|
||||
List<Tuple<CourseIndex, float>> recommenedCourses = new List<Tuple<CourseIndex, float>>();
|
||||
@ -59,4 +79,24 @@ public class User
|
||||
|
||||
return recommenedCourses;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the progress of a certain course
|
||||
/// </summary>
|
||||
/// <param name="courseIndex">Index of course</param>
|
||||
/// <returns><c>Progress</c> belonging to the <c>courseIndex</c>, <c>null</c> if course was not found</returns>
|
||||
public Progress GetCourseProgress(CourseIndex courseIndex)
|
||||
{
|
||||
return courses.Find((p) => p.Get<CourseIndex>("courseIndex") == courseIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the progress of certain minigame
|
||||
/// </summary>
|
||||
/// <param name="minigameIndex">Index of the minigame</param>
|
||||
/// <returns><c>Progress</c> belonging to the <c>minigameIndex</c>, <c>null</c> if minigame was not found</returns>
|
||||
public Progress GetMinigameProgress(MinigameIndex minigameIndex)
|
||||
{
|
||||
return minigames.Find((p) => p.Get<MinigameIndex>("minigameIndex") == minigameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,34 +5,56 @@ using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// UserCreationScreen scene manager
|
||||
/// </summary>
|
||||
public class UserCreationScreen : MonoBehaviour
|
||||
{
|
||||
// Max length of a username
|
||||
/// <summary>
|
||||
/// Maximum lenght of a username
|
||||
/// </summary>
|
||||
private const int MAX_USERNAME_LENGTH = 12;
|
||||
|
||||
[Header("UI References")]
|
||||
// Reference to the input text field for username
|
||||
/// <summary>
|
||||
/// Reference to the input text field for username
|
||||
/// </summary>
|
||||
public TMP_InputField inputName;
|
||||
// Reference to the avatar-list container
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the avatar-list container
|
||||
/// </summary>
|
||||
public Transform avatarsContainer;
|
||||
|
||||
[Header("Prefab")]
|
||||
// Avatar prefab
|
||||
/// <summary>
|
||||
/// Avatar prefab
|
||||
/// </summary>
|
||||
public GameObject avatarPrefab;
|
||||
// List of all sprites that are supported as avatars
|
||||
|
||||
/// <summary>
|
||||
/// List of all sprites that are supported as avatars
|
||||
/// </summary>
|
||||
public List<Sprite> sprites = new List<Sprite>();
|
||||
|
||||
[Header("Users List")]
|
||||
// Reference to the UserList ScriptableObject
|
||||
/// <summary>
|
||||
/// Reference to the UserList ScriptableObject
|
||||
/// </summary>
|
||||
public UserList users;
|
||||
|
||||
/// <summary>
|
||||
/// Current selected avatar
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
// Current selected avatar
|
||||
private int selectedAvatar = 0;
|
||||
// List of references to avatar background sprites (so we can color them nicely)
|
||||
|
||||
/// <summary>
|
||||
/// List of references to avatar background sprites (so we can color them nicely)
|
||||
/// </summary>
|
||||
private List<Image> avatars = new List<Image>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
for (int i = 0; i < sprites.Count; i++)
|
||||
@ -60,7 +82,10 @@ public class UserCreationScreen : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Update the current selected avatar
|
||||
/// <summary>
|
||||
/// Update the current selected avatar
|
||||
/// </summary>
|
||||
/// <param name="newAvatar">Index to the new avatar in the <c>this.avatars</c> list</param>
|
||||
private void UpdateAvatar(int newAvatar)
|
||||
{
|
||||
avatars[selectedAvatar].color = Color.gray;
|
||||
@ -68,13 +93,20 @@ public class UserCreationScreen : MonoBehaviour
|
||||
avatars[selectedAvatar].color = Color.blue;
|
||||
}
|
||||
|
||||
// Check if a given string is a correct username (using Regex)
|
||||
/// <summary>
|
||||
/// Check if a given string is a correct username (using Regex)
|
||||
/// </summary>
|
||||
/// <param name="username">The username to be checked</param>
|
||||
/// <returns><c>true</c> if the username was valid, <c>false</c> otherwise</returns>
|
||||
static public bool IsValidUsername(string username)
|
||||
{
|
||||
return new Regex($@"^[abcdefghijklmnopqrstuvwxyz]{{1,{MAX_USERNAME_LENGTH}}}$").IsMatch(username);
|
||||
}
|
||||
|
||||
// Create a new user (will be called by button)
|
||||
/// <summary>
|
||||
/// Create a new user
|
||||
/// (this method will be called by a button callback)
|
||||
/// </summary>
|
||||
public void CreateUser()
|
||||
{
|
||||
string username = inputName.text;
|
||||
|
||||
@ -3,31 +3,55 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Keep track of all users
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/UserList")]
|
||||
public class UserList : ScriptableObject
|
||||
{
|
||||
// Serializable UserList content
|
||||
/// <summary>
|
||||
/// Helper class to enable serialization of the UserList class
|
||||
/// (<c>ScriptableObkect</c>s cannot be serialized)
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class StoredUserList
|
||||
{
|
||||
/// <summary>
|
||||
/// The index of the current/last logged in user in the <c>storedUsers</c> list
|
||||
/// </summary>
|
||||
public int currentUserIndex;
|
||||
/// <summary>
|
||||
/// A list containing all users (which can be serialized)
|
||||
/// </summary>
|
||||
public List<User> storedUsers = new List<User>();
|
||||
}
|
||||
[Header("Users")]
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the serializable version of <c>UserList</c>
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
// Reference to serializable version of UserList
|
||||
private StoredUserList storedUserList = new StoredUserList();
|
||||
|
||||
// Path to .json file
|
||||
/// <summary>
|
||||
/// Path of the <c>.json</c>-file to store all serialized data
|
||||
/// </summary>
|
||||
public static string PATH = null;
|
||||
|
||||
/// <summary>
|
||||
/// OnEnable will make sure the <c>PATH</c>-variable is correctly initialized
|
||||
/// </summary>
|
||||
void OnEnable()
|
||||
{
|
||||
PATH = $"{Application.dataPath}/users.json";
|
||||
Load();
|
||||
}
|
||||
|
||||
// Create a new User
|
||||
/// <summary>
|
||||
/// Create a new user
|
||||
/// </summary>
|
||||
/// <param name="name">The username of the new user</param>
|
||||
/// <param name="avatar">Reference to the user avatar</param>
|
||||
/// <returns>A newly created user</returns>
|
||||
public User CreateNewUser(string name, Sprite avatar)
|
||||
{
|
||||
User user = new User();
|
||||
@ -36,7 +60,12 @@ public class UserList : ScriptableObject
|
||||
return user;
|
||||
}
|
||||
|
||||
// Create a new User and add to list
|
||||
/// <summary>
|
||||
/// Create a new user and save (add to list)
|
||||
/// </summary>
|
||||
/// <param name="name">The username of the new user</param>
|
||||
/// <param name="avatar">Reference to the user avatar</param>
|
||||
/// <returns>A newly created user</returns>
|
||||
public User CreateAndAddNewUser(string name, Sprite avatar)
|
||||
{
|
||||
User user = CreateNewUser(name, avatar);
|
||||
@ -45,7 +74,11 @@ public class UserList : ScriptableObject
|
||||
return user;
|
||||
}
|
||||
|
||||
// Get user by username, returns `null` if no user can be found with such name
|
||||
/// <summary>
|
||||
/// Get a user by username
|
||||
/// </summary>
|
||||
/// <param name="username">The username of the user</param>
|
||||
/// <returns><c>User</c>-object if a user with such username was found, <c>null</c> otherwise</returns>
|
||||
public User GetUserByUsername(string username)
|
||||
{
|
||||
foreach (User user in storedUserList.storedUsers)
|
||||
@ -54,19 +87,27 @@ public class UserList : ScriptableObject
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get a list of all users
|
||||
/// <summary>
|
||||
/// Get a list of all users currently stored
|
||||
/// </summary>
|
||||
/// <returns>A list of all users</returns>
|
||||
public List<User> GetUsers()
|
||||
{
|
||||
return storedUserList.storedUsers;
|
||||
}
|
||||
|
||||
// Get the current active user
|
||||
/// <summary>
|
||||
/// Get the current logged in user
|
||||
/// </summary>
|
||||
/// <returns>The current logged in user</returns>
|
||||
public User GetCurrentUser()
|
||||
{
|
||||
return storedUserList.storedUsers[storedUserList.currentUserIndex];
|
||||
}
|
||||
|
||||
// Save the userList
|
||||
/// <summary>
|
||||
/// Save the users
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
string json = JsonUtility.ToJson(storedUserList);
|
||||
@ -74,7 +115,9 @@ public class UserList : ScriptableObject
|
||||
File.WriteAllText(PATH, json);
|
||||
}
|
||||
|
||||
// Load the userList into this object
|
||||
/// <summary>
|
||||
/// Override the current content of the userlist by what is stored on disk
|
||||
/// </summary>
|
||||
public void Load()
|
||||
{
|
||||
try
|
||||
|
||||
@ -3,24 +3,34 @@ using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the Progress class
|
||||
/// </summary>
|
||||
public class TestProgress : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// A dummy serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
// Dummy struct
|
||||
private struct SerializableStruct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dummy non-serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
private struct NonSerializableStruct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
|
||||
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
|
||||
/// <summary>
|
||||
/// Helper method
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if <c>Progress.AddOrUpdate(...)</c> throws a <c>SerializationException</c></returns>
|
||||
private bool AddNonSerializableStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -30,7 +40,10 @@ public class TestProgress : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
|
||||
/// <summary>
|
||||
/// Helper method
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if <c>Progress.Get(...)</c> throws a <c>KeyNotFoundException</c></returns>
|
||||
private bool AccessInvalidKey()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -39,7 +52,10 @@ public class TestProgress : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper method, returns true if `Progress.Get(...)` throws a `InvalidCastException`
|
||||
/// <summary>
|
||||
/// Helper method
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if <c>Progress.Get(...)</c> throws a <c>InvalidCastException</c></returns>
|
||||
private bool AccessInvalidType()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -49,6 +65,9 @@ public class TestProgress : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
TestNewProgress();
|
||||
@ -68,18 +87,27 @@ public class TestProgress : MonoBehaviour
|
||||
TestProgressGetStruct();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for creation of a new progress
|
||||
/// </summary>
|
||||
public void TestNewProgress()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether invalid data will not be added
|
||||
/// </summary>
|
||||
public void TestProgressAddInvalidData()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(!progress.AddOrUpdate<GameObject>("key", null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a duplicated key will be added
|
||||
/// </summary>
|
||||
public void TestProgressAddDuplicateKey()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -87,45 +115,69 @@ public class TestProgress : MonoBehaviour
|
||||
Debug.Assert(progress.AddOrUpdate<int>("key 1", 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>int</c> value can be added
|
||||
/// </summary>
|
||||
public void TestProgressAddInt()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<int>("key", 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>double</c> value can be added
|
||||
/// </summary>
|
||||
public void TestProgressAddDouble()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<double>("key", 1.0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>string</c> value can be added
|
||||
/// </summary>
|
||||
public void TestProgressAddString()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<string>("key", "Hello World!"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a serializable struct can be added
|
||||
/// </summary>
|
||||
public void TestProgressAddSerializableStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a non-serializable struct will throw an error
|
||||
/// </summary>
|
||||
public void TestProgressAddNonSerializableStruct()
|
||||
{
|
||||
Debug.Assert(AddNonSerializableStruct());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an invalid key will throw an error
|
||||
/// </summary>
|
||||
public void TestProgressGetInvalidKey()
|
||||
{
|
||||
Debug.Assert(AccessInvalidKey());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an invalid type will throw an error
|
||||
/// </summary>
|
||||
public void TestProgressGetInvalidType()
|
||||
{
|
||||
Debug.Assert(AccessInvalidType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a value is correctly updated
|
||||
/// </summary>
|
||||
public void TestProgressUpdate()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -135,6 +187,9 @@ public class TestProgress : MonoBehaviour
|
||||
Debug.Assert(progress.Get<int>("key") == 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>int</c> value can be read
|
||||
/// </summary>
|
||||
public void TestProgressGetInt()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -142,6 +197,9 @@ public class TestProgress : MonoBehaviour
|
||||
Debug.Assert(progress.Get<int>("key") == 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>double</c> value can be read
|
||||
/// </summary>
|
||||
public void TestProgressGetDouble()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -149,6 +207,9 @@ public class TestProgress : MonoBehaviour
|
||||
Debug.Assert(progress.Get<double>("key") == 1.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>string</c> value can be read
|
||||
/// </summary>
|
||||
public void TestProgressGetString()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
@ -156,6 +217,9 @@ public class TestProgress : MonoBehaviour
|
||||
Debug.Assert(progress.Get<string>("key") == "Hello World!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a serializable struct can be read
|
||||
/// </summary>
|
||||
public void TestProgressGetStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
|
||||
168
Assets/Accounts/Tests/TestUser.cs
Normal file
168
Assets/Accounts/Tests/TestUser.cs
Normal file
@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the User class
|
||||
/// </summary>
|
||||
public class TestUser : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
TestNewUser();
|
||||
TestUserAddCourse();
|
||||
TestUserAddMinigame();
|
||||
TestGetRecentCoursesEmpty();
|
||||
TestGetRecentCoursesAll();
|
||||
TestGetRecommendedCoursesEmpty();
|
||||
TestGetRecommendedCoursesAll();
|
||||
TestGetCourseProgressNull();
|
||||
TestGetCourseProgressValid();
|
||||
TestGetMinigameProgressNull();
|
||||
TestGetMinigameProgressValid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for the creation of a new user
|
||||
/// </summary>
|
||||
public void TestNewUser()
|
||||
{
|
||||
User user = new User();
|
||||
Debug.Assert(user != null);
|
||||
Debug.Assert(user.courses.Count == 0);
|
||||
Debug.Assert(user.minigames.Count == 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether progress on a new course can be added
|
||||
/// </summary>
|
||||
public void TestUserAddCourse()
|
||||
{
|
||||
User user = new User();
|
||||
Progress p = new Progress();
|
||||
user.courses.Add(p);
|
||||
Debug.Assert(user.courses.Count == 1);
|
||||
Debug.Assert(user.minigames.Count == 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether progress on a new minigame can be added
|
||||
/// </summary>
|
||||
public void TestUserAddMinigame()
|
||||
{
|
||||
User user = new User();
|
||||
Progress p = new Progress();
|
||||
user.minigames.Add(p);
|
||||
Debug.Assert(user.courses.Count == 0);
|
||||
Debug.Assert(user.minigames.Count == 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetRecentCourses will return empty when no progress is stored
|
||||
/// </summary>
|
||||
public void TestGetRecentCoursesEmpty()
|
||||
{
|
||||
User user = new User();
|
||||
Debug.Assert(user.GetRecentCourses().Count == 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Temporary test for GetRecentCourses will return all progress that is stored
|
||||
/// </summary>
|
||||
public void TestGetRecentCoursesAll()
|
||||
{
|
||||
User user = new User();
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
|
||||
p.AddOrUpdate<float>("courseProgress", 0.5f);
|
||||
user.courses.Add(p);
|
||||
List<Tuple<CourseIndex, float>> list = user.GetRecentCourses();
|
||||
Debug.Assert(list.Count == 1);
|
||||
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
|
||||
Debug.Assert(list[0].Item2 == 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetRecommendedCourses will return <c>Tuple<CourseIndex.FINGERSPELLING, 0.0></c> when no progress is stored
|
||||
/// </summary>
|
||||
public void TestGetRecommendedCoursesEmpty()
|
||||
{
|
||||
User user = new User();
|
||||
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
|
||||
Debug.Assert(list.Count == 1);
|
||||
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
|
||||
Debug.Assert(list[0].Item2 == 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Temporary test for GetRecommenedCourses will return all progress that is stored
|
||||
/// </summary>
|
||||
public void TestGetRecommendedCoursesAll()
|
||||
{
|
||||
User user = new User();
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
|
||||
p.AddOrUpdate<float>("courseProgress", 0.5f);
|
||||
user.courses.Add(p);
|
||||
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
|
||||
Debug.Assert(list.Count == 1);
|
||||
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
|
||||
Debug.Assert(list[0].Item2 == 0.5f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetCourseProgress returns null when course cannot be found
|
||||
/// </summary>
|
||||
public void TestGetCourseProgressNull()
|
||||
{
|
||||
User user = new User();
|
||||
Debug.Assert(user.GetCourseProgress(CourseIndex.FINGERSPELLING) == null);
|
||||
Debug.Assert(user.GetCourseProgress((CourseIndex)100) == null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetCourseProgress returns correct progress object
|
||||
/// </summary>
|
||||
public void TestGetCourseProgressValid()
|
||||
{
|
||||
User user = new User();
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
|
||||
p.AddOrUpdate<float>("courseProgress", 3.14159265f);
|
||||
user.courses.Add(p);
|
||||
Progress q = user.GetCourseProgress(CourseIndex.FINGERSPELLING);
|
||||
Debug.Assert(q.Get<CourseIndex>("courseIndex") == CourseIndex.FINGERSPELLING);
|
||||
Debug.Assert(q.Get<float>("courseProgress") == 3.14159265f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetMinigameProgress returns null when minigame cannot be found
|
||||
/// </summary>
|
||||
public void TestGetMinigameProgressNull()
|
||||
{
|
||||
User user = new User();
|
||||
Debug.Assert(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE) == null);
|
||||
Debug.Assert(user.GetMinigameProgress((MinigameIndex)100) == null);
|
||||
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
|
||||
user.minigames.Add(p);
|
||||
Debug.Assert(user.GetMinigameProgress(MinigameIndex.HANGMAN) == null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetMinigameProgress returns correct progress object
|
||||
/// </summary>
|
||||
public void TestGetMinigameProgressValid()
|
||||
{
|
||||
User user = new User();
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
|
||||
user.minigames.Add(p);
|
||||
Progress q = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
||||
Debug.Assert(q.Get<CourseIndex>("minigameIndex") == CourseIndex.FINGERSPELLING);
|
||||
}
|
||||
}
|
||||
11
Assets/Accounts/Tests/TestUser.cs.meta
Normal file
11
Assets/Accounts/Tests/TestUser.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97bd2549f1c48d34db7cbccca17fc336
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -1,13 +1,22 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the UserCreationScreen class
|
||||
/// </summary>
|
||||
public class TestUserCreationScreen : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
TestIsValidUsernameTrue();
|
||||
TestIsValidUsernameFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tets IsValidUsername will return <c>true</c> for an valid username
|
||||
/// </summary>
|
||||
public void TestIsValidUsernameTrue()
|
||||
{
|
||||
foreach (char c in "abcdefghijklmnopqrstuvwxyz")
|
||||
@ -16,6 +25,9 @@ public class TestUserCreationScreen : MonoBehaviour
|
||||
Debug.Assert(UserCreationScreen.IsValidUsername("abcdefghijkl"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tets IsValidUsername will return <c>false</c> for an invalid username
|
||||
/// </summary>
|
||||
public void TestIsValidUsernameFalse()
|
||||
{
|
||||
Debug.Assert(!UserCreationScreen.IsValidUsername(string.Empty));
|
||||
|
||||
@ -1,21 +1,33 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Class to handle scene loading callbacks
|
||||
/// </summary>
|
||||
public class ChangeSceneOnClick : MonoBehaviour
|
||||
{
|
||||
// Load scene from path name
|
||||
/// <summary>
|
||||
/// Method used as callback for gameobject onClick events
|
||||
/// </summary>
|
||||
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
// Load scene from reference
|
||||
/// <summary>
|
||||
/// Method used as callback for gameobject onClick events
|
||||
/// </summary>
|
||||
/// <param name="scene">Reference to a scene</param>
|
||||
public void LoadScene(Scene scene)
|
||||
{
|
||||
SceneManager.LoadScene(scene.buildIndex);
|
||||
}
|
||||
|
||||
// Load scene from build index
|
||||
/// <summary>
|
||||
/// Method used as callback from gameobject onClick events
|
||||
/// </summary>
|
||||
/// <param name="buildIndex">Build index of the scene to be loaded</param>
|
||||
public void LoadScene(int buildIndex)
|
||||
{
|
||||
SceneManager.LoadScene(buildIndex);
|
||||
|
||||
@ -3,33 +3,58 @@ using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the display of courses in the ListCourseScreen and CourseScreenManager scene
|
||||
/// </summary>
|
||||
public class CourseItem : MonoBehaviour
|
||||
{
|
||||
[Header("Course")]
|
||||
// Reference to the course
|
||||
/// <summary>
|
||||
/// Reference to the course object
|
||||
/// </summary>
|
||||
public Course course;
|
||||
// Progress of the current user on this course
|
||||
|
||||
/// <summary>
|
||||
/// Progress of the current user on this specific course
|
||||
/// </summary>
|
||||
public float progress;
|
||||
|
||||
[Header("UI references")]
|
||||
// Reference to thumbnail object
|
||||
/// <summary>
|
||||
/// UI Reference to the image for displaying the course thumbnail
|
||||
/// </summary>
|
||||
public Image thumbnail;
|
||||
// Reference to title object
|
||||
|
||||
/// <summary>
|
||||
/// UI Reference to the gameobject for displaying the course title
|
||||
/// </summary>
|
||||
public TMP_Text title;
|
||||
// Refetence to object so correct callback can be trigger on click
|
||||
|
||||
/// <summary>
|
||||
/// UI Reference to the button so the correct callback can be trigger on click
|
||||
/// </summary>
|
||||
public Button button;
|
||||
// Reference to progress bar
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the slider that displays the progress of the user
|
||||
/// </summary>
|
||||
public GameObject slider;
|
||||
// Reference to `COMPLETED`
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the gameobject that holds the text 'COMPLETED'
|
||||
/// </summary>
|
||||
public GameObject completed;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
// Use public function so that this component can get Instantiated
|
||||
GenerateContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (Re)generate the CourseItem object and update its appearance
|
||||
/// </summary>
|
||||
public void GenerateContent()
|
||||
{
|
||||
// Set appearance
|
||||
|
||||
@ -1,20 +1,29 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// ListCourseScreen scene manager
|
||||
/// </summary>
|
||||
public class CourseListManager : MonoBehaviour
|
||||
{
|
||||
[Header("Course list UI components")]
|
||||
// Reference to course-list holder object
|
||||
/// <summary>
|
||||
/// Reference to the course-list container object
|
||||
/// </summary>
|
||||
public Transform courseContainer;
|
||||
|
||||
[Header("Prefabs")]
|
||||
// Prefab of item
|
||||
/// <summary>
|
||||
/// Prefab of the course item object
|
||||
/// </summary>
|
||||
public GameObject courseItemPrefab;
|
||||
|
||||
[Header("Courses")]
|
||||
// Reference to the list of all courses
|
||||
/// <summary>
|
||||
/// Reference to the list of all courses
|
||||
/// </summary>
|
||||
public CourseList courseList;
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
foreach (Course course in courseList.courses)
|
||||
@ -28,7 +37,10 @@ public class CourseListManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Method used as callback for on click events
|
||||
/// <summary>
|
||||
/// Method used as callback for course item onClick events
|
||||
/// </summary>
|
||||
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
|
||||
@ -3,26 +3,44 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// CourseScreen scene manager
|
||||
/// </summary>
|
||||
public class CourseScreenManager : MonoBehaviour
|
||||
{
|
||||
[Header("Course Screen Components")]
|
||||
// Reference to text that displays when there are no recent courses
|
||||
/// <summary>
|
||||
/// Reference to text that displays when there are no recent courses
|
||||
/// </summary>
|
||||
public GameObject noRecentCourses;
|
||||
// Reference to recent-courses-list holder object
|
||||
|
||||
/// <summary>
|
||||
/// Reference to recent-courses-list container object
|
||||
/// </summary>
|
||||
public Transform recentCoursesContainer;
|
||||
// Reference to recommended-courses-list holder object
|
||||
|
||||
/// <summary>
|
||||
/// Reference to recommended-courses-list container object
|
||||
/// </summary>
|
||||
public Transform recommendedCoursesContainer;
|
||||
|
||||
[Header("Prefabs")]
|
||||
// CourseItem prefab
|
||||
/// <summary>
|
||||
/// Prefab of the course item object
|
||||
/// </summary>
|
||||
public GameObject courseItem;
|
||||
|
||||
[Header("User")]
|
||||
// Reference to the users so we can get the current user;
|
||||
/// <summary>
|
||||
/// Reference to the users so we can get the current user;
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
// Reference to the courses
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the courses
|
||||
/// </summary>
|
||||
public CourseList courseList;
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
User user = userList.GetCurrentUser();
|
||||
@ -55,7 +73,10 @@ public class CourseScreenManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Method used as callback for on click events
|
||||
/// <summary>
|
||||
/// Method used as callback for course item onClick events
|
||||
/// </summary>
|
||||
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
|
||||
@ -1,19 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Class for holding all (static) data about a certain minigame
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/Minigame")]
|
||||
public class Minigame : ScriptableObject
|
||||
{
|
||||
[Header("Minigame info")]
|
||||
// Minigame index
|
||||
/// <summary>
|
||||
/// Index of the minigame
|
||||
/// </summary>
|
||||
public MinigameIndex index;
|
||||
// Minigame title
|
||||
|
||||
/// <summary>
|
||||
/// The minigame title
|
||||
/// </summary>
|
||||
public string title;
|
||||
// Short desciption of the course
|
||||
|
||||
/// <summary>
|
||||
/// A short description of the minigame
|
||||
/// </summary>
|
||||
public string description;
|
||||
// Thumbnail of the course
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the minigame thumbnail
|
||||
/// </summary>
|
||||
public Sprite thumbnail;
|
||||
|
||||
[Header("Scene")]
|
||||
// Reference to the minigame starting scene
|
||||
/// <summary>
|
||||
/// The path to the minigame starting scene (<c>path == $"Assets/{minigameEntryPoint}"</c>)
|
||||
/// </summary>
|
||||
public string minigameEntryPoint;
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
|
||||
// TODO: add other courses
|
||||
/// <summary>
|
||||
/// Enum for easy indexing and checking if a minigame is of a certain kind
|
||||
/// </summary>
|
||||
public enum MinigameIndex
|
||||
{
|
||||
SPELLING_BEE,
|
||||
|
||||
@ -3,27 +3,43 @@ using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the display of minigames in the ListMinigameScreen scene
|
||||
/// </summary>
|
||||
public class MinigameItem : MonoBehaviour
|
||||
{
|
||||
// TODO: change to ScriptableObject Minigame;
|
||||
[Header("ScriptableObject Course")]
|
||||
/// <summary>
|
||||
/// Reference to the minigame object
|
||||
/// </summary>
|
||||
public Minigame minigame;
|
||||
|
||||
[Header("UI references")]
|
||||
// Reference to thumbnail object
|
||||
/// <summary>
|
||||
/// UI Reference to the image for displaying the minigame thumbnail
|
||||
/// </summary>
|
||||
public Image thumbnail;
|
||||
// Reference to title object
|
||||
|
||||
/// <summary>
|
||||
/// UI Reference to the gameobject for displaying the minigame title
|
||||
/// </summary>
|
||||
public TMP_Text title;
|
||||
// Refetence to object so correct callback can be trigger on click
|
||||
|
||||
/// <summary>
|
||||
/// UI Reference to the button so the correct callback can be trigger on click
|
||||
/// </summary>
|
||||
public Button button;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
// Use public function so that this component can get Instantiated
|
||||
GenerateContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (Re)generate the MinigameItem object and update its appearance
|
||||
/// </summary>
|
||||
public void GenerateContent()
|
||||
{
|
||||
// Set appearance
|
||||
|
||||
@ -1,14 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Keep track off installed minigames
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/MinigameList")]
|
||||
public class MinigameList : ScriptableObject
|
||||
{
|
||||
[Header("Current Minigame")]
|
||||
// Index of the current course
|
||||
/// <summary>
|
||||
/// Index of the active/to be loaded/current minigame
|
||||
/// </summary>
|
||||
public int currentMinigameIndex = 0;
|
||||
|
||||
[Header("Minigames")]
|
||||
// List of minigames
|
||||
/// <summary>
|
||||
/// List of all installed minigames
|
||||
/// </summary>
|
||||
public List<Minigame> minigames = new List<Minigame>();
|
||||
}
|
||||
|
||||
@ -1,20 +1,29 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// ListMinigameScreen scene manager
|
||||
/// </summary>
|
||||
public class MinigameListManager : MonoBehaviour
|
||||
{
|
||||
[Header("Minigame list UI components")]
|
||||
// Reference to minigame-list holder object
|
||||
/// <summary>
|
||||
/// Reference to minigame-list container object
|
||||
/// </summary>
|
||||
public Transform minigameContainer;
|
||||
|
||||
[Header("Prefabs")]
|
||||
// Prefab of item
|
||||
/// <summary>
|
||||
/// Prefab of the minigame item object
|
||||
/// </summary>
|
||||
public GameObject minigameItemPrefab;
|
||||
|
||||
[Header("Minigames")]
|
||||
// Reference to the list of all minigames
|
||||
/// <summary>
|
||||
/// Reference to the list of all minigames
|
||||
/// </summary>
|
||||
public MinigameList minigameList;
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
foreach (Minigame minigame in minigameList.minigames)
|
||||
@ -28,7 +37,10 @@ public class MinigameListManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Method used as callback for on click events
|
||||
/// <summary>
|
||||
/// Method used as callback for minigame item onClick events
|
||||
/// </summary>
|
||||
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
/// <summary>
|
||||
/// StartScreen scene manager
|
||||
/// </summary>
|
||||
public class StartScreenManager : MonoBehaviour
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Referece to the userlist to check whether an user account is present
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Check on load whether a user is already present,
|
||||
/// if not load the UserCreationScreen scene so the user can create a new account
|
||||
/// </summary>
|
||||
void Awake()
|
||||
{
|
||||
if (!File.Exists(UserList.PATH) || userList.GetUsers().Count <= 0)
|
||||
|
||||
@ -2,18 +2,29 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Handles actions when a user presses the account button (upper left corner)
|
||||
/// </summary>
|
||||
public class UserButton : MonoBehaviour
|
||||
{
|
||||
[Header("User")]
|
||||
// Reference to the user list, so we can extract the current user
|
||||
/// <summary>
|
||||
/// Reference to the user list, so we can extract the current user
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
[Header("UI References")]
|
||||
// Reference to the avatar object
|
||||
/// <summary>
|
||||
/// UI Reference to the avatar object
|
||||
/// </summary>
|
||||
public Image avatar;
|
||||
// Reference to the username object
|
||||
|
||||
/// <summary>
|
||||
/// UI Reference to the username object
|
||||
/// </summary>
|
||||
public TMP_Text username;
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
User user = userList.GetCurrentUser();
|
||||
|
||||
@ -3,32 +3,56 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
|
||||
/// <summary>
|
||||
/// Class for holding all (static) data about a certain course
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/Course")]
|
||||
public class Course : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Small class to hold information about a single learnable (e.g., a word or a letter)
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
// Small class to hold information about a single learnable (e.g., a word or a letter)
|
||||
public class Learnable
|
||||
{
|
||||
// Name of the word/letter to learn
|
||||
/// <summary>
|
||||
/// Name of the word/letter to learn
|
||||
/// </summary>
|
||||
public string name;
|
||||
// Sprite of this word/letter
|
||||
|
||||
/// <summary>
|
||||
/// Sprite of this word/letter
|
||||
/// </summary>
|
||||
public Sprite image;
|
||||
// Example video clip
|
||||
|
||||
/// <summary>
|
||||
/// Example video clip
|
||||
/// </summary>
|
||||
public VideoClip clip;
|
||||
}
|
||||
|
||||
[Header("Course info")]
|
||||
// Course index
|
||||
/// <summary>
|
||||
/// Index of the course
|
||||
/// </summary>
|
||||
public CourseIndex index;
|
||||
// Course title
|
||||
|
||||
/// <summary>
|
||||
/// The course title
|
||||
/// </summary>
|
||||
public string title;
|
||||
// Short desciption of the course
|
||||
|
||||
/// <summary>
|
||||
/// A short description of the course
|
||||
/// </summary>
|
||||
public string description;
|
||||
// Thumbnail of the course
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the course thumbnail
|
||||
/// </summary>
|
||||
public Sprite thumbnail;
|
||||
|
||||
[Header("Learnable words")]
|
||||
// List of learnable words/letters
|
||||
/// <summary>
|
||||
/// List of all learnable words/letters
|
||||
/// </summary>
|
||||
public List<Learnable> learnables = new List<Learnable>();
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
|
||||
// TODO: add other courses
|
||||
/// <summary>
|
||||
/// Enum for easy indexing and checking if a course is of a certain kind
|
||||
/// </summary>
|
||||
public enum CourseIndex
|
||||
{
|
||||
FINGERSPELLING
|
||||
|
||||
@ -1,14 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Keep track of all courses
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/CourseList")]
|
||||
public class CourseList : ScriptableObject
|
||||
{
|
||||
[Header("Current Course")]
|
||||
// Index of the current course
|
||||
/// <summary>
|
||||
/// Index of the active/to be loaded/current course
|
||||
/// </summary>
|
||||
public int currentCourseIndex = 0;
|
||||
|
||||
[Header("Courses")]
|
||||
// List of courses
|
||||
/// <summary>
|
||||
/// List of all installed courses
|
||||
/// </summary>
|
||||
public List<Course> courses = new List<Course>();
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class StartPause : MonoBehaviour
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Webcam : MonoBehaviour
|
||||
{
|
||||
@ -13,7 +13,8 @@ public class Webcam : MonoBehaviour
|
||||
public GameObject popup;
|
||||
public TextMeshProUGUI dynamic;
|
||||
|
||||
void Awake(){
|
||||
void Awake()
|
||||
{
|
||||
popup.SetActive(false);
|
||||
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
@ -55,20 +56,25 @@ public class Webcam : MonoBehaviour
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
public void Show_feedback(){
|
||||
if(popup.activeSelf){
|
||||
public void Show_feedback()
|
||||
{
|
||||
if (popup.activeSelf)
|
||||
{
|
||||
dynamic.text = "";
|
||||
popup.SetActive(false);
|
||||
return;
|
||||
}
|
||||
double index = UnityEngine.Random.value;
|
||||
if(index < 0.5){
|
||||
if (index < 0.5)
|
||||
{
|
||||
dynamic.text = "Poor";
|
||||
}
|
||||
else if(index > 0.8){
|
||||
else if (index > 0.8)
|
||||
{
|
||||
dynamic.text = "Excellent";
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
dynamic.text = "Good";
|
||||
}
|
||||
popup.SetActive(true);
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
public class BasicTest
|
||||
{
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
public class BasicTest
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpellingBeeWebcam : MonoBehaviour
|
||||
{
|
||||
@ -13,7 +11,8 @@ public class SpellingBeeWebcam : MonoBehaviour
|
||||
public RawImage display;
|
||||
public TextMeshProUGUI dynamic;
|
||||
|
||||
void Awake(){
|
||||
void Awake()
|
||||
{
|
||||
//popup.SetActive(false);
|
||||
|
||||
WebCamDevice device = WebCamTexture.devices[camdex];
|
||||
|
||||
@ -3,29 +3,54 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the display of themes in the ThemeSelectionController scene
|
||||
/// </summary>
|
||||
public class ThemeItem : MonoBehaviour
|
||||
{
|
||||
// TODO: change to ScriptableObject Theme;
|
||||
[Header("ScriptableObject Theme")]
|
||||
/// <summary>
|
||||
/// The theme title
|
||||
/// </summary>
|
||||
public string themeTitle;
|
||||
|
||||
/// <summary>
|
||||
/// A short description of the theme
|
||||
/// </summary>
|
||||
public string themeDescription;
|
||||
|
||||
/// <summary>
|
||||
/// The callback function to start the game with the correct theme loaded
|
||||
/// </summary>
|
||||
public UnityAction startGameCallback;
|
||||
|
||||
[Header("UI references")]
|
||||
// Reference to thumbnail object
|
||||
/// <summary>
|
||||
/// UI reference to the gameobject for displaying the theme title
|
||||
/// </summary>
|
||||
public TMP_Text title;
|
||||
// Reference to description object
|
||||
|
||||
/// <summary>
|
||||
/// UI reference to the gameobject for displaying the description
|
||||
/// </summary>
|
||||
public TMP_Text description;
|
||||
// Refetence to object so correct callback can be trigger on click
|
||||
|
||||
/// <summary>
|
||||
/// UI reference to the button so the correct callback can be trigger on click
|
||||
/// </summary>
|
||||
public Button button;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Start is called before the first frame update
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
// Use public function so that this component can get Instantiated
|
||||
GenerateContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (Re)generate the ThemeItem object and update its appearance
|
||||
/// </summary>
|
||||
public void GenerateContent()
|
||||
{
|
||||
// Set appearance
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user