npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ygocore

v0.3.4

Published

[WIP] bindings for ygocore (https://github.com/Fluorohydride/ygopro-core)

Downloads

160

Readme

node-ygocore

WIP node bindings for ygopro-core (the OCG script engine)

NOTE This is not Ygopro the game!!!

Install

npm install ygocore

How to use

To use this package, you need to know how ocgcore works.

Note

I'm not the author/contributer of ygopro, if my understandings on ocgcore's API are not correct, please fire me an issue. Thanks!

import { engine } from 'ygopro';

this project is writen in Typescript, each method is type-annotated.

Prepare a duel

create a duel instance

ocgapi: create_duel()

const duel = engine.createDuel(/* any random seed */ 0);

set duelist's LP/cards to draw

ocgapi: set_player_info()

engine.setPlayerInfo(duel, { /* ... */ });

add card to the field

ocgapi: new_card()

engine.newCard(duel, { /* ... */ });

Duel!

start the duel

ocgapi: start_duel()

engine.startDuel(duel, options);

process for one step

ocgapi: process(), get_message()

const { flags, data } = engine.process(duel);

data is a buffer (of type Buffer) contains messages returned from ocgcore, to deserialize it, you can use ygocore-interface's parseMessage (see below)

write player's response

ocgapi: set_responsei(), set_responseb()

engine.setResponse(duel, response);

End the duel

ocgapi: end_duel()

engine.endDuel(duel);

Query the game field

query cards by location

ocgapi: query_field_card

const data = engine.queryFieldCard(duel, { /* player, location, ... */ });

Again, to deserialize the message, you can use ygocore-interface's parseFieldCardQueryResult.

query single card

ocgapi: query_card

const data = engine.queryCard(duel, { /* player, location, sequence, ... */ });

Again and again, to deserialize the message, you can use ygocore-interface's parseCardQueryResult.

query card count

ocgapi: query_field_count

const howManyCards = engine.queryFieldCount(duel, { /* ... */ });

ygocore-interface

const { parseMessage } from 'ygocore-interface';

const messages = parseMessage(data /* from engine.process */);

for (const message of messages) {
  if (message.msgtype == 'MSG_SELECT_IDLECMD') {
    // message is not of type 'MsgSelectIdlecmd'
    // handle MsgSelectIdlecmd here.

    // refresh M zone:
    const mzone = parseFieldCardQueryResult(engine.queryFieldCard(duel, {
      player, location, queryFlags, useCache
    });

    for (const card of mzone) {
      // play with card...
      // type card.
      //          ^
      //          |
      //      nice code completion!
    }
  }

  // handle other messages here.
}

Constants in common.h are also exported:

import { LOCATION, QUERY } from 'ygocore-interface';

/* .... */

const location = LOCATION.HAND;
const queryFlags = /* ... + ... + */ QUERY.LSCALE + QUERY.RSCALE + QUERY.STATUS;
const hand = parseFieldCardQueryResult(engine.queryFieldCard(duel, {
  player, location, queryFlags, useCache
});