From 8a3b40cf740aab0a17915878f8182dc97d3f4b7f Mon Sep 17 00:00:00 2001 From: Simon Esposito Date: Wed, 17 Jul 2024 18:42:23 +0100 Subject: [PATCH] Add enableRanks option to leaderboards. Add runtime function to disable ranks on an active leaderboard. --- CHANGELOG.md | 5 +++++ index.d.ts | 8 ++++++-- runtime/runtime.go | 8 ++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b14350..ceb33d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr ## [Unreleased] ### Added - New runtime functions to get and delete notifications by id. +- Add runtime function to disable ranks for an active leaderboard. + +### Changed +- Add leaderboard and tournament create param to enable or disable ranks. + ### Fixed - Add ErrGracePeriodExpired. diff --git a/index.d.ts b/index.d.ts index 9e2aced..929deac 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4221,11 +4221,12 @@ declare namespace nkruntime { * Create a new leaderboard. * * @param leaderboardID - Leaderboard id. - * @param authoritative - Opt. Authoritative Leaderboard if true. + * @param authoritative - Opt. Whether to only allow authoritative score submissions. * @param sortOrder - Opt. Sort leaderboard in desc or asc order. Defauts to "desc". * @param operator - Opt. Score operator "best", "set" or "incr" (refer to the docs for more info). Defaults to "best". * @param resetSchedule - Cron string to set the periodicity of the leaderboard reset. Set as null to never reset. * @param metadata - Opt. metadata object. + * @param enableRank - Opt. Enable ranks for the leaderboard. Defaults to false. * @throws {TypeError, GoError} */ leaderboardCreate( @@ -4235,6 +4236,7 @@ declare namespace nkruntime { operator?: Operator, resetSchedule?: null | string, metadata?: {[key: string]: any} | null, + enableRank?: boolean, ): void; /** @@ -4330,7 +4332,7 @@ declare namespace nkruntime { * Create a new tournament. * * @param tournamentID - Tournament id. - * @param authoritative - Opt. Whether or not to only allow authoritative score submissions. + * @param authoritative - Opt. Whether to only allow authoritative score submissions. * @param sortOrder - Opt. Sort tournament in desc or asc order. Defaults to "desc". * @param operator - Opt. Score operator "best", "set" or "incr" (refer to the docs for more info). Defaults to "best". * @param duration - Opt. Duration of the tournament (unix epoch). @@ -4344,6 +4346,7 @@ declare namespace nkruntime { * @param maxSize - Opt. Maximum size of participants in a tournament. * @param maxNumScore - Opt. Maximum submission attempts for a tournament record. * @param joinRequired - Opt. Whether the tournament needs to be joint before a record write is allowed. + * @param enableRank - Opt. Enable ranks for the leaderboard. Defaults to false. * @throws {TypeError, GoError} */ tournamentCreate( @@ -4362,6 +4365,7 @@ declare namespace nkruntime { maxSize?: number | null, maxNumScore?: number | null, joinRequired?: boolean, + enableRank?: boolean, ): void; /** diff --git a/runtime/runtime.go b/runtime/runtime.go index 4299ae7..13cad0a 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -171,6 +171,8 @@ var ( ErrFriendInvalidCursor = errors.New("friend cursor invalid") + ErrLeaderboardNotFound = errors.New("leaderboard not found") + ErrTournamentNotFound = errors.New("tournament not found") ErrTournamentAuthoritative = errors.New("tournament only allows authoritative submissions") ErrTournamentMaxSizeReached = errors.New("tournament max size reached") @@ -1113,9 +1115,10 @@ type NakamaModule interface { MultiUpdate(ctx context.Context, accountUpdates []*AccountUpdate, storageWrites []*StorageWrite, storageDeletes []*StorageDelete, walletUpdates []*WalletUpdate, updateLedger bool) ([]*api.StorageObjectAck, []*WalletUpdateResult, error) - LeaderboardCreate(ctx context.Context, id string, authoritative bool, sortOrder, operator, resetSchedule string, metadata map[string]interface{}) error + LeaderboardCreate(ctx context.Context, id string, authoritative bool, sortOrder, operator, resetSchedule string, metadata map[string]interface{}, enableRanks bool) error LeaderboardDelete(ctx context.Context, id string) error LeaderboardList(limit int, cursor string) (*api.LeaderboardList, error) + LeaderboardRanksDisable(ctx context.Context, id string) error LeaderboardRecordsList(ctx context.Context, id string, ownerIDs []string, limit int, cursor string, expiry int64) (records []*api.LeaderboardRecord, ownerRecords []*api.LeaderboardRecord, nextCursor string, prevCursor string, err error) LeaderboardRecordsListCursorFromRank(id string, rank, overrideExpiry int64) (string, error) LeaderboardRecordWrite(ctx context.Context, id, ownerID, username string, score, subscore int64, metadata map[string]interface{}, overrideOperator *int) (*api.LeaderboardRecord, error) @@ -1141,12 +1144,13 @@ type NakamaModule interface { SubscriptionsList(ctx context.Context, userID string, limit int, cursor string) (*api.SubscriptionList, error) SubscriptionGetByProductId(ctx context.Context, userID, productID string) (*api.ValidatedSubscription, error) - TournamentCreate(ctx context.Context, id string, authoritative bool, sortOrder, operator, resetSchedule string, metadata map[string]interface{}, title, description string, category, startTime, endTime, duration, maxSize, maxNumScore int, joinRequired bool) error + TournamentCreate(ctx context.Context, id string, authoritative bool, sortOrder, operator, resetSchedule string, metadata map[string]interface{}, title, description string, category, startTime, endTime, duration, maxSize, maxNumScore int, joinRequired, enableRanks bool) error TournamentDelete(ctx context.Context, id string) error TournamentAddAttempt(ctx context.Context, id, ownerID string, count int) error TournamentJoin(ctx context.Context, id, ownerID, username string) error TournamentsGetId(ctx context.Context, tournamentIDs []string) ([]*api.Tournament, error) TournamentList(ctx context.Context, categoryStart, categoryEnd, startTime, endTime, limit int, cursor string) (*api.TournamentList, error) + TournamentRanksDisable(ctx context.Context, id string) error TournamentRecordsList(ctx context.Context, tournamentId string, ownerIDs []string, limit int, cursor string, overrideExpiry int64) (records []*api.LeaderboardRecord, ownerRecords []*api.LeaderboardRecord, prevCursor string, nextCursor string, err error) TournamentRecordWrite(ctx context.Context, id, ownerID, username string, score, subscore int64, metadata map[string]interface{}, operatorOverride *int) (*api.LeaderboardRecord, error) TournamentRecordDelete(ctx context.Context, id, ownerID string) error