Skip to content

Commit

Permalink
Merge pull request #307 from dojoengine/burner-props
Browse files Browse the repository at this point in the history
fix: type build
  • Loading branch information
ponderingdemocritus authored Oct 24, 2024
2 parents 0d4315e + 2b25408 commit 87afb34
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 29 deletions.
40 changes: 17 additions & 23 deletions examples/example-vite-react-sdk/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
},
},
},
Position: {
$: {
where: {
player: {
$is: addAddressPadding(
account.account.address
),
},
},
},
},
},
},
(response) => {
Expand All @@ -55,7 +66,8 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
response.data &&
response.data[0].entityId !== "0x0"
) {
state.setEntities(response.data);
console.log("subscribed", response.data[0]);
state.updateEntity(response.data[0]);
}
},
{ logging: true }
Expand Down Expand Up @@ -212,28 +224,10 @@ function App({ sdk }: { sdk: SDK<Schema> }) {
className={`${col} h-12 w-12 bg-gray-600 rounded-full shadow-md active:shadow-inner active:bg-gray-500 focus:outline-none text-2xl font-bold text-gray-200`}
key={direction}
onClick={async () => {
const condition =
(direction === "Up" &&
position?.vec?.y !==
undefined &&
position.vec.y > 0) ||
(direction === "Left" &&
position?.vec?.x !==
undefined &&
position.vec.x > 0) ||
direction === "Right" ||
direction === "Down";

if (!condition) {
console.log(
"Reached the borders of the world."
);
} else {
await client.actions.move({
account: account.account,
direction: { type: direction },
});
}
await client.actions.move({
account: account.account,
direction: { type: direction },
});
}}
>
{label}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-burner/src/context/burnerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const BurnerContext = createContext<BurnerManagerOptions | null>(null);
/**
* Props for the BurnerProvider component {@link BurnerProvider}
*/
interface BurnerProviderProps {
export interface BurnerProviderProps {
children: ReactNode;
initOptions: BurnerManagerOptions;
}
Expand Down
40 changes: 36 additions & 4 deletions packages/sdk/src/state/zustand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,44 @@ export function createDojoStore<T extends SchemaType>() {
set((state: Draft<GameState<T>>) => {
if (
entity.entityId &&
state.entities[entity.entityId]
state.entities[entity.entityId] &&
entity.models
) {
Object.assign(
state.entities[entity.entityId],
entity
const existingEntity =
state.entities[entity.entityId];

// Create new models object without spread
const mergedModels: typeof existingEntity.models =
Object.assign({}, existingEntity.models);

// Iterate through each namespace in the new models
Object.entries(entity.models).forEach(
([namespace, namespaceModels]) => {
const typedNamespace =
namespace as keyof ParsedEntity<T>["models"];
if (!(typedNamespace in mergedModels)) {
mergedModels[
typedNamespace as keyof typeof mergedModels
] = {} as any;
}

mergedModels[
typedNamespace as keyof typeof mergedModels
] = Object.assign(
{},
mergedModels[
typedNamespace as keyof typeof mergedModels
],
namespaceModels
);
}
);
// Update the entity
state.entities[entity.entityId] = {
...existingEntity,
...entity,
models: mergedModels,
};
}
});
},
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ To run the examples, you'll need to set up three terminal windows:
3. Run Torii (indexer) with the world address and allowed origins:
```bash
torii --world 0xb4079627ebab1cd3cf9fd075dda1ad2454a7a448bf659591f259efa2519b18 --allowed-origins "*"
torii --world 0xc82dfe2cb4f8a90dba1e88dfa24578aeb1c19152d51e3c7cf413be6d65d9e --allowed-origins "*"
```
Note: The world address may change. Ensure you're using the correct address from your migration output.
Expand Down

0 comments on commit 87afb34

Please sign in to comment.