Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Dec 7, 2023
1 parent 7ce3dc9 commit 37105a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
24 changes: 14 additions & 10 deletions client/src/dojo/createNetworkLayer.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
import { world } from "./world";
import { setup } from "./setup";
import { Account } from "starknet";
import { createSyncManager } from "@dojoengine/react";

export type NetworkLayer = Awaited<ReturnType<typeof createNetworkLayer>>;

export const createNetworkLayer = async () => {
const { components, systemCalls, network } = await setup();

const { Position, PlayerID, Energy, RPSType, PlayerAddress } =
network.contractComponents;

const { burnerManager, toriiClient, account } = network;

const initial_sync = () => {
const models: any = [];

for (let i = 1; i <= 30; i++) {
let keys = [BigInt(i)];
models.push({
model: network.contractComponents.Position,
model: Position,
keys,
});
models.push({
model: network.contractComponents.RPSType,
model: RPSType,
keys,
});
models.push({
model: network.contractComponents.PlayerAddress,
model: PlayerAddress,
keys,
});
models.push({
model: network.contractComponents.Energy,
model: Energy,
keys,
});
}

models.push({
model: network.contractComponents.PlayerID,
keys: [BigInt(network.account.address)],
model: PlayerID,
keys: [BigInt(account.address)],
});

return models;
};

const { sync } = createSyncManager(network.toriiClient, initial_sync());
const { sync } = createSyncManager(toriiClient, initial_sync());

sync();

Expand All @@ -48,7 +52,7 @@ export const createNetworkLayer = async () => {
components,
systemCalls,
network,
account: network.burnerManager.account as Account,
burnerManage: network.burnerManager,
account,
burnerManager,
};
};
15 changes: 8 additions & 7 deletions client/src/ui/hooks/useDojo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ export const useDojo = () => {
throw new Error("Store not initialized");
}

const { networkLayer, phaserLayer } = layers;

const { get, create, select, list, isDeploying, clear } = useBurnerManager({
burnerManager: layers.networkLayer.burnerManage,
burnerManager: layers.networkLayer.burnerManager,
});

return {
networkLayer: layers.networkLayer as NetworkLayer,
phaserLayer: layers.phaserLayer as PhaserLayer,
networkLayer: networkLayer as NetworkLayer,
phaserLayer: phaserLayer as PhaserLayer,
account: {
account: layers.networkLayer.burnerManage.account as Account,
account: networkLayer.burnerManager.account as Account,
get,
create,
select,
list,
clear,
isDeploying,
},
systemCalls: layers.networkLayer.systemCalls,
toriiClient: layers.networkLayer.network.toriiClient,
contractComponents: layers.networkLayer.network.contractComponents,
systemCalls: networkLayer.systemCalls,
contractComponents: networkLayer.network.contractComponents,
};
};

0 comments on commit 37105a3

Please sign in to comment.