UNPKG

@cruncheevos/core

Version:

Parse and generate achievements and leaderboards for RetroAchievements.org

146 lines (145 loc) 5.31 kB
import { Condition } from './condition.js'; import { AssetData, DeepPartial } from './util.js'; export declare namespace Achievement { type Type = '' | 'missable' | 'progression' | 'win_condition'; interface InputObject extends AchievementCommon { conditions: Condition.GroupSet | string; } type Input = InputObject | string; } interface AchievementCommon extends AssetData<string | number> { /** * Achievement's author name, it's not necessary and * is not sent to servers, but local RACache * files do mention the author. */ author?: string; /** * Amount of points that players will get when earning * the Achievement. Must be set to any positive integer or 0. * * Server accepts following values: 0, 1, 2, 3, 4, 5, 10, 25, 50, 100. * * Server may still have odd Achievements with incorrect point values, * which is the reason for allowing any positive integer for points. */ points: number; /** * Optional type of achievement, accepted strings are self-explanatory. * * Falsy values are treated as empty string, which marks no type set. */ type?: Achievement.Type; /** * Optional numeric string representing Achievement's badge ID on server. * * Alternatively, can be set to a string like `'local\\\\mybadge.png'`, which will be recognized by RAIntegration. */ badge?: string | number; conditions: Condition.GroupSet | Condition.GroupNormalized | string; } interface AchievementData extends AchievementCommon { id: number; badge?: string; /** * 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 */ conditions: Condition.GroupNormalized; } /** * This class represents an achievement for RetroAchievements. Achievement can be a part of AchievementSet class instance, or used separately if your goal is to parse and produce string representations of achievement that would go into local RACache file. * * Achievements are immutable, if you need to a make a new Achievement instance based of existing one - use `with()` method. */ export declare class Achievement implements AchievementData { id: number; title: string; description: string; author: string; points: number; type: Achievement.Type; badge: string; conditions: Condition.GroupNormalized; /** * Creates Achievement using object representing it. * * @example * import { define as $ } from '@cruncheevos/core' * * new Achievement({ * id: 58, // 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' * } * }) * * new Achievement({ * // ... * conditions: '0=1' * }) * * new Achievement({ * // ... * conditions: [ * ['', 'Mem', '8bit', 0x00fff0, '=', 'Value', '', 0], * ['', 'Mem', '8bit', 0x00fffb, '=', 'Value', '', 0], * ] // same as providing an object: { core: [ ... ] } * }) */ constructor(def: Achievement.InputObject); /** * Creates Achievement using string representing it, taken from `RACache/Data/GameId-User.txt` file. * * @example * new Achievement( * '58:"0xHfff0=0_0xHfffb=0S0xHfe10>d0xHfe10_0xHfe11=0S0=1"' + * ':My Achievement:Do something funny::::peepy:5:::::"local\\\\my_achievement.png"' * ) */ constructor(def: string); /** * @ignore Stub definition to please TypeScript, this accepts all the previous types. */ constructor(def: Achievement.Input); /** * Returns new Achievement instance with different values merged. * * @param {DeepPartial<Achievement.InputObject>} data DeepPartial<Achievement.InputObject> * * @example * someAchievement * .with({ title: someAchievement.title + 'suffix' }) */ with(data: DeepPartial<Achievement.InputObject>): Achievement; /** * Returns string representation of Achievement suitable * for `RACache/Data/GameId-User.txt` file. * * @param desiredData optional parameter, set this to `'achievement'` or `'conditions'` to have corresponding string returned. Default option is `'achievement'`. * * @example * * someAchievement.toString() * someAchievement.toString('achievement') * // '58:"0=1":My Achievement:Do something funny::::cruncheevos:5:::::00000' * * someAchievement.toString('conditions') // '0=1' */ toString(desiredData?: 'achievement' | 'conditions'): string; } export {};