<commit_before>'use strict';

function LoginWorld() {
    this.__init__();
}

LoginWorld.prototype = {

    // Create account fields.
    create_username: null,

    // Post calls.
    post_create_account   : null,
    post_login            : null,

    //
    current_world: null,

    //
    attempted_username: null,
    attempted_password: null,

    /*             ___     __           ___
      |    | \  / |__     /__` \ / |\ |  |   /\  \_/    .
      |___ |  \/  |___    .__/  |  | \|  |  /~~\ / \    .*/
    login_username_character_change: function() {

    },

    login_button_clicked: function() {
        var error = false;
        var error_message = '';

        var login_username_text = this.login_username.get_input_text();
        var login_password_text = this.login_password.get_input_text();

        // TODO : Create a class to handle this kind of logic.

        if (login_username_text.length < 4) {
            error = true;
            error_message = 'Username must be at least 4 characters.';
        }
        if (!error) {
            if (login_password_text.length < 4) {
                error = true;
                error_message = 'Passwords are at least 4 characters!';
            }
        }

        if (!error) {
            GUI_TYPING_INTERFACE.add_server_message('Sending login request to server...');
            this.attempted_username = login_username_text;
            this.attempted_password = <PASSWORD>;
            var data = {};
            data[ENTITY_PROPERTY_USERNAME] = login_username_text;
            data[ENTITY_PROPERTY_PASSWORD] = login_password_text;
            this.post_login.perform_post(data, this.login_button_event.bind(this));
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + error_message);
        }
    },

    login_button_event: function(data) {
        if (data === SERVER_REPLY_GENERIC_YES) {
            GUI_TYPING_INTERFACE.add_server_message('Logged in!');
            if (this.remember_username_checkbox.checked) {
                MANAGER_COOKIES.set(COOKIE_REMEMBERED_USERNAME, this.attempted_username);
            }
            CURRENT_PLAYER.login(this.attempted_username, this.attempted_password);
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + data);
        }
    },

    create_account_button_clicked: function() {
        var error = false;
        var error_message = '';

        // TODO : Eventually make input parsing live for the user.
        var email_text = this.create_email.get_input_text();
        var username_text = this.create_username.get_input_text();
        var password_text = this.create_password.get_input_text();

        this.attempted_password = this.create_password.get_input_text();

        var password_repeat_text = this.create_repeat_password.get_input_text();

        if (!is_email_valid(email_text)) {
            error = true;
            error_message = 'invalid email format';
        }
        if (!error) {
            if (username_text.length < 4) {
                error = true;
                error_message = 'username text length < 4';
            }
        }
        if (!error) {
            if (password_text.length < 4 || password_text !== password_repeat_text) {
                error = true;
                if (password_text.length < 4) {
                    error_message = 'password length < 4';
                } else {
                    error_message = 'passwords do not match';
                }
            }
        }

        if (!error) {
            GUI_TYPING_INTERFACE.add_server_message('Sending create account request to server...');
            var data = {};
            data[ENTITY_PROPERTY_USERNAME] = username_text;
            data[ENTITY_PROPERTY_PASSWORD] = <PASSWORD>;
            data[ENTITY_PROPERTY_EMAIL]    = email_text;
            this.post_create_account.perform_post(data, this.create_account_button_event.bind(this));
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + error_message);
        }
    },

    create_account_button_event: function(data) {
        if (data === SERVER_REPLY_GENERIC_YES) {
            // Auto-login for successful account creations.
            GUI_TYPING_INTERFACE.add_server_message('Account created! Now sending login request to server!');
            this.attempted_username = this.create_username.get_input_text();
            this.attempted_password = this.create_password.get_input_text();
            var local_data = {};
            local_data[ENTITY_PROPERTY_USERNAME] = this.attempted_username;
            local_data[ENTITY_PROPERTY_PASSWORD] = this.attempted_password;
            this.post_login.perform_post(local_data, this.login_button_event.bind(this));
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + data);
        }
    },

    remember_username_clicked: function() {
        this.remember_username_checkbox.toggle();
        if (this.remember_username_checkbox.status()) {
            MANAGER_COOKIES.set(COOKIE_SHOULD_REMEMBER_USERNAME, 'true');
        } else {
            MANAGER_COOKIES.set(COOKIE_SHOULD_REMEMBER_USERNAME, 'false');
        }
    },

    __init__: function() {
        this.post_create_account = new PostHelper(POST_URL_CREATE_ACCOUNT);
        this.post_login          = new PostHelper(POST_URL_LOGIN);

        // Inherit from World.
        World.call(this, 'LoginWorld');

        var global_y_offset = 50;

        var login_wall_width = 500;
        var login_wall_height = 400;
        var login_wall_position = new THREE.Vector3(400, 400, 0);
        var login_wall_look_at = new THREE.Vector3(0, login_wall_position.y, 0);
        var login_wall_normal = new THREE.Vector3(login_wall_look_at.x - login_wall_position.x, login_wall_look_at.y - login_wall_position.y, login_wall_look_at.z - login_wall_position.z);
        login_wall_normal.normalize();

        this.login_wall = new FloatingWall(login_wall_width, login_wall_height, login_wall_position, login_wall_look_at, this);


        /*

        const LOGIN_X = 0;

        // LOGIN_BELOW

        var login_width = 150;<commit_msg>general updating 70<commit_after>'use strict';

function LoginWorld() {
    this.__init__();
}

LoginWorld.prototype = {

    // Create account fields.
    create_username: null,

    // Post calls.
    post_create_account   : null,
    post_login            : null,

    //
    current_world: null,

    //
    attempted_username: null,
    attempted_password: <PASSWORD>,

    /*             ___     __           ___
      |    | \  / |__     /__` \ / |\ |  |   /\  \_/    .
      |___ |  \/  |___    .__/  |  | \|  |  /~~\ / \    .*/
    login_username_character_change: function() {

    },

    login_button_clicked: function() {
        var error = false;
        var error_message = '';

        var login_username_text = this.login_username.get_input_text();
        var login_password_text = this.login_password.get_input_text();

        // TODO : Create a class to handle this kind of logic.

        if (login_username_text.length < 4) {
            error = true;
            error_message = 'Username must be at least 4 characters.';
        }
        if (!error) {
            if (login_password_text.length < 4) {
                error = true;
                error_message = 'Passwords are at least 4 characters!';
            }
        }

        if (!error) {
            GUI_TYPING_INTERFACE.add_server_message('Sending login request to server...');
            this.attempted_username = login_username_text;
            this.attempted_password = <PASSWORD>;
            var data = {};
            data[ENTITY_PROPERTY_USERNAME] = login_username_text;
            data[ENTITY_PROPERTY_PASSWORD] = login_password_text;
            this.post_login.perform_post(data, this.login_button_event.bind(this));
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + error_message);
        }
    },

    login_button_event: function(data) {
        if (data === SERVER_REPLY_GENERIC_YES) {
            GUI_TYPING_INTERFACE.add_server_message('Logged in!');
            if (this.remember_username_checkbox.checked) {
                MANAGER_COOKIES.set(COOKIE_REMEMBERED_USERNAME, this.attempted_username);
            }
            CURRENT_PLAYER.login(this.attempted_username, this.attempted_password);
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + data);
        }
    },

    create_account_button_clicked: function() {
        var error = false;
        var error_message = '';

        // TODO : Eventually make input parsing live for the user.
        var email_text = this.create_email.get_input_text();
        var username_text = this.create_username.get_input_text();
        var password_text = this.create_password.get_input_text();

        this.attempted_password = this.create_password.get_input_text();

        var password_repeat_text = this.create_repeat_password.get_input_text();

        if (!is_email_valid(email_text)) {
            error = true;
            error_message = 'invalid email format';
        }
        if (!error) {
            if (username_text.length < 4) {
                error = true;
                error_message = 'username text length < 4';
            }
        }
        if (!error) {
            if (password_text.length < 4 || password_text !== password_repeat_text) {
                error = true;
                if (password_text.length < 4) {
                    error_message = 'password length < 4';
                } else {
                    error_message = 'passwords do not match';
                }
            }
        }

        if (!error) {
            GUI_TYPING_INTERFACE.add_server_message('Sending create account request to server...');
            var data = {};
            data[ENTITY_PROPERTY_USERNAME] = username_text;
            data[ENTITY_PROPERTY_PASSWORD] = password_text;
            data[ENTITY_PROPERTY_EMAIL]    = email_text;
            this.post_create_account.perform_post(data, this.create_account_button_event.bind(this));
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + error_message);
        }
    },

    create_account_button_event: function(data) {
        if (data === SERVER_REPLY_GENERIC_YES) {
            // Auto-login for successful account creations.
            GUI_TYPING_INTERFACE.add_server_message('Account created! Now sending login request to server!');
            this.attempted_username = this.create_username.get_input_text();
            this.attempted_password = this.create_password.get_input_text();
            var local_data = {};
            local_data[ENTITY_PROPERTY_USERNAME] = this.attempted_username;
            local_data[ENTITY_PROPERTY_PASSWORD] = <PASSWORD>;
            this.post_login.perform_post(local_data, this.login_button_event.bind(this));
        } else {
            GUI_TYPING_INTERFACE.add_server_message('Error : ' + data);
        }
    },

    remember_username_clicked: function() {
        this.remember_username_checkbox.toggle();
        if (this.remember_username_checkbox.status()) {
            MANAGER_COOKIES.set(COOKIE_SHOULD_REMEMBER_USERNAME, 'true');
        } else {
            MANAGER_COOKIES.set(COOKIE_SHOULD_REMEMBER_USERNAME, 'false');
        }
    },

    __init__: function() {
        this.post_create_account = new PostHelper(POST_URL_CREATE_ACCOUNT);
        this.post_login          = new PostHelper(POST_URL_LOGIN);

        // Inherit from World.
        World.call(this, 'LoginWorld');

        var global_y_offset = 50;

        var login_wall_width = 600;
        var login_wall_height = 400;
        var login_wall_position = new THREE.Vector3(400, 400, 0);
        var login_wall_look_at = new THREE.Vector3(0, login_wall_position.y, 0);
        var login_wall_normal = new THREE.Vector3(login_wall_look_at.x - login_wall_position.x, login_wall_look_at.y - login_wall_position.y, login_wall_look_at.z - login_wall_position.z);
        login_wall_normal.normalize();

        this.login_wall = new FloatingWall(login_wall_width, login_wall_height, login_wall_position, login_wall_normal, this);


        /*

        const LOGIN_X = 0;

        // LOGIN_BELOW

        var login_width = 150;
{'fraction_non_alphanumeric': 0.09764582153547448, 'fraction_numerical': 0.005501173044252084, 'mean_word_length': 2.1439471007121056, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '537370', 'n_tokens_mistral': 3817, 'n_tokens_neox': 3618, 'n_words': 615}