From d37bb441b26d2facbc893b9e1b8ba5b84057cad5 Mon Sep 17 00:00:00 2001 From: miyaji255 <84168445+miyaji255@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:19:12 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AA?= =?UTF-8?q?=E3=83=BC=E4=BD=9C=E6=88=90=E3=82=BF=E3=83=96=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IStoryCreatorService.cs | 8 +++ KoeBook.Core/Models/StoryGenre.cs | 4 ++ KoeBook/App.xaml.cs | 2 + KoeBook/KoeBook.csproj | 10 +++ KoeBook/ViewModels/CreateStoryViewModel.cs | 67 +++++++++++++++++++ KoeBook/Views/CreateStoryPage.xaml | 64 ++++++++++++++++++ KoeBook/Views/CreateStoryPage.xaml.cs | 24 +++++++ KoeBook/Views/ShellPage.xaml | 6 ++ KoeBook/Views/ShellPage.xaml.cs | 1 + 9 files changed, 186 insertions(+) create mode 100644 KoeBook.Core/Contracts/Services/IStoryCreatorService.cs create mode 100644 KoeBook.Core/Models/StoryGenre.cs create mode 100644 KoeBook/ViewModels/CreateStoryViewModel.cs create mode 100644 KoeBook/Views/CreateStoryPage.xaml create mode 100644 KoeBook/Views/CreateStoryPage.xaml.cs diff --git a/KoeBook.Core/Contracts/Services/IStoryCreatorService.cs b/KoeBook.Core/Contracts/Services/IStoryCreatorService.cs new file mode 100644 index 0000000..e032f7e --- /dev/null +++ b/KoeBook.Core/Contracts/Services/IStoryCreatorService.cs @@ -0,0 +1,8 @@ +using KoeBook.Core.Models; + +namespace KoeBook.Core.Contracts.Services; + +public interface IStoryCreaterService +{ + public ValueTask CreateStoryAsync(StoryGenre genre, string intruction, CancellationToken cancellationToken); +} diff --git a/KoeBook.Core/Models/StoryGenre.cs b/KoeBook.Core/Models/StoryGenre.cs new file mode 100644 index 0000000..c6e4513 --- /dev/null +++ b/KoeBook.Core/Models/StoryGenre.cs @@ -0,0 +1,4 @@ +namespace KoeBook.Core.Models; + +public record class StoryGenre(string Genre, string Description); + diff --git a/KoeBook/App.xaml.cs b/KoeBook/App.xaml.cs index bbb16cc..077511c 100644 --- a/KoeBook/App.xaml.cs +++ b/KoeBook/App.xaml.cs @@ -93,6 +93,8 @@ public App() services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); // Configuration services.Configure(context.Configuration.GetSection(nameof(LocalSettingsOptions))); diff --git a/KoeBook/KoeBook.csproj b/KoeBook/KoeBook.csproj index a83ccf0..b7b7f96 100644 --- a/KoeBook/KoeBook.csproj +++ b/KoeBook/KoeBook.csproj @@ -18,6 +18,7 @@ + @@ -28,6 +29,7 @@ + @@ -68,4 +70,12 @@ true + + + + + + + + diff --git a/KoeBook/ViewModels/CreateStoryViewModel.cs b/KoeBook/ViewModels/CreateStoryViewModel.cs new file mode 100644 index 0000000..de9d68f --- /dev/null +++ b/KoeBook/ViewModels/CreateStoryViewModel.cs @@ -0,0 +1,67 @@ +using System.Collections.Immutable; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using KoeBook.Core.Contracts.Services; +using KoeBook.Core.Models; +using KoeBook.Services; + +namespace KoeBook.ViewModels; + +public sealed partial class CreateStoryViewModel : ObservableObject +{ + private readonly IStoryCreaterService _storyCreaterService; + private readonly GenerationTaskRunnerService _generationTaskRunnerService; + + public ImmutableArray Genres { get; } = [ + new("青春小説", "学校生活、友情、恋愛など、若者の成長物語"), + new("ミステリー・サスペンス", "謎解きや犯罪、真相究明などのスリリングな物語"), + new("SF", "未来、科学技術、宇宙などを題材にした物語"), + new("ホラー", "恐怖や怪奇現象を扱った、読者の恐怖心をくすぐる物語"), + new("ロマンス", "恋愛や結婚、人間関係などを扱った、胸キュンな物語"), + new("コメディ", "ユーモアやギャグ、風刺などを交えた、読者を笑わせる物語"), + new("歴史小説", "過去の出来事や人物を題材にした、歴史の背景が感じられる物語"), + new("ノンフィクション・エッセイ", "実際の経験や知識、考えを綴った、リアルな物語"), + new("詩集", "感情や思考、風景などを言葉で表現した、韻文形式の作品集"), + ]; + + [ObservableProperty] + private StoryGenre _selectedGenre; + + [ObservableProperty] + private string _intruction = ""; + + [ObservableProperty] + private string _storyText = """ + # h1 + ## h2 + ### h3 + + 1. aaa + 2. bbb + 3. ccc + + --- + """; + + public CreateStoryViewModel(GenerationTaskRunnerService generationTaskRunnerService) + { + _selectedGenre = Genres[0]; + _generationTaskRunnerService = generationTaskRunnerService; + //_storyCreaterService = storyCreaterService; + _storyCreaterService = null!; + } + + public bool CanCreateStory => !string.IsNullOrWhiteSpace(Intruction); + + [RelayCommand(CanExecute = nameof(CanCreateStory))] + private async Task OnCreateStoryAsync(CancellationToken cancellationToken) + { + StoryText = await _storyCreaterService.CreateStoryAsync(SelectedGenre, Intruction, cancellationToken); + } + + [RelayCommand] + private async void OnStartGenerateTask (CancellationToken cancellationToken) + { + } +} + diff --git a/KoeBook/Views/CreateStoryPage.xaml b/KoeBook/Views/CreateStoryPage.xaml new file mode 100644 index 0000000..17c8e66 --- /dev/null +++ b/KoeBook/Views/CreateStoryPage.xaml @@ -0,0 +1,64 @@ + + + + + + + + + + + +