Skip to content

Commit 491ee29

Browse files
authored
Merge pull request #384 from Wieku/dev
0.10.2
2 parents 43e6e66 + 6e0cbb1 commit 491ee29

File tree

6 files changed

+54
-182
lines changed

6 files changed

+54
-182
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ If you try to run *danser-cli* without any arguments there's a surprise waiting
8080
* `-noupdatecheck` - skips checking GitHub for a newer version of danser
8181
* `-ss=20.5` - creates a screenshot at the given time in .png format
8282
* `-quickstart` - skips intro (`-skip` flag), sets `LeadInTime` and `LeadInHold` to 0.
83-
* `-offset=20` - local audio offset in ms, applies to recordings unlike `Audio.Offset`. Inverted compared to stable.
83+
* `-offset=20` - local audio offset in ms, applies to recordings unlike `Audio.Offset`. ~~Inverted compared to stable~~ not anymore.
8484
* `-preciseprogress` - prints record progress in 1% increments.
8585

8686
Examples which should give the same result:

app/osuapi/api.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ const (
1515
CountryMode
1616
)
1717

18-
func LookupBeatmap(checksum string) (int, error) {
18+
func LookupBeatmap(checksum string) (*LookupResult, error) {
1919
resp, err := makeRequest("beatmaps/lookup?checksum=" + checksum)
2020

2121
if err != nil {
22-
return -1, err
22+
return nil, err
2323
}
2424

2525
buf, err2 := io.ReadAll(resp.Body)
2626
if err2 != nil {
27-
return -1, err
27+
return nil, err
2828
}
2929

3030
lRes := &LookupResult{}
3131
if err = json.Unmarshal(buf, &lRes); err != nil {
32-
return -1, err
32+
return nil, err
3333
}
3434

35-
return lRes.ID, nil
35+
return lRes, nil
3636
}
3737

3838
func GetScoresCheksum(checksum string, legacyOnly bool, mode ScoreType, limit int, mods ...string) ([]Score, error) {
39-
id, err := LookupBeatmap(checksum)
39+
lRes, err := LookupBeatmap(checksum)
4040

4141
if err != nil {
4242
return nil, err
4343
}
4444

45-
return GetScores(id, legacyOnly, mode, limit, mods...)
45+
return GetScores(lRes.ID, legacyOnly, mode, limit, mods...)
4646
}
4747

48-
func GetScores(beatmapId int, legacyOnly bool, mode ScoreType, limit int, mods ...string) ([]Score, error) {
48+
func GetScores(beatmapId int64, legacyOnly bool, mode ScoreType, limit int, mods ...string) ([]Score, error) {
4949
vls := url.Values{}
5050

5151
prefix := "solo-"
@@ -71,7 +71,7 @@ func GetScores(beatmapId int, legacyOnly bool, mode ScoreType, limit int, mods .
7171
}
7272
}
7373

74-
resp, err := makeRequest("beatmaps/" + strconv.Itoa(beatmapId) + "/" + prefix + "scores?" + vls.Encode())
74+
resp, err := makeRequest("beatmaps/" + strconv.FormatInt(beatmapId, 10) + "/" + prefix + "scores?" + vls.Encode())
7575

7676
if err != nil {
7777
return nil, err

app/osuapi/structs.go

Lines changed: 24 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,41 @@
11
package osuapi
22

3-
import (
4-
"time"
5-
)
6-
73
type ScoresResult struct {
84
Scores []Score `json:"scores"`
95
}
106

11-
type Mods struct {
12-
Acronym string `json:"acronym"`
13-
}
14-
15-
type CurrentUserAttributes struct {
16-
Pin any `json:"pin"`
17-
}
18-
19-
type Country struct {
20-
Code string `json:"code"`
21-
Name string `json:"name"`
22-
}
23-
24-
type Cover struct {
25-
CustomURL string `json:"custom_url"`
26-
URL string `json:"url"`
27-
ID any `json:"id"`
28-
}
29-
307
type User struct {
31-
AvatarURL string `json:"avatar_url"`
32-
CountryCode string `json:"country_code"`
33-
DefaultGroup string `json:"default_group"`
34-
ID int `json:"id"`
35-
IsActive bool `json:"is_active"`
36-
IsBot bool `json:"is_bot"`
37-
IsDeleted bool `json:"is_deleted"`
38-
IsOnline bool `json:"is_online"`
39-
IsSupporter bool `json:"is_supporter"`
40-
LastVisit any `json:"last_visit"`
41-
PmFriendsOnly bool `json:"pm_friends_only"`
42-
ProfileColour any `json:"profile_colour"`
43-
Username string `json:"username"`
44-
Country Country `json:"country"`
45-
Cover Cover `json:"cover"`
8+
AvatarURL string `json:"avatar_url"`
9+
CountryCode string `json:"country_code"`
10+
ID int64 `json:"id"`
11+
Username string `json:"username"`
4612
}
4713

4814
type Score struct {
49-
ClassicTotalScore int64 `json:"classic_total_score"`
50-
Preserve bool `json:"preserve"`
51-
Processed bool `json:"processed"`
52-
Ranked bool `json:"ranked"`
53-
MaximumStatistics map[string]int64 `json:"maximum_statistics,omitempty"`
54-
Mods []any `json:"mods"`
55-
Statistics map[string]int64 `json:"statistics,omitempty"`
56-
BeatmapID int `json:"beatmap_id"`
57-
BestID any `json:"best_id"`
58-
ID int64 `json:"id"`
59-
Rank string `json:"rank"`
60-
Type string `json:"type"`
61-
UserID int `json:"user_id"`
62-
Accuracy float64 `json:"accuracy"`
63-
BuildID any `json:"build_id"`
64-
EndedAt time.Time `json:"ended_at"`
65-
HasReplay bool `json:"has_replay"`
66-
IsPerfectCombo bool `json:"is_perfect_combo"`
67-
LegacyPerfect bool `json:"legacy_perfect"`
68-
LegacyScoreID int64 `json:"legacy_score_id"`
69-
LegacyTotalScore int64 `json:"legacy_total_score"`
70-
MaxCombo int64 `json:"max_combo"`
71-
Passed bool `json:"passed"`
72-
Pp float64 `json:"pp"`
73-
RulesetID int `json:"ruleset_id"`
74-
StartedAt any `json:"started_at"`
75-
Score int64 `json:"score"`
76-
TotalScore int64 `json:"total_score"`
77-
Replay bool `json:"replay"`
78-
CurrentUserAttributes CurrentUserAttributes `json:"current_user_attributes"`
79-
User User `json:"user"`
80-
TotalScoreWithoutMods int64 `json:"total_score_without_mods,omitempty"`
15+
ClassicTotalScore int64 `json:"classic_total_score"`
16+
BeatmapID int64 `json:"beatmap_id"`
17+
ID int64 `json:"id"`
18+
UserID int64 `json:"user_id"`
19+
Accuracy float64 `json:"accuracy"`
20+
LegacyScoreID int64 `json:"legacy_score_id"`
21+
LegacyTotalScore int64 `json:"legacy_total_score"`
22+
MaxCombo int64 `json:"max_combo"`
23+
Score int64 `json:"score"`
24+
TotalScore int64 `json:"total_score"`
25+
User User `json:"user"`
26+
TotalScoreWithoutMods int64 `json:"total_score_without_mods,omitempty"`
8127
}
8228

8329
type LookupResult struct {
84-
BeatmapsetID int `json:"beatmapset_id"`
85-
DifficultyRating float64 `json:"difficulty_rating"`
86-
ID int `json:"id"`
87-
Mode string `json:"mode"`
88-
Status string `json:"status"`
89-
TotalLength int `json:"total_length"`
90-
UserID int `json:"user_id"`
91-
Version string `json:"version"`
92-
Accuracy float64 `json:"accuracy"`
93-
Ar float64 `json:"ar"`
94-
Bpm float64 `json:"bpm"`
95-
Convert bool `json:"convert"`
96-
CountCircles int `json:"count_circles"`
97-
CountSliders int `json:"count_sliders"`
98-
CountSpinners int `json:"count_spinners"`
99-
Cs float64 `json:"cs"`
100-
DeletedAt any `json:"deleted_at"`
101-
Drain float64 `json:"drain"`
102-
HitLength int `json:"hit_length"`
103-
IsScoreable bool `json:"is_scoreable"`
104-
LastUpdated time.Time `json:"last_updated"`
105-
ModeInt int `json:"mode_int"`
106-
Passcount int `json:"passcount"`
107-
Playcount int `json:"playcount"`
108-
Ranked int `json:"ranked"`
109-
URL string `json:"url"`
110-
Checksum string `json:"checksum"`
111-
Beatmapset Beatmapset `json:"beatmapset"`
112-
Failtimes Failtimes `json:"failtimes"`
113-
MaxCombo int `json:"max_combo"`
114-
}
115-
116-
type Covers struct {
117-
Cover string `json:"cover"`
118-
Cover2X string `json:"cover@2x"`
119-
Card string `json:"card"`
120-
Card2X string `json:"card@2x"`
121-
List string `json:"list"`
122-
List2X string `json:"list@2x"`
123-
Slimcover string `json:"slimcover"`
124-
Slimcover2X string `json:"slimcover@2x"`
125-
}
126-
127-
type RequiredMeta struct {
128-
MainRuleset int `json:"main_ruleset"`
129-
NonMainRuleset int `json:"non_main_ruleset"`
130-
}
131-
132-
type NominationsSummary struct {
133-
Current int `json:"current"`
134-
EligibleMainRulesets []string `json:"eligible_main_rulesets"`
135-
RequiredMeta RequiredMeta `json:"required_meta"`
136-
}
137-
138-
type Availability struct {
139-
DownloadDisabled bool `json:"download_disabled"`
140-
MoreInformation any `json:"more_information"`
30+
BeatmapsetID int64 `json:"beatmapset_id"`
31+
ID int64 `json:"id"`
32+
Mode string `json:"mode"`
33+
URL string `json:"url"`
34+
Checksum string `json:"checksum"`
35+
Beatmapset Beatmapset `json:"beatmapset"`
14136
}
14237

14338
type Beatmapset struct {
144-
Artist string `json:"artist"`
145-
ArtistUnicode string `json:"artist_unicode"`
146-
Covers Covers `json:"covers"`
147-
Creator string `json:"creator"`
148-
FavouriteCount int `json:"favourite_count"`
149-
Hype any `json:"hype"`
150-
ID int `json:"id"`
151-
Nsfw bool `json:"nsfw"`
152-
Offset int `json:"offset"`
153-
PlayCount int `json:"play_count"`
154-
PreviewURL string `json:"preview_url"`
155-
Source string `json:"source"`
156-
Spotlight bool `json:"spotlight"`
157-
Status string `json:"status"`
158-
Title string `json:"title"`
159-
TitleUnicode string `json:"title_unicode"`
160-
TrackID any `json:"track_id"`
161-
UserID int `json:"user_id"`
162-
Video bool `json:"video"`
163-
Bpm int `json:"bpm"`
164-
CanBeHyped bool `json:"can_be_hyped"`
165-
DeletedAt any `json:"deleted_at"`
166-
DiscussionEnabled bool `json:"discussion_enabled"`
167-
DiscussionLocked bool `json:"discussion_locked"`
168-
IsScoreable bool `json:"is_scoreable"`
169-
LastUpdated time.Time `json:"last_updated"`
170-
LegacyThreadURL string `json:"legacy_thread_url"`
171-
NominationsSummary NominationsSummary `json:"nominations_summary"`
172-
Ranked int `json:"ranked"`
173-
RankedDate time.Time `json:"ranked_date"`
174-
Storyboard bool `json:"storyboard"`
175-
SubmittedDate time.Time `json:"submitted_date"`
176-
Tags string `json:"tags"`
177-
Availability Availability `json:"availability"`
178-
Ratings []int `json:"ratings"`
179-
}
180-
181-
type Failtimes struct {
182-
Fail []int `json:"fail"`
183-
Exit []int `json:"exit"`
39+
ID int64 `json:"id"`
40+
Offset float64 `json:"offset"`
18441
}

app/rulesets/osu/performance/pp241007/difficulty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,5 @@ func (diffCalc *DifficultyCalculator) GetVersion() int {
208208
}
209209

210210
func (diffCalc *DifficultyCalculator) GetVersionMessage() string {
211-
return "2024-10-07: no post yet"
211+
return "2024-10-07: https://osu.ppy.sh/home/news/2024-10-28-performance-points-star-rating-updates"
212212
}

app/settings/audio.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func initAudio() *audio {
88
MusicVolume: 0.5,
99
SampleVolume: 0.5,
1010
Offset: 0,
11+
OnlineOffset: false,
1112
HitsoundPositionMultiplier: 1.0,
1213
IgnoreBeatmapSamples: false,
1314
IgnoreBeatmapSampleVolume: false,
@@ -28,6 +29,7 @@ type audio struct {
2829
MusicVolume float64 `scale:"100.0" format:"%.0f%%"` //=0.5
2930
SampleVolume float64 `scale:"100.0" format:"%.0f%%"` //=0.5
3031
Offset int64 `min:"-300" max:"300" format:"%dms" label:"Universal Offset"`
32+
OnlineOffset bool `label:"Apply online offset (needs API access)"`
3133
HitsoundPositionMultiplier float64
3234
IgnoreBeatmapSamples bool `label:"Ignore beatmap hitsounds"` //= false
3335
IgnoreBeatmapSampleVolume bool `label:"Ignore hitsound volume changes"` //= false

app/states/player.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/wieku/danser-go/app/discord"
1515
"github.com/wieku/danser-go/app/graphics"
1616
"github.com/wieku/danser-go/app/input"
17+
"github.com/wieku/danser-go/app/osuapi"
1718
"github.com/wieku/danser-go/app/rulesets/osu"
1819
"github.com/wieku/danser-go/app/settings"
1920
"github.com/wieku/danser-go/app/states/components/common"
@@ -72,6 +73,8 @@ type Player struct {
7273
profiler *frame.Counter
7374
profilerU *frame.Counter
7475

76+
onlineOffset float64
77+
7578
mainCamera *camera2.Camera
7679
objectCamera *camera2.Camera
7780
bgCamera *camera2.Camera
@@ -512,6 +515,16 @@ func NewPlayer(beatMap *beatmap.BeatMap) *Player {
512515
player.nightcore.SetMap(player.bMap, player.musicPlayer)
513516
}
514517

518+
if settings.Audio.OnlineOffset { // Try to load online offset
519+
onlineBeatmap, err2 := osuapi.LookupBeatmap(beatMap.MD5)
520+
if err2 != nil {
521+
log.Println("Failed to load online offset:", err.Error())
522+
} else if onlineBeatmap != nil {
523+
player.onlineOffset = onlineBeatmap.Beatmapset.Offset
524+
log.Println(fmt.Sprintf("Online offset loaded: %.0fms", player.onlineOffset))
525+
}
526+
}
527+
515528
if settings.RECORD {
516529
return player
517530
}
@@ -558,10 +571,10 @@ func NewPlayer(beatMap *beatmap.BeatMap) *Player {
558571

559572
oldOffset := 0.0
560573
if player.bMap.Version < 5 {
561-
oldOffset = -24
574+
oldOffset = 24
562575
}
563576

564-
player.progressMsF = player.rawPositionF + (platformOffset+float64(settings.Audio.Offset)+float64(settings.LOCALOFFSET))*speed + oldOffset
577+
player.progressMsF = player.rawPositionF + (platformOffset+float64(settings.Audio.Offset))*speed - oldOffset - float64(settings.LOCALOFFSET) - player.onlineOffset
565578

566579
player.updateMain(delta)
567580

@@ -638,10 +651,10 @@ func (player *Player) Update(delta float64) bool {
638651

639652
oldOffset := 0.0
640653
if player.bMap.Version < 5 {
641-
oldOffset = -24
654+
oldOffset = 24
642655
}
643656

644-
player.progressMsF = player.rawPositionF + float64(settings.LOCALOFFSET)*speed + oldOffset
657+
player.progressMsF = player.rawPositionF - oldOffset - float64(settings.LOCALOFFSET) - player.onlineOffset
645658

646659
player.updateMain(delta)
647660

0 commit comments

Comments
 (0)