<commit_before>'use strict';
const EventEmitter = require('events');
const mob_symbols = require('./mob.js')._symbols;
const {has_component} = require('../utils.js');

var id_counter = 0;

const _loc = Symbol('_loc');
const _x = Symbol('_x');
const _y = Symbol('_y');
const _z = Symbol('_z');
const _bounds_x = Symbol('_bounds_x');
const _bounds_y = Symbol('_bounds_y');
const _bounds_width = Symbol('_bounds_width');
const _bounds_height = Symbol('_bounds_height');
const _crosses = Symbol('_crosses');

const _walking = Symbol('_walking');
const _walk_stepping = Symbol('_walk_stepping');
const _walk_step = Symbol('_walk_step');

const _icon = Symbol('_icon');
const _icon_state = Symbol('_icon_state');
const _dir = Symbol('_dir');
const _layer = Symbol('_layer');
const _name = Symbol('_name');
const _glide_size = Symbol('_glide_size');
const _screen_loc_x = Symbol('_screen_loc_x');
const _screen_loc_y = Symbol('_screen_loc_y');
const _flick = Symbol('_flick');

const _opacity = Symbol('_opacity');

const _changeloc = Symbol('_changeloc');
const _emit_parent_move = Symbol('_emit_parent_move');

class Atom extends EventEmitter {
	constructor(server, template, x, y, z) {
		if(typeof template == "string")
			template = server.templates[template];
		if(!server || !template)
			throw 'Invalid arguments while instantiating ';
		super();

		this.template = template;

		Object.defineProperty(this, 'server', {enumerable: false,configurable: false,writable: false,value: server});
		Object.defineProperty(this, 'object_id', {enumerable: true,configurable: false,writable: false,value: `ID_${id_counter++}`});
		Object.defineProperty(this, 'contents', {enumerable: true,configurable: false,writable: false,value: []});

		this[_name] = "object";
		this[_glide_size] = 10;
		this[_layer] = 0;
		this[_dir] = 2;
		this.gender = "neutral";

		this[_crosses] = [];

		this.server.process_template(template);
		server.atoms.set(this.object_id, this);

		this[_bounds_x] = 0;
		this[_bounds_y] = 0;
		this[_bounds_width] = 1;
		this[_bounds_height] = 1;
		this[mob_symbols._viewers] = [];

		this.density = 0;
		this.pass_flags = 0;
		this.let_pass_flags = 0;
		this[_opacity] = false;

		this[_walking] = false;
		this[_walk_stepping] = false;
		this.walk_dir = 0;
		this.walk_size = 1;
		this.walk_delay = 0.15;
		this.walk_reason = "walking";

		if(template.vars) {
			for(var key in template.vars) {
				if(!template.vars.hasOwnProperty(key) || key == "appearance" || key == "components" || key == "overlays")
					continue;
				this[key] = template.vars[key];
			}
		}

		if(template.vars && template.vars.appearance)
			Object.assign(this, template.vars.appearance);

		this.overlays = new Proxy({}, {
			set: (target, key, value) => {
				if(value === undefined || value === null) {
					target[key] = undefined;
					this[mob_symbols._update_var](key, 2);
					return true;
				}
				if((typeof value) == "string")
					value = {"icon_state": value, "overlay_layer": 1};
				if(value instanceof Atom)
					value = value.appearance;
				if(typeof value != "object")
					throw new TypeError(`Object or string expected for overlay. Got ${value} instead.`);
				value = new Proxy(Object.assign({}, value), {
					set: (target2, key2, value2) => {
						target2[key2] = value2;
						this[mob_symbols._update_var](key, 2);
					}
				});
				target[key] = value;
				this[mob_symbols._update_var](key, 2);
				return true;
			}
		});

		this.components = {};
		if(template.components) {
			for(let i = 0; i < template.components.length; i++) {
				let componentName = template.components[i];
				if(this.components[componentName])
					throw new Error(`Template '${template.id}' defines component '${componentName}' multiple times`);
				let componentConstructor = this.server.components[componentName];
				if(!componentConstructor)
					throw new Error(`Template '${template.id}' references non-existent component '${componentName}'`);
				let templateVars = template.vars && template.vars.components && template.vars.components[componentName] ? template.vars.components[componentName] : {};
				this.components[componentName] = new this.server.components[componentName](this, templateVars);
			}
		}

		if(typeof x === "number") {
			x = +x;
			y = +y;
			z = +z;
			if(x !== x) x = 0;
			if(y !== y) y = 0;
			if(z !== z) z = 0;
			z = Math.floor(z);

			this[_changeloc](x, y, z, this.server.location(x,y,z));
		} else if(typeof x === "object" && x !== null) {
			if(x.is_base_loc) {
				this[_changeloc](x.x, x.y, x.z, x);
			} else {
				this[_changeloc](0, 0, 0, x);
			}
		} else {
			this[_changeloc](0, 0, 0, null);
		}
	}

	get c() {
		return this.components;
	}

	[_changeloc](newX, newY, newZ = this[_z], newLoc, newBounds_x, newBounds_y, newBounds_width, newBounds_height) {
		if(newLoc && !newLoc.is_base_loc && this.loc && !this.loc.is_base_loc && newLoc == this.loc)
			return;
		var old_fine_loc = this.fine_loc;
		var new_fine_loc = {x:newX, y:newY, z:newZ, loc:newLoc, is_fine_loc: true};
		var movement = {old: old_fine_loc, new: new_fine_loc};
		if(old_fine_loc.loc && old_fine_loc.loc.is_base_loc && new_fine_loc.loc && new_fine_loc.loc.is_base_loc) {<commit_msg>makes the error message more descriptive<commit_after>'use strict';
const EventEmitter = require('events');
const mob_symbols = require('./mob.js')._symbols;
const {has_component} = require('../utils.js');

var id_counter = 0;

const _loc = Symbol('_loc');
const _x = Symbol('_x');
const _y = Symbol('_y');
const _z = Symbol('_z');
const _bounds_x = Symbol('_bounds_x');
const _bounds_y = Symbol('_bounds_y');
const _bounds_width = Symbol('_bounds_width');
const _bounds_height = Symbol('_bounds_height');
const _crosses = Symbol('_crosses');

const _walking = Symbol('_walking');
const _walk_stepping = Symbol('_walk_stepping');
const _walk_step = Symbol('_walk_step');

const _icon = Symbol('_icon');
const _icon_state = Symbol('_icon_state');
const _dir = Symbol('_dir');
const _layer = Symbol('_layer');
const _name = Symbol('_name');
const _glide_size = Symbol('_glide_size');
const _screen_loc_x = Symbol('_screen_loc_x');
const _screen_loc_y = Symbol('_screen_loc_y');
const _flick = Symbol('_flick');

const _opacity = Symbol('_opacity');

const _changeloc = Symbol('_changeloc');
const _emit_parent_move = Symbol('_emit_parent_move');

class Atom extends EventEmitter {
	constructor(server, template, x, y, z) {
		if(typeof template == "string")
			template = server.templates[template];
		if(!server || !template)
			throw new Error(`Invalid arguments while instantiating: server: ${server}, template: ${template}`);
		super();

		this.template = template;

		Object.defineProperty(this, 'server', {enumerable: false,configurable: false,writable: false,value: server});
		Object.defineProperty(this, 'object_id', {enumerable: true,configurable: false,writable: false,value: `ID_${id_counter++}`});
		Object.defineProperty(this, 'contents', {enumerable: true,configurable: false,writable: false,value: []});

		this[_name] = "object";
		this[_glide_size] = 10;
		this[_layer] = 0;
		this[_dir] = 2;
		this.gender = "neutral";

		this[_crosses] = [];

		this.server.process_template(template);
		server.atoms.set(this.object_id, this);

		this[_bounds_x] = 0;
		this[_bounds_y] = 0;
		this[_bounds_width] = 1;
		this[_bounds_height] = 1;
		this[mob_symbols._viewers] = [];

		this.density = 0;
		this.pass_flags = 0;
		this.let_pass_flags = 0;
		this[_opacity] = false;

		this[_walking] = false;
		this[_walk_stepping] = false;
		this.walk_dir = 0;
		this.walk_size = 1;
		this.walk_delay = 0.15;
		this.walk_reason = "walking";

		if(template.vars) {
			for(var key in template.vars) {
				if(!template.vars.hasOwnProperty(key) || key == "appearance" || key == "components" || key == "overlays")
					continue;
				this[key] = template.vars[key];
			}
		}

		if(template.vars && template.vars.appearance)
			Object.assign(this, template.vars.appearance);

		this.overlays = new Proxy({}, {
			set: (target, key, value) => {
				if(value === undefined || value === null) {
					target[key] = undefined;
					this[mob_symbols._update_var](key, 2);
					return true;
				}
				if((typeof value) == "string")
					value = {"icon_state": value, "overlay_layer": 1};
				if(value instanceof Atom)
					value = value.appearance;
				if(typeof value != "object")
					throw new TypeError(`Object or string expected for overlay. Got ${value} instead.`);
				value = new Proxy(Object.assign({}, value), {
					set: (target2, key2, value2) => {
						target2[key2] = value2;
						this[mob_symbols._update_var](key, 2);
					}
				});
				target[key] = value;
				this[mob_symbols._update_var](key, 2);
				return true;
			}
		});

		this.components = {};
		if(template.components) {
			for(let i = 0; i < template.components.length; i++) {
				let componentName = template.components[i];
				if(this.components[componentName])
					throw new Error(`Template '${template.id}' defines component '${componentName}' multiple times`);
				let componentConstructor = this.server.components[componentName];
				if(!componentConstructor)
					throw new Error(`Template '${template.id}' references non-existent component '${componentName}'`);
				let templateVars = template.vars && template.vars.components && template.vars.components[componentName] ? template.vars.components[componentName] : {};
				this.components[componentName] = new this.server.components[componentName](this, templateVars);
			}
		}

		if(typeof x === "number") {
			x = +x;
			y = +y;
			z = +z;
			if(x !== x) x = 0;
			if(y !== y) y = 0;
			if(z !== z) z = 0;
			z = Math.floor(z);

			this[_changeloc](x, y, z, this.server.location(x,y,z));
		} else if(typeof x === "object" && x !== null) {
			if(x.is_base_loc) {
				this[_changeloc](x.x, x.y, x.z, x);
			} else {
				this[_changeloc](0, 0, 0, x);
			}
		}
	}

	get c() {
		return this.components;
	}

	[_changeloc](newX, newY, newZ = this[_z], newLoc, newBounds_x, newBounds_y, newBounds_width, newBounds_height) {
		if(newLoc && !newLoc.is_base_loc && this.loc && !this.loc.is_base_loc && newLoc == this.loc)
			return;
		var old_fine_loc = this.fine_loc;
		var new_fine_loc = {x:newX, y:newY, z:newZ, loc:newLoc, is_fine_loc: true};
		var movement = {old: old_fine_loc, new: new_fine_loc};
		if(old_fine_loc.loc && old_fine_loc.loc.is_base_loc && new_fine_loc.loc && new_fine_loc.loc.is_base_loc) {
{'fraction_non_alphanumeric': 0.1641705069124424, 'fraction_numerical': 0.006816436251920123, 'mean_word_length': 4.414241164241164, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7439123', 'n_tokens_mistral': 4135, 'n_tokens_neox': 3621, 'n_words': 777}