Skip to content

Commit 2ecf029

Browse files
committed
feat: 导入为宴会场时优化
1 parent c95cb00 commit 2ecf029

File tree

7 files changed

+45
-18
lines changed

7 files changed

+45
-18
lines changed

MaiChartManager/Controllers/ImportChartController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public record ImportChartResult(IEnumerable<ImportChartMessage> Errors, bool Fat
135135
public ImportChartResult ImportChart([FromForm] int id, IFormFile file, [FromForm] bool ignoreLevelNum, [FromForm] int addVersionId, [FromForm] int genreId, [FromForm] int version,
136136
[FromForm] bool debug = false, [FromForm] bool noShiftChart = false)
137137
{
138+
var isUtage = id > 100000;
138139
var errors = new List<ImportChartMessage>();
139140
var music = settings.MusicList.First(it => it.Id == id);
140141
var maiData = new Dictionary<string, string>(new SimaiFile(file.OpenReadStream()).ToKeyValuePairs());
@@ -167,6 +168,9 @@ public ImportChartResult ImportChart([FromForm] int id, IFormFile file, [FromFor
167168

168169
foreach (var (level, chart) in allCharts)
169170
{
171+
// 宴会场只导入第一个谱面
172+
if (isUtage && music.Charts[0].Enable) break;
173+
170174
// var levelPadding = Converter.CalcMusicPadding(chart, first);
171175
var bpm = chart.TimingChanges[0].tempo;
172176
music.Bpm = (int)Math.Floor(bpm);
@@ -190,6 +194,8 @@ public ImportChartResult ImportChart([FromForm] int id, IFormFile file, [FromFor
190194
// | | 原先音频的开头
191195
// | 加了 padding 的音频开头
192196

197+
# region 设定 targetLevel
198+
193199
var targetLevel = level - 2;
194200

195201
// 处理非标准难度
@@ -214,6 +220,10 @@ public ImportChartResult ImportChart([FromForm] int id, IFormFile file, [FromFor
214220
}
215221
}
216222

223+
if (isUtage) targetLevel = 0;
224+
225+
# endregion
226+
217227
var targetChart = music.Charts[targetLevel];
218228
targetChart.Path = $"{id:000000}_0{targetLevel}.ma2";
219229
var levelNumStr = maiData.GetValueOrDefault($"lv_{level}");

MaiChartManager/Controllers/MusicController.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ public string AddMusic(int id)
124124
return "当前资源目录里已经存在这个 ID 了";
125125
}
126126

127-
var isDx = id >= 10000;
128-
129-
var music = MusicXmlWithABJacket.CreateNew(id % 10000, StaticSettings.GamePath, settings.AssetDir, isDx);
127+
var music = MusicXmlWithABJacket.CreateNew(id, StaticSettings.GamePath, settings.AssetDir);
130128
settings.MusicList.Add(music);
131129

132130
return "";

MaiChartManager/Front/src/components/ImportChartButton/ErrorDisplayIdInput.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { computed, defineComponent, PropType } from "vue";
1+
import { computed, defineComponent, effect, PropType, watch } from "vue";
22
import { NAlert, NButton, NCheckbox, NCollapse, NCollapseItem, NFlex, NForm, NFormItem, NInputNumber, NModal, NScrollbar, NSelect, SelectOption } from "naive-ui";
33
import { ImportChartMessage, MessageLevel } from "@/client/apiGen";
44
import { ImportChartMessageEx, ImportMeta } from "@/components/ImportChartButton/index";
55
import noJacket from '@/assets/noJacket.webp';
66
import { addVersionList, genreList } from "@/store/refs";
77
import GenreInput from "@/components/GenreInput";
88
import VersionInput from "@/components/VersionInput";
9+
import { UTAGE_GENRE } from "@/consts";
910

1011
export default defineComponent({
1112
props: {
@@ -46,14 +47,20 @@ export default defineComponent({
4647
set: (val) => emit('update:noShiftChart', val)
4748
})
4849

50+
watch([() => genreId.value, () => show.value], ([val]) => {
51+
for (const meta of props.meta) {
52+
meta.id = meta.id % 1e5 + (val === UTAGE_GENRE ? 1e5 : 0);
53+
}
54+
})
55+
4956
return () => <NModal
5057
preset="card"
5158
class="w-[min(50vw,50em)]"
5259
title="导入提示"
5360
v-model:show={show.value}
5461
>{{
5562
default: () => <NFlex vertical size="large">
56-
<NScrollbar class="max-h-35vh">
63+
<NScrollbar class="max-h-30vh">
5764
<NFlex vertical>
5865
{
5966
props.errors.map((error, i) => {
@@ -91,7 +98,7 @@ export default defineComponent({
9198
</NScrollbar>
9299
{!!props.meta.length && <>
93100
为新导入的歌曲指定 ID
94-
<NScrollbar class="max-h-30vh">
101+
<NScrollbar class="max-h-25vh">
95102
<NFlex vertical size="large">
96103
{props.meta.map((meta, i) => <MusicIdInput key={i} meta={meta}/>)}
97104
</NFlex>
@@ -130,7 +137,11 @@ const MusicIdInput = defineComponent({
130137
meta: {type: Object as PropType<ImportMeta>, required: true},
131138
},
132139
setup(props) {
133-
const dxBase = computed(() => props.meta.id >= 1e4 ? 1e4 : 0);
140+
const dxBase = computed(() => {
141+
const dx = props.meta.id % 1e5 >= 1e4 ? 1e4 : 0
142+
const utage = props.meta.id >= 1e5 ? 1e5 : 0
143+
return dx + utage;
144+
});
134145
const img = computed(() => props.meta.bg ? URL.createObjectURL(props.meta.bg) : noJacket);
135146

136147
return () => <NFlex align="center" size="large">

MaiChartManager/Front/src/components/MusicEdit/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import JacketBox from "./JacketBox";
77
import dxIcon from "@/assets/dxIcon.png";
88
import stdIcon from "@/assets/stdIcon.png";
99
import ChartPanel from "./ChartPanel";
10-
import { DIFFICULTY, LEVEL_COLOR } from "@/consts";
10+
import { DIFFICULTY, LEVEL_COLOR, UTAGE_GENRE } from "@/consts";
1111
import ProblemsDisplay from "@/components/ProblemsDisplay";
1212
import AcbAwb from "@/components/MusicEdit/AcbAwb";
1313
import GenreInput from "@/components/GenreInput";
@@ -82,7 +82,7 @@ const Component = defineComponent({
8282
<NFormItem label="版本分类">
8383
<GenreInput options={addVersionList.value} v-model:value={info.value.addVersionId}/>
8484
</NFormItem>
85-
{info.value.genreId === 107 && // 宴会场
85+
{info.value.genreId === UTAGE_GENRE && // 宴会场
8686
<>
8787
<NFormItem label="宴谱种类">
8888
<NInput v-model:value={info.value.utageKanji}/>

MaiChartManager/Front/src/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const LEVELS = [0, 1, 2, 3, 4, 5, 6, 7, '7+', 8, '8+', 9, '9+', 10, '10+'
22
export const LEVEL_COLOR = ['rgb(34, 187, 91)', 'rgb(251, 156, 45)', 'rgb(246, 72, 97)', 'rgb(158, 69, 226)',
33
'rgb(228, 166, 255)'] as const;
44
export const DIFFICULTY = ['Basic', 'Advanced', 'Expert', 'Master', 'Re:Master'] as const;
5+
export const UTAGE_GENRE = 107;

MaiChartManager/Models/MusicXmlWithABJacket.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public MusicBrief GetBrief()
2828
return new MusicBrief(Id, NonDxId, Name, HasJacket, Modified, chartsAvailable, Problems);
2929
}
3030

31-
public new static MusicXmlWithABJacket CreateNew(int id, string gamePath, string assetDir, bool isDx)
31+
public new static MusicXmlWithABJacket CreateNew(int id, string gamePath, string assetDir)
3232
{
33-
var old = MusicXml.CreateNew(id, gamePath, assetDir, isDx);
33+
var old = MusicXml.CreateNew(id, gamePath, assetDir);
3434
return new MusicXmlWithABJacket(old.FilePath, old.GamePath);
3535
}
3636

@@ -61,6 +61,16 @@ public List<string> Problems
6161
res.Add("没有启用的谱面");
6262
}
6363

64+
if (GenreId == 107 && !Charts[0].Enable)
65+
{
66+
res.Add("宴会场必须启用绿谱");
67+
}
68+
69+
if (GenreId == 107 && Id < 100000)
70+
{
71+
res.Add("宴会场歌曲的 ID 小于 100000");
72+
}
73+
6474
return res;
6575
}
6676
}

Sitreamai/Models/MusicXml.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ public MusicXml(string filePath, string gamePath)
2727
}
2828
}
2929

30-
public static MusicXml CreateNew(int id, string gamePath, string assetDir, bool isDx)
30+
public static MusicXml CreateNew(int dxId, string gamePath, string assetDir)
3131
{
32-
if (id > 10000)
33-
{
34-
throw new ArgumentException("id must be less than 10000");
35-
}
36-
37-
var dxId = isDx ? id + 10000 : id;
32+
var id = dxId % 10000;
33+
// var isDx = dxId % 100000 >= 10000;
34+
// var isUtage = dxId >= 100000;
3835
var data = $"""
3936
<?xml version="1.0" encoding="utf-8"?>
4037
<MusicData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

0 commit comments

Comments
 (0)