Skip to content

Commit

Permalink
Update For Latest WIP bevy_mod_js_scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Sep 22, 2022
1 parent d64d8c7 commit 6907ab8
Show file tree
Hide file tree
Showing 4 changed files with 473 additions and 439 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion assets/items/health/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 14 additions & 10 deletions lib.bevy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ declare interface BevyScript {
declare class ComponentId {
index: number;
}
declare class Entity {
id: number;
generation: number;
}

type ComponentInfo = {
id: ComponentId;
Expand All @@ -47,18 +43,23 @@ type BevyType<T> = {
typeName: string;
};


type ExtractBevyType<T> = T extends BevyType<infer U> ? U
: T extends ComponentId ? Value
type ExtractBevyType<T> = T extends BevyType<infer U>
? U
: T extends ComponentId
? Value
: never;
type MapQueryArgs<Q> = { [C in keyof Q]: ExtractBevyType<Q[C]> };

type QueryParameter = BevyType<unknown> | ComponentId;
type QueryItem<Q> = {
entity: Entity;
components: MapQueryArgs<Q>,
components: MapQueryArgs<Q>;
};

declare class QueryItems<Q> extends Array<QueryItem<Q>> {
get(entity: Entity): MapQueryArgs<Q> | undefined;
}

declare class World {
get components(): ComponentInfo[];
get resources(): ComponentInfo[];
Expand All @@ -67,8 +68,11 @@ declare class World {
resource(componentId: ComponentId): Value | null;
resource<T>(type: BevyType<T>): T | null;

query<Q extends QueryParameter[]>(...query: Q): QueryItem<Q>[];
get<Q extends QueryParameter[]>(entity: Entity, ...components: Q): MapQueryArgs<Q>;
query<Q extends QueryParameter[]>(...query: Q): QueryItems<Q>;
get<Q extends QueryParameter[]>(
entity: Entity,
...components: Q
): MapQueryArgs<Q>;
}

declare let world: World;
Loading

0 comments on commit 6907ab8

Please sign in to comment.