PlotDirector/PlotLine/Services/CharacterQuickAttributes.cs

30 lines
2.5 KiB
C#

using PlotLine.Models;
namespace PlotLine.Services;
// One vocabulary for the directory legend, indicators and assignment menus.
public sealed record CharacterQuickValue(string Value,string Label,string Icon,string Tone="secondary",IReadOnlyList<string>? RecordedLabels=null);
public sealed record CharacterQuickGroup(string Id,string Label,IReadOnlyList<CharacterQuickValue> Values, CharacterQuickValue? RecordedFallback=null);
public static class CharacterQuickAttributes
{
public static IReadOnlyList<CharacterQuickGroup> Definitions(IEnumerable<CharacterSexValue> sex) => [
new("importance","Story importance",[new("10","Major","attribute-star-filled","warning"),new("6","Supporting","attribute-star-half","info"),new("2","Minor","attribute-star"),new("","Unclassified","help")]),
new("life","Life status",[new("0","Living","attribute-heart","success"),new("1","Deceased","attribute-flower","data-5"),new("","Unrecorded","help")]),
new("sex","Sex",new[]{new CharacterQuickValue("","Not set","help")}.Concat(sex.Select(SexValue)).ToArray(), new("","Recorded sex","sex-other","data-5")),
new("type", "Character Type", CharacterTypes.Values),
new("quickAdd","Quick Add Bar",[new("1","Included","attribute-pin","primary"),new("0","Excluded","attribute-unpin")])
];
private static CharacterQuickValue SexValue(CharacterSexValue value)
{
var (icon,tone)=(value.IsSystem?value.SexName:"") switch {"Male"=>("sex-male","info"),"Female"=>("sex-female","data-7"),_=>("sex-other","data-5")};
return new(value.CharacterSexValueID.ToString(),value.SexName,icon,tone,value.IsSystem?[value.SexName.Trim().ToLowerInvariant()]:null);
}
public static object Presentation(CharacterQuickValue value)
{
var icon=ApplicationRibbon.Icon(value.Icon);
return new{value.Value,value.Label,value.Tone,value.Icon,value.RecordedLabels,path=icon.IconPath,icon.Filled};
}
public static object Snapshot(Character c)=>new {id=c.CharacterID,name=c.CharacterName,version=c.UpdatedDate.ToString("O"),values=new Dictionary<string,string>{["type"]=c.CharacterTypeCode,["importance"]=c.CharacterImportance?.ToString()??"",["life"]=c.IsDeceased.HasValue?(c.IsDeceased.Value?"1":"0"):"",["sex"]=c.SexValueID?.ToString()??(string.IsNullOrWhiteSpace(c.Sex)?"":"legacy:"+c.Sex),["quickAdd"]=c.ShowInQuickAddBar?"1":"0"}};
}
public sealed record CharacterQuickChange(int Id,string? Value,string Version);
public sealed record CharacterQuickAssignment(int ProjectId,string Attribute,CharacterQuickChange[] Changes);