This commit is contained in:
ntr
2018-11-29 20:19:17 +11:00
parent 0dd96ae961
commit 38af55aacd
6 changed files with 85 additions and 82 deletions
+2 -2
View File
@@ -115,9 +115,9 @@ function registerEvents(registry, events) {
],
});
const prompt = document.querySelector('#login'); // Selector of your toast
events.once('ACCOUNT', function closeLoginCb() {
toast.hide({ transitionOut: 'fadeOut' }, prompt, 'event');
const prompt = document.querySelector('#login'); // Selector of your toast
if (prompt) toast.hide({ transitionOut: 'fadeOut' }, prompt, 'event');
});
}
+16 -21
View File
@@ -15,8 +15,6 @@ function errorToast(err) {
function createSocket(events) {
let ws;
let gameStateTimeout;
function connect() {
ws = new WebSocket(SOCKET_URL);
ws.binaryType = 'arraybuffer';
@@ -29,7 +27,7 @@ function createSocket(events) {
});
events.loginPrompt();
if (!process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV !== 'production') {
send({ method: 'account_login', params: { name: 'ntr', password: 'grepgrepgrep' } });
}
});
@@ -64,9 +62,9 @@ function createSocket(events) {
account = login;
events.setAccount(login);
send({ method: 'account_cryps', params: {} });
send({ method: 'item_list', params: {} });
console.log(account);
sendAccountItems();
sendAccountCryps();
sendGameJoinableList();
}
function accountCryps(response) {
@@ -86,15 +84,13 @@ function createSocket(events) {
function crypSpawn(response) {
const [structName, cryp] = response;
console.log('got a new cryp', cryp);
}
function gamePve(response) {
const [structName, game] = response;
console.log('got a new game', game);
}
function itemList(response) {
function accountItems(response) {
const [structName, items] = response;
events.setItems(items);
}
@@ -116,6 +112,14 @@ function createSocket(events) {
send({ method: 'account_create', params: { name, password } });
}
function sendAccountCryps() {
send({ method: 'account_cryps', params: {} });
}
function sendAccountItems() {
send({ method: 'account_items', params: {} });
}
function sendCrypSpawn(name) {
send({ method: 'cryp_spawn', params: { name } });
}
@@ -170,15 +174,6 @@ function createSocket(events) {
events.setActiveItem(null);
}
// -------------
// Events
// -------------
function clearGameStateInterval() {
clearInterval(gameStateTimeout);
}
// -------------
// Handling
// -------------
@@ -192,7 +187,7 @@ function createSocket(events) {
account_login: accountLogin,
account_create: accountLogin,
account_cryps: accountCryps,
item_list: itemList,
account_items: accountItems,
};
// decodes the cbor and
@@ -201,7 +196,6 @@ function createSocket(events) {
// decode binary msg from server
const blob = new Uint8Array(event.data);
const res = cbor.decode(blob);
console.log(res);
// check for error and split into response type and data
if (res.err) return errorToast(res.err);
@@ -211,9 +205,10 @@ function createSocket(events) {
}
return {
clearGameStateInterval,
sendAccountLogin,
sendAccountCreate,
sendAccountCryps,
sendAccountItems,
sendGameState,
sendGamePve,
sendGamePvp,