import game from "..";
import { Key } from "../game";

var interiorId = -1;
var enterExit = undefined;

game.events.add('SERVER:InteriorManager_ClearHelpText', () => {
    game.ui.clearHelpText();

    enterExit = undefined;
    game.events.unbindKey(Key.E, false, keyPressHandler);
});

game.events.add('SERVER:InteriorManager_ShowHelpText', (interior, intId, entEx) => {
    game.ui.setHelpText('Drücke ~INPUT_CONTEXT~, um ~b~' + interior + ' ~s~zu ' + (entEx === 0 ? 'betreten' : 'verlassen'));

    interiorId = intId;
    enterExit = entEx;

    game.events.bindKey(Key.E, false, keyPressHandler);
});

function keyPressHandler() {
    if (game.ui.inChat) return;
    game.events.callServer('InteriorManager_UseTeleport', [interiorId, enterExit]);
}