From 477b76acd5c7f389c31c221eedacfc878536dea0 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 14 Nov 2024 23:12:29 -0600 Subject: [PATCH] refactor: schema setter --- app/silphius/ecs/component.js | 9 +++++---- app/silphius/ecs/schema-types/script.js | 9 ++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/app/silphius/ecs/component.js b/app/silphius/ecs/component.js index 9d965d1..a024649 100644 --- a/app/silphius/ecs/component.js +++ b/app/silphius/ecs/component.js @@ -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; diff --git a/app/silphius/ecs/schema-types/script.js b/app/silphius/ecs/schema-types/script.js index 9429f52..59a17e6 100644 --- a/app/silphius/ecs/schema-types/script.js +++ b/app/silphius/ecs/schema-types/script.js @@ -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}); }, }; }