Giter VIP home page Giter VIP logo

knowdev-splinterlib's Introduction

Splinterlib ๐Ÿ”ฎ

Helper library for Splinterlands APIs

โ„น๏ธ What is Splinterlands?

Splinterlands is a digital NFT collectable card game that runs on the Hive blockchain. Its a lot like Magic the Gathering. What makes an NFT/blockchain game different is "true player ownership" of assets. In other words you can buy, sell, trade, or rent any of your assets with other players.

๐Ÿ“‹ Usage

Install

npm install --save @knowdev/splinterlib

Require

const Splinterlib = require("@knowdev/splinterlib");

See "Reference" (below) for a detailed API

Enable Logging

Requires a separate package which is already installed as a dependency

npm install --save @knowdev/log
const log = require("@knowdev/log");

Splinterlib.setLogger(log);

๐Ÿ“– Reference

Wrapped Functions ๐Ÿช„

More convenient set of functions that interact with the underlying API

Async Battle History Iterator

/** Returns asyncIterator (see below) */
const battleHistory = await Splinterlib.battleHistoryAsyncIterator(
  player,         // Required string
  {
    beforeBlock,  // Optional integer, starting Hive block to retrieve backwards from (defaults to current block)
    filter,       // Optional function returning true or false as to whether to include this battle in results (see "Battle Filter" below)
    limit,        // Optional integer, number of results per API call
    max,          // Optional integer, maximum results to return
    resultsClass, // Optional class, used to instantiate each result
  }
)

for await (const battle of battleHistory) {
  //
}

Helper Functions ๐Ÿ’

Battle Filter

/** Returns function */
const filter = Splinterlib.battleFilter({
  format,           // Optional string, from BATTLE.FORMAT constant (below)
  ignoreSurrender,  // Optional boolean, default true
  league,           // Optional string, from LEAGUE constant (below)
  loser,            // Optional string, losing player
  mana,             // Optional integer, mana cap of match
  manaPlusMinus,    // Optional integer, range around mana to include, default 0
  ruleset,          // Optional array, from RULESET constant (below)
  rulesetAnd,       // Optional boolean, require all rulesets, default false
  splinter,         // Optional array, from SPLINTER constant (below)
  winner,           // Optional string, winning player
})

Card Collection Filter

/** Returns function */
const filter = Splinterlib.cardCollectionFilter({
  ability,          // Optional string or array of strings from ALL.ABILITIES (below)
  abilityAnd,       // Optional boolean, whether to require all passed abilities (default false)
  edition,          // Optional string or array of strings ("or" search), from ALL.CARD.EDITIONS (below)
  format,           // Optional string or array of strings ("and" search), from ALL.BATTLE.FORMATS constant (below)
  mana,             // Optional integer, mana of card; see below for more options
  name,             // Optional string, match beginning of words in card name
  nameMatchAny,     // Optional boolean, match anywhere in name (default false)
  rarity,           // Optional string or array of strings ("or" search), from ALL.CARD.RARITIES (below)
  splinter,         // Optional array or array of strings ("or" search), from ALL.SPLINTERS (below)
  type,             // Optional string, from ALL.CARD.TYPES (below)
});

const manaFilter = Splinterlib.cardCollectionFilter({
  mana: {
    [FILTER.GREATER_THAN_OR_EQUAL]: 3,
    [FILTER.LESS_THAN_OR_EQUAL]: 6,
  }
}).

Collections ๐Ÿ—‚

Card Universe

Uses a cached version of card details unless process.env.SPLINTERLIB_FETCH or process.env.SPLINTERLIB_FETCH_CARDS is true.

const cardArray = Splinterlib.cardUniverse.all();

const card = Splinterlib.cardUniverse.getTemplate(12);

// Pull fresh copy of card database from server
const cardArray = await Splinterlib.cardUniverse.refresh();

// Pull fresh copy of card database from QA server
const cardArray = await Splinterlib.cardUniverse.refresh({ qa: true });

Player Cards

TBD: card instances?

Site Settings

TBD

Models ๐Ÿงฑ

Battle (model)

An instance of a particular battle that was waged or fled.

battle.createdDate;
battle.id;
battle.manaCap;
battle.winner;
battle.loser;
battle.rulesets;
battle.type;
battle.players;
battle.teams;
battle.formats;

Card Instance

Full characteristics about this particular instance of the card. In addition to template attributes this would include level, foil, alpha/beta edition.

Card Template

Partial characteristics about the card regardless of it's particular instance. E.g., type, splinter.

const card = Splinterlib.cardUniverse.getTemplate(12);

card.id = 12;
card.name = "Pirate Captain";
card.splinter = SPLINTER.WATER;
card.type = CARD.TYPE.MONSTER;
card.rarity = CARD.RARITY.COMMON;
card.isStarter = true;
card.edition = CARD.EDITION.ALPHA_BETA;
card.formats = [
  BATTLE.FORMAT.ALPHA,
  BATTLE.FORMAT.ALPHA_BETA,
  BATTLE.FORMAT.NO_LEGENDARIES,
  BATTLE.FORMAT.NO_LEGENDARY_SUMMONERS,
  BATTLE.FORMAT.WILD,
];

Direct API ๐ŸŒ

Direct implementations of the Splinterlands API with minimal parsing of encoded types

Battle History

/** Returns array of result objects */
const results = await Splinterlib.battleHistoryApi(
  player,         // Required string
  {
    beforeBlock,  // Optional integer, starting Hive block to retrieve backwards from (defaults to current block)
    limit,        // Optional integer, number of results (default 50)
    raw,          // Optional boolean, skip parsing encoded objects and dates in results (default false)
    types,        // Advanced: optional string, defaults to "sm_battle,battle"
    queryParams,  // Advanced: optional object of additional parameters to pass to endpoint
  }
);

Card Details

/** Returns array of card details */
const results = await Splinterlib.cardDetailsApi();

Constants ๐Ÿ’ฌ

const {
  ALL,
  BATTLE,
  CARD,
  LEAGUE,
  RULESET,
  SPLINTER,
} = require("@knowdev/splinterlib");

ALL

  • ALL.ABILITIES
  • ALL.BATTLE.FORMATS
  • ALL.CARD.EDITIONS
  • ALL.CARD.RARITIES
  • ALL.CARD.TYPES
  • ALL.SPLINTERS

BATTLE (constant)

  • BATTLE.FORMAT
    • BATTLE.FORMAT.ALPHA
    • BATTLE.FORMAT.ALPHA_BETA
    • BATTLE.FORMAT.GOLD
    • BATTLE.FORMAT.MODERN
    • BATTLE.FORMAT.NO_LEGENDARIES
    • BATTLE.FORMAT.NO_LEGENDARY_SUMMONERS
    • BATTLE.FORMAT.UNTAMED
    • BATTLE.FORMAT.UNTAMED_DICE
    • BATTLE.FORMAT.WILD
  • BATTLE.TYPE
    • BATTLE.TYPE.BRAWL
    • BATTLE.TYPE.RANKED
    • BATTLE.TYPE.SURRENDER
    • BATTLE.TYPE.TOURNAMENT

CARD

  • CARD.EDITION
    • CARD.EDITION.ALPHA
    • CARD.EDITION.ALPHA_BETA (interpreted to mean cards from alpha or beta)
    • CARD.EDITION.BETA
    • CARD.EDITION.PROMO
    • CARD.EDITION.REWARD
    • CARD.EDITION.UNTAMED
    • CARD.EDITION.DICE
    • CARD.EDITION.GLADIUS
  • CARD.RARITY
    • CARD.RARITY.COMMON
    • CARD.RARITY.RARE
    • CARD.RARITY.EPIC
    • CARD.RARITY.LEGENDARY
  • CARD.TYPE
    • CARD.TYPE.MONSTER
    • CARD.TYPE.SUMMONER

FILTER

  • FILTER.EQUALS
  • FILTER.LESS_THAN
  • FILTER.LESS_THAN_OR_EQUAL
  • FILTER.GREATER_THAN
  • FILTER.GREATER_THAN_OR_EQUAL

LEAGUE

  • LEAGUE.NOVICE
  • LEAGUE.BRONZE
  • LEAGUE.SILVER
  • LEAGUE.GOLD
  • LEAGUE.DIAMOND
  • LEAGUE.CHAMPION
LEAGUE.SUMMONER_CAPS

Each key contains an object with COMMON, RARE, EPIC, and LEGENDARY

  • LEAGUE.SUMMONER_CAPS.NOVICE
  • LEAGUE.SUMMONER_CAPS.BRONZE
  • LEAGUE.SUMMONER_CAPS.SILVER
  • LEAGUE.SUMMONER_CAPS.GOLD
  • LEAGUE.SUMMONER_CAPS.DIAMOND
  • LEAGUE.SUMMONER_CAPS.CHAMPION

RULESET

  • RULESET.AIM_TRUE
  • RULESET.ARMORED_UP
  • RULESET.BACK_TO_BASICS
  • RULESET.BROKEN_ARROWS
  • RULESET.CLOSE_RANGE
  • RULESET.EARTHQUAKE
  • RULESET.EQUAL_OPPORTUNITY
  • RULESET.EQUALIZER
  • RULESET.EVEN_STEVENS
  • RULESET.EXPLOSIVE_WEAPONRY
  • RULESET.FOG_OF_WAR
  • RULESET.HEALED_OUT
  • RULESET.HEAVY_HITTERS
  • RULESET.HOLY_PROTECTION
  • RULESET.KEEP_YOUR_DISTANCE
  • RULESET.LITTLE_LEAGUE
  • RULESET.LOST_LEGENDARIES
  • RULESET.LOST_MAGIC
  • RULESET.MELEE_MAYHEM
  • RULESET.NOXIOUS_FUMES
  • RULESET.ODD_ONES_OUT
  • RULESET.REVERSE_SPEED
  • RULESET.RISE_OF_THE_COMMONS
  • RULESET.SILENCED_SUMMONERS
  • RULESET.SPREADING_FURY
  • RULESET.STAMPEDE
  • RULESET.STANDARD
  • RULESET.SUPER_SNEAK
  • RULESET.TAKING_SIDES
  • RULESET.TARGET_PRACTICE
  • RULESET.UNPROTECTED
  • RULESET.UP_CLOSE_AND_PERSONAL
  • RULESET.WEAK_MAGIC

SPLINTER

  • SPLINTER.DEATH
  • SPLINTER.DRAGON
  • SPLINTER.EARTH
  • SPLINTER.FIRE
  • SPLINTER.LIFE
  • SPLINTER.WATER

๐Ÿš€ Deployment

npm publish --access=public

๐Ÿ“ Changelog

  • 0.6.6: Fix bug on modern reward definition
  • 0.6.5: Filter on multiple formats
  • 0.6.4: Export cardCollectionFilter
  • 0.6.3: Card universe returns abilities(), initial Chaos Legion support
  • 0.6.2: Expand ALL constant, allow refresh against QA server
  • 0.6.0: Card collection filtering
  • 0.5.0: Breaking change: rename cardUniverse get to getTemplate ๐Ÿ’ฅ
  • 0.4.0: Breaking change: rename parameters ๐Ÿ’ฅ
  • 0.3.0: Battle filter
  • 0.2.1: Constants
  • 0.2.0: Battle history iterator
  • 0.1.0: Battle history API

๐Ÿ›ฃ Roadmap

  1. Card Universe: Filtering
  2. Interactive Demo of Card Universe
  3. Player Collection: Filtering
  4. Interactive Demo of Player Collections

Task List โ˜‘๏ธ

  • Card Template
    • Card images
      • Crop
    • ...Filter abilities/stats by league caps
  • Card Universe
    • ...Card Sort
      • Stats
    • Card filter
      • Limit to league cap
  • Player collection
    • Card instances
      • Abilities
      • Stats
    • Card filter
  • Battle Summary
    • Mana
    • Rulesets
    • Available splinters
    • Monster
      • Damage
        • Blocked
        • Kills
      • Taken
      • Move (position)
        • Count
      • Killed (round)
        • Position
  • Interactive Demo
    • Card universe
    • Player collection
    • Battle history

Wishlist ๐ŸŒ 

All of the APIs! โšก๏ธ๐Ÿง™โ€โ™‚๏ธโšก๏ธ

  • ๐Ÿ”ฎ Active quest
  • ๐Ÿ›ก Follow
  • ๐Ÿ›ก Report

๐Ÿ“œ License

All rights reserved. Safe for use around pets.

knowdev-splinterlib's People

Contributors

nullfame avatar

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.