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

cu-events

v0.1.8

Published

Camelot Unchained Client Library - Events

Downloads

10

Readme

cu-events

Camelot Unchained Client Library - Events


Notice: This library is currently under heavy development and is not guaranteed to be in a working state as this time. This notice will be removed when the library is stable.

Overview

Provides the ability to listen for changing data from the client, grouped by topic, with a one-to-one relationship with the handlesSomething flags from .ui files. So, if writing a UI that deals with character data, listen for 'character' events.

Installation

npm install git+https://github.com/Mehuge/cu-events.git#master

Example (JS)

var events = require('cu-events');
 events.on('character', function(data) {
    console.dir(data);
});

Example (TypeScript/ES6)

import events from 'cu-events';
events.on('enemytarget', (data: any) => {
    console.dir(data);
});

Event Groupings

Three event groups are currently defined:

character

Handles Character events which include information about

  • name
  • race
  • health
  • stamina

enemytarget

Handles Enemy Target events which include information about

  • name
  • health
  • stamina

friendlytarget

Handles Friendly Target events which include information about

  • name
  • health
  • stamina

controlgame

Handles information about the current control game (from /api/game/controlgame).

  • score
  • control points

controlgame-score

Handles the current games score and server population (from /api/game/controlgame and /api/game/players).

  • score
  • population counts

Planned Groupings

chat

Handle Chat Events (example)

  • Chat messages
  • Starting chat
  • Console messages

These grouping will likely be defined by the UIs that need a data store to monitor events. An event group doesn't necessarily have to be restricted to cuAPI.On* events, it could include polled data from REST APIs.

... TBA

Handles Flags

These are the handles flags currently supported by the client, many will include events and provide information that a UI might need. Some are to control behaviour.

Handles Flag | Event Group | State | Description ------------------------|-------------------|-------------|---------------- handlesAbilities | abilities | | handlesAnnouncements | announcements | | handlesBuilding | building | | handlesCharacter | character | implemented | health, stamina, race, name handlesChat | chat | | handlesBeginChat | chat | | handlesConsole | chat | | handlesConfig | config | | handlesEnemyTarget | enemytarget | implemented | health, stamina, name handlesEquippedGear | equippedgear | | handlesFriendlyTarget | friendlytarget | implemented | health, stamina, name handlesInput | | ignore | no associated events handlesInventory | inventory | | handlesLogging | logging | | handlesLogin | login | | handlesControlGame | controlgame | implemented | score, control points handlesControlGameScore | controlgame-score | implemented | score, population

Adding New Event Groups

Let us look at another possible grouping of events, the chat events. Unlike the character, enemytarget and friendlytarget events where having a single data structure passed for each triggering of the event, for chat events, it makes more sense to send different data depending on the type of event, so with that in mind, here is an example implementation of a chat event group Note: this is just an example

To add a new event group, such as handlesChat ('chat') follow these steps:

Step 1: Add a new class src/ts/classes/HandlesChat.ts with the following content:

export default class HandlesChat {
	name: string = 'chat';
}

Step 2: Add a new listener src/ts/listeners/Chat.ts with the following content. The basic pattern for a listener is

  • import EventEmitter
  • a run() function that does the actual listening / firing of events
  • an exported class with a start method (possibly also a stop method)
import EventEmitter from '../classes/EventEmitter';
function run(emitter : EventEmitter) {
	const info : any = {};
	cuAPI.OnChat((type: number, from: string, 
				body: string, nick: string, 
				iscse: boolean) => {
		info.type = 'chat';
		info.message = {
			type: type,
			from: from,
			body: body,
			nick: nick,
			iscse: iscse
		};
		emitter.emit('chat', info);
	});
	cuAPI.OnBeginChat((mode: number, text: string) => {
		info.type = 'begin';
		info.message = {
			mode: mode,
			text: text
		};
		emitter.emit('chat', info);
	});
	cuAPI.OnConsoleText((text: string) => {
		info.type = 'console';
		info.message = {
			lines = text.split('\n');
		};
		emitter.emit('chat', info);
	});
}
export default class ChatListener {
	listening: boolean = false;
	start(emitter : EventEmitter) {
		if (!this.listening) {
			run(emitter);
			this.listening = true;
		}
	}
}

Step 3: Hook it all up in src\ts\main.ts as follows

a) Imports

import HandlesChat from './classes/HandlesChat';
import ChatListener from './listeners/ChatListener';

b) Create a handlesChat object

const handlesChat : HandlesChat = new HandlesChat();

c) Create a listener in the listener table

[handlesChat.name]: new ChatListener(handlesChat),

d) Finally, add the handlesChat object to the exports

handlesChat,

Example Usage

events.on('chat', function(chat) {
	switch(chat.type) {
	case 'begin':
		// handle begin chat (put focus in chat box)
		break;
	case 'chat':
		// handle chat message
		break;
	case 'console':
		// handle console text
		break;
	}		
});