mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-11 14:19:38 +00:00
Improved version selection with chart packs
This commit is contained in:
@@ -43,8 +43,7 @@ export class ChartSidebarComponent implements OnInit {
|
||||
const albumArt = this.albumArtService.getImage(result.id)
|
||||
const results = await this.electronService.invoke('song-details', result.id)
|
||||
this.charts = groupBy(results, 'chartID').sort((v1, v2) => v1[0].avTagName.length - v2[0].avTagName.length)
|
||||
// This sorting is very inefficient, but there's rarely more than two or three in this list, so it's fine
|
||||
this.charts.forEach(chart => chart.sort((v1, v2) => new Date(v2.lastModified).getTime() - new Date(v1.lastModified).getTime()))
|
||||
this.sortCharts()
|
||||
await this.selectChart(0)
|
||||
this.initChartDropdown()
|
||||
|
||||
@@ -52,6 +51,19 @@ export class ChartSidebarComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts `this.charts` and its subarrays in the correct order.
|
||||
* The chart dropdown should display in a random order, but verified charters are prioritized.
|
||||
* The version dropdown should be ordered by lastModified date.
|
||||
* (but prefer the non-pack version if it's only a few days older)
|
||||
*/
|
||||
private sortCharts() {
|
||||
for (const chart of this.charts) {
|
||||
// TODO: sort by verified charter
|
||||
this.searchService.sortChart(chart)
|
||||
}
|
||||
}
|
||||
|
||||
albumArtSrc: SafeUrl = ''
|
||||
/**
|
||||
* Updates the sidebar to display the album art.
|
||||
|
||||
@@ -64,7 +64,8 @@ export class StatusBarComponent {
|
||||
|
||||
if (this.chartGroups.length == 0) {
|
||||
for (const versions of versionGroups) {
|
||||
const downloadVersion = versions.find(version => version.versionID == version.latestVersionID)
|
||||
this.searchService.sortChart(versions)
|
||||
const downloadVersion = versions[0]
|
||||
const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID)
|
||||
this.downloadService.addDownload(
|
||||
downloadVersion.versionID, {
|
||||
@@ -81,16 +82,19 @@ export class StatusBarComponent {
|
||||
}
|
||||
|
||||
downloadAllCharts() {
|
||||
for (const version of this.batchResults) {
|
||||
if (version.versionID != version.latestVersionID) { continue }
|
||||
const downloadSong = this.selectedResults.find(song => song.id == version.songID)
|
||||
const chartGroups = groupBy(this.batchResults, 'chartID')
|
||||
for (const chart of chartGroups) {
|
||||
this.searchService.sortChart(chart)
|
||||
const downloadVersion = chart[0]
|
||||
const downloadSong = this.selectedResults.find(song => song.id == downloadVersion.songID)
|
||||
this.downloadService.addDownload(
|
||||
version.versionID, {
|
||||
avTagName: version.avTagName,
|
||||
downloadVersion.versionID, {
|
||||
avTagName: downloadVersion.avTagName,
|
||||
artist: downloadSong.artist,
|
||||
charter: version.charters,
|
||||
driveData: version.driveData
|
||||
})
|
||||
charter: downloadVersion.charters,
|
||||
driveData: downloadVersion.driveData
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable, EventEmitter } from '@angular/core'
|
||||
import { ElectronService } from './electron.service'
|
||||
import { SearchType, SongResult, SongSearch } from 'src/electron/shared/interfaces/search.interface'
|
||||
import { VersionResult } from 'src/electron/shared/interfaces/songDetails.interface'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -72,4 +73,25 @@ export class SearchService {
|
||||
get allResultsVisible() {
|
||||
return this._allResultsVisible
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders `versionResults` by lastModified date, but prefer the
|
||||
* non-pack version if it's only a few days older.
|
||||
*/
|
||||
sortChart(versionResults: VersionResult[]) {
|
||||
const dates: { [versionID: number]: number } = {}
|
||||
versionResults.forEach(version => dates[version.versionID] = new Date(version.lastModified).getTime())
|
||||
versionResults.sort((v1, v2) => {
|
||||
const diff = dates[v1.versionID] - dates[v2.versionID]
|
||||
if (Math.abs(diff) < 6.048e+8 && v1.driveData.inChartPack != v2.driveData.inChartPack) {
|
||||
if (v1.driveData.inChartPack) {
|
||||
return 1 // prioritize v2
|
||||
} else {
|
||||
return -1 // prioritize v1
|
||||
}
|
||||
} else {
|
||||
return diff
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user