Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Flag a component mutated after getting him #185

Open
IfnotFr opened this issue Jun 11, 2020 · 0 comments
Open

Flag a component mutated after getting him #185

IfnotFr opened this issue Jun 11, 2020 · 0 comments

Comments

@IfnotFr
Copy link
Contributor

IfnotFr commented Jun 11, 2020

Hi,

I had the case several times, I need to check one value from a component before editing values. It makes something very ugly : loading first time in read mode, and second time in mutate mode for flagging him modified.

const component = entity.getComponent(MyComponent)
if(component .something === true) {
    component = entity.getMutableComponent(MyComponent)
    component.foo = 'bar'
}

I think it can be cleaner to flag the component instead of loading it two times :

const component = entity.getComponent(MyComponent)
if(component.something === true) {
    component.setMutated() // or fireMutated, flagMutated, fireChange, or something else ...
    component.foo = 'bar'
}

I tried a PR but it looks the Component does not have any Entity property for firing up the event.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant