Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move require statements to the beginning #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
14 changes: 9 additions & 5 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const Sound = require('./lib/sound.js');
const Matrix = require('./lib/matrix.js');
const {Eye, Plane} = require('./lib/eye.js');

const LightingModule = require('./lib/lighting.js');
const IconLoader = require('./lib/icon_loader.js');
const Renderer = require('./lib/renderer.js');
const AudioLoader = require('./lib/audio_loader.js');

class BluespessClient extends EventEmitter {
constructor(wsurl, resRoot = "") {
super();
Expand Down Expand Up @@ -36,7 +41,7 @@ class BluespessClient extends EventEmitter {
if(global.AudioContext)
this.audio_ctx = new AudioContext();
}
this.importModule(require('./lib/lighting.js'));
this.importModule(LightingModule);
}

handle_login() {
Expand Down Expand Up @@ -315,10 +320,9 @@ BluespessClient.dropdown = function(elem1, elem2, {point = null, autoremove = tr
if(autoremove)
elem2.focus();
};

BluespessClient.prototype.enqueue_icon_meta_load = require('./lib/icon_loader.js');
BluespessClient.prototype.anim_loop = require('./lib/renderer.js');
BluespessClient.prototype.get_audio_buffer = require('./lib/audio_loader.js');
BluespessClient.prototype.enqueue_icon_meta_load = IconLoader;
BluespessClient.prototype.anim_loop = Renderer;
BluespessClient.prototype.get_audio_buffer = AudioLoader;

BluespessClient.Atom = Atom;
BluespessClient.Component = Component;
Expand Down
2 changes: 1 addition & 1 deletion client/lib/lighting.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const {Component} = require('../index.js');
const Component = require('./component.js');

class LightingObject extends Component {
constructor(atom, template) {
Expand Down
2 changes: 1 addition & 1 deletion lib/atom/atom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const EventEmitter = require('events');
const mob_symbols = require('./mob.js')._symbols;
const mob_symbols = require('./mob')._symbols;
const {has_component} = require('../utils.js');
const Component = require('./component.js');

Expand Down
2 changes: 1 addition & 1 deletion lib/atom/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const EventEmitter = require('events');
const mob_symbols = require('./mob.js')._symbols;
const mob_symbols = require('./mob/symbols.js');
const _networked_vars = Symbol('_networked_vars');

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/atom/lighting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const {Component, Atom} = require('../server.js');
const Atom = require('./atom.js');
const Component = require('./component.js');

const _enabled = Symbol('_enabled');
const _color = Symbol('_color');
Expand Down
27 changes: 7 additions & 20 deletions lib/atom/mob.js → lib/atom/mob/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
'use strict';

const {chain_func, is_atom, to_chat, has_component} = require('../utils.js');
const _observers = Symbol('_observers');
const _viewers = Symbol('_viewers');
const _viewing = Symbol('_viewing');
const _key = Symbol('_key');
const _client = Symbol('_client');
const _server_to_net = Symbol('_server_to_net');
const _visible_tiles = Symbol('_visible_tiles');
const _screen_set = Symbol('_screen_set');
const _update_var = Symbol('_update_var');
const _add_viewing = Symbol('_add_viewing');
const _remove_viewing = Symbol('_remove_viewing');
const _common_tiles_count = Symbol('_common_tiles_count');
const _panel_map = Symbol('_panel_map');
const _visgroups = Symbol('_visgroups');
const _eye_to_eyeid = Symbol('_eye_to_eyeid');
module.exports._symbols = {_observers, _client, _viewers, _viewing, _visible_tiles, _server_to_net, _add_viewing, _remove_viewing, _update_var, _common_tiles_count, _visgroups, _key};

const Component = require('./component.js');
const {chain_func, is_atom, to_chat, has_component} = require('../../utils.js');

const {_observers, _viewers, _viewing, _key, _client, _server_to_net, _visible_tiles, _screen_set, _update_var, _add_viewing, _remove_viewing, _common_tiles_count, _panel_map, _visgroups, _eye_to_eyeid} = require('./symbols.js');
module.exports._symbols = require('./symbols.js');

const Component = require('../component.js');

var id_counter = 0;

Expand Down Expand Up @@ -75,7 +62,7 @@ class Eye extends Component {

if(this.a.c.Hearer)
this.a.c.Hearer.show_message = chain_func(this.a.c.Hearer.show_message, this.show_message.bind(this));

/** @type {boolean} */this.xray;
}

Expand Down
17 changes: 17 additions & 0 deletions lib/atom/mob/symbols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const _observers = Symbol('_observers');
const _viewers = Symbol('_viewers');
const _viewing = Symbol('_viewing');
const _key = Symbol('_key');
const _client = Symbol('_client');
const _server_to_net = Symbol('_server_to_net');
const _visible_tiles = Symbol('_visible_tiles');
const _screen_set = Symbol('_screen_set');
const _update_var = Symbol('_update_var');
const _add_viewing = Symbol('_add_viewing');
const _remove_viewing = Symbol('_remove_viewing');
const _common_tiles_count = Symbol('_common_tiles_count');
const _panel_map = Symbol('_panel_map');
const _visgroups = Symbol('_visgroups');
const _eye_to_eyeid = Symbol('_eye_to_eyeid');

module.exports = {_observers, _client, _viewers, _viewing, _visible_tiles, _server_to_net, _add_viewing, _remove_viewing, _update_var, _common_tiles_count, _visgroups, _key};
4 changes: 2 additions & 2 deletions lib/atom/visgroup.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
const {chain_func} = require('../utils.js');
const mob_symbols = require('./mob.js')._symbols;
const mob_symbols = require('./mob')._symbols;

/**
/**
* @typedef {import('./atom')} Bluespess.Atom
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const {has_component} = require('./utils.js');
const mob_symbols = require('./atom/mob.js')._symbols;
const mob_symbols = require('./atom/mob')._symbols;
const EventEmitter = require('events');
const Component = require('./atom/component.js');

Expand Down
10 changes: 7 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const utils = require('./utils.js');
const VisibilityGroup = require('./atom/visgroup.js');
const Dimension = require('./dimension.js');

const MobModule = require('./atom/mob');
const LightingModule = require('./atom/lighting.js');
const HearerModule = require('./atom/hearer.js');

const _net_tick = Symbol('_net_tick');
const _is_template_processed = Symbol('_is_template_processed');
const _is_server_started = Symbol('_is_server_started');
Expand Down Expand Up @@ -56,9 +60,9 @@ class Bluespess extends EventEmitter {
this.demo_stream = null;

// Import default modules
this.importModule(require('./atom/mob.js'));
this.importModule(require('./atom/lighting.js'));
this.importModule(require('./atom/hearer.js'));
this.importModule(MobModule);
this.importModule(LightingModule);
this.importModule(HearerModule);

this.net_tick_delay = 50;

Expand Down