Starting validation of character_template and character types
This commit is contained in:
parent
37ced9ef83
commit
d52d60f652
@ -6,6 +6,11 @@ namespace SessionZero.SzfLib.Helpers;
|
|||||||
|
|
||||||
public static class SzfHelper
|
public static class SzfHelper
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the SzfObject type by its type identifier attribute.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="szfType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static Type? FindSzfObjectTypeByAttributeType(string szfType)
|
public static Type? FindSzfObjectTypeByAttributeType(string szfType)
|
||||||
{
|
{
|
||||||
var obj = Assembly
|
var obj = Assembly
|
||||||
@ -18,6 +23,12 @@ public static class SzfHelper
|
|||||||
return obj.IsAbstract || obj.IsInterface ? null : obj;
|
return obj.IsAbstract || obj.IsInterface ? null : obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Does basic validation of a SzfObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <param name="canHaveEmptyFieldValues"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static SzfError BasicSzfValidation(ISzfObject obj, bool canHaveEmptyFieldValues = false)
|
public static SzfError BasicSzfValidation(ISzfObject obj, bool canHaveEmptyFieldValues = false)
|
||||||
{
|
{
|
||||||
SzfError result = new SzfError();
|
SzfError result = new SzfError();
|
||||||
@ -36,6 +47,12 @@ public static class SzfHelper
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all sections and subsections of a SzfObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static IEnumerable<SzfSection> GetAllSectionsAndSubsections(ISzfObject obj)
|
public static IEnumerable<SzfSection> GetAllSectionsAndSubsections(ISzfObject obj)
|
||||||
{
|
{
|
||||||
List<SzfSection> allSections = new List<SzfSection>();
|
List<SzfSection> allSections = new List<SzfSection>();
|
||||||
@ -49,6 +66,11 @@ public static class SzfHelper
|
|||||||
return allSections;
|
return allSections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all subsections of a given section recursively.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="section"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static IEnumerable<SzfSection> GetAllSubsections(SzfSection section)
|
public static IEnumerable<SzfSection> GetAllSubsections(SzfSection section)
|
||||||
{
|
{
|
||||||
List<SzfSection> subsections = new List<SzfSection>();
|
List<SzfSection> subsections = new List<SzfSection>();
|
||||||
@ -62,6 +84,11 @@ public static class SzfHelper
|
|||||||
return subsections;
|
return subsections;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all fields from all sections and subsections of an SzfObject.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static IEnumerable<SzfField> GetAllFields(ISzfObject obj)
|
public static IEnumerable<SzfField> GetAllFields(ISzfObject obj)
|
||||||
{
|
{
|
||||||
List<SzfField> allFields = new List<SzfField>();
|
List<SzfField> allFields = new List<SzfField>();
|
||||||
|
@ -2,5 +2,6 @@ namespace SessionZero.SzfLib.Objects;
|
|||||||
|
|
||||||
public interface ISzfCharacter
|
public interface ISzfCharacter
|
||||||
{
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public ISzfCharacterTemplate TryResolveCharacterTemplate(string lookup);
|
||||||
}
|
}
|
@ -6,7 +6,29 @@ namespace SessionZero.SzfLib.Objects;
|
|||||||
public class SzfCharacter : SzfObject, ISzfCharacter
|
public class SzfCharacter : SzfObject, ISzfCharacter
|
||||||
{
|
{
|
||||||
public override string SzfType { get; set; } = "character";
|
public override string SzfType { get; set; } = "character";
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public ISzfCharacterTemplate? Template { get; set; }
|
||||||
|
|
||||||
|
public SzfCharacter()
|
||||||
|
{
|
||||||
|
Name = GetMetadataField("Name");
|
||||||
|
}
|
||||||
|
|
||||||
public override SzfError Validate()
|
public override SzfError Validate()
|
||||||
|
{
|
||||||
|
var result = new SzfError();
|
||||||
|
|
||||||
|
if (Template is null)
|
||||||
|
{
|
||||||
|
result.AddError($"Template is missing from character with name '{Name}'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ISzfCharacterTemplate TryResolveCharacterTemplate(string lookup)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ public class SzfCharacterTemplate : SzfObject, ISzfCharacterTemplate
|
|||||||
public override string SzfType { get; set; } = "character_template";
|
public override string SzfType { get; set; } = "character_template";
|
||||||
public override SzfError Validate()
|
public override SzfError Validate()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var result = new SzfError();
|
||||||
|
|
||||||
|
var basicValidation = SzfHelper.BasicSzfValidation(this, true);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user