Giter Club home page Giter Club logo

starrail.js's Introduction

StarRail.js

StarRail.js

npm version npm downloads

About

A Node.js Enka.Network API wrapper for Honkai: Star Rail.

Features

  • User Data and Character Stats by UID with Enka.Network API (or with MiHoMo API).
  • All Characters and All Light Cones Data.
  • Cache Updater for the new update of Honkai: Star Rail. (Update characters and light cones immediately.)

Installation

Node.js 16 or newer is required.

Install starrail.js including Star Rail cache data.

npm install starrail.js@latest
Install using ghproxy.com
npm install starrail.js@latest --sr-ghproxy=true

If you have already moved the cache to another folder, you can also install without downloading the cache.

npm install starrail.js@latest --sr-nocache=true

About Star Rail Cache Data

Star Rail cache data is from Dimbreath/StarRailData

This data contains data of characters, light cones, materials, and more structure information of Star Rail.

You can change your cache directory.

const { StarRail } = require("starrail.js");

// Change the directory to store cache data.
// Default directory is node_modules/starrail.js/cache.
const client = new StarRail();
client.cachedAssetsManager.cacheDirectoryPath = "./cache";
client.cachedAssetsManager.cacheDirectorySetup();

// OR

const client = new StarRail({ cacheDirectory: "./cache" });
client.cachedAssetsManager.cacheDirectorySetup();

Updating

You can update your Star Rail cache data.

const { StarRail } = require("starrail.js");
const client = new StarRail({ showFetchCacheLog: true }); // showFetchCacheLog is true by default

client.cachedAssetsManager.fetchAllContents(); // returns promise

Also, you can activate auto cache updater.

When using the auto-cache updater, we recommend moving the cache directory directly under your project folder.

const { StarRail } = require("starrail.js");
const client = new StarRail();

client.cachedAssetsManager.activateAutoCacheUpdater({
    instant: true, // Run the first update check immediately
    timeout: 60 * 60 * 1000, // 1 hour interval
    onUpdateStart: async () => {
        console.log("Updating Star Rail Data...");
    },
    onUpdateEnd: async () => {
        client.cachedAssetsManager.refreshAllData(); // Refresh memory
        console.log("Updating Completed!");
    }
});

// // deactivate
// client.cachedAssetsManager.deactivateAutoCacheUpdater();

Where is the image file for ImageAssets?

As far as I know, there are few cdns for starrail. So, this library cannot provide urls of some images and ImageAssets#url is often unavailable. But you can extract image files from StarRail Game Data with HoyoStudio or something else.

If you would like ImageAssets#url to show the paths to your extracted images, you can use imageBaseUrls option.

const { StarRail } = require("starrail.js");
const client = new StarRail();

client.options.imageBaseUrls.push(
    {
        regexList: [/.*/], // for all images
        /*  
          "LOWER_CASE" if the names of folders in your extracted directory are in lowercase. e.g. "spriteoutput/itemicon/relicicons/IconRelic_101_1.png"
          "UPPER_CAMEL_CASE" if the names of folders in your extracted directory are in upper camel case. e.g. "SpriteOutput/ItemIcon/RelicIcons/IconRelic_101_1.png"
          "NONE" if your extracted files are not grouped in folders. e.g. "IconRelic_101_1.png"
        */
        filePath: "LOWER_CASE",
        priority: 10,
        url: "Your directory path to assets/asbres", // path to directory of extracted files
    }
);

How to use

Fetching Player Data

StarRail#fetchUser

const { StarRail } = require("starrail.js");
const client = new StarRail();

client.fetchUser(800069903).then(user => {
  console.log(user);
});

Star Rail Character List

StarRail#getAllCharacters

const { StarRail } = require("starrail.js");
const client = new StarRail();

const characters = client.getAllCharacters();
// print character names in language "en"
console.log(characters.map(c => c.name.get("en")));

Star Rail Light Cone List

StarRail#getAllLightCones

const { StarRail } = require("starrail.js");
const client = new StarRail();

const lightCones = client.getAllLightCones();
// print light cone names in language "jp"
console.log(lightCones.map(w => w.name.get("jp")));

More examples are available in example folder.

For more information, please check Documentation.

You can see the changelog here.

starrail.js's People

Contributors

dependabot[bot] avatar yuko1101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

starrail.js's Issues

[Request] Allow to export json files

When using this library, I often run into out of memory problem. It would be better if the data can be exported into a json file for convenient uses, instead of reading the gigantic raw files everytime I need the data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.