JaimeGensler / thyseus

An archetypal Entity Component System, built entirely in Typescript
MIT License
74 stars 3 forks source link

[BUG] Initial struct values 0 on Res & SystemRes #44

Closed lucas-jones closed 1 year ago

lucas-jones commented 1 year ago

Bug Description

The initial values when defining a struct are not set correctly for Res and SystemRes

import { World, StartSchedule, DefaultSchedule, struct, Res } from 'thyseus';

function start(world: World) {
    async function loop() {
        await world.runSchedule(DefaultSchedule);
        requestAnimationFrame(loop);
    }
    loop();
}

@struct
export class TestResource {
    value: number = 2;
}

export function systemExample(test: Res<TestResource>) {
    console.log(test.value)
}

const world = await World.new()
    .addSystemsToSchedule(StartSchedule, start)
    .addSystems(systemExample, /* Your systems here! */)
    .build();

world.start();

Console logs out 0

Thyseus Version (e.g. v0.9.0)**

0.14.0

Bundler / Build Tool (e.g. Vite, Webpack)**

Vite

Environment & Version (e.g. \<browser> \<version>, Node \<version>)**

Brower

Reproduction URL (optional)**

JaimeGensler commented 1 year ago

Thanks for the report & repro! Fairly certain this is because we aren't calling serialize() for these newly constructed instances, but are calling deserialize() in the system, which causes the value to be overwritten with 0. Should be a simple fix!

If I'm able to push 0.15 out this weekend it'll just be included in that. If it doesn't look like that'll happen, I'll cut a 0.14.1 release so this can be resolved and not block folks.

Cheers!