Closed zicklag closed 1 year ago
Just pushed an update that adds non-primitive patching.
This let me load ( weak ) asset handles in my game quite ergonomically:
type AnimatedSprite = {
start: usize;
end: usize;
atlas: HandleTextureAtlas;
flip_x: boolean;
flip_y: boolean;
repeat: boolean;
fps: f32;
};
const AnimatedSprite: BevyType<AnimatedSprite> = {
typeName: "jumpy::animation::AnimatedSprite",
};
export default {
preUpdate() {
for (const entity of MapElement.getSpawnedEntities()) {
let animated_sprite = Value.create(AnimatedSprite, {
start: 0,
end: 4,
repeat: true,
fps: 6,
atlas: {
id: Assets.getHandleId(
"../../../resources/default_decoration.atlas.yaml"
),
},
});
world.insert(entity, animated_sprite);
}
},
};
If https://github.com/bevyengine/bevy/pull/6187 is merged, I think we'll be able to spawn sprites from scripts, with the nuance that the script can only create weak handles, so the game needs to provide a way for scripts to somehow register assets to load with strong handles.
In my game I have YAML files with a preload_assets
field for that, because I preload all the assets in my game anyway.
Have you seen https://github.com/bevyengine/bevy/pull/5923? It would let you insert new assets and get back a handle.
No I haven't, that's awesome! 🎉
I think that pretty much fixes the bulk of the things I was worried about for asset handling in scripts.
Can you rebase this? Otherwise it looks good. Sorry for leaving these PRs uncommented for so long.
Yep, I'll rebase this today, and no problem about the delay. I was totally fine working off my fork.
Pushed the rebase.
Thanks a ton for the PR and the patience for having this unmerged for so long. I rebased the PR on main and merged it in https://github.com/jakobhellermann/bevy_mod_js_scripting/pull/36.
No problem! :D
This PR
world.spawn()
method.id
of aHandle<T>
in Bevy even thoughHandleId
is not a JS primitive.Value.patch()
PR where non-primitive assignments stopped throwing an error when they failed.It's worth noting that non-primitive patching doesn't work yet. That will require a kind of recursive value ref unwrapping helper, which I haven't implemented yet.