@cruncheevos/core
Version:
Parse and generate achievements and leaderboards for RetroAchievements.org
148 lines (147 loc) • 5.98 kB
TypeScript
import { Condition } from './condition.js';
import { AssetData, DeepPartial } from './util.js';
export declare namespace Leaderboard {
type Type = 'SCORE' | 'TIME' | 'FRAMES' | 'MILLISECS' | 'SECS' | 'TIMESECS' | 'MINUTES' | 'SECS_AS_MINS' | 'VALUE' | 'UNSIGNED' | 'TENS' | 'HUNDREDS' | 'THOUSANDS' | 'FIXED1' | 'FIXED2' | 'FIXED3';
type InputConditions = LeaderboardConditions<Condition.GroupSet>;
interface InputObject extends LeaderboardCommon {
conditions: InputConditions | string;
}
type Input = InputObject | string;
}
interface LeaderboardConditions<Type> {
start: Type;
cancel: Type;
submit: Type;
value: Type;
}
interface LeaderboardCommon extends AssetData<string | number> {
/**
* Specifies how to interpret Leaderboard's value.
*
* Additional info [can be seen here](https://docs.retroachievements.org/developer-docs/leaderboards.html#value-format)
*/
type: Leaderboard.Type;
/**
* Self explanatory, affects how leaderboard results are displayed.
*/
lowerIsBetter: boolean;
conditions: LeaderboardConditions<Condition.GroupSet | Condition.GroupNormalized> | string;
}
interface LeaderboardData extends LeaderboardCommon {
id: number;
/**
* Object representing four condition groups that make up Leaderboard code.
*
* Each group is an array of arrays containing Condition class instances:
* * Outer array represents Condition groups like Core, Alt 1, Alt 2 ...
* * Inner array represents individual Conditions within the group
* * For `value` group, each outer array represents Value retrieval
* and Max of these values is taken
*
* @alias \{ start: Condition[][], cancel: Condition[][], submit: Condition[][], value: Condition[][] \}
*/
conditions: LeaderboardConditions<Condition.GroupNormalized>;
}
/**
* This class represents a leaderboard for RetroAchievements. Leaderboards can be a part of AchievementSet class instances, or used separately if your goal is to parse and produce string representations of leaderboard that would go into local RACache file.
*
* Leaderboard are immutable, if you need to a make a new Leaderboard instance based of existing one - use `with()` method.
*/
export declare class Leaderboard implements LeaderboardData {
id: number;
setId: number;
title: string;
description: string;
type: Leaderboard.Type;
lowerIsBetter: boolean;
conditions: LeaderboardConditions<Condition.GroupNormalized>;
/**
* Creates Leaderboard using object representing it.
*
* @example
* import { define as $ } from '@cruncheevos/core'
*
* new Leaderboard({
* id: 58, // or numeric string
* setId: 1024, // or numeric string, optional
* title: 'My Leaderboard',
* description: 'Best score while doing something funny',
* type: 'SCORE',
* lowerIsBetter: false,
* conditions: {
* start: {
* core: [
* ['', 'Mem', '8bit', 0x00fff0, '=', 'Value', '', 0],
* ['', 'Mem', '8bit', 0x00fffb, '=', 'Value', '', 0],
* ],
* alt1: $(
* ['', 'Mem', '8bit', 0x00fe10, '>', 'Delta', '8bit', 0x00fe10],
* ['', 'Mem', '8bit', 0x00fe11, '=', 'Value', '', 0],
* ),
* alt2: '0=1',
* },
* cancel: [
* ['', 'Mem', '16bit', 0x34684, '=', 'Value', '', 0x140]
* ], // same as providing an object: { core: [ ... ] }
* submit: '0xH59d76=2',
* value: [['Measured', 'Mem', '32bit', 0x34440, '*', 'Value', '', 2]],
* },
* })
*/
constructor(def: Leaderboard.InputObject);
/**
* Creates Leaderboard using string representing it, taken from `RACache/Data/GameId-User.txt` file.
*
* @example
* new Leaderboard(
* 'L58:"0xHfff0=1S":"0=1":"1=1":"M:0xX34440*2"' +
* ':SCORE:My Leaderboard:Best score while doing something funny:0'
* )
*
* new Leaderboard(
* 'L58|1024:"0xHfff0=1S":"0=1":"1=1":"M:0xX34440*2"' +
* ':SCORE:My Leaderboard:Best score while doing something funny:0'
* )
*/
constructor(def: string);
/**
* @ignore Stub definition to please TypeScript, this accepts all the previous types.
*/
constructor(def: Leaderboard.Input);
/**
* Returns new Leaderboard instance with different values merged.
*
* @param {DeepPartial<Leaderboard.InputObject>} data DeepPartial<Leaderboard.InputObject>
*
* @example
* someLeaderboard
* .with({ title: someLeaderboard.title + 'suffix' })
*/
with(data: DeepPartial<Leaderboard.InputObject>): Leaderboard;
/**
* Returns string representation of Leaderboard suitable
* for `RACache/Data/GameId-User.txt` file.
*
* @param desiredData optional parameter, set this to `'leaderboard'`,
* `'leaderboard-legacy'` or `'conditions'` to have corresponding string returned.
* `'leaderboard-legacy'` will omit `setId` from the output. Default option is `'leaderboard'`.
*
* @example
*
* someLeaderboard.toString()
* someLeaderboard.toString('leaderboard')
* // 'L58:"0xHfff0=1S":"0=1":"1=1":"M:0xX34440*2":SCORE:My Leaderboard:Best score while doing something funny:0'
*
* someLeaderboard.toString('conditions') // '"0xHfff0=1S":"0=1":"1=1":"M:0xX34440*2"'
*
* // if setId is set
* someLeaderboard.toString()
* someLeaderboard.toString('leaderboard')
* // 'L58|1024:"0xHfff0=1S":"0=1":"1=1":"M:0xX34440*2":SCORE:My Leaderboard:Best score while doing something funny:0'
*
* someLeaderboard.toString('leaderboard-legacy')
* // 'L58:"0xHfff0=1S":"0=1":"1=1":"M:0xX34440*2":SCORE:My Leaderboard:Best score while doing something funny:0'
*/
toString(desiredData?: 'leaderboard' | 'leaderboard-legacy' | 'conditions'): string;
}
export {};