From 85f1f076107e432ab986847df9d8dd0f44fd2c01 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 02:35:05 +0300 Subject: [PATCH 1/9] Move require statements to the beginning --- client/index.js | 14 +++++++++----- lib/server.js | 10 +++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/client/index.js b/client/index.js index 12032d0..40e0140 100644 --- a/client/index.js +++ b/client/index.js @@ -9,6 +9,11 @@ const Sound = require('./lib/sound.js'); const Matrix = require('./lib/matrix.js'); const {Eye, Plane} = require('./lib/eye.js'); +const Lighting = 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(); @@ -36,7 +41,7 @@ class BluespessClient extends EventEmitter { if(global.AudioContext) this.audio_ctx = new AudioContext(); } - this.importModule(require('./lib/lighting.js')); + this.importModule(Lighting); } handle_login() { @@ -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; diff --git a/lib/server.js b/lib/server.js index 7c44232..f8cf178 100644 --- a/lib/server.js +++ b/lib/server.js @@ -11,6 +11,10 @@ const utils = require('./utils.js'); const VisibilityGroup = require('./atom/visgroup.js'); const Dimension = require('./dimension.js'); +const Mob = require('./atom/mob.js'); +const Lighting = require('./atom/lighting.js'); +const Hearer = 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'); @@ -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(Mob); + this.importModule(Lighting); + this.importModule(Hearer); this.net_tick_delay = 50; From 1df4634349377f15f29ea621332e619bd384b7b9 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:11:50 +0300 Subject: [PATCH 2/9] Fix cyclic dependency in client/lib/lighting.js --- client/lib/lighting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/lib/lighting.js b/client/lib/lighting.js index 033bc66..2b6b792 100644 --- a/client/lib/lighting.js +++ b/client/lib/lighting.js @@ -1,5 +1,5 @@ 'use strict'; -const {Component} = require('../index.js'); +const Component = require('./component.js'); class LightingObject extends Component { constructor(atom, template) { From 272df3953aec3705faf047d86dc6d47357f7cd80 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:13:34 +0300 Subject: [PATCH 3/9] Move mob symbols to a separate module --- lib/atom/component.js | 2 +- lib/atom/{mob.js => mob/index.js} | 36 ++++++++++++++++--------------- lib/atom/mob/symbols.js | 17 +++++++++++++++ 3 files changed, 37 insertions(+), 18 deletions(-) rename lib/atom/{mob.js => mob/index.js} (94%) create mode 100644 lib/atom/mob/symbols.js diff --git a/lib/atom/component.js b/lib/atom/component.js index 58835cf..c1a646e 100644 --- a/lib/atom/component.js +++ b/lib/atom/component.js @@ -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'); /** diff --git a/lib/atom/mob.js b/lib/atom/mob/index.js similarity index 94% rename from lib/atom/mob.js rename to lib/atom/mob/index.js index f7d8188..83d314b 100644 --- a/lib/atom/mob.js +++ b/lib/atom/mob/index.js @@ -1,22 +1,24 @@ '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 _symbols = require('./symbols.js'); + +const _observers = _symbols._observers; +const _viewers = _symbols._viewers; +const _viewing = _symbols._viewing; +const _key = _symbols._key; +const _client = _symbols._client; +const _server_to_net = _symbols._server_to_net; +const _visible_tiles = _symbols._visible_tiles; +const _screen_set = _symbols._screen_set; +const _update_var = _symbols._update_var; +const _add_viewing = _symbols._add_viewing; +const _remove_viewing = _symbols._remove_viewing; +const _common_tiles_count = _symbols._common_tiles_count; +const _panel_map = _symbols._panel_map; +const _visgroups = _symbols._visgroups; +const _eye_to_eyeid = _symbols._eye_to_eyeid; +module.exports._symbols = _symbols; const Component = require('./component.js'); @@ -75,7 +77,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; } diff --git a/lib/atom/mob/symbols.js b/lib/atom/mob/symbols.js new file mode 100644 index 0000000..6c9ce6f --- /dev/null +++ b/lib/atom/mob/symbols.js @@ -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}; From c4434a5e91325cd79aa95b5addfacdb1665a3f0b Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:17:56 +0300 Subject: [PATCH 4/9] Fix cyclic dependencies in lib/atom/lighting.js --- lib/atom/lighting.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/atom/lighting.js b/lib/atom/lighting.js index f1cc311..07fae9d 100644 --- a/lib/atom/lighting.js +++ b/lib/atom/lighting.js @@ -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'); From e55c895bf232f111bd0b48b151c273a9ef7851e7 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:22:34 +0300 Subject: [PATCH 5/9] Rename imported modules to avoid confusion --- client/index.js | 4 ++-- lib/server.js | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/index.js b/client/index.js index 40e0140..5b5a1b9 100644 --- a/client/index.js +++ b/client/index.js @@ -9,7 +9,7 @@ const Sound = require('./lib/sound.js'); const Matrix = require('./lib/matrix.js'); const {Eye, Plane} = require('./lib/eye.js'); -const Lighting = require('./lib/lighting.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'); @@ -41,7 +41,7 @@ class BluespessClient extends EventEmitter { if(global.AudioContext) this.audio_ctx = new AudioContext(); } - this.importModule(Lighting); + this.importModule(LightingModule); } handle_login() { diff --git a/lib/server.js b/lib/server.js index f8cf178..7255ff9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -11,9 +11,9 @@ const utils = require('./utils.js'); const VisibilityGroup = require('./atom/visgroup.js'); const Dimension = require('./dimension.js'); -const Mob = require('./atom/mob.js'); -const Lighting = require('./atom/lighting.js'); -const Hearer = require('./atom/hearer.js'); +const MobModule = require('./atom/mob.js'); +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'); @@ -60,9 +60,9 @@ class Bluespess extends EventEmitter { this.demo_stream = null; // Import default modules - this.importModule(Mob); - this.importModule(Lighting); - this.importModule(Hearer); + this.importModule(MobModule); + this.importModule(LightingModule); + this.importModule(HearerModule); this.net_tick_delay = 50; From 5022b01d82bf97ef3dd2a4ff6e03a198bdde7eda Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:26:14 +0300 Subject: [PATCH 6/9] Fix mob imports --- lib/atom/atom.js | 2 +- lib/atom/visgroup.js | 4 ++-- lib/client.js | 2 +- lib/server.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/atom/atom.js b/lib/atom/atom.js index 930a8fc..c376b0f 100644 --- a/lib/atom/atom.js +++ b/lib/atom/atom.js @@ -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'); diff --git a/lib/atom/visgroup.js b/lib/atom/visgroup.js index 4a871c4..a17a4bf 100644 --- a/lib/atom/visgroup.js +++ b/lib/atom/visgroup.js @@ -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 */ diff --git a/lib/client.js b/lib/client.js index 3638d57..06e6441 100644 --- a/lib/client.js +++ b/lib/client.js @@ -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'); diff --git a/lib/server.js b/lib/server.js index 7255ff9..413b423 100644 --- a/lib/server.js +++ b/lib/server.js @@ -11,7 +11,7 @@ const utils = require('./utils.js'); const VisibilityGroup = require('./atom/visgroup.js'); const Dimension = require('./dimension.js'); -const MobModule = require('./atom/mob.js'); +const MobModule = require('./atom/mob'); const LightingModule = require('./atom/lighting.js'); const HearerModule = require('./atom/hearer.js'); From ddba2462ed6183f9a093fec264d5fe6edc8ae155 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:52:50 +0300 Subject: [PATCH 7/9] Simplify symbols import in lib/atom/mob/index.js --- lib/atom/mob/index.js | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/lib/atom/mob/index.js b/lib/atom/mob/index.js index 83d314b..56f2196 100644 --- a/lib/atom/mob/index.js +++ b/lib/atom/mob/index.js @@ -1,23 +1,9 @@ 'use strict'; const {chain_func, is_atom, to_chat, has_component} = require('../utils.js'); -const _symbols = require('./symbols.js'); -const _observers = _symbols._observers; -const _viewers = _symbols._viewers; -const _viewing = _symbols._viewing; -const _key = _symbols._key; -const _client = _symbols._client; -const _server_to_net = _symbols._server_to_net; -const _visible_tiles = _symbols._visible_tiles; -const _screen_set = _symbols._screen_set; -const _update_var = _symbols._update_var; -const _add_viewing = _symbols._add_viewing; -const _remove_viewing = _symbols._remove_viewing; -const _common_tiles_count = _symbols._common_tiles_count; -const _panel_map = _symbols._panel_map; -const _visgroups = _symbols._visgroups; -const _eye_to_eyeid = _symbols._eye_to_eyeid; +const _symbols = require('./symbols.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} = _symbols; module.exports._symbols = _symbols; const Component = require('./component.js'); From 2f2f7a808a50d152a03f1197e7548c74d9d9be60 Mon Sep 17 00:00:00 2001 From: Kinrany Date: Thu, 28 Mar 2019 03:53:57 +0300 Subject: [PATCH 8/9] Remove one more line --- lib/atom/mob/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/atom/mob/index.js b/lib/atom/mob/index.js index 56f2196..c9dec60 100644 --- a/lib/atom/mob/index.js +++ b/lib/atom/mob/index.js @@ -2,9 +2,8 @@ const {chain_func, is_atom, to_chat, has_component} = require('../utils.js'); -const _symbols = require('./symbols.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} = _symbols; -module.exports._symbols = _symbols; +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'); From ae611d215081695a12d206b171d6b6dc4120bb7d Mon Sep 17 00:00:00 2001 From: Kinrany Date: Fri, 29 Mar 2019 00:52:55 +0300 Subject: [PATCH 9/9] Fix relative references in lib/atom/mob/index.js --- lib/atom/mob/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atom/mob/index.js b/lib/atom/mob/index.js index c9dec60..56048b6 100644 --- a/lib/atom/mob/index.js +++ b/lib/atom/mob/index.js @@ -1,11 +1,11 @@ 'use strict'; -const {chain_func, is_atom, to_chat, has_component} = require('../utils.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'); +const Component = require('../component.js'); var id_counter = 0;