PROGRESS! mostly ui, got admin stuff
This commit is contained in:
parent
2658f3d28c
commit
e730f9a870
6 changed files with 198 additions and 68 deletions
|
@ -1,7 +1,21 @@
|
|||
class Tavern {
|
||||
// Callback definitions!
|
||||
onlogin = (_loggedIn) => { };
|
||||
onmessage = (_message) => { };
|
||||
onspawntoken = (_spawnToken) => { };
|
||||
onmovetoken = (_moveToken) => { };
|
||||
onshowscene = (_scene) => { };
|
||||
onscenelist = (_sceneList) => { };
|
||||
onconnectedplayers = (_playersList) => { };
|
||||
|
||||
constructor() {
|
||||
this.socket = new WebSocket('ws:/' + window.location.host + '/ws');
|
||||
this.socket.onopen = () => this.connected = true;
|
||||
this.socket.onclose = () => {
|
||||
this.connected = false;
|
||||
this.loggedIn = false;
|
||||
this.call(this.onclose);
|
||||
};
|
||||
this.msgs = [];
|
||||
this.connected = false;
|
||||
this.loggedIn = false;
|
||||
|
@ -36,6 +50,9 @@ class Tavern {
|
|||
if (m.scene_list) {
|
||||
this.call(this.onscenelist, m.scene_list);
|
||||
}
|
||||
if (m.connected_players) {
|
||||
this.call(this.onconnectedplayers, m.connected_players);
|
||||
}
|
||||
}
|
||||
}
|
||||
call(f, ...args) {
|
||||
|
@ -101,7 +118,7 @@ class Tavern {
|
|||
}
|
||||
get_scene = (id) => {
|
||||
if (!this.connected || this.loggedIn) { return; }
|
||||
this.socket.send(JSON.stringify({ get_scene: { id: id } }))
|
||||
this.socket.send(JSON.stringify({ get_scene: { scene: id } }))
|
||||
}
|
||||
get_scene_list = () => {
|
||||
if (!this.connected || this.loggedIn) { return; }
|
||||
|
@ -120,9 +137,25 @@ class Tavern {
|
|||
this.socket.send(JSON.stringify({ create_scene: { title: title } }));
|
||||
}
|
||||
shutdown = () => {
|
||||
if (!this.connected || this.loggedIn) { return; }
|
||||
if (!this.connected || this.loggedIn || !this.admin) { return; }
|
||||
this.socket.send(JSON.stringify('shutdown'));
|
||||
}
|
||||
save = () => {
|
||||
if (!this.connected || this.loggedIn || !this.admin) { return; }
|
||||
this.socket.send(JSON.stringify('save'));
|
||||
}
|
||||
kick = (id) => {
|
||||
if (!this.connected || this.loggedIn || !this.admin) { return; }
|
||||
this.socket.send(JSON.stringify({ kick: id }));
|
||||
}
|
||||
show_scene = (id) => {
|
||||
if (!this.connected || this.loggedIn || !this.admin) { return; }
|
||||
this.socket.send(JSON.stringify({ show_scene: { scene: id } }));
|
||||
}
|
||||
set_scene_visible = (id, visible) => {
|
||||
if (!this.connected || this.loggedIn || !this.admin) { return; }
|
||||
this.socket.send(JSON.stringify({ set_scene_visible: { scene: id, visible: visible } }));
|
||||
}
|
||||
}
|
||||
|
||||
const tavern = new Tavern();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue