forked from kc3hack/2024_H
-
Notifications
You must be signed in to change notification settings - Fork 0
ストーリー作成タブを追加 #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ストーリー作成タブを追加 #37
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d37bb44
ストーリー作成タブを追加
miyaji255 56c0ab6
#29 テキストボックスの配置を変更
miyaji255 cb6de09
#29 XMLを表示
miyaji255 df9ca53
#29 不要なライブラリを削除
miyaji255 7a8ad5d
fmt
miyaji255 5efa7ea
誤字を修正
miyaji255 c42d74d
誤字修正
miyaji255 e74202d
AiStoryでhtmlにルビを出力するように修正
miyaji255 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using KoeBook.Core.Models; | ||
|
||
namespace KoeBook.Core.Contracts.Services; | ||
|
||
public interface IStoryCreatorService | ||
{ | ||
/// <returns>XML</returns> | ||
public ValueTask<string> CreateStoryAsync(StoryGenre genre, string instruction, CancellationToken cancellationToken); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace KoeBook.Core.Models; | ||
|
||
public record class StoryGenre(string Genre, string Description); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using KoeBook.Core.Contracts.Services; | ||
using KoeBook.Core.Models; | ||
|
||
namespace KoeBook.Services.CoreMocks | ||
{ | ||
public class StoryCreatorServiceMock : IStoryCreatorService | ||
{ | ||
public ValueTask<string> CreateStoryAsync(StoryGenre genre, string instruction, CancellationToken cancellationToken) | ||
{ | ||
return ValueTask.FromResult(""" | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Book> | ||
<Title>境界線の向こう側</Title> | ||
<Content> | ||
<Section> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
</Section> | ||
<Section> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
<Paragraph><Text>高校2年の夏、バレー部のエースで</Text><Ruby><Rb>端正</Rb><Rt>はんせい</Rt></Ruby><Text>な顔立ちの山田祐樹は、バスケ部のキャプテンで</Text><Ruby><Rb>凛</Rb><Rt>りん</Rt></Ruby><Text>とした佇まいの田中麻衣に密かに想いを寄せていた。しかし、両者の部活</Text><Ruby><Rb>仲間</Rb><Rt>なかま</Rt></Ruby><Text>たちの目を</Text><Ruby><Rb>憚</Rb><Rt>はばか</Rt></Ruby><Text>り、互いに素振りも見せずにいた。</Text></Paragraph> | ||
</Section> | ||
</Content> | ||
</Book> | ||
"""); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.Collections.Immutable; | ||
using System.Xml.Serialization; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using KoeBook.Contracts.Services; | ||
using KoeBook.Core.Contracts.Services; | ||
using KoeBook.Core.Models; | ||
using KoeBook.Models; | ||
|
||
namespace KoeBook.ViewModels; | ||
|
||
public sealed partial class CreateStoryViewModel : ObservableObject | ||
{ | ||
private readonly IGenerationTaskService _generationTaskService; | ||
private readonly IDialogService _dialogService; | ||
private readonly IStoryCreatorService _storyCreatorService; | ||
|
||
public ImmutableArray<StoryGenre> Genres { get; } = [ | ||
new("青春小説", "学校生活、友情、恋愛など、若者の成長物語"), | ||
new("ミステリー・サスペンス", "謎解きや犯罪、真相究明などのスリリングな物語"), | ||
new("SF", "未来、科学技術、宇宙などを題材にした物語"), | ||
new("ホラー", "恐怖や怪奇現象を扱った、読者の恐怖心をくすぐる物語"), | ||
new("ロマンス", "恋愛や結婚、人間関係などを扱った、胸キュンな物語"), | ||
new("コメディ", "ユーモアやギャグ、風刺などを交えた、読者を笑わせる物語"), | ||
new("歴史小説", "過去の出来事や人物を題材にした、歴史の背景が感じられる物語"), | ||
new("ノンフィクション・エッセイ", "実際の経験や知識、考えを綴った、リアルな物語"), | ||
new("詩集", "感情や思考、風景などを言葉で表現した、韻文形式の作品集"), | ||
]; | ||
|
||
[ObservableProperty] | ||
private StoryGenre _selectedGenre; | ||
|
||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(CreateStoryCommand))] | ||
private string _instruction = ""; | ||
|
||
[ObservableProperty] | ||
[NotifyCanExecuteChangedFor(nameof(StartGenerateTaskCommand))] | ||
[NotifyPropertyChangedFor(nameof(AiStoryTitle))] | ||
private AiStory? _aiStory; | ||
|
||
public string AiStoryTitle => AiStory?.Title ?? ""; | ||
|
||
public CreateStoryViewModel(IGenerationTaskService generationTaskService, IDialogService dialogService, IStoryCreatorService storyCreatorService) | ||
{ | ||
_selectedGenre = Genres[0]; | ||
_generationTaskService = generationTaskService; | ||
_dialogService = dialogService; | ||
_storyCreatorService = storyCreatorService; | ||
} | ||
|
||
public bool CanCreateStory => !string.IsNullOrWhiteSpace(Instruction); | ||
|
||
[RelayCommand(CanExecute = nameof(CanCreateStory))] | ||
private async Task OnCreateStoryAsync(CancellationToken cancellationToken) | ||
{ | ||
using var sr = new StringReader(await _storyCreatorService.CreateStoryAsync(SelectedGenre, Instruction, cancellationToken)); | ||
var serializer = new XmlSerializer(typeof(AiStory)); | ||
try | ||
{ | ||
AiStory = (AiStory?)serializer.Deserialize(sr); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
await _dialogService.ShowAsync("生成失敗", "AIによるコードの生成に失敗しました", "OK", cancellationToken); | ||
} | ||
} | ||
|
||
public bool CanStartGenerate => AiStory is not null; | ||
|
||
[RelayCommand(CanExecute = nameof(CanStartGenerate))] | ||
private void OnStartGenerateTask() | ||
{ | ||
var aiStory = AiStory!; | ||
AiStory = null; | ||
_generationTaskService.Register(new GenerationTask(Guid.NewGuid(), aiStory, true)); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.