Skip to content
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

增加列表中歌曲随机乱序排列,修复专辑名排序无效bug #1440

Merged
merged 8 commits into from
Jul 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Add files via upload
  • Loading branch information
findstused committed Jul 1, 2023
commit 60c954f59a2709396994f6b92d7d989f64eb23ba
140 changes: 89 additions & 51 deletions src/renderer/worker/main/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,65 +79,103 @@ const getIntv = (musicInfo: LX.Music.MusicInfo) => {
* @param localeId 排序语言
* @returns
*/
export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up' | 'down', fieldName: 'name' | 'singer' | 'albumName' | 'interval' | 'source', localeId: string) => {
export const sortListMusicInfo = async(list: LX.Music.MusicInfo[], sortType: 'up' | 'down' | 'disorder', fieldName: 'name' | 'singer' | 'albumName' | 'interval' | 'source', localeId: string) => {
// console.log(sortType, fieldName, localeId)
// const locale = new Intl.Locale(localeId)
if (sortType == 'up') {
if (fieldName == 'interval') {
list.sort((a, b) => {
if (a.interval == null) {
return b.interval == null ? 0 : -1
} else return b.interval == null ? 1 : getIntv(a) - getIntv(b)
})
} else {
switch (fieldName) {
case 'name':
case 'singer':
case 'source':
list.sort((a, b) => {
if (a[fieldName] == null) {
return b[fieldName] == null ? 0 : -1
} else return b[fieldName] == null ? 1 : a[fieldName].localeCompare(b[fieldName], localeId)
})
break
case 'albumName':
list.sort((a, b) => {
if (a.meta.albumName == null) {
return b.meta.albumName == null ? 0 : -1
} else return b.meta.albumName == null ? 1 : a.meta.albumName.localeCompare(b.meta.albumName, localeId)
})
break
if (sortType == 'disorder' && (fieldName =='name' || fieldName == 'singer' || fieldName =='albumName' || fieldName =='interval' || fieldName =='source')){

let change_num:number[]=[]

for(let i:number = 0;i<list.length;i++){
if(change_num.length == 0){
let r_num:number = Math.floor(Math.random()*list.length)
change_num.push(r_num)
}
else{
let sign:boolean = false
do{
let r_num:number = Math.floor(Math.random()*list.length)
for(let j:number = 0 ; j<change_num.length; j++){
if(change_num[j] == r_num){
break;
}
if (j == change_num.length-1){
change_num.push(r_num)
sign = true
}
}
}while(!sign)

}

}
} else {
if (fieldName == 'interval') {
list.sort((a, b) => {
if (a.interval == null) {
return b.interval == null ? 0 : 1
} else return b.interval == null ? -1 : getIntv(b) - getIntv(a)
})

let list2:LX.Music.MusicInfo[]=[]
for(let k:number = 0;k<change_num.length;k++){
list2.push(list[change_num[k]])
}
return list2
}
else{
if (sortType == 'up') {
if (fieldName == 'interval') {
list.sort((a, b) => {
if (a.interval == null) {
return b.interval == null ? 0 : -1
} else return b.interval == null ? 1 : getIntv(a) - getIntv(b)
})
} else {
switch (fieldName) {
case 'name':
case 'singer':
case 'source':
list.sort((a, b) => {
if (a[fieldName] == null) {
return b[fieldName] == null ? 0 : -1
} else return b[fieldName] == null ? 1 : a[fieldName].localeCompare(b[fieldName], localeId)
})
break
case 'albumName':
list.sort((a, b) => {
if (a.meta.albumName == null) {
return b.meta.albumName == null ? 0 : -1
} else return b.meta.albumName == null ? 1 : a.meta.albumName.localeCompare(b.meta.albumName, localeId)
})
break
}
}
} else {
switch (fieldName) {
case 'name':
case 'singer':
case 'source':
list.sort((a, b) => {
if (a[fieldName] == null) {
return b[fieldName] == null ? 0 : 1
} else return b[fieldName] == null ? -1 : b[fieldName].localeCompare(a[fieldName], localeId)
})
break
case 'albumName':
list.sort((a, b) => {
if (a.meta.albumName == null) {
return b.meta.albumName == null ? 0 : 1
} else return b.meta.albumName == null ? -1 : b.meta.albumName.localeCompare(a.meta.albumName, localeId)
})
break
if (fieldName == 'interval') {
list.sort((a, b) => {
if (a.interval == null) {
return b.interval == null ? 0 : 1
} else return b.interval == null ? -1 : getIntv(b) - getIntv(a)
})
} else {
switch (fieldName) {
case 'name':
case 'singer':
case 'source':
list.sort((a, b) => {
if (a[fieldName] == null) {
return b[fieldName] == null ? 0 : 1
} else return b[fieldName] == null ? -1 : b[fieldName].localeCompare(a[fieldName], localeId)
})
break
case 'albumName':
list.sort((a, b) => {
if (a.meta.albumName == null) {
return b.meta.albumName == null ? 0 : 1
} else return b.meta.albumName == null ? -1 : b.meta.albumName.localeCompare(a.meta.albumName, localeId)
})
break
}
}
}
return list

}
return list

}

const variantRxp = /(\(|().+(\)|))/g
Expand Down