/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of xAPI4Unity. */ #if UNITY_EDITOR using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; namespace xAPI4Unity.Editor.Parser.Definitions { /// /// Class that represents an xAPI definition /// internal abstract class xAPIDefinition { /// /// Context of the definition /// public string Context { get; set; } /// /// (File) name of the definition /// public string DefName { get; set; } /// /// Names of the definition by language /// [JsonProperty("name")] public readonly IDictionary Names; /// /// Descriptions by the definition by language /// [JsonProperty("description")] public readonly IDictionary Descriptions; /// /// Creates an empty xAPIDefinition /// public xAPIDefinition() { } /// /// Creates an xAPIDefinition. /// /// Context of the definition /// (File) name of the definition /// Names of the definition by language /// Descriptions of the definition by language public xAPIDefinition(string context, string name, IDictionary names, IDictionary descriptions) { Context = context; DefName = name; Names = names; Descriptions = descriptions; } /// /// Gets the name of the definition by language /// public string GetName(string language) { if (!Names.ContainsKey(language)) { throw new ArgumentException("There is no name for the language " + language + "."); } return Names[language]; } /// /// Gets the description of the definition by language /// public string GetDescription(string language, bool replaceLang = false) { if (Descriptions.ContainsKey(language)) return Descriptions[language]; if (replaceLang) { if (Descriptions.Count > 0) { return Descriptions.First().Value; } } else { throw new ArgumentException("There is no description for the language " + language + "."); } return Descriptions[language]; } /// /// Gets the name and the description of the definition by language /// public KeyValuePair GetNameDescription(string language) { var namesContainLang = Names.ContainsKey(language); var descsContainLang = Descriptions.ContainsKey(language); if (!namesContainLang) { if (!descsContainLang) { throw new ArgumentException("There is no name and no description for the language " + language + "."); } throw new ArgumentException("There is no name for the language " + language + "."); } else if (!descsContainLang) { throw new ArgumentException("There is no description for the language " + language + "."); } return new KeyValuePair(Names[language], Descriptions[language]); } /// /// Get the languages of the definition /// public string[] GetLanguages() => Names.Keys.Union(Descriptions.Keys).ToArray(); public virtual string GetDefinitionGroup() => throw new NotImplementedException(); } } #endif