Enka Network API Reference

website·Indexed 30 days ago

https://enka-network-api.vercel.app/

API documentation for Enka Network, featuring classes and interfaces for Genshin Impact data such as GenshinUser, ICharacter, IWeapon, and IArtifact. Includes the EnkaClient for managing user data, cache options, and utility functions for character and skill attribute resolution.

Tokens
25.4K
Snippets
213
Records
285
Agent score
75%

What's inside Enka Network API

  1. Overview of Enka Network API package capabilities

    The Enka Network API package provides a simplified way to access Genshin Impact data without requiring manual asset ID lookups. It supports retrieving detailed lists of game objects, including characters, weapons, and player profiles, featuring comprehensive skill data and weapon capabilities. The package is designed for developer productivity with built-in support for auto-completion in intelligent editors like VSCode.
  2. Use the IGOOD interface for item data

    The IGOOD interface defines the structure for item-related data in the API. It inherits from IGOODComponent and contains metadata about the source and version, as well as optional collections of game assets like artifacts, characters, materials, and weapons.
    interface IGOOD extends IGOODComponent {
      format: GOOD;
      source: string;
      version: number;
      artifacts?: IArtifact[];
      characters?: ICharacter[];
      materials?: Record<string, number>;
      weapons?: IWeapon[];
    }
  3. DetailedGenshinUser class overview

    The DetailedGenshinUser class extends GenshinUser and implements the IGOODComponentResolvable<IGOOD> interface. It is used to represent a detailed profile of a Genshin Impact user, providing access to achievements, characters, and profile settings.
  4. ArtifactSplitSubstat class overview

    The ArtifactSplitSubstat class extends StatProperty and is used to represent and manage individual artifact substats. It provides utilities for calculating values, handling percentage-based stats, and retrieving associated text assets via an EnkaClient.
  5. IArtifact Interface Definition

    The IArtifact interface extends IGOODComponent and represents an artifact object. It contains metadata about the artifact's level, rarity, location, and its statistical properties including main stats and substats.
    interface IArtifact extends IGOODComponent {
      level: number;
      location: string;
      lock: boolean;
      mainStatKey: StatKey;
      rarity: number;
      setKey: string;
      slotKey: SlotKey;
      substats: ISubstat[];
      astralMark?: boolean;
      elixirCrafted?: boolean;
      totalRolls?: number;
      unactivatedSubstats?: ISubstat[];
    }
  6. Use DynamicTextAssets to resolve text placeholders

    The DynamicTextAssets class is used for text assets containing placeholders. Use getReplacedText() to resolve these placeholders based on the user information provided in the EnkaClient configuration.
    const enka = new EnkaClient({
        defaultLanguage: "en",
        textAssetsDynamicData: {
            userInfo: {
                travelerGender: "FEMALE", // Lumine
                travelerNickname: "nickname",
                platform: "PC",
            }
        }
    });
    
    // Assuming dynamicTextAssets is an instance of DynamicTextAssets
    // Original: "#Hello {M:Mr}{F:Ms}.{NICKNAME}. {LAYOUT_MOBILE#Tap}{LAYOUT_PC#Press}{LAYOUT_PS#Press} the button."
    
    dynamicTextAssets.get();
    // Returns the raw string with placeholders
    
    dynamicTextAssets.getReplacedText();
    // Returns: "Hello Ms.nickname. Press the button."
    
    dynamicTextAssets.copyWithUserInfo({
        travelerGender: "MALE", // Aether
        travelerNickname: "Tom",
        platform: "MOBILE",
    }).getReplacedText();
    // Returns: "Hello Mr.Tom. Tap the button."
  7. Instantiate CharacterData

    The CharacterData class is used to manage and access character-specific information. It requires a data object and an instance of EnkaClient for initialization.
    const character = new CharacterData(data, enkaClient, optionalSkillDepotId);
  8. Download and update game cache assets

    The CachedAssetsManager provides several methods to maintain the local game data cache:

    • checkForUpdates(): Checks if the local cache needs updating.
    • updateContents(): Updates the cache contents.
    • fetchAllContents(): Ensures all required contents are downloaded.
    • refreshAllData(): Refreshes all cached data.
    • cacheDirectorySetup(): Sets up the directory for the cache.
  9. Install enka-network-api

    Install the enka-network-api package using npm. Node.js 16 or newer is required. You can choose to install with or without the Genshin cache data, or use a proxy for the cache download.
    # Standard installation including cache data
    npm install enka-network-api@latest
    
    # Install using ghproxy.com for cache data
    npm install enka-network-api@latest --enka-ghproxy=true
    
    # Install without downloading the cache (use if cache is already moved to another folder)
    npm install enka-network-api@latest --enka-nocache=true