Skip to content

Commit 50f09e0

Browse files
committed
컷신툴 (3/7)
- 컷 복사 기능 구현 진행 중...
1 parent 87516df commit 50f09e0

File tree

14 files changed

+291
-42
lines changed

14 files changed

+291
-42
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace CutEditor.Model;
2+
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Newtonsoft.Json.Linq;
6+
7+
public sealed class CutPreset
8+
{
9+
private static readonly JsonSerializer JsonSerializer;
10+
private readonly JToken token;
11+
12+
static CutPreset()
13+
{
14+
var setting = new JsonSerializerSettings
15+
{
16+
NullValueHandling = NullValueHandling.Ignore,
17+
Formatting = Formatting.Indented,
18+
Converters =
19+
[
20+
new StringEnumConverter(),
21+
],
22+
};
23+
24+
JsonSerializer = JsonSerializer.Create(setting);
25+
}
26+
27+
public CutPreset(Cut cut)
28+
{
29+
this.token = JToken.FromObject(cut.ToOutputJsonType(), JsonSerializer);
30+
}
31+
32+
public Cut CreateCut(long newUid)
33+
{
34+
this.token["Uid"] = newUid;
35+
return new Cut(this.token, debugName: "CutPreset");
36+
}
37+
}

Tool/DesktopUiLab/CutEditor/CutEditor.Model/ExcelFormats/CutOutputExcelFormat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ public CutOutputExcelFormat()
5050
public EmotionEffect? Emotion { get; set; }
5151
public string Korean { get; set; } = string.Empty;
5252
public string English { get; set; } = string.Empty;
53+
public string EnglishComment { get; set; } = string.Empty;
5354
public string Japanese { get; set; } = string.Empty;
55+
public string JapaneseComment { get; set; } = string.Empty;
5456
public string ChineseSimplified { get; set; } = string.Empty;
5557
public string ChineseTraditional { get; set; } = string.Empty;
58+
public string ChineseComment { get; set; } = string.Empty;
5659

5760
public string Get(L10nType l10nType)
5861
{

Tool/DesktopUiLab/CutEditor/CutEditor.Model/ExcelFormats/StringOutputExcelFormat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ public StringOutputExcelFormat()
2727
public string PrimeKey { get; set; } = string.Empty;
2828
public string Korean { get; set; } = string.Empty;
2929
public string English { get; set; } = string.Empty;
30+
public string EnglishComment { get; set; } = string.Empty;
3031
public string Japanese { get; set; } = string.Empty;
32+
public string JapaneseComment { get; set; } = string.Empty;
3133
public string ChineseSimplified { get; set; } = string.Empty;
3234
public string ChineseTraditional { get; set; } = string.Empty;
35+
public string ChineseComment { get; set; } = string.Empty;
3336

3437
public string Get(L10nType l10nType)
3538
{

Tool/DesktopUiLab/CutEditor/CutEditor.ViewModel/L10n/Strategies/CutsceneNormalStrategy.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ public override bool SaveToFile(string name, L10nType l10nType)
111111
return false;
112112
}
113113

114-
if (CutFileIo.SaveCutData(name, this.mappings.Select(e => e.Cut), isShorten: false) == false)
114+
var cuts = this.mappings
115+
.Select(e => e.Cut)
116+
.DistinctBy(e => e.Uid);
117+
118+
if (CutFileIo.SaveCutData(name, cuts, isShorten: false) == false)
115119
{
116120
viewModel.WriteLog("적용에 실패했습니다.");
117121
return false;

Tool/DesktopUiLab/CutEditor/CutEditor.ViewModel/L10n/Strategies/CutsceneShortenStrategy.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ public override bool SaveToFile(string name, L10nType l10nType)
119119
continue;
120120
}
121121

122+
var cuts = this.mappings
123+
.Select(e => e.Cut)
124+
.DistinctBy(e => e.Uid);
125+
122126
Log.Debug($"단축 컷신 번역 적용. 파일명:{fileName} 업데이트 데이터 개수:{changedCount}");
123-
if (CutFileIo.SaveCutData(fileName, mappings.Select(e => e.Cut), isShorten: true) == false)
127+
if (CutFileIo.SaveCutData(fileName, cuts, isShorten: true) == false)
124128
{
125129
Log.Error($"{fileName} 파일 저장 실패.");
126130
continue;

Tool/DesktopUiLab/CutEditor/CutEditor.ViewModel/UndoCommands/CreateCutFromText.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ public void Redo()
112112

113113
var controller = this.vmCuts.Services.GetRequiredService<ICutsListController>();
114114
controller.FocusElement(index);
115-
116-
this.vmCuts.CutPaster.ClearReserved();
117115
}
118116

119117
public void Undo()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
namespace CutEditor.ViewModel.UndoCommands;
2+
3+
using System;
4+
using CutEditor.Model;
5+
using CutEditor.Model.Interfaces;
6+
using Du.Core.Interfaces;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using static CutEditor.ViewModel.VmCutPaster;
9+
10+
internal sealed class PasteCopiedCut(
11+
VmCuts vmCuts,
12+
IReadOnlyList<VmCut> targets,
13+
int positionIndex,
14+
PasteDirection direction) : IDormammu
15+
{
16+
public static PasteCopiedCut? Create(VmCuts vmCuts, IReadOnlyList<CutPreset> presets, PasteDirection direction)
17+
{
18+
if (presets.Count == 0)
19+
{
20+
return null;
21+
}
22+
23+
int positionIndex = vmCuts.Cuts.Count - 1; // 선택컷이 없으면 마지막에 붙인다.
24+
if (vmCuts.SelectedCuts.Count > 0)
25+
{
26+
positionIndex = vmCuts.Cuts.IndexOf(vmCuts.SelectedCuts[0]);
27+
}
28+
29+
var targets = presets.Select(e => e.CreateCut(vmCuts.NewCutUid()))
30+
.Select(e => new VmCut(e, vmCuts))
31+
.ToList();
32+
33+
return new PasteCopiedCut(vmCuts, targets, positionIndex, direction);
34+
}
35+
36+
public void Redo()
37+
{
38+
int index = direction switch
39+
{
40+
PasteDirection.Upside => positionIndex,
41+
PasteDirection.Downside => positionIndex + 1,
42+
_ => throw new InvalidOperationException(),
43+
};
44+
45+
vmCuts.SelectedCuts.Clear();
46+
foreach (var target in targets)
47+
{
48+
vmCuts.Cuts.Insert(index, target);
49+
index++;
50+
51+
vmCuts.SelectedCuts.Add(target);
52+
}
53+
54+
var controller = vmCuts.Services.GetRequiredService<ICutsListController>();
55+
controller.FocusElement(index);
56+
}
57+
58+
public void Undo()
59+
{
60+
// 삭제된 후 선택될 항목을 결정.
61+
int selectedIndex = vmCuts.Cuts.IndexOf(targets[0]);
62+
if (selectedIndex > 0)
63+
{
64+
selectedIndex--;
65+
}
66+
67+
foreach (var cut in targets)
68+
{
69+
vmCuts.Cuts.Remove(cut);
70+
}
71+
72+
vmCuts.SelectedCuts.Clear();
73+
vmCuts.SelectedCuts.Add(vmCuts.Cuts[selectedIndex]);
74+
75+
var controller = vmCuts.Services.GetRequiredService<ICutsListController>();
76+
controller.FocusElement(selectedIndex);
77+
}
78+
}

Tool/DesktopUiLab/CutEditor/CutEditor.ViewModel/UndoCommands/PasteCut.cs renamed to Tool/DesktopUiLab/CutEditor/CutEditor.ViewModel/UndoCommands/PasteReservedCut.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@
44
using CutEditor.Model.Interfaces;
55
using Du.Core.Interfaces;
66
using Microsoft.Extensions.DependencyInjection;
7-
using static CutEditor.ViewModel.UndoCommands.PasteCut;
7+
using static CutEditor.ViewModel.VmCutPaster;
88

9-
internal sealed class PasteCut(
9+
internal sealed class PasteReservedCut(
1010
VmCuts vmCuts,
1111
IReadOnlyList<VmCut> targets,
1212
int positionIndex,
13-
PasteDirection direction,
14-
bool reReserveWhenUndo) : IDormammu
13+
PasteDirection direction) : IDormammu
1514
{
16-
public enum PasteDirection
17-
{
18-
Upside,
19-
Downside,
20-
}
21-
22-
public static PasteCut? Create(VmCuts vmCuts, PasteDirection direction, bool reReserve)
15+
public static PasteReservedCut? Create(VmCuts vmCuts, PasteDirection direction)
2316
{
2417
if (vmCuts.CutPaster.Reserved.Count == 0)
2518
{
@@ -32,7 +25,7 @@ public enum PasteDirection
3225
positionIndex = vmCuts.Cuts.IndexOf(vmCuts.SelectedCuts[0]);
3326
}
3427

35-
return new PasteCut(vmCuts, vmCuts.CutPaster.Reserved.ToArray(), positionIndex, direction, reReserve);
28+
return new PasteReservedCut(vmCuts, vmCuts.CutPaster.Reserved.ToArray(), positionIndex, direction);
3629
}
3730

3831
public void Redo()
@@ -76,17 +69,12 @@ public void Undo()
7669
vmCuts.Cuts.Remove(cut);
7770
}
7871

79-
var selected = vmCuts.Cuts[selectedIndex];
8072
vmCuts.SelectedCuts.Clear();
8173
vmCuts.SelectedCuts.Add(vmCuts.Cuts[selectedIndex]);
8274

8375
var controller = vmCuts.Services.GetRequiredService<ICutsListController>();
8476
controller.FocusElement(selectedIndex);
8577

86-
if (reReserveWhenUndo)
87-
{
88-
// 클립보드 텍스트에서 붙여넣은 경우는 undo할 때 reserve에 유지하지 않는다.
89-
vmCuts.CutPaster.SetReserved(targets);
90-
}
78+
vmCuts.CutPaster.SetReserved(targets);
9179
}
9280
}

0 commit comments

Comments
 (0)