refactor: schema setter
This commit is contained in:
parent
e3d0cc2477
commit
477b76acd5
|
@ -118,6 +118,7 @@ export default class Component {
|
|||
instanceFromSchema() {
|
||||
const Component = this;
|
||||
const {concrete} = Component.schema.specification;
|
||||
const setContext = {ecs: this.ecs};
|
||||
const Instance = class {
|
||||
$$entity = 0;
|
||||
destroy() {}
|
||||
|
@ -125,7 +126,7 @@ export default class Component {
|
|||
const {properties} = concrete;
|
||||
for (const key in values) {
|
||||
if (properties[key]?.$.set) {
|
||||
properties[key].$.set(Component, this, `$$${key}`, values[key]);
|
||||
properties[key].$.set(this, `$$${key}`, values[key], setContext);
|
||||
}
|
||||
else {
|
||||
this[`$$${key}`] = values[key];
|
||||
|
@ -133,7 +134,7 @@ export default class Component {
|
|||
}
|
||||
for (const key in defaults) {
|
||||
if (properties[key]?.$.set) {
|
||||
properties[key].$.set(Component, this, `$$${key}`, defaults[key]);
|
||||
properties[key].$.set(this, `$$${key}`, defaults[key], setContext);
|
||||
}
|
||||
else {
|
||||
this[`$$${key}`] = defaults[key];
|
||||
|
@ -168,7 +169,7 @@ export default class Component {
|
|||
for (const key in values) {
|
||||
if (properties[key]) {
|
||||
if (properties[key]?.$.set) {
|
||||
properties[key].$.set(Component, this, `$$${key}`, values[key]);
|
||||
properties[key].$.set(this, `$$${key}`, values[key], setContext);
|
||||
}
|
||||
else {
|
||||
this[`$$${key}`] = values[key];
|
||||
|
@ -197,7 +198,7 @@ export default class Component {
|
|||
set: function set(value) {
|
||||
if (this[`$$${key}`] !== value) {
|
||||
if (concrete.properties[key]?.$.set) {
|
||||
concrete.properties[key].$.set(Component, this, `$$${key}`, value);
|
||||
concrete.properties[key].$.set(this, `$$${key}`, value, setContext);
|
||||
}
|
||||
else {
|
||||
this[`$$${key}`] = value;
|
||||
|
|
|
@ -7,16 +7,11 @@ export default function () {
|
|||
json: (value) => {
|
||||
return value ? value.path : '';
|
||||
},
|
||||
set: (Component, receiver, key, value) => {
|
||||
set: (receiver, key, value, {ecs}) => {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
receiver[key] = Component.ecs.readScript(
|
||||
value,
|
||||
{
|
||||
ecs: Component.ecs,
|
||||
},
|
||||
);
|
||||
receiver[key] = ecs.readScript(value, {ecs});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user