Skip to content

Commit

Permalink
Add enableRanks option to leaderboards. (#154)
Browse files Browse the repository at this point in the history
Add runtime function to disable ranks on an active leaderboard.
  • Loading branch information
sesposito authored Jul 23, 2024
1 parent 2d134b5 commit b530f4e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 6 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -4235,6 +4236,7 @@ declare namespace nkruntime {
operator?: Operator,
resetSchedule?: null | string,
metadata?: {[key: string]: any} | null,
enableRank?: boolean,
): void;

/**
Expand Down Expand Up @@ -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).
Expand All @@ -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(
Expand All @@ -4362,6 +4365,7 @@ declare namespace nkruntime {
maxSize?: number | null,
maxNumScore?: number | null,
joinRequired?: boolean,
enableRank?: boolean,
): void;

/**
Expand Down
8 changes: 6 additions & 2 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit b530f4e

Please sign in to comment.