refactor: mixin

This commit is contained in:
cha0s 2024-01-05 20:02:38 -06:00
parent 2c48d5b808
commit 9dc84ba910
45 changed files with 181 additions and 81 deletions

View File

@ -12,7 +12,22 @@ export const hooks = {
cache.reset();
}
},
'@flecks/core.mixin': (Flecks) => (
class FlecksWithAvocadoBehavior extends Flecks {
constructor(...args) {
super(...args);
if (!this.avocado) {
this.avocado = {};
}
this.avocado.behavior = {
globals: {},
};
}
}
),
'@flecks/core.starting': async (flecks) => {
flecks.set('$avocado/behavior.globals', flecks.invokeMerge('@avocado/behavior.globals'));
flecks.avocado.behavior.globals = flecks.invokeMerge('@avocado/behavior.globals');
},
};

View File

@ -49,7 +49,7 @@ export default (flecks) => {
}
return {
[Populated]: true,
...flecks.get('$avocado/behavior.globals'),
...flecks.avocado.behavior,
...locals,
};
}

View File

@ -31,7 +31,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
({
currentRoutine: this.$$currentRoutine,
} = this.constructor.defaultState());
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
this.$$context = Script.createContext();
}
@ -79,7 +79,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
static async loadScripts(scripts, context) {
return mapValuesAsync(scripts, async (codeOrUri) => {
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
const script = await Script.load(codeOrUri);
script.context = context;
return script;
@ -88,7 +88,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
async load(json) {
await super.load(json);
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
this.$$context = Script.createContext({
entity: this.entity,
});

View File

@ -10,11 +10,26 @@ export const hooks = {
Flecks.decorate(require.context('./traits/decorators', false, /\.js$/))
),
'@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)),
'@flecks/core.mixin': (Flecks) => (
class FlecksWithAvocadoDialog extends Flecks {
constructor(...args) {
super(...args);
if (!this.avocado) {
this.avocado = {};
}
this.avocado.dialog = {
parser: undefined,
};
}
}
),
'@flecks/core.starting': (flecks) => {
const dialogFunctions = flecks.invokeMerge('@avocado/dialog.functions');
const resolver = (type) => (dialogFunctions[type] ? dialogFunctions[type] : (i) => i);
flecks.set('$avocado/dialog.parser', async (text) => {
const {Entity} = flecks.avocado.Resources;
flecks.avocado.dialog.parser = async (text) => {
const {Entity} = flecks.avocado.resource.Resources;
const letters = await Promise.all(
parse(text, resolver)
.map((letter) => Entity.load({traits: letter})),
@ -23,7 +38,7 @@ export const hooks = {
letters,
words: await wordize(letters, flecks),
};
});
};
},
'@flecks/socket.packets': Flecks.provide(require.context('./packets', false, /\.js$/)),
};

View File

@ -38,7 +38,7 @@ export default (Trait, flecks) => class DialogInitiator extends Trait {
openDialog: async (text) => {
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
if (!this.entity.list) {
return;
}

View File

@ -43,7 +43,7 @@ export default (flecks) => {
({
letters: this.$$letters,
words: this.$$words,
} = await flecks.get('$avocado/dialog.parser')(
} = await flecks.avocado.dialog.parser(
`<rate frequency={${this.params.rate}}>${text}</rate>`,
));
if (this.$$letters.length > 0) {

View File

@ -1,5 +1,5 @@
const createWord = async (letters, flecks) => {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const word = await Entity.load({
traits: {
DomNode: {

View File

@ -1,6 +1,6 @@
export default async (flecks) => {
const {Entity} = flecks.avocado.Resources;
const Traits = flecks.get('$avocado/traits.traits');
const {Entity} = flecks.avocado.resource.Resources;
const {Traits} = flecks.avocado.traits;
const AllTraits = Object.fromEntries(
Object.entries(Traits)
.filter(([key]) => !Number.isInteger(parseInt(key, 10))),

View File

@ -25,7 +25,7 @@ const EntityComponent = ({
uri,
}) => {
const flecks = useFlecks();
const {Entity, EntityList} = flecks.avocado.Resources;
const {Entity, EntityList} = flecks.avocado.resource.Resources;
const [entity, setEntity] = useState();
const dep = uri ? join(uri, path) : path;
useEffect(() => {

View File

@ -1,7 +1,7 @@
import {JsonController} from '@avocado/resource/persea';
export default (buffer, flecks) => {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const json = Entity.withDefaults(JsonController.fromBuffer(buffer));
return {
...json,

View File

@ -1,7 +1,7 @@
import {JsonController} from '@avocado/resource/persea';
export default (resource, flecks) => {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const json = Entity.withoutDefaults(resource);
return JsonController.toBuffer({
...json,

View File

@ -60,14 +60,14 @@ const Traits = ({
</button>
</Tab>
));
const Traits = flecks.get('$avocado/traits.traits');
const {Traits} = flecks.avocado.traits;
const suggestible = difference(
Object.entries(Traits)
.filter(([key]) => !Number.isInteger(parseInt(key, 10)))
.map(([, {type}]) => type),
types,
);
const Components = flecks.get('$avocado/traits/persea.components');
const {Components} = flecks.avocado.traits.persea;
const tabPanels = types.map((type) => {
const Component = Components[type] || JsonTraitComponent;
return (

View File

@ -26,7 +26,7 @@ export default (flecks) => {
await super.acceptPacket(packet);
const {s13nType} = packet;
if ('create' === s13nType) {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const {id} = packet.data.synchronized;
const entity = this.synchronized(Entity.resourceId, id);
if (entity) {
@ -85,7 +85,7 @@ export default (flecks) => {
return;
}
await this.destroyEntities();
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const entityInstances = await Promise.all(json.map((entity) => Entity.load(entity)));
for (let i = 0; i < entityInstances.length; i++) {
this.addEntity(entityInstances[i]);
@ -105,7 +105,7 @@ export default (flecks) => {
packetsFor(informed) {
const packets = [];
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
// Visible entities.
const {areaToInform} = informed;
const previousVisibleEntities = this.$$informedEntities.get(informed);
@ -202,7 +202,7 @@ export default (flecks) => {
}
toJSON() {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const json = [];
for (let i = 0; i < this.$$flatEntities.length; i++) {
const entity = this.$$flatEntities[i];

View File

@ -74,7 +74,7 @@ export default (flecks) => {
}
async $$addTrait(type, json = {}) {
const {[type]: Trait} = flecks.get('$avocado/traits.traits');
const {[type]: Trait} = flecks.avocado.traits.Traits;
if (!Trait) {
// eslint-disable-next-line no-console
console.error(`Tried to add trait "${type}" which isn't registered!`);
@ -150,7 +150,7 @@ export default (flecks) => {
}
async addTraits(traits) {
const Traits = flecks.get('$avocado/traits.traits');
const {Traits} = flecks.avocado.traits;
const reorganized = {};
const add = (type) => {
const deps = Traits[type]?.dependencies() || [];
@ -192,7 +192,7 @@ export default (flecks) => {
}
createContext(locals = {}) {
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
return Script.createContext({
...this.contextOrDefault,
...locals,
@ -200,7 +200,7 @@ export default (flecks) => {
}
static dependencyTree(types) {
const Traits = flecks.get('$avocado/traits.traits');
const {Traits} = flecks.avocado.traits;
const tree = new Set(types);
const checking = types;
while (checking.length > 0) {
@ -330,7 +330,7 @@ export default (flecks) => {
const implementation = this.$$hooks[hook].find(({type: hookType}) => hookType === type);
this.$$hooks[hook].splice(this.$$hooks[hook].indexOf(implementation), 1);
}
const {[type]: Trait} = flecks.get('$avocado/traits.traits');
const {[type]: Trait} = flecks.avocado.traits.Traits;
const properties = enumerateTraitAccessorKeys(Trait.prototype);
for (let i = 0; i < properties.length; ++i) {
const property = properties[i];
@ -453,7 +453,7 @@ export default (flecks) => {
}
static withDefaults(json = {}) {
const Traits = flecks.get('$avocado/traits.traits');
const {Traits} = flecks.avocado.traits;
return {
...json,
traits: Object.entries(json.traits)
@ -467,7 +467,7 @@ export default (flecks) => {
}
static withoutDefaults(json) {
const Traits = flecks.get('$avocado/traits.traits');
const {Traits} = flecks.avocado.traits;
const without = {
...json,
traits: Object.entries(json.traits)

View File

@ -68,7 +68,7 @@ export default (flecks) => class Alive extends decorate(Trait) {
async die() {
this.entity.emit('startedDying');
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
const deathScript = await Script.load(this.params.deathScript, this.entity.contextOrDefault);
await this.entity.addTickingPromise(deathScript.tickingPromise());
const died = this.entity.invokeHookFlat('died');
@ -117,7 +117,7 @@ export default (flecks) => class Alive extends decorate(Trait) {
async load(json) {
await super.load(json);
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
this.$$deathCheck = await Script.load(this.params.deathCheck, this.entity.contextOrDefault);
}

View File

@ -224,7 +224,7 @@ export default (flecks) => class Spawner extends decorate(Trait) {
const childIndex = this.$$children.length;
this.$$children.push(null);
const list = this.destinationEntityList();
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const child = await Entity.load(json);
this.$$children[childIndex] = child;
// Listen for destroy event.

View File

@ -19,7 +19,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -18,7 +18,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -17,7 +17,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();
@ -36,7 +36,7 @@ it('can add and remove traits', async () => {
}
};
flecks.set('$avocado/traits.traits.TestTrait', TestTrait);
flecks.avocado.traits.Traits['TestTrait'] = TestTrait;
await entity.addTrait('TestTrait');
expect(entity.is('TestTrait')).to.be.true;
entity.removeTrait('TestTrait');
@ -55,7 +55,7 @@ it('can add traits asynchronously', async () => {
}
}
flecks.set('$avocado/traits.traits.Async', AsyncTrait);
flecks.avocado.traits.Traits['Async'] = AsyncTrait;
const start = Date.now();
await Entity.load({
traits: {
@ -95,8 +95,8 @@ it('can invoke hooks', async () => {
}
}
flecks.set('$avocado/traits.traits.AnotherTrait', AnotherTrait);
flecks.set('$avocado/traits.traits.YetAnotherTrait', YetAnotherTrait);
flecks.avocado.traits.Traits['AnotherTrait'] = AnotherTrait;
flecks.avocado.traits.Traits['YetAnotherTrait'] = YetAnotherTrait;
const entity = new Entity();
await entity.addTrait('AnotherTrait');
await entity.addTrait('YetAnotherTrait');

View File

@ -17,7 +17,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -17,7 +17,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -17,7 +17,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -17,7 +17,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity} = flecks.avocado.Resources);
({Entity} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -19,7 +19,7 @@ beforeEach(async () => {
},
});
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
({Entity, EntityList} = flecks.avocado.Resources);
({Entity, EntityList} = flecks.avocado.resource.Resources);
});
afterEach(() => {
flecks.destroy();

View File

@ -31,7 +31,7 @@ export default (flecks) => class Interactive extends decorate(Trait) {
return {
interact: async (initiator) => {
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
const script = await Script.load(this.params.interactScript, {
entity: this.entity,
initiator,

View File

@ -17,7 +17,7 @@ const Emitter = memo(({
path,
}) => {
const flecks = useFlecks();
const {Emitted} = flecks.get('$avocado/traits.traits');
const {Emitted} = flecks.avocado.traits.Traits;
return (
<div className="emitter">
<JsonTabs

View File

@ -20,7 +20,7 @@ const Particle = ({
}) => {
const flecks = useFlecks();
const patch = useJsonPatcher();
const {EntityList} = flecks.avocado.Resources;
const {EntityList} = flecks.avocado.resource.Resources;
const entityList = new EntityList();
const entityListView = new EntityListView(entityList);
entityList.addEntity(entity);

View File

@ -145,7 +145,7 @@ export default (flecks) => class Collider extends decorate(Trait) {
}
async pushCollisionTickingPromise(codeOrUri, other, incident) {
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
this.entity.addTickingPromise(Script.loadTickingPromise(codeOrUri, {
...this.entity.contextOrDefault,
incident,

View File

@ -108,7 +108,7 @@ export default (flecks) => class Emitted extends decorate(Trait) {
if (!this.params.onDead) {
return;
}
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
this.entity.addTickingPromise(Script.loadTickingPromise(this.params.onDead, {
...this.entity.contextOrDefault,
}));

View File

@ -59,7 +59,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
}
async emitParticleJson(json) {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
let entity;
if (this.$$pool.length > 0) {
entity = this.$$pool.pop();
@ -282,7 +282,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
}
static withDefaults(json = {}) {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
return {
params: {
...this.defaultParamsWith(json.params || {}),
@ -297,7 +297,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
}
static withoutDefaults(json) {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
return {
params: {
...this.defaultParamsWith(json.params || {}),

View File

@ -18,13 +18,16 @@ export const hooks = {
if (!this.avocado) {
this.avocado = {};
}
this.avocado.Resources = {};
if (!this.avocado.resource) {
this.avocado.resource = {};
}
this.avocado.resource.Resources = {};
}
}
),
'@flecks/core.starting': (flecks) => {
flecks.avocado.Resources = flecks.gather(
flecks.avocado.resource.Resources = flecks.gather(
'@avocado/resource.resources',
{
idProperty: 'resourceId',

View File

@ -2,6 +2,6 @@ import {useFlecks} from '@flecks/react';
export default (uri) => (
useFlecks()
.get('$avocado/resource/persea.controllers')
.avocado.resource.persea.Controllers
.find(({matcher}) => uri.match(matcher))
);

View File

@ -22,6 +22,24 @@ export {
};
export const hooks = {
'@flecks/core.mixin': (Flecks) => (
class FlecksWithAvocadoResourcePersea extends Flecks {
constructor(...args) {
super(...args);
if (!this.avocado) {
this.avocado = {};
}
if (!this.avocado.resource) {
this.avocado.resource = {};
}
this.avocado.resource.persea = {
Controllers: {},
};
}
}
),
'@flecks/core.starting': async (flecks) => {
const Controllers = (
await flecks.invokeSequentialAsync('@avocado/resource/persea.controllers')
@ -31,7 +49,7 @@ export const hooks = {
TextController,
BinaryController,
);
flecks.set('$avocado/resource/persea.controllers', Controllers);
this.avocado.resource.persea.Controllers = Controllers;
},
'@flecks/redux.reducers': () => reducer,
};

View File

@ -30,7 +30,7 @@ export default (flecks) => (Resource) => (
}
async createSynchronized(type, id, json) {
const {[type]: Resource} = flecks.avocado.Resources;
const {[type]: Resource} = flecks.avocado.resource.Resources;
if (!(type in this.$$synchronized)) {
this.$$synchronized[type] = {};
}

View File

@ -18,7 +18,7 @@ import {
const AnimationVisualization = ({json}) => {
const flecks = useFlecks();
// const {uuid} = useParams();
const {Animation} = flecks.avocado.Resources;
const {Animation} = flecks.avocado.resource.Resources;
const [animations, setAnimations] = useState([]);
const [container] = useState(new Container());
useEffect(() => {

View File

@ -29,7 +29,7 @@ const Animation = ({
if (!fullJson) {
return;
}
const {Animation} = flecks.avocado.Resources;
const {Animation} = flecks.avocado.resource.Resources;
const loadJson = async () => {
const animationView = new AnimationView(await Animation.load(fullJson));
const drawCross = (primitives, origin, color) => {

View File

@ -192,7 +192,7 @@ export default (flecks) => class Animated extends decorate(Trait) {
async load(json) {
await super.load(json);
if (Object.keys(this.params.animations).length > 0) {
const {Animation} = flecks.avocado.Resources;
const {Animation} = flecks.avocado.resource.Resources;
const animations = await mapValuesAsync(
this.params.animations,
(json) => Animation.load(json),

View File

@ -41,14 +41,14 @@ const RoomComponent = ({
const {uri, uuid} = useContext(Context);
const dispatch = useDispatch();
const flecks = useFlecks();
const {Room, Tiles} = flecks.avocado.Resources;
const {Room, Tiles} = flecks.avocado.resource.Resources;
const previousResource = usePrevious(resource);
const [events, setEvents] = useState();
const [scale, setScale] = useState(3);
const [side, setSide] = useState(0);
const [room, setRoom] = useState();
const [roomRenderable, setRoomRenderable] = useState();
const roomSides = flecks.get('$avocado/topdown/persea.room-sides');
const {RoomSides} = flecks.avocado.topdown.persea;
// Stage event stream.
const onRef = useCallback((stage) => {
setEvents(stage?.events());
@ -236,7 +236,7 @@ const RoomComponent = ({
</div>
{
React.createElement(
roomSides[side],
RoomSides[side],
{
active: true,
events,

View File

@ -10,11 +10,28 @@ export const hooks = {
'@avocado/resource/persea.controllers': () => [
RoomController,
],
'@flecks/core.mixin': (Flecks) => (
class FlecksWithAvocadoTopdownPersea extends Flecks {
constructor(...args) {
super(...args);
if (!this.avocado) {
this.avocado = {};
}
if (!this.avocado.topdown) {
this.avocado.topdown = {};
}
this.avocado.topdown.persea = {
RoomSides: {},
};
}
}
),
'@flecks/core.starting': (flecks) => {
flecks.set(
'$avocado/topdown/persea.room-sides',
flecks.invokeFlat('@avocado/topdown/persea.room-sides').flat(),
);
flecks.avocado.topdown.persea.RoomSides = flecks.invokeFlat(
'@avocado/topdown/persea.room-sides',
).flat();
},
'@avocado/topdown/persea.room-sides': () => [
TilesSide,

View File

@ -448,7 +448,7 @@ function TilesPage({
<VectorComponent
disabled={!resource.tiles[currentLayer]}
onChange={(event, newArea) => {
const {Tiles} = flecks.avocado.Resources;
const {Tiles} = flecks.avocado.resource.Resources;
// Create new tiles.
const newTiles = new Tiles();
newTiles.area = newArea;

View File

@ -24,7 +24,7 @@ export default (flecks) => {
constructor() {
super();
this.$$s13nId = s13nId++;
const {EntityList} = flecks.avocado.Resources;
const {EntityList} = flecks.avocado.resource.Resources;
this.entityList = new EntityList();
this.entityList.on('entityAdded', this.onEntityAdded, this);
this.entityList.on('entityRemoved', this.onEntityRemoved, this);
@ -66,7 +66,7 @@ export default (flecks) => {
}
async loadTiles(tiles) {
const {Tiles} = flecks.avocado.Resources;
const {Tiles} = flecks.avocado.resource.Resources;
this.removeAllTiles();
(await Promise.all(tiles.map((json, i) => Tiles.load({s13nId: i, ...json}))))
.forEach((tiles) => {

View File

@ -13,7 +13,7 @@
// await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
// });
// it('has sane defaults', async () => {
// const {Layer} = flecks.avocado.Resources;
// const {Layer} = flecks.avocado.resource.Resources;
// const layer = new Layer();
// expect(Object.keys(layer.entities).length).to.equal(0);
// expect(layer.tiles.size).to.deep.equal([0, 0]);

View File

@ -11,13 +11,13 @@
// await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
// });
// it("has sane defaults", async () => {
// const {Tiles} = flecks.avocado.Resources;
// const {Tiles} = flecks.avocado.resource.Resources;
// const tiles = new Tiles();
// expect(tiles.size).to.deep.equal([0, 0]);
// expect(tiles.data.length).to.equal(0);
// });
// it("gets and sets tile data", async () => {
// const {Tiles} = flecks.avocado.Resources;
// const {Tiles} = flecks.avocado.resource.Resources;
// const tiles = new Tiles({data: [0, 1, 2, 3], size: [2, 2]});
// expect(tiles.tileAt([0, 0])).to.equal(0);
// expect(tiles.tileAt([1, 0])).to.equal(1);
@ -30,7 +30,7 @@
// expect(tiles.data).to.deep.equal([69, 420, 311, 42]);
// });
// it("can get a data slice", async () => {
// const {Tiles} = flecks.avocado.Resources;
// const {Tiles} = flecks.avocado.resource.Resources;
// const tiles = new Tiles(
// {
// data: [
@ -50,7 +50,7 @@
// expect(tiles.slice([1, 1, 0, 0])).to.deep.equal([]);
// });
// it("can get convex hulls around indices", () => {
// const {Tiles} = flecks.avocado.Resources;
// const {Tiles} = flecks.avocado.resource.Resources;
// const hulls = [
// [
// [2, 0],
@ -81,7 +81,7 @@
// expect(tiles.indexHulls(new Set([1]))).to.deep.equal(hulls);
// });
// it("can stamp at", async () => {
// const {Tiles} = flecks.avocado.Resources;
// const {Tiles} = flecks.avocado.resource.Resources;
// const tiles = new Tiles(
// {
// data: [
@ -112,7 +112,7 @@
// ]);
// });
// it("can handle pathological hulls", () => {
// const {Tiles} = flecks.avocado.Resources;
// const {Tiles} = flecks.avocado.resource.Resources;
// const hulls = [
// [
// [ 0, 0 ],

View File

@ -2,7 +2,22 @@ export {default as Trait} from './trait';
export {default as StateProperty} from './state-property';
export const hooks = {
'@flecks/core.mixin': (Flecks) => (
class FlecksWithAvocadoTraitrs extends Flecks {
constructor(...args) {
super(...args);
if (!this.avocado) {
this.avocado = {};
}
this.avocado.traits = {
Traits: {},
};
}
}
),
'@flecks/core.starting': (flecks) => {
flecks.set('$avocado/traits.traits', flecks.gather('@avocado/traits.traits'));
flecks.avocado.traits.Traits = flecks.gather('@avocado/traits.traits');
},
};

View File

@ -1,8 +1,25 @@
export const hooks = {
'@flecks/core.mixin': (Flecks) => (
class FlecksWithAvocadoTraitrs extends Flecks {
constructor(...args) {
super(...args);
if (!this.avocado) {
this.avocado = {};
}
if (!this.avocado.traits) {
this.avocado.traits = {};
}
this.avocado.traits.persea = {
Components: {},
};
}
}
),
'@flecks/core.starting': async (flecks) => {
flecks.set(
'$avocado/traits/persea.components',
flecks.invokeMerge('@avocado/traits/persea.components'),
flecks.avocado.traits.persea.Components = flecks.invokeMerge(
'@avocado/traits/persea.components',
);
},
};