diff --git a/packages/entity/index.js b/packages/entity/index.js index 850ee24..2f8ff27 100644 --- a/packages/entity/index.js +++ b/packages/entity/index.js @@ -138,6 +138,6 @@ export { hasTrait, lookupTrait, registerTrait, -} from './traits/registry'; +} from './trait-registry'; export {simpleState, Trait} from './trait'; diff --git a/packages/entity/trait-registry.js b/packages/entity/trait-registry.js new file mode 100644 index 0000000..7635925 --- /dev/null +++ b/packages/entity/trait-registry.js @@ -0,0 +1,13 @@ +const traitRegistry = new Map(); + +export function registerTrait(Trait) { + traitRegistry.set(Trait.type(), Trait); +} + +export function hasTrait(type) { + return traitRegistry.has(type); +} + +export function lookupTrait(type) { + return traitRegistry.get(type); +} diff --git a/packages/entity/traits/index.js b/packages/entity/traits.js similarity index 99% rename from packages/entity/traits/index.js rename to packages/entity/traits.js index bc0ef31..2a5f227 100644 --- a/packages/entity/traits/index.js +++ b/packages/entity/traits.js @@ -4,7 +4,7 @@ import * as I from 'immutable'; import {Resource} from '@avocado/resource'; -import {hasTrait, lookupTrait, registerTrait} from './registry'; +import {hasTrait, lookupTrait, registerTrait} from './trait-registry'; function enumerateProperties(prototype) { const result = {}; diff --git a/packages/entity/traits/registry.js b/packages/entity/traits/registry.js deleted file mode 100644 index 22c51e9..0000000 --- a/packages/entity/traits/registry.js +++ /dev/null @@ -1,35 +0,0 @@ -// import {registerType} from '@avocado/behavior'; - -const traitRegistry = new Map(); - -export function registerTrait(Trait) { - traitRegistry.set(Trait.type(), Trait); - // registerType(`entity:trait:${Trait.type()}`, Trait.contextType()); -} - -export function hasTrait(type) { - return traitRegistry.has(type); -} - -export function lookupTrait(type) { - return traitRegistry.get(type); -} - -// Register core traits. -import {Animated} from './animated'; -registerTrait(Animated); - -import {Directional} from './directional'; -registerTrait(Directional); - -import {Existent} from './existent'; -registerTrait(Existent); - -import {Graphical} from './graphical'; -registerTrait(Graphical); - -import {Mobile} from './mobile'; -registerTrait(Mobile); - -import {Positioned} from './positioned'; -registerTrait(Positioned);