NSSTC / sim-ecs

Batteries included TypeScript ECS
https://nsstc.github.io/sim-ecs/
Mozilla Public License 2.0
84 stars 12 forks source link

"Without" does not seem to work properly #18

Closed Stmated closed 3 years ago

Stmated commented 3 years ago

In system.ts there is this code:

if (!entity.hasComponent(accessStruct[access].component) || accessStruct[access].type == EAccess.UNSET) {
    return false;
}

But should this not be:

if (accessStruct[access].type == EAccess.UNSET) {
    if (entity.hasComponent(accessStruct[access].component)) {
        return false;
    }
} else {
    if (!entity.hasComponent(accessStruct[access].component)) {
        return false;
    }
}

Or the shorter:

if (entity.hasComponent(accessStruct[access].component) == (accessStruct[access].type == EAccess.UNSET)) {
    return false;
}

Since as things stand right now it will always check if it has the component and then return false if it does not.

minecrawler commented 3 years ago

Thank you for reporting this problem! I am a bit busy at work and with my life right now, so I might need a few days to take a look at it. We need a some test cases and then we can fix the code. I will be able to do so in a few days, however I also welcome PRs :)

minecrawler commented 3 years ago

Had time sooner than anticipated and got rid of some code duplication while at it. It should now work and the checking part (in entity.ts) is now tested.