UNPKG

@cruncheevos/core

Version:

Parse and generate achievements and leaderboards for RetroAchievements.org

166 lines (165 loc) 6.17 kB
import { Achievement } from './achievement.js'; import { Leaderboard } from './leaderboard.js'; import { PartialByKey } from './util.js'; export declare namespace AchievementSet { type AchievementInput = PartialByKey<Achievement.InputObject, 'id'> | string; type LeaderboardInput = PartialByKey<Leaderboard.InputObject, 'id'> | string; interface Input { gameId: number | string; title: string; } } /** * This class represents AchievementSet that can be converted into * RACache/Data/GameId-User.txt file * * AchievementSet is mostly to be used with standalone scripts that export it * for `@cruncheevos/cli` to update local file in RACache. */ export declare class AchievementSet { /** * Game ID matching the one on RetroAchievement servers, * must be set correctly if using this class with @cruncheevos/cli */ gameId: number; /** * Game title or name, it doesn't have to be exact match and * is merely put on the second line of produced local file. */ title: string; /** * Object containing all added achievements, with achievement id as a key. * Treat it as read-only unless you know better. * * Also implements Symbol.iterator which yields each Achievement stored. * * @alias \{ [id: string]: Achievement \} */ achievements: Record<string, Achievement> & Iterable<Achievement>; /** * Object containing all added leaderboards, with leaderboard id as a key. * Treat it as read-only unless you know better. * * Also implements Symbol.iterator which yields each Leaderboard stored. * * @alias \{ [id: string]: Leaderboard \} */ leaderboards: Record<string, Leaderboard> & Iterable<Leaderboard>; /** * Creates AchievementSet. * * @example * new AchievementSet({ gameId: 1234, title: 'Funny Game' }) */ constructor(opts: AchievementSet.Input); /** * Adds Achievement to the set, accepts same data as {@link Achievement} class constructor, * but you're allowed to omit id when passing an object (id will be assigned automatically, similar to how RAIntegration does it). * * Also returns current AchievementSet instance, allowing you to chain calls. * * @example * import { AchievementSet, define as $ } from '@cruncheevos/core' * * const set = new AchievementSet({ gameId: 1234, title: 'Funny Game' }) * * set.addAchievement({ * id: 58, // optional, or numeric string * title: 'My Achievement', * description: 'Do something funny', * points: 5, * badge: `local\\\\my_achievement.png`, // optional, or ID of badge on server * author: 'peepy', // optional and is not uploaded to server * conditions: { * 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' * } * }).addAchievement(...) */ addAchievement(def: AchievementSet.AchievementInput | Achievement): this; /** * Adds Leaderboard to the set, accepts same data as {@link Leaderboard} class constructor, * but you're allowed to omit id when passing an object (id will be assigned automatically, similar to how RAIntegration does it). * * Also returns current AchievementSet instance, allowing you to chain calls. * * @example * import { AchievementSet, define as $ } from '@cruncheevos/core' * * const set = new AchievementSet({ gameId: 1234, title: 'Funny Game' }) * * set.addLeaderboard({ * id: 58, // optional, or numeric string * 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]], * }, * }).addLeaderboard(...) */ addLeaderboard(def: AchievementSet.LeaderboardInput | Leaderboard): this; /** * Allows to iterate the whole set for both achievements and leaderboards. * * @example * for (const asset of achSet) { * if (asset instanceof Achievement) { * // ... * } * if (asset instanceof Leaderboard) { * // ... * } * } */ [Symbol.iterator](): Generator<Leaderboard | Achievement, void, unknown>; /** * Returns string representation of AchievementSet suitable for * `RACache/Data/GameId-User.txt` file. * * First line is version, always set to 1.0, second line is game's title. * Then come string representations of achievements and leaderboards, * each sorted by id. * * @example * new AchievementSet({ gameId: 1234, title: 'Funny Game' }) * .addAchievement(...) * .addAchievement(...) * .addLeaderboard(...) * .addLeaderboard(...) * .toString() * // may result in: * ` * 1.0 * Funny Game * 57:"0x cafe=102":Ach2:Desc2::::cruncheevos:2:::::00000 * 111000001:"0x cafe=101":Ach1:Desc1::::cruncheevos:1:::::00000 * L58:"0x cafe=102":"0=1":"1=1":"M:0x feed":FRAMES:Lb2:Desc2:1 * L111000001:"0x cafe=101":"0=1":"1=1":"M:0x feed":SCORE:Lb1:Desc1:0 * ` */ toString(): string; }