this.websocket.onopen = function(event) {
window.setInterval(function() { server.send(['PING']) }, 30000);
tui.log_msg("@ server connected! :)");
- tui.init_login();
+ tui.switch_mode(mode_login);
};
this.websocket.onclose = function(event) {
tui.log_msg("@ server disconnected :(");
};
};
},
- init_login: function() {
- this.log_msg("@ please enter your username:");
- this.switch_mode(mode_login);
- },
switch_mode: function(mode, keep_pos=false) {
if (mode == mode_study && !keep_pos && game.player_id in game.things) {
explorer.position = game.things[game.player_id].position;
this.recalc_input_lines();
}
}
- if (mode == mode_portal && explorer.position in game.portals) {
+ if (mode == mode_login) {
+ if (this.login_name) {
+ server.send(['LOGIN', this.login_name]);
+ } else {
+ this.log_msg("? need login name");
+ }
+ } else if (mode == mode_portal && explorer.position in game.portals) {
let portal = game.portals[explorer.position]
- this.inputEl.value = portal;
- this.recalc_input_lines();
+ this.inputEl.value = portal;
+ this.recalc_input_lines();
} else if (mode == mode_teleport) {
tui.log_msg("@ May teleport to: " + tui.teleport_target);
tui.log_msg("@ Enter 'YES!' to entusiastically affirm.");
event.preventDefault();
}
if (tui.mode == mode_login && event.key == 'Enter') {
+ tui.login_name = tui.inputEl.value;
server.send(['LOGIN', tui.inputEl.value]);
- tui.switch_mode(mode_login);
+ tui.empty_input();
} else if (tui.mode == mode_portal && event.key == 'Enter') {
explorer.set_portal(tui.inputEl.value);
tui.switch_mode(mode_study, true);