BrandonCookeDev / smashgg-promise

No-dependency Javascript distribution offering a Promise library wrapping around Smash.gg's public API
https://www.npmjs.com/package/smashgg-promise
1 stars 0 forks source link
javascript promise smashgg tournament

smashgg-promise

Author: Brandon Cooke & Jarrod Blanton

smashgg-promise is an alternative to the smash.gg library. Smashgg-Promise provides Promise functionality to the created smashgg object, and is usable on browsers.

Version

Requirements

Installation

Issues

Contents

Example

smashgg.getTournament('to12')
    .then(to12 => {
        to12.getAllPlayers()
        .then(players => {
            var playerCount = players.length;
            console.log(`${playerCount} players entered Tipped Off 12`);
            // Log basic info about every player
            players.forEach(player => {
                console.log(
                    'Name: ' + player.getName() + '\n',
                    'Tag: ' + player.getTag() + '\n',
                    'State: ' + player.getState() + '\n'
                );
            })
        })
        .catch(err => console.error(err));

        to12.getAllMatches()
            .then(matches => {
                console.log(`${sets.length} total matches were played at Tipped Off 12`);
                matches.forEach(match => {
                    console.log(
                        // Get score
                        `[${match.getRound() + ': ' + match.getWinner().getTag() + ' ' + match.getWinnerScore() + ' - ' + match.getLoserScore() + ' ' + match.getLoser().getTag()}] \n`,
                        // Get winner final placement
                        `${match.getWinner().getTag()} placed  ${match.getWinner().getFinalPlacement()} \n`,
                        // Get loser final placement
                        `${match.getLoser().getTag()} placed ${match.getLoser().getFinalPlacement()} \n`
                    );
                })
            })
            .catch(err => console.error(err));
    })
.catch(error => {
    console.error('An error occurred: ', error);
})
Output
370 players entered Tipped Off 12

Name: Grayson Garrett
 Tag: Gas$
 State: GA

Name: Austin Crews
 Tag: Gladiator
 State: GA

Name: Davis Robertson
 Tag: NIX
 State: SC

.... continues ....

1393 total matches were played at Tipped Off 12

[Winners Round 1: Cloud-9 0 - -1 T] 
 Cloud-9 placed  97 
 T placed 129 

[Winners Round 1: DarkGenex 2 - 0 TheGromm] 
 DarkGenex placed  65 
 TheGromm placed 193 

[Winners Round 1: Gas$ 2 - 0 Ghost] 
 Gas$ placed  49 
 Ghost placed 129 

.... continues ....

Docs

Tournament

A Tournament in smash-promise is a collection of Events, Phases, and Phases Groups that categorize different games played, game types within those games, and the matches that make up those games.

smashgg.getTournament('to12')
    .then(to12 => {
        // Do stuff with tournament
    })
    .catch(e => console.error(e));

Constructor

Methods

Promises

Getters

Event

An Event in smash-promise is a broad collection of matches for a single game and game type. For instance, Melee Singles is an Event while Melee Doubles is another Event. Events are comprised of optional Phases and Phases Groups.

smashgg.getEvent('to12', 'melee-singles')
    .then(to12event => { 
        to12event.getEventPhases().then(phases => {
            // Do stuff with event phases
        })
        .catch(e => console.error(e));
    })
    .catch(e => console.error(e));

Constructor

Methods

Promises

Getters

Phase

A phase in smash-promise is a subset of matches and brackets inside an Event. For example, a wave in pools is a Phase. Everything in that Phase is a Group (or Phase Group).

smashgg.getPhase(100046)
    .then(to12phase => {
        var info = [
            {
                key: 'Name',
                value: to12phase.getName()
            },
            {
                key: 'EventId',
                value: to12phase.getEventId()
            }
        ]
    })
    .catch(e => console.error(e))

Constructor

Methods

Promises

Getters

PhaseGroup

A Phase Group is the lowest unit on smash.gg. It is a bracket of some sort that belongs to a Phase.

smashgg.getPhaseGroup(301994)
    .then(to12phasegroup => {
        // Do stuff with phase group
    })
    .catch(e => console.error(e));

Constructor

Methods

Promises

Getters

Match

A Match is a data object that holds information about a tournament set that took place at a tournament. The keyword Match is used in order to prevent accidental overriding of the native Set class.

smashgg.getTournament('to12')
    .then(to12 => {
        to12.getAllMatches()
            .then(matches => {
                // Do stuff with matches
            })
            .catch(e => console.error(e));
    })
    .catch(e => console.error(e))

Constructor

Properties

Methods

Getters

Player

A Player is a data object that holds information about players who went to a tournament using smash.gg.

smashgg.getTournament('to12')
    .then(to12 => {
        to12.getAllPlayers()
            .then(players => {
                // Do stuff with players
            })
            .catch(e => console.error(e))
    })
    .catch(e => console.error(e));

Constructor

Properties

Methods

Statics

Getters