3 Commits

Author SHA1 Message Date
be642cfb88 Release v1.0.1 2021-04-15 10:08:45 +02:00
8d165c2984 Verified 0.8.1 combatibility 2021-04-15 10:05:35 +02:00
de4a289395 Add game system support 2021-04-15 09:52:50 +02:00
4 changed files with 41 additions and 7 deletions

View File

@@ -1,2 +1,10 @@
## 1.0.1
### New features
- Added support for game systems
### Compatibility
- Add support for Foundry 0.8.1
## 1.0.0
### Initial release

View File

@@ -64,6 +64,17 @@ Call `registerModule` to make socketlib listen for sockets that come in for your
**Return value**: A socket instance is returned, that is used for all further interactions with socketlib.
#### socketlib.registerSystem
```javascript
registerSystem(systemId);
```
Call `registerSystem` to make socketlib listen for sockets that come in for your game system. This is the first function in socketlib that your game system should call.
- **systemId** the id of your game system as specified in your game system's manifest.
**Return value**: A socket instance is returned, that is used for all further interactions with socketlib.
#### socket.register
```javascript
socket.register(name, func);

View File

@@ -2,9 +2,9 @@
"name": "socketlib",
"title": "socketlib",
"description": "A library for easier handling of foundry sockets",
"version": "1.0.0",
"version": "1.0.1",
"minimumCoreVersion" : "0.7.9",
"compatibleCoreVersion" : "0.7.9",
"compatibleCoreVersion" : "0.8.1",
"library": true,
"authors": [
{
@@ -17,7 +17,7 @@
"src/socketlib.js"
],
"url": "https://github.com/manuelVo/foundryvtt-socketlib",
"download": "https://github.com/manuelVo/foundryvtt-socketlib/archive/v1.0.0.zip",
"download": "https://github.com/manuelVo/foundryvtt-socketlib/archive/v1.0.1.zip",
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-socketlib/master/module.json",
"readme": "https://github.com/manuelVo/foundryvtt-socketlib/blob/master/README.md",
"changelog": "https://github.com/manuelVo/foundryvtt-socketlib/blob/master/CHANGELOG.md",

View File

@@ -39,17 +39,32 @@ class Socketlib {
console.error(`socketlib | Failed to register socket for module '${moduleName}'. Please set '"socket":true' in your manifset and restart foundry (you need to reload your world - simply reloading your browser won't do).`);
return undefined;
}
const newSocket = new SocketlibSocket(moduleName);
const newSocket = new SocketlibSocket(moduleName, "module");
this.modules.set(moduleName, newSocket);
return newSocket;
}
registerSystem(systemId) {
if (game.system.id !== systemId) {
console.error(`socketlib | Someone tried to register system '${systemId}', but that system isn't active. As a result the registration request has been ignored.`);
return undefined;
}
const existingSocket = this.system;
if (existingSocket)
return existingSocket;
if (!game.system.data.socket) {
console.error(`socketlib | Failed to register socket for system '${systemId}'. Please set '"socket":true' in your manifest and restart foundry (you need to reload your world - simply reloading your browser won't do).`);
}
const newSocket = new SocketlibSocket(systemId, "system");
this.system = newSocket;
return newSocket;
}
}
class SocketlibSocket {
constructor(moduleName) {
this.moduleName = moduleName;
constructor(moduleName, moduleType) {
this.functions = new Map();
this.socketName = `module.${moduleName}`;
this.socketName = `${moduleType}.${moduleName}`;
this.pendingRequests = new Map();
game.socket.on(this.socketName, this._onSocketReceived.bind(this));
}