refactor: mixin
This commit is contained in:
parent
b3407b2d3f
commit
2c48d5b808
|
@ -31,7 +31,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
|
||||||
({
|
({
|
||||||
currentRoutine: this.$$currentRoutine,
|
currentRoutine: this.$$currentRoutine,
|
||||||
} = this.constructor.defaultState());
|
} = this.constructor.defaultState());
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
this.$$context = Script.createContext();
|
this.$$context = Script.createContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
|
||||||
|
|
||||||
static async loadScripts(scripts, context) {
|
static async loadScripts(scripts, context) {
|
||||||
return mapValuesAsync(scripts, async (codeOrUri) => {
|
return mapValuesAsync(scripts, async (codeOrUri) => {
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
const script = await Script.load(codeOrUri);
|
const script = await Script.load(codeOrUri);
|
||||||
script.context = context;
|
script.context = context;
|
||||||
return script;
|
return script;
|
||||||
|
@ -88,7 +88,7 @@ export default (flecks) => class Behaved extends decorate(Trait) {
|
||||||
|
|
||||||
async load(json) {
|
async load(json) {
|
||||||
await super.load(json);
|
await super.load(json);
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
this.$$context = Script.createContext({
|
this.$$context = Script.createContext({
|
||||||
entity: this.entity,
|
entity: this.entity,
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@ export const hooks = {
|
||||||
const dialogFunctions = flecks.invokeMerge('@avocado/dialog.functions');
|
const dialogFunctions = flecks.invokeMerge('@avocado/dialog.functions');
|
||||||
const resolver = (type) => (dialogFunctions[type] ? dialogFunctions[type] : (i) => i);
|
const resolver = (type) => (dialogFunctions[type] ? dialogFunctions[type] : (i) => i);
|
||||||
flecks.set('$avocado/dialog.parser', async (text) => {
|
flecks.set('$avocado/dialog.parser', async (text) => {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const letters = await Promise.all(
|
const letters = await Promise.all(
|
||||||
parse(text, resolver)
|
parse(text, resolver)
|
||||||
.map((letter) => Entity.load({traits: letter})),
|
.map((letter) => Entity.load({traits: letter})),
|
||||||
|
|
|
@ -38,7 +38,7 @@ export default (Trait, flecks) => class DialogInitiator extends Trait {
|
||||||
|
|
||||||
openDialog: async (text) => {
|
openDialog: async (text) => {
|
||||||
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
|
if ('web' === process.env.FLECKS_CORE_BUILD_TARGET) {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
if (!this.entity.list) {
|
if (!this.entity.list) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const createWord = async (letters, flecks) => {
|
const createWord = async (letters, flecks) => {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const word = await Entity.load({
|
const word = await Entity.load({
|
||||||
traits: {
|
traits: {
|
||||||
DomNode: {
|
DomNode: {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export default async (flecks) => {
|
export default async (flecks) => {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const Traits = flecks.get('$avocado/traits.traits');
|
const Traits = flecks.get('$avocado/traits.traits');
|
||||||
const AllTraits = Object.fromEntries(
|
const AllTraits = Object.fromEntries(
|
||||||
Object.entries(Traits)
|
Object.entries(Traits)
|
||||||
|
|
|
@ -25,7 +25,7 @@ const EntityComponent = ({
|
||||||
uri,
|
uri,
|
||||||
}) => {
|
}) => {
|
||||||
const flecks = useFlecks();
|
const flecks = useFlecks();
|
||||||
const {Entity, EntityList} = flecks.get('$avocado/resource.resources');
|
const {Entity, EntityList} = flecks.avocado.Resources;
|
||||||
const [entity, setEntity] = useState();
|
const [entity, setEntity] = useState();
|
||||||
const dep = uri ? join(uri, path) : path;
|
const dep = uri ? join(uri, path) : path;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {JsonController} from '@avocado/resource/persea';
|
import {JsonController} from '@avocado/resource/persea';
|
||||||
|
|
||||||
export default (buffer, flecks) => {
|
export default (buffer, flecks) => {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const json = Entity.withDefaults(JsonController.fromBuffer(buffer));
|
const json = Entity.withDefaults(JsonController.fromBuffer(buffer));
|
||||||
return {
|
return {
|
||||||
...json,
|
...json,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {JsonController} from '@avocado/resource/persea';
|
import {JsonController} from '@avocado/resource/persea';
|
||||||
|
|
||||||
export default (resource, flecks) => {
|
export default (resource, flecks) => {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const json = Entity.withoutDefaults(resource);
|
const json = Entity.withoutDefaults(resource);
|
||||||
return JsonController.toBuffer({
|
return JsonController.toBuffer({
|
||||||
...json,
|
...json,
|
||||||
|
|
|
@ -26,7 +26,7 @@ export default (flecks) => {
|
||||||
await super.acceptPacket(packet);
|
await super.acceptPacket(packet);
|
||||||
const {s13nType} = packet;
|
const {s13nType} = packet;
|
||||||
if ('create' === s13nType) {
|
if ('create' === s13nType) {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const {id} = packet.data.synchronized;
|
const {id} = packet.data.synchronized;
|
||||||
const entity = this.synchronized(Entity.resourceId, id);
|
const entity = this.synchronized(Entity.resourceId, id);
|
||||||
if (entity) {
|
if (entity) {
|
||||||
|
@ -85,7 +85,7 @@ export default (flecks) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.destroyEntities();
|
await this.destroyEntities();
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const entityInstances = await Promise.all(json.map((entity) => Entity.load(entity)));
|
const entityInstances = await Promise.all(json.map((entity) => Entity.load(entity)));
|
||||||
for (let i = 0; i < entityInstances.length; i++) {
|
for (let i = 0; i < entityInstances.length; i++) {
|
||||||
this.addEntity(entityInstances[i]);
|
this.addEntity(entityInstances[i]);
|
||||||
|
@ -105,7 +105,7 @@ export default (flecks) => {
|
||||||
|
|
||||||
packetsFor(informed) {
|
packetsFor(informed) {
|
||||||
const packets = [];
|
const packets = [];
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
// Visible entities.
|
// Visible entities.
|
||||||
const {areaToInform} = informed;
|
const {areaToInform} = informed;
|
||||||
const previousVisibleEntities = this.$$informedEntities.get(informed);
|
const previousVisibleEntities = this.$$informedEntities.get(informed);
|
||||||
|
@ -202,7 +202,7 @@ export default (flecks) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const json = [];
|
const json = [];
|
||||||
for (let i = 0; i < this.$$flatEntities.length; i++) {
|
for (let i = 0; i < this.$$flatEntities.length; i++) {
|
||||||
const entity = this.$$flatEntities[i];
|
const entity = this.$$flatEntities[i];
|
||||||
|
|
|
@ -192,7 +192,7 @@ export default (flecks) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
createContext(locals = {}) {
|
createContext(locals = {}) {
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
return Script.createContext({
|
return Script.createContext({
|
||||||
...this.contextOrDefault,
|
...this.contextOrDefault,
|
||||||
...locals,
|
...locals,
|
||||||
|
|
|
@ -68,7 +68,7 @@ export default (flecks) => class Alive extends decorate(Trait) {
|
||||||
|
|
||||||
async die() {
|
async die() {
|
||||||
this.entity.emit('startedDying');
|
this.entity.emit('startedDying');
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
const deathScript = await Script.load(this.params.deathScript, this.entity.contextOrDefault);
|
const deathScript = await Script.load(this.params.deathScript, this.entity.contextOrDefault);
|
||||||
await this.entity.addTickingPromise(deathScript.tickingPromise());
|
await this.entity.addTickingPromise(deathScript.tickingPromise());
|
||||||
const died = this.entity.invokeHookFlat('died');
|
const died = this.entity.invokeHookFlat('died');
|
||||||
|
@ -117,7 +117,7 @@ export default (flecks) => class Alive extends decorate(Trait) {
|
||||||
|
|
||||||
async load(json) {
|
async load(json) {
|
||||||
await super.load(json);
|
await super.load(json);
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
this.$$deathCheck = await Script.load(this.params.deathCheck, this.entity.contextOrDefault);
|
this.$$deathCheck = await Script.load(this.params.deathCheck, this.entity.contextOrDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ export default (flecks) => class Spawner extends decorate(Trait) {
|
||||||
const childIndex = this.$$children.length;
|
const childIndex = this.$$children.length;
|
||||||
this.$$children.push(null);
|
this.$$children.push(null);
|
||||||
const list = this.destinationEntityList();
|
const list = this.destinationEntityList();
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
const child = await Entity.load(json);
|
const child = await Entity.load(json);
|
||||||
this.$$children[childIndex] = child;
|
this.$$children[childIndex] = child;
|
||||||
// Listen for destroy event.
|
// Listen for destroy event.
|
||||||
|
|
|
@ -19,7 +19,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -18,7 +18,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -17,7 +17,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -17,7 +17,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -17,7 +17,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -17,7 +17,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -17,7 +17,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity} = flecks.get('$avocado/resource.resources'));
|
({Entity} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -19,7 +19,7 @@ beforeEach(async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));
|
||||||
({Entity, EntityList} = flecks.get('$avocado/resource.resources'));
|
({Entity, EntityList} = flecks.avocado.Resources);
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
flecks.destroy();
|
flecks.destroy();
|
||||||
|
|
|
@ -31,7 +31,7 @@ export default (flecks) => class Interactive extends decorate(Trait) {
|
||||||
return {
|
return {
|
||||||
|
|
||||||
interact: async (initiator) => {
|
interact: async (initiator) => {
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
const script = await Script.load(this.params.interactScript, {
|
const script = await Script.load(this.params.interactScript, {
|
||||||
entity: this.entity,
|
entity: this.entity,
|
||||||
initiator,
|
initiator,
|
||||||
|
|
|
@ -20,7 +20,7 @@ const Particle = ({
|
||||||
}) => {
|
}) => {
|
||||||
const flecks = useFlecks();
|
const flecks = useFlecks();
|
||||||
const patch = useJsonPatcher();
|
const patch = useJsonPatcher();
|
||||||
const {EntityList} = flecks.get('$avocado/resource.resources');
|
const {EntityList} = flecks.avocado.Resources;
|
||||||
const entityList = new EntityList();
|
const entityList = new EntityList();
|
||||||
const entityListView = new EntityListView(entityList);
|
const entityListView = new EntityListView(entityList);
|
||||||
entityList.addEntity(entity);
|
entityList.addEntity(entity);
|
||||||
|
|
|
@ -145,7 +145,7 @@ export default (flecks) => class Collider extends decorate(Trait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async pushCollisionTickingPromise(codeOrUri, other, incident) {
|
async pushCollisionTickingPromise(codeOrUri, other, incident) {
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
this.entity.addTickingPromise(Script.loadTickingPromise(codeOrUri, {
|
this.entity.addTickingPromise(Script.loadTickingPromise(codeOrUri, {
|
||||||
...this.entity.contextOrDefault,
|
...this.entity.contextOrDefault,
|
||||||
incident,
|
incident,
|
||||||
|
|
|
@ -108,7 +108,7 @@ export default (flecks) => class Emitted extends decorate(Trait) {
|
||||||
if (!this.params.onDead) {
|
if (!this.params.onDead) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {Script} = flecks.get('$avocado/resource.resources');
|
const {Script} = flecks.avocado.Resources;
|
||||||
this.entity.addTickingPromise(Script.loadTickingPromise(this.params.onDead, {
|
this.entity.addTickingPromise(Script.loadTickingPromise(this.params.onDead, {
|
||||||
...this.entity.contextOrDefault,
|
...this.entity.contextOrDefault,
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -59,7 +59,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async emitParticleJson(json) {
|
async emitParticleJson(json) {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
let entity;
|
let entity;
|
||||||
if (this.$$pool.length > 0) {
|
if (this.$$pool.length > 0) {
|
||||||
entity = this.$$pool.pop();
|
entity = this.$$pool.pop();
|
||||||
|
@ -282,7 +282,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static withDefaults(json = {}) {
|
static withDefaults(json = {}) {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
...this.defaultParamsWith(json.params || {}),
|
...this.defaultParamsWith(json.params || {}),
|
||||||
|
@ -297,7 +297,7 @@ export default (flecks) => class Emitter extends decorate(Trait) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static withoutDefaults(json) {
|
static withoutDefaults(json) {
|
||||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
const {Entity} = flecks.avocado.Resources;
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
...this.defaultParamsWith(json.params || {}),
|
...this.defaultParamsWith(json.params || {}),
|
||||||
|
|
|
@ -10,13 +10,26 @@ export const hooks = {
|
||||||
resourceCache.reset();
|
resourceCache.reset();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
'@flecks/core.mixin': (Flecks) => (
|
||||||
|
class FlecksWithAvocadoResource extends Flecks {
|
||||||
|
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
if (!this.avocado) {
|
||||||
|
this.avocado = {};
|
||||||
|
}
|
||||||
|
this.avocado.Resources = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
),
|
||||||
'@flecks/core.starting': (flecks) => {
|
'@flecks/core.starting': (flecks) => {
|
||||||
flecks.set('$avocado/resource.resources', flecks.gather(
|
flecks.avocado.Resources = flecks.gather(
|
||||||
'@avocado/resource.resources',
|
'@avocado/resource.resources',
|
||||||
{
|
{
|
||||||
idProperty: 'resourceId',
|
idProperty: 'resourceId',
|
||||||
typeProperty: 'resourceType',
|
typeProperty: 'resourceType',
|
||||||
},
|
},
|
||||||
));
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ import SynchronizedPacket from './synchronized';
|
||||||
export default (flecks) => class SynchronizedUpdatePacket extends SynchronizedPacket {
|
export default (flecks) => class SynchronizedUpdatePacket extends SynchronizedPacket {
|
||||||
|
|
||||||
static pack(data) {
|
static pack(data) {
|
||||||
const {Bundle} = flecks.get('$flecks/socket.packets');
|
const {Bundle} = flecks.socket.Packets;
|
||||||
data.packets = Bundle.encode(data.packets);
|
data.packets = Bundle.encode(data.packets);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ export default (flecks) => class SynchronizedUpdatePacket extends SynchronizedPa
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpack(data) {
|
static unpack(data) {
|
||||||
const {Bundle} = flecks.get('$flecks/socket.packets');
|
const {Bundle} = flecks.socket.Packets;
|
||||||
data.packets = Bundle.decode(data.packets);
|
data.packets = Bundle.decode(data.packets);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ export default (flecks) => (Resource) => (
|
||||||
}
|
}
|
||||||
|
|
||||||
async createSynchronized(type, id, json) {
|
async createSynchronized(type, id, json) {
|
||||||
const {[type]: Resource} = flecks.get('$avocado/resource.resources');
|
const {[type]: Resource} = flecks.avocado.Resources;
|
||||||
if (!(type in this.$$synchronized)) {
|
if (!(type in this.$$synchronized)) {
|
||||||
this.$$synchronized[type] = {};
|
this.$$synchronized[type] = {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {
|
||||||
const AnimationVisualization = ({json}) => {
|
const AnimationVisualization = ({json}) => {
|
||||||
const flecks = useFlecks();
|
const flecks = useFlecks();
|
||||||
// const {uuid} = useParams();
|
// const {uuid} = useParams();
|
||||||
const {Animation} = flecks.get('$avocado/resource.resources');
|
const {Animation} = flecks.avocado.Resources;
|
||||||
const [animations, setAnimations] = useState([]);
|
const [animations, setAnimations] = useState([]);
|
||||||
const [container] = useState(new Container());
|
const [container] = useState(new Container());
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -29,7 +29,7 @@ const Animation = ({
|
||||||
if (!fullJson) {
|
if (!fullJson) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const {Animation} = flecks.get('$avocado/resource.resources');
|
const {Animation} = flecks.avocado.Resources;
|
||||||
const loadJson = async () => {
|
const loadJson = async () => {
|
||||||
const animationView = new AnimationView(await Animation.load(fullJson));
|
const animationView = new AnimationView(await Animation.load(fullJson));
|
||||||
const drawCross = (primitives, origin, color) => {
|
const drawCross = (primitives, origin, color) => {
|
||||||
|
|
|
@ -192,7 +192,7 @@ export default (flecks) => class Animated extends decorate(Trait) {
|
||||||
async load(json) {
|
async load(json) {
|
||||||
await super.load(json);
|
await super.load(json);
|
||||||
if (Object.keys(this.params.animations).length > 0) {
|
if (Object.keys(this.params.animations).length > 0) {
|
||||||
const {Animation} = flecks.get('$avocado/resource.resources');
|
const {Animation} = flecks.avocado.Resources;
|
||||||
const animations = await mapValuesAsync(
|
const animations = await mapValuesAsync(
|
||||||
this.params.animations,
|
this.params.animations,
|
||||||
(json) => Animation.load(json),
|
(json) => Animation.load(json),
|
||||||
|
|
|
@ -41,7 +41,7 @@ const RoomComponent = ({
|
||||||
const {uri, uuid} = useContext(Context);
|
const {uri, uuid} = useContext(Context);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const flecks = useFlecks();
|
const flecks = useFlecks();
|
||||||
const {Room, Tiles} = flecks.get('$avocado/resource.resources');
|
const {Room, Tiles} = flecks.avocado.Resources;
|
||||||
const previousResource = usePrevious(resource);
|
const previousResource = usePrevious(resource);
|
||||||
const [events, setEvents] = useState();
|
const [events, setEvents] = useState();
|
||||||
const [scale, setScale] = useState(3);
|
const [scale, setScale] = useState(3);
|
||||||
|
|
|
@ -448,7 +448,7 @@ function TilesPage({
|
||||||
<VectorComponent
|
<VectorComponent
|
||||||
disabled={!resource.tiles[currentLayer]}
|
disabled={!resource.tiles[currentLayer]}
|
||||||
onChange={(event, newArea) => {
|
onChange={(event, newArea) => {
|
||||||
const {Tiles} = flecks.get('$avocado/resource.resources');
|
const {Tiles} = flecks.avocado.Resources;
|
||||||
// Create new tiles.
|
// Create new tiles.
|
||||||
const newTiles = new Tiles();
|
const newTiles = new Tiles();
|
||||||
newTiles.area = newArea;
|
newTiles.area = newArea;
|
||||||
|
|
|
@ -24,7 +24,7 @@ export default (flecks) => {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.$$s13nId = s13nId++;
|
this.$$s13nId = s13nId++;
|
||||||
const {EntityList} = flecks.get('$avocado/resource.resources');
|
const {EntityList} = flecks.avocado.Resources;
|
||||||
this.entityList = new EntityList();
|
this.entityList = new EntityList();
|
||||||
this.entityList.on('entityAdded', this.onEntityAdded, this);
|
this.entityList.on('entityAdded', this.onEntityAdded, this);
|
||||||
this.entityList.on('entityRemoved', this.onEntityRemoved, this);
|
this.entityList.on('entityRemoved', this.onEntityRemoved, this);
|
||||||
|
@ -66,7 +66,7 @@ export default (flecks) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadTiles(tiles) {
|
async loadTiles(tiles) {
|
||||||
const {Tiles} = flecks.get('$avocado/resource.resources');
|
const {Tiles} = flecks.avocado.Resources;
|
||||||
this.removeAllTiles();
|
this.removeAllTiles();
|
||||||
(await Promise.all(tiles.map((json, i) => Tiles.load({s13nId: i, ...json}))))
|
(await Promise.all(tiles.map((json, i) => Tiles.load({s13nId: i, ...json}))))
|
||||||
.forEach((tiles) => {
|
.forEach((tiles) => {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
|
// await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
|
||||||
// });
|
// });
|
||||||
// it('has sane defaults', async () => {
|
// it('has sane defaults', async () => {
|
||||||
// const {Layer} = flecks.get('$avocado/resource.resources');
|
// const {Layer} = flecks.avocado.Resources;
|
||||||
// const layer = new Layer();
|
// const layer = new Layer();
|
||||||
// expect(Object.keys(layer.entities).length).to.equal(0);
|
// expect(Object.keys(layer.entities).length).to.equal(0);
|
||||||
// expect(layer.tiles.size).to.deep.equal([0, 0]);
|
// expect(layer.tiles.size).to.deep.equal([0, 0]);
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
// await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
|
// await Promise.all(flecks.invokeFlat('@flecks/core/starting'));
|
||||||
// });
|
// });
|
||||||
// it("has sane defaults", async () => {
|
// it("has sane defaults", async () => {
|
||||||
// const {Tiles} = flecks.get('$avocado/resource.resources');
|
// const {Tiles} = flecks.avocado.Resources;
|
||||||
// const tiles = new Tiles();
|
// const tiles = new Tiles();
|
||||||
// expect(tiles.size).to.deep.equal([0, 0]);
|
// expect(tiles.size).to.deep.equal([0, 0]);
|
||||||
// expect(tiles.data.length).to.equal(0);
|
// expect(tiles.data.length).to.equal(0);
|
||||||
// });
|
// });
|
||||||
// it("gets and sets tile data", async () => {
|
// it("gets and sets tile data", async () => {
|
||||||
// const {Tiles} = flecks.get('$avocado/resource.resources');
|
// const {Tiles} = flecks.avocado.Resources;
|
||||||
// const tiles = new Tiles({data: [0, 1, 2, 3], size: [2, 2]});
|
// const tiles = new Tiles({data: [0, 1, 2, 3], size: [2, 2]});
|
||||||
// expect(tiles.tileAt([0, 0])).to.equal(0);
|
// expect(tiles.tileAt([0, 0])).to.equal(0);
|
||||||
// expect(tiles.tileAt([1, 0])).to.equal(1);
|
// expect(tiles.tileAt([1, 0])).to.equal(1);
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
// expect(tiles.data).to.deep.equal([69, 420, 311, 42]);
|
// expect(tiles.data).to.deep.equal([69, 420, 311, 42]);
|
||||||
// });
|
// });
|
||||||
// it("can get a data slice", async () => {
|
// it("can get a data slice", async () => {
|
||||||
// const {Tiles} = flecks.get('$avocado/resource.resources');
|
// const {Tiles} = flecks.avocado.Resources;
|
||||||
// const tiles = new Tiles(
|
// const tiles = new Tiles(
|
||||||
// {
|
// {
|
||||||
// data: [
|
// data: [
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
// expect(tiles.slice([1, 1, 0, 0])).to.deep.equal([]);
|
// expect(tiles.slice([1, 1, 0, 0])).to.deep.equal([]);
|
||||||
// });
|
// });
|
||||||
// it("can get convex hulls around indices", () => {
|
// it("can get convex hulls around indices", () => {
|
||||||
// const {Tiles} = flecks.get('$avocado/resource.resources');
|
// const {Tiles} = flecks.avocado.Resources;
|
||||||
// const hulls = [
|
// const hulls = [
|
||||||
// [
|
// [
|
||||||
// [2, 0],
|
// [2, 0],
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
// expect(tiles.indexHulls(new Set([1]))).to.deep.equal(hulls);
|
// expect(tiles.indexHulls(new Set([1]))).to.deep.equal(hulls);
|
||||||
// });
|
// });
|
||||||
// it("can stamp at", async () => {
|
// it("can stamp at", async () => {
|
||||||
// const {Tiles} = flecks.get('$avocado/resource.resources');
|
// const {Tiles} = flecks.avocado.Resources;
|
||||||
// const tiles = new Tiles(
|
// const tiles = new Tiles(
|
||||||
// {
|
// {
|
||||||
// data: [
|
// data: [
|
||||||
|
@ -112,7 +112,7 @@
|
||||||
// ]);
|
// ]);
|
||||||
// });
|
// });
|
||||||
// it("can handle pathological hulls", () => {
|
// it("can handle pathological hulls", () => {
|
||||||
// const {Tiles} = flecks.get('$avocado/resource.resources');
|
// const {Tiles} = flecks.avocado.Resources;
|
||||||
// const hulls = [
|
// const hulls = [
|
||||||
// [
|
// [
|
||||||
// [ 0, 0 ],
|
// [ 0, 0 ],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user