diff --git a/client/index.js b/client/index.js index c918322..0c1c1d0 100644 --- a/client/index.js +++ b/client/index.js @@ -14,7 +14,9 @@ import {Room, RoomView} from '@avocado/topdown'; import {World} from '@avocado/physics/matter/world'; import {clearAnimation, setAnimation, Ticker} from '@avocado/timing'; // 1st party. -import {InputPacket, KeysPacket, StatePacket} from '../common/packet'; +import {InputPacket} from '../common/packet/input.packet'; +import {KeysPacket} from '../common/packet/keys.packet'; +import {StatePacket} from '../common/packet/state.packet'; import {augmentParserWithThroughput} from '../common/parser-throughput'; import {WorldTime} from '../common/world-time'; import {App} from './app'; diff --git a/common/packet/index.js b/common/packet/index.js deleted file mode 100644 index 999003c..0000000 --- a/common/packet/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import {registerPacket} from '@avocado/packet'; - -import {InputPacket} from './input'; -registerPacket(InputPacket); - -import {KeysPacket} from './keys'; -registerPacket(KeysPacket); - -import {StatePacket} from './state'; -registerPacket(StatePacket); - -export {InputPacket, KeysPacket, StatePacket}; diff --git a/common/packet/input.js b/common/packet/input.packet.js similarity index 100% rename from common/packet/input.js rename to common/packet/input.packet.js diff --git a/common/packet/keys.js b/common/packet/keys.packet.js similarity index 100% rename from common/packet/keys.js rename to common/packet/keys.packet.js diff --git a/common/packet/state.js b/common/packet/state.packet.js similarity index 100% rename from common/packet/state.js rename to common/packet/state.packet.js diff --git a/defgen.js b/defgen.js index e54b9c5..99a8cdb 100644 --- a/defgen.js +++ b/defgen.js @@ -43,9 +43,9 @@ module.exports = function(source) { // Validate schema. validateOptions(schema, options, 'Avocado defgen'); // Extract options. - const {paths, registrar, type} = options; + const {classTransformer: transformer, paths, registrar, type} = options; // Search avocado. - options.paths.push(path.resolve( + paths.push(path.resolve( __dirname, 'node_modules', '@avocado', )); // Get all trait source paths. @@ -79,16 +79,18 @@ module.exports = function(source) { const rest = part.substr(1).toLowerCase(); return className + firstLetter + rest; }, ''); + const transformed = transformer ? transformer(className) : className; // Import and register. return [ - `import {${className}} from '${importPath}';`, - `${registrar.function}(${className});`, + `import {${transformed}} from '${importPath}';`, + `${registrar.function}(${transformed});`, ].join('\n'); }); // Import trait registry first. - return [ + const output = [ `import {${registrar.function}} from '${registrar.module}'`, '', ...importDefinitions ].join('\n'); + return output; } diff --git a/register-packets.js b/register-packets.js new file mode 100644 index 0000000..e69de29 diff --git a/server/game.js b/server/game.js index fd4aaac..99e56ef 100644 --- a/server/game.js +++ b/server/game.js @@ -6,7 +6,7 @@ import {performance} from 'perf_hooks'; import {Synchronizer} from '@avocado/state'; import {Ticker} from '@avocado/timing'; // 1st party. -import {InputPacket} from '../common/packet'; +import {InputPacket} from '../common/packet/input.packet'; import {WorldTime} from '../common/world-time'; import {createEntityForConnection} from './create-entity-for-connection'; import {createRoom} from './create-server-room'; diff --git a/server/traits/informed.trait.js b/server/traits/informed.trait.js index 6a8f16a..abd5180 100644 --- a/server/traits/informed.trait.js +++ b/server/traits/informed.trait.js @@ -7,8 +7,8 @@ import {Trait} from '@avocado/entity'; import {Rectangle, Vector} from '@avocado/math'; import {Packer, Synchronizer} from '@avocado/state'; -import {KeysPacket} from '../../common/packet/keys'; -import {StatePacket} from '../../common/packet/state'; +import {KeysPacket} from '../../common/packet/keys.packet'; +import {StatePacket} from '../../common/packet/state.packet'; const decorate = compose( ); diff --git a/webpack.client.config.js b/webpack.client.config.js index aaab909..45549fb 100644 --- a/webpack.client.config.js +++ b/webpack.client.config.js @@ -7,6 +7,7 @@ const config = require('./webpack.common.config'); config.entry = { client: [ '@babel/polyfill', + path.join(__dirname, 'register-packets.js'), path.join(__dirname, 'register-traits.js'), '@avocado/behavior/item/initialize', path.join(__dirname, 'client', 'index.js'), @@ -37,6 +38,9 @@ config.devtool = 'eval-source-map'; config.module.rules[1].use.options.paths.push( path.resolve(__dirname, 'client'), ); +config.module.rules[2].use.options.paths.push( + path.resolve(__dirname, 'client'), +); config.node = { fs: 'empty', path: 'empty', diff --git a/webpack.common.config.js b/webpack.common.config.js index 4180bf7..5c94443 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -16,6 +16,25 @@ const config = { loader: 'babel-loader', }, }, + { + test: /register-packets\.js/, + use: { + loader: './defgen', + options: { + classTransformer: (Packet) => { + return `${Packet}Packet`; + }, + paths: [ + path.resolve(__dirname, 'common'), + ], + registrar: { + function: 'registerPacket', + module: '@avocado/packet', + }, + type: 'packet', + }, + }, + }, { test: /register-traits\.js/, use: { @@ -26,7 +45,7 @@ const config = { ], registrar: { function: 'registerTrait', - module: '@avocado/entity/trait-registry', + module: '@avocado/entity', }, type: 'trait', }, diff --git a/webpack.server.config.js b/webpack.server.config.js index 0e77562..32043b3 100644 --- a/webpack.server.config.js +++ b/webpack.server.config.js @@ -9,6 +9,7 @@ config.entry = { server: [ 'source-map-support/register', '@babel/polyfill', + path.join(__dirname, 'register-packets.js'), path.join(__dirname, 'register-traits.js'), '@avocado/behavior/item/initialize', path.join(__dirname, 'server', 'index.js'), @@ -22,6 +23,9 @@ config.externals = [ config.module.rules[1].use.options.paths.push( path.resolve(__dirname, 'server'), ); +config.module.rules[2].use.options.paths.push( + path.resolve(__dirname, 'server'), +); const nodeArgs = []; if (process.argv.find((arg) => '--prof' === arg)) { nodeArgs.push('--prof');