diff --git a/Cargo.lock b/Cargo.lock index 43157abf..9d36d317 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -648,7 +648,7 @@ dependencies = [ [[package]] name = "bevy_mod_js_scripting" version = "0.1.0" -source = "git+https://github.com/zicklag/bevy_mod_js_scripting.git?branch=punchy#7fe242ce4876e2a6f7e67e861d2fda15c7720e2b" +source = "git+https://github.com/zicklag/bevy_mod_js_scripting.git?branch=punchy#279a9a1ab6506f5a0311a06ae9db1df80b8487eb" dependencies = [ "anyhow", "bevy", diff --git a/assets/items/health/health.ts b/assets/items/health/health.ts index 684a057b..1b830a53 100644 --- a/assets/items/health/health.ts +++ b/assets/items/health/health.ts @@ -12,10 +12,11 @@ export default { postUpdate() { const grabEvents = punchy.getItemGrabEvents(); + const fighterQuery = world.query(Health, Stats); for (const event of grabEvents) { const fighter = event.fighter; - const [health, stats] = world.get(fighter, Health, Stats); + const [health, stats] = fighterQuery.get(fighter); health[0] = stats.max_health; } diff --git a/lib.bevy.d.ts b/lib.bevy.d.ts index 8fac6f90..5987fdad 100644 --- a/lib.bevy.d.ts +++ b/lib.bevy.d.ts @@ -23,10 +23,6 @@ declare interface BevyScript { declare class ComponentId { index: number; } -declare class Entity { - id: number; - generation: number; -} type ComponentInfo = { id: ComponentId; @@ -47,18 +43,23 @@ type BevyType = { typeName: string; }; - -type ExtractBevyType = T extends BevyType ? U - : T extends ComponentId ? Value +type ExtractBevyType = T extends BevyType + ? U + : T extends ComponentId + ? Value : never; type MapQueryArgs = { [C in keyof Q]: ExtractBevyType }; type QueryParameter = BevyType | ComponentId; type QueryItem = { entity: Entity; - components: MapQueryArgs, + components: MapQueryArgs; }; +declare class QueryItems extends Array> { + get(entity: Entity): MapQueryArgs | undefined; +} + declare class World { get components(): ComponentInfo[]; get resources(): ComponentInfo[]; @@ -67,8 +68,11 @@ declare class World { resource(componentId: ComponentId): Value | null; resource(type: BevyType): T | null; - query(...query: Q): QueryItem[]; - get(entity: Entity, ...components: Q): MapQueryArgs; + query(...query: Q): QueryItems; + get( + entity: Entity, + ...components: Q + ): MapQueryArgs; } declare let world: World; diff --git a/lib.bevy.types.ts b/lib.bevy.types.ts index d720706d..3989b3c2 100644 --- a/lib.bevy.types.ts +++ b/lib.bevy.types.ts @@ -1,4 +1,5 @@ // generated with https://github.com/jakobhellermann/bevy_reflect_ts_type_export +// bevy_core type bool = boolean; type f32 = number; type f64 = number; @@ -13,572 +14,600 @@ type u32 = number; type u64 = number; type usize = number; type Cowstr = String; -type Vec3A = Vec3; -type AnimationPlayer = { - paused: bool, - repeat: bool, - speed: f32, - elapsed: f32, - animation_clip: HandleAnimationClip, + +type Name = { + hash: number, + name: string, }; -const AnimationPlayer: BevyType = { typeName: "bevy_animation::AnimationPlayer" }; -type HandleAnimationClip = { - id: HandleId, +const Name: BevyType = { typeName: "bevy_core::name::Name" }; +// core +type Rangef32 = unknown; +type Duration = unknown; + +const Rangef32: BevyType = { typeName: "core::ops::range::Range" }; +const Duration: BevyType = { typeName: "core::time::Duration" }; +// hashbrown +type HashSetString = unknown; + +const HashSetString: BevyType = { typeName: "hashbrown::set::HashSet" }; +// bevy_math +type Rect = { + min: Vec2, + max: Vec2, }; -const HandleAnimationClip: BevyType = { typeName: "bevy_asset::handle::Handle" }; -type HandleAudioSink = { - id: HandleId, +const Rect: BevyType = { typeName: "bevy_math::rect::Rect" }; +// std +type Instant = unknown; + +const Instant: BevyType = { typeName: "std::time::Instant" }; +// bevy_ecs +type Entity = unknown; + +const Entity: BevyType = { typeName: "bevy_ecs::entity::Entity" }; +// bevy_time +type Stopwatch = { + elapsed: Duration, + paused: boolean, +}; +type Time = { + delta: Duration, + last_update: Instant | null, + delta_seconds_f64: number, + delta_seconds: number, + seconds_since_startup: number, + time_since_startup: Duration, + startup: Instant, +}; +type Timer = { + stopwatch: Stopwatch, + duration: Duration, + repeating: boolean, + finished: boolean, + times_finished_this_tick: number, }; -const HandleAudioSink: BevyType = { typeName: "bevy_asset::handle::Handle" }; +const Stopwatch: BevyType = { typeName: "bevy_time::stopwatch::Stopwatch" }; +const Time: BevyType