Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sysmsg submodule #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Documentation
- Submodule `me`: [here](doc/me.md)
- Submodule `sysmsg`: [here](doc/sysmsg.md)
- Submodule `contract`: [here](doc/contract.md)
- Submodule `inventory`: [here](doc/inventory.md)

Expand Down
11 changes: 11 additions & 0 deletions doc/sysmsg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# sysmsg
Submodule representing the incoming system message. Accessible through `mod.game.sysmsg`.

# Functions
None

# Events
## update
- Emitted when a new system messages arrives on `S_SYSTEM_MESSAGE`.
- Exemplary usage: `mod.game.sysmsg.on('update', (id, tokens) => { ... })`
- Parameters: `id` is id of the system message, and `tokens` is the tokens associated with the system message
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TeraGameState extends EventEmitter {
// Now initialize default submodules
this.installHooks();
this.initialize('me');
this.initialize('sysmsg');
}

destructor() {
Expand Down
43 changes: 43 additions & 0 deletions lib/sysmsg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const EventEmitter = require('events');

class Sysmsg extends EventEmitter {

constructor(parent) {
super();
this.setMaxListeners(0);

this.parent = parent;

this.reset();
this.installHooks();
}

destructor() {
this.reset();
this.parent = undefined;
}

installHook(name, version, cb) {
return this.parent.mod.hook(name, version, { order: -10000, filter: { fake: null, modified: null, silenced: null } }, cb);
}

installHooks() {
this.parent.on('leave_game', () => { this.reset(); });

this.installHook('S_SYSTEM_MESSAGE', 1, (event) => {
let msg = this.parent.mod.parseSystemMessage(event.message);
this.id = msg.id;
this.tokens = msg.tokens;

this.emit('update', msg.id, msg.tokens);
});
}

reset() {
this.id = null;
this.tokens = null;
}

}

module.exports = Sysmsg;
10 changes: 6 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"files": {
"index.js": "527db5686384eddb8df0e48d295460d44190d9f45b7edc8900686c7fd7d67122",
"module.json": "6f969d093fa5e024757824bd2814073378be4ebfdf41dfdfbd50db34f285fcc1",
"index.js": "7dc29d6ac31a2593f7e3cfa4afa576a5e188262bea7231a0c76f589358a99f5d",
"module.json": "4f61176eb40b7f496ad9464e941ca9c3c1764f04dbd6ca283f327715ed5fdbff",
"lib/me.js": "1d449ce3808cae2b514ac507ef6e84e168baa479c04e0dbec5c47cb01351beb4",
"lib/contract.js": "297bbff8c8887754f6e50a4fdffb2c1444aa9a7d8f5ef02941d43ad374117b58",
"lib/sysmsg.js": "9bb9e8c1837a6cf09814a3c65c869cb8c0e1a42a0bd748942634814f8310823e",
"lib/contract.js": "297bbff8c8887754f6e50a4fdffb2c1444aa9a7d8f5ef02941d43ad374117b58",
"lib/inventory.js": "812d51305f0bee923cec6da210becf44a4af684a62c47d6aeaea499867b45a61"
},
"defs": {
Expand All @@ -26,6 +27,7 @@
"S_REJECT_CONTRACT": "event",
"S_CANCEL_CONTRACT": "event",
"S_INVEN_USERDATA": [1, 2],
"S_ITEMLIST": [2, 3]
"S_ITEMLIST": [2, 3],
"S_SYSTEM_MESSAGE": 1
}
}
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "tera-game-state",
"author": "Caali",
"description": "Tracks the game's current state and provides a high-level API for developers to base their mods on.",
"version": "1.0",
"version": "1.1",
"servers": ["https://raw.githubusercontent.com/tera-toolbox/tera-game-state/master/"],
"dependencies": {
"tera-game-state-helper": "https://raw.githubusercontent.com/tera-toolbox/tera-game-state-helper/master/module.json"
Expand Down