fix: spawning
This commit is contained in:
parent
165afde69d
commit
ac0b951ef0
|
@ -1,5 +1,7 @@
|
|||
import {Context} from '@avocado/behavior';
|
||||
import {compose} from '@latus/core';
|
||||
import {StateProperty, Trait} from '@avocado/traits';
|
||||
import merge from 'deepmerge';
|
||||
|
||||
const decorate = compose(
|
||||
StateProperty('isSpawning', {
|
||||
|
@ -204,7 +206,13 @@ export default (latus) => class Spawner extends decorate(Trait) {
|
|||
return Promise.all(promises);
|
||||
},
|
||||
|
||||
spawn: async (key, json = {}, latus) => {
|
||||
spawn: async (key, json = {}, context) => {
|
||||
if (!context && json instanceof Context) {
|
||||
/* eslint-disable no-param-reassign */
|
||||
context = json;
|
||||
json = {};
|
||||
/* eslint-enable no-param-reassign */
|
||||
}
|
||||
if (!this.maySpawn()) {
|
||||
return undefined;
|
||||
}
|
||||
|
@ -212,14 +220,36 @@ export default (latus) => class Spawner extends decorate(Trait) {
|
|||
if (!spawnJSON) {
|
||||
return undefined;
|
||||
}
|
||||
const entity = await this.entity.spawnRaw(spawnJSON);
|
||||
await entity.load(latus ? json : {});
|
||||
const entity = await this.entity.spawnRaw(merge(
|
||||
spawnJSON,
|
||||
json || {},
|
||||
{
|
||||
arrayMerge: (l, r) => r,
|
||||
},
|
||||
));
|
||||
// await entity.load(json);
|
||||
return entity;
|
||||
},
|
||||
|
||||
spawnAt: async (key, position, json = {}, latus) => {
|
||||
spawnAt: async (key, position, json = {}, context) => {
|
||||
if (!context && json instanceof Context) {
|
||||
/* eslint-disable no-param-reassign */
|
||||
context = json;
|
||||
json = {};
|
||||
/* eslint-enable no-param-reassign */
|
||||
}
|
||||
const entity = this.maySpawn()
|
||||
? await this.entity.spawn(key, latus ? json : {}, latus)
|
||||
? await this.entity.spawn(
|
||||
key,
|
||||
merge(
|
||||
{traits: {Positioned: {}}},
|
||||
json,
|
||||
{
|
||||
arrayMerge: (l, r) => r,
|
||||
},
|
||||
),
|
||||
context,
|
||||
)
|
||||
: undefined;
|
||||
if (entity) {
|
||||
entity.setPosition(position);
|
||||
|
@ -249,7 +279,13 @@ export default (latus) => class Spawner extends decorate(Trait) {
|
|||
|
||||
spawnRawAt: async (json, position) => {
|
||||
const entity = this.maySpawn()
|
||||
? await this.entity.spawnRaw(json)
|
||||
? await this.entity.spawnRaw(merge(
|
||||
{traits: {Positioned: {}}},
|
||||
json,
|
||||
{
|
||||
arrayMerge: (l, r) => r,
|
||||
},
|
||||
))
|
||||
: undefined;
|
||||
if (entity) {
|
||||
entity.setPosition(position);
|
||||
|
|
Loading…
Reference in New Issue
Block a user