Move Razor component logic into code-behind files
This commit is contained in:
167
RpgRoller/Components/Pages/HomeControls/CharacterPanel.razor.cs
Normal file
167
RpgRoller/Components/Pages/HomeControls/CharacterPanel.razor.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using RpgRoller.Components.Pages;
|
||||
using RpgRoller.Contracts;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace RpgRoller.Components.Pages.HomeControls;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public partial class CharacterPanel
|
||||
{
|
||||
private bool ShowCreateSkillModal { get; set; }
|
||||
private bool ShowEditSkillModal { get; set; }
|
||||
private Guid? EditingSkillId { get; set; }
|
||||
private SkillFormModel CreateSkillInitialModel { get; set; } = new();
|
||||
private SkillFormModel EditSkillInitialModel { get; set; } = new();
|
||||
private int CreateSkillFormVersion { get; set; }
|
||||
private int EditSkillFormVersion { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsCampaignDataLoading { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public CampaignDetails? SelectedCampaign { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Guid? SelectedCharacterId { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public CharacterSummary? SelectedCharacter { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsMutating { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public IReadOnlyList<SkillSummary> SelectedCharacterSkills { get; set; } = [];
|
||||
|
||||
[Parameter]
|
||||
public Guid? SelectedSkillId { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public SkillSummary? SelectedSkill { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsD6 { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string RollVisibility { get; set; } = "public";
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> RollVisibilityChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public RollResult? LastRoll { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public Func<Guid, string> OwnerLabel { get; set; } = _ => string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public Func<SkillSummary, string> SkillDefinitionLabel { get; set; } = _ => string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public Func<CharacterSummary, bool> CanEditCharacter { get; set; } = _ => false;
|
||||
|
||||
[Parameter]
|
||||
public Func<SkillSummary, bool> CanEditSkill { get; set; } = _ => false;
|
||||
|
||||
[Parameter]
|
||||
public Func<SkillSummary, bool> CanRollSkill { get; set; } = _ => false;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<Guid> CharacterSelected { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<Guid> SkillSelected { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<CharacterSummary> EditCharacterRequested { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<Guid> SkillCreated { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<Guid> SkillUpdated { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback RollRequested { get; set; }
|
||||
|
||||
private void OpenCreateSkillModal()
|
||||
{
|
||||
CreateSkillInitialModel = new SkillFormModel
|
||||
{
|
||||
Name = string.Empty,
|
||||
DiceRollDefinition = string.Empty,
|
||||
WildDice = IsD6 ? 1 : 0,
|
||||
AllowFumble = IsD6
|
||||
};
|
||||
|
||||
CreateSkillFormVersion++;
|
||||
ShowCreateSkillModal = true;
|
||||
}
|
||||
|
||||
private void OpenEditSkillModal()
|
||||
{
|
||||
if (SelectedSkill is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditingSkillId = SelectedSkill.Id;
|
||||
EditSkillInitialModel = new SkillFormModel
|
||||
{
|
||||
Name = SelectedSkill.Name,
|
||||
DiceRollDefinition = SelectedSkill.DiceRollDefinition,
|
||||
WildDice = SelectedSkill.WildDice,
|
||||
AllowFumble = SelectedSkill.AllowFumble
|
||||
};
|
||||
|
||||
EditSkillFormVersion++;
|
||||
ShowEditSkillModal = true;
|
||||
}
|
||||
|
||||
private void CloseSkillModals()
|
||||
{
|
||||
ShowCreateSkillModal = false;
|
||||
ShowEditSkillModal = false;
|
||||
EditingSkillId = null;
|
||||
}
|
||||
|
||||
private async Task OnSkillCreatedAsync(Guid skillId)
|
||||
{
|
||||
CloseSkillModals();
|
||||
await SkillCreated.InvokeAsync(skillId);
|
||||
}
|
||||
|
||||
private async Task OnSkillUpdatedAsync(Guid skillId)
|
||||
{
|
||||
CloseSkillModals();
|
||||
await SkillUpdated.InvokeAsync(skillId);
|
||||
}
|
||||
|
||||
private async Task OnRollVisibilityChangedAsync(ChangeEventArgs args)
|
||||
{
|
||||
var selectedVisibility = args.Value?.ToString() ?? "public";
|
||||
await RollVisibilityChanged.InvokeAsync(selectedVisibility);
|
||||
}
|
||||
|
||||
private async Task OnRollSubmitAsync()
|
||||
{
|
||||
await RollRequested.InvokeAsync();
|
||||
}
|
||||
|
||||
private static string InitialsFor(string value)
|
||||
{
|
||||
var words = value.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
if (words.Length == 0)
|
||||
{
|
||||
return "?";
|
||||
}
|
||||
|
||||
if (words.Length == 1)
|
||||
{
|
||||
return words[0].Length >= 2 ? words[0][..2].ToUpperInvariant() : words[0].ToUpperInvariant();
|
||||
}
|
||||
|
||||
return string.Concat(words[0][0], words[1][0]).ToUpperInvariant();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user