Skip to content

Commit

Permalink
fix: add LoadingState component from SyncWorker (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Dec 14, 2022
1 parent f094624 commit 2026abc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/std-client/src/setup/setupMUDNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
InputType,
} from "@latticexyz/network";
import { BehaviorSubject, concatMap, from, Subject } from "rxjs";
import { World } from "@latticexyz/recs";
import { defineComponent, Type, World } from "@latticexyz/recs";
import { computed } from "mobx";
import { keccak256 } from "@latticexyz/utils";
import { Contract, ContractInterface } from "ethers";
Expand All @@ -28,7 +28,7 @@ import {
export async function setupMUDNetwork<C extends ContractComponents, SystemTypes extends { [key: string]: Contract }>(
networkConfig: SetupContractConfig,
world: World,
components: C,
contractComponents: C,
SystemAbis: { [key in keyof SystemTypes]: ContractInterface },
options?: { initialGasPrice?: number; fetchSystemCalls?: boolean }
) {
Expand All @@ -42,8 +42,26 @@ export async function setupMUDNetwork<C extends ContractComponents, SystemTypes
metadata: { contractId: "world.component.components" },
});

(components as NetworkComponents<C>).SystemsRegistry = SystemsRegistry;
(components as NetworkComponents<C>).ComponentsRegistry = ComponentsRegistry;
// used by SyncWorker to notify client of sync progress
const LoadingState = defineComponent(
world,
{
state: Type.Number,
msg: Type.String,
percentage: Type.Number,
},
{
id: "LoadingState",
metadata: { contractId: "component.LoadingState" },
}
);

const components: NetworkComponents<C> = {
...contractComponents,
SystemsRegistry,
ComponentsRegistry,
LoadingState,
};

// Mapping from component contract id to key in components object
const mappings: Mappings<C> = {};
Expand Down Expand Up @@ -135,5 +153,6 @@ export async function setupMUDNetwork<C extends ContractComponents, SystemTypes
mappings,
registerComponent,
registerSystem,
components,
};
}
5 changes: 5 additions & 0 deletions packages/std-client/src/setup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ export type ContractComponents = {
export type NetworkComponents<C extends ContractComponents> = C & {
SystemsRegistry: Component<{ value: Type.String }>;
ComponentsRegistry: Component<{ value: Type.String }>;
LoadingState: Component<{
state: Type.Number;
msg: Type.String;
percentage: Type.Number;
}>;
};

0 comments on commit 2026abc

Please sign in to comment.