Skip to content

Commit

Permalink
Merge pull request #384 from Wieku/dev
Browse files Browse the repository at this point in the history
0.10.2
  • Loading branch information
Wieku authored Nov 6, 2024
2 parents 43e6e66 + 6e0cbb1 commit 491ee29
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 182 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ If you try to run *danser-cli* without any arguments there's a surprise waiting
* `-noupdatecheck` - skips checking GitHub for a newer version of danser
* `-ss=20.5` - creates a screenshot at the given time in .png format
* `-quickstart` - skips intro (`-skip` flag), sets `LeadInTime` and `LeadInHold` to 0.
* `-offset=20` - local audio offset in ms, applies to recordings unlike `Audio.Offset`. Inverted compared to stable.
* `-offset=20` - local audio offset in ms, applies to recordings unlike `Audio.Offset`. ~~Inverted compared to stable~~ not anymore.
* `-preciseprogress` - prints record progress in 1% increments.

Examples which should give the same result:
Expand Down
18 changes: 9 additions & 9 deletions app/osuapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ const (
CountryMode
)

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

if err != nil {
return -1, err
return nil, err
}

buf, err2 := io.ReadAll(resp.Body)
if err2 != nil {
return -1, err
return nil, err
}

lRes := &LookupResult{}
if err = json.Unmarshal(buf, &lRes); err != nil {
return -1, err
return nil, err
}

return lRes.ID, nil
return lRes, nil
}

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

if err != nil {
return nil, err
}

return GetScores(id, legacyOnly, mode, limit, mods...)
return GetScores(lRes.ID, legacyOnly, mode, limit, mods...)
}

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

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

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

if err != nil {
return nil, err
Expand Down
191 changes: 24 additions & 167 deletions app/osuapi/structs.go
Original file line number Diff line number Diff line change
@@ -1,184 +1,41 @@
package osuapi

import (
"time"
)

type ScoresResult struct {
Scores []Score `json:"scores"`
}

type Mods struct {
Acronym string `json:"acronym"`
}

type CurrentUserAttributes struct {
Pin any `json:"pin"`
}

type Country struct {
Code string `json:"code"`
Name string `json:"name"`
}

type Cover struct {
CustomURL string `json:"custom_url"`
URL string `json:"url"`
ID any `json:"id"`
}

type User struct {
AvatarURL string `json:"avatar_url"`
CountryCode string `json:"country_code"`
DefaultGroup string `json:"default_group"`
ID int `json:"id"`
IsActive bool `json:"is_active"`
IsBot bool `json:"is_bot"`
IsDeleted bool `json:"is_deleted"`
IsOnline bool `json:"is_online"`
IsSupporter bool `json:"is_supporter"`
LastVisit any `json:"last_visit"`
PmFriendsOnly bool `json:"pm_friends_only"`
ProfileColour any `json:"profile_colour"`
Username string `json:"username"`
Country Country `json:"country"`
Cover Cover `json:"cover"`
AvatarURL string `json:"avatar_url"`
CountryCode string `json:"country_code"`
ID int64 `json:"id"`
Username string `json:"username"`
}

type Score struct {
ClassicTotalScore int64 `json:"classic_total_score"`
Preserve bool `json:"preserve"`
Processed bool `json:"processed"`
Ranked bool `json:"ranked"`
MaximumStatistics map[string]int64 `json:"maximum_statistics,omitempty"`
Mods []any `json:"mods"`
Statistics map[string]int64 `json:"statistics,omitempty"`
BeatmapID int `json:"beatmap_id"`
BestID any `json:"best_id"`
ID int64 `json:"id"`
Rank string `json:"rank"`
Type string `json:"type"`
UserID int `json:"user_id"`
Accuracy float64 `json:"accuracy"`
BuildID any `json:"build_id"`
EndedAt time.Time `json:"ended_at"`
HasReplay bool `json:"has_replay"`
IsPerfectCombo bool `json:"is_perfect_combo"`
LegacyPerfect bool `json:"legacy_perfect"`
LegacyScoreID int64 `json:"legacy_score_id"`
LegacyTotalScore int64 `json:"legacy_total_score"`
MaxCombo int64 `json:"max_combo"`
Passed bool `json:"passed"`
Pp float64 `json:"pp"`
RulesetID int `json:"ruleset_id"`
StartedAt any `json:"started_at"`
Score int64 `json:"score"`
TotalScore int64 `json:"total_score"`
Replay bool `json:"replay"`
CurrentUserAttributes CurrentUserAttributes `json:"current_user_attributes"`
User User `json:"user"`
TotalScoreWithoutMods int64 `json:"total_score_without_mods,omitempty"`
ClassicTotalScore int64 `json:"classic_total_score"`
BeatmapID int64 `json:"beatmap_id"`
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
Accuracy float64 `json:"accuracy"`
LegacyScoreID int64 `json:"legacy_score_id"`
LegacyTotalScore int64 `json:"legacy_total_score"`
MaxCombo int64 `json:"max_combo"`
Score int64 `json:"score"`
TotalScore int64 `json:"total_score"`
User User `json:"user"`
TotalScoreWithoutMods int64 `json:"total_score_without_mods,omitempty"`
}

type LookupResult struct {
BeatmapsetID int `json:"beatmapset_id"`
DifficultyRating float64 `json:"difficulty_rating"`
ID int `json:"id"`
Mode string `json:"mode"`
Status string `json:"status"`
TotalLength int `json:"total_length"`
UserID int `json:"user_id"`
Version string `json:"version"`
Accuracy float64 `json:"accuracy"`
Ar float64 `json:"ar"`
Bpm float64 `json:"bpm"`
Convert bool `json:"convert"`
CountCircles int `json:"count_circles"`
CountSliders int `json:"count_sliders"`
CountSpinners int `json:"count_spinners"`
Cs float64 `json:"cs"`
DeletedAt any `json:"deleted_at"`
Drain float64 `json:"drain"`
HitLength int `json:"hit_length"`
IsScoreable bool `json:"is_scoreable"`
LastUpdated time.Time `json:"last_updated"`
ModeInt int `json:"mode_int"`
Passcount int `json:"passcount"`
Playcount int `json:"playcount"`
Ranked int `json:"ranked"`
URL string `json:"url"`
Checksum string `json:"checksum"`
Beatmapset Beatmapset `json:"beatmapset"`
Failtimes Failtimes `json:"failtimes"`
MaxCombo int `json:"max_combo"`
}

type Covers struct {
Cover string `json:"cover"`
Cover2X string `json:"cover@2x"`
Card string `json:"card"`
Card2X string `json:"card@2x"`
List string `json:"list"`
List2X string `json:"list@2x"`
Slimcover string `json:"slimcover"`
Slimcover2X string `json:"slimcover@2x"`
}

type RequiredMeta struct {
MainRuleset int `json:"main_ruleset"`
NonMainRuleset int `json:"non_main_ruleset"`
}

type NominationsSummary struct {
Current int `json:"current"`
EligibleMainRulesets []string `json:"eligible_main_rulesets"`
RequiredMeta RequiredMeta `json:"required_meta"`
}

type Availability struct {
DownloadDisabled bool `json:"download_disabled"`
MoreInformation any `json:"more_information"`
BeatmapsetID int64 `json:"beatmapset_id"`
ID int64 `json:"id"`
Mode string `json:"mode"`
URL string `json:"url"`
Checksum string `json:"checksum"`
Beatmapset Beatmapset `json:"beatmapset"`
}

type Beatmapset struct {
Artist string `json:"artist"`
ArtistUnicode string `json:"artist_unicode"`
Covers Covers `json:"covers"`
Creator string `json:"creator"`
FavouriteCount int `json:"favourite_count"`
Hype any `json:"hype"`
ID int `json:"id"`
Nsfw bool `json:"nsfw"`
Offset int `json:"offset"`
PlayCount int `json:"play_count"`
PreviewURL string `json:"preview_url"`
Source string `json:"source"`
Spotlight bool `json:"spotlight"`
Status string `json:"status"`
Title string `json:"title"`
TitleUnicode string `json:"title_unicode"`
TrackID any `json:"track_id"`
UserID int `json:"user_id"`
Video bool `json:"video"`
Bpm int `json:"bpm"`
CanBeHyped bool `json:"can_be_hyped"`
DeletedAt any `json:"deleted_at"`
DiscussionEnabled bool `json:"discussion_enabled"`
DiscussionLocked bool `json:"discussion_locked"`
IsScoreable bool `json:"is_scoreable"`
LastUpdated time.Time `json:"last_updated"`
LegacyThreadURL string `json:"legacy_thread_url"`
NominationsSummary NominationsSummary `json:"nominations_summary"`
Ranked int `json:"ranked"`
RankedDate time.Time `json:"ranked_date"`
Storyboard bool `json:"storyboard"`
SubmittedDate time.Time `json:"submitted_date"`
Tags string `json:"tags"`
Availability Availability `json:"availability"`
Ratings []int `json:"ratings"`
}

type Failtimes struct {
Fail []int `json:"fail"`
Exit []int `json:"exit"`
ID int64 `json:"id"`
Offset float64 `json:"offset"`
}
2 changes: 1 addition & 1 deletion app/rulesets/osu/performance/pp241007/difficulty.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,5 @@ func (diffCalc *DifficultyCalculator) GetVersion() int {
}

func (diffCalc *DifficultyCalculator) GetVersionMessage() string {
return "2024-10-07: no post yet"
return "2024-10-07: https://osu.ppy.sh/home/news/2024-10-28-performance-points-star-rating-updates"
}
2 changes: 2 additions & 0 deletions app/settings/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func initAudio() *audio {
MusicVolume: 0.5,
SampleVolume: 0.5,
Offset: 0,
OnlineOffset: false,
HitsoundPositionMultiplier: 1.0,
IgnoreBeatmapSamples: false,
IgnoreBeatmapSampleVolume: false,
Expand All @@ -28,6 +29,7 @@ type audio struct {
MusicVolume float64 `scale:"100.0" format:"%.0f%%"` //=0.5
SampleVolume float64 `scale:"100.0" format:"%.0f%%"` //=0.5
Offset int64 `min:"-300" max:"300" format:"%dms" label:"Universal Offset"`
OnlineOffset bool `label:"Apply online offset (needs API access)"`
HitsoundPositionMultiplier float64
IgnoreBeatmapSamples bool `label:"Ignore beatmap hitsounds"` //= false
IgnoreBeatmapSampleVolume bool `label:"Ignore hitsound volume changes"` //= false
Expand Down
21 changes: 17 additions & 4 deletions app/states/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/wieku/danser-go/app/discord"
"github.com/wieku/danser-go/app/graphics"
"github.com/wieku/danser-go/app/input"
"github.com/wieku/danser-go/app/osuapi"
"github.com/wieku/danser-go/app/rulesets/osu"
"github.com/wieku/danser-go/app/settings"
"github.com/wieku/danser-go/app/states/components/common"
Expand Down Expand Up @@ -72,6 +73,8 @@ type Player struct {
profiler *frame.Counter
profilerU *frame.Counter

onlineOffset float64

mainCamera *camera2.Camera
objectCamera *camera2.Camera
bgCamera *camera2.Camera
Expand Down Expand Up @@ -512,6 +515,16 @@ func NewPlayer(beatMap *beatmap.BeatMap) *Player {
player.nightcore.SetMap(player.bMap, player.musicPlayer)
}

if settings.Audio.OnlineOffset { // Try to load online offset
onlineBeatmap, err2 := osuapi.LookupBeatmap(beatMap.MD5)
if err2 != nil {
log.Println("Failed to load online offset:", err.Error())
} else if onlineBeatmap != nil {
player.onlineOffset = onlineBeatmap.Beatmapset.Offset
log.Println(fmt.Sprintf("Online offset loaded: %.0fms", player.onlineOffset))
}
}

if settings.RECORD {
return player
}
Expand Down Expand Up @@ -558,10 +571,10 @@ func NewPlayer(beatMap *beatmap.BeatMap) *Player {

oldOffset := 0.0
if player.bMap.Version < 5 {
oldOffset = -24
oldOffset = 24
}

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

player.updateMain(delta)

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

oldOffset := 0.0
if player.bMap.Version < 5 {
oldOffset = -24
oldOffset = 24
}

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

player.updateMain(delta)

Expand Down

0 comments on commit 491ee29

Please sign in to comment.