refactor: restructure traits, no autoregister

This commit is contained in:
cha0s 2019-03-19 19:52:00 -05:00
parent a02353f95a
commit 3b0efe4e9b
4 changed files with 15 additions and 37 deletions

View File

@ -138,6 +138,6 @@ export {
hasTrait, hasTrait,
lookupTrait, lookupTrait,
registerTrait, registerTrait,
} from './traits/registry'; } from './trait-registry';
export {simpleState, Trait} from './trait'; export {simpleState, Trait} from './trait';

View File

@ -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);
}

View File

@ -4,7 +4,7 @@ import * as I from 'immutable';
import {Resource} from '@avocado/resource'; import {Resource} from '@avocado/resource';
import {hasTrait, lookupTrait, registerTrait} from './registry'; import {hasTrait, lookupTrait, registerTrait} from './trait-registry';
function enumerateProperties(prototype) { function enumerateProperties(prototype) {
const result = {}; const result = {};

View File

@ -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);