Skip to content

Commit

Permalink
feat(create-mud): use app namespace (#2823)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
qbzzt and holic authored May 14, 2024
1 parent 4a61a12 commit 1836024
Show file tree
Hide file tree
Showing 29 changed files with 47 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-tools-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/create-mud": patch
---

Templates now use an `app` namespace by default, instead of the root namespace. This helps keep the root namespace clear for intentionally root-level things and avoids pitfalls with root systems calling other root systems.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function createSystemCalls(
* is in the root namespace, `.increment` can be called directly
* on the World contract.
*/
const tx = await worldContract.write.increment();
const tx = await worldContract.write.app__increment();
await waitForTransaction(tx);
return getComponentValue(Counter, singletonEntity);
};
Expand Down
1 change: 1 addition & 0 deletions templates/phaser/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "app",
tables: {
Counter: {
schema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract PostDeploy is Script {
// ------------------ EXAMPLES ------------------

// Call increment on the world via the registered function selector
uint32 newValue = IWorld(worldAddress).increment();
uint32 newValue = IWorld(worldAddress).app__increment();
console.log("Increment via IWorld:", newValue);

vm.stopBroadcast();
Expand Down

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

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

2 changes: 1 addition & 1 deletion templates/phaser/packages/contracts/test/CounterTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract CounterTest is MudTest {
assertEq(counter, 1);

// Expect the counter to be 2 after calling increment.
IWorld(worldAddress).increment();
IWorld(worldAddress).app__increment();
counter = Counter.get();
assertEq(counter, 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createSystemCalls(
* is in the root namespace, `.increment` can be called directly
* on the World contract.
*/
const tx = await worldContract.write.increment();
const tx = await worldContract.write.app__increment();
await waitForTransaction(tx);
return getComponentValue(Counter, singletonEntity);
};
Expand Down
1 change: 1 addition & 0 deletions templates/react-ecs/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "app",
tables: {
Counter: {
schema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract PostDeploy is Script {
// ------------------ EXAMPLES ------------------

// Call increment on the world via the registered function selector
uint32 newValue = IWorld(worldAddress).increment();
uint32 newValue = IWorld(worldAddress).app__increment();
console.log("Increment via IWorld:", newValue);

vm.stopBroadcast();
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract CounterTest is MudTest {
assertEq(counter, 1);

// Expect the counter to be 2 after calling increment.
IWorld(worldAddress).increment();
IWorld(worldAddress).app__increment();
counter = Counter.get();
assertEq(counter, 2);
}
Expand Down
8 changes: 5 additions & 3 deletions templates/react/packages/client/src/mud/createSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ export function createSystemCalls(
{ tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult,
) {
const addTask = async (label: string) => {
const tx = await worldContract.write.addTask([label]);
const tx = await worldContract.write.app__addTask([label]);
await waitForTransaction(tx);
};

const toggleTask = async (id: Hex) => {
const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
const tx = isComplete ? await worldContract.write.resetTask([id]) : await worldContract.write.completeTask([id]);
const tx = isComplete
? await worldContract.write.app__resetTask([id])
: await worldContract.write.app__completeTask([id]);
await waitForTransaction(tx);
};

const deleteTask = async (id: Hex) => {
const tx = await worldContract.write.deleteTask([id]);
const tx = await worldContract.write.app__deleteTask([id]);
await waitForTransaction(tx);
};

Expand Down
1 change: 1 addition & 0 deletions templates/react/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "app",
tables: {
Tasks: {
schema: {
Expand Down
6 changes: 3 additions & 3 deletions templates/react/packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ contract PostDeploy is Script {
Tasks.set("1", TasksData({ description: "Walk the dog", createdAt: block.timestamp, completedAt: 0 }));

// Or we can call our own systems
IWorld(worldAddress).addTask("Take out the trash");
IWorld(worldAddress).app__addTask("Take out the trash");

bytes32 key = IWorld(worldAddress).addTask("Do the dishes");
IWorld(worldAddress).completeTask(key);
bytes32 key = IWorld(worldAddress).app__addTask("Do the dishes");
IWorld(worldAddress).app__completeTask(key);

vm.stopBroadcast();
}
Expand Down

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

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

2 changes: 1 addition & 1 deletion templates/react/packages/contracts/test/TasksTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract TasksTest is MudTest {
assertEq(task.completedAt, 0);

// Expect the task to be completed after calling completeTask from our TasksSystem
IWorld(worldAddress).completeTask("1");
IWorld(worldAddress).app__completeTask("1");
assertEq(Tasks.getCompletedAt("1"), block.timestamp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function createSystemCalls(
* Because MoveSystem is in the root namespace, .move can be called directly
* on the World contract.
*/
const tx = await worldContract.write.move([x, y, z]);
const tx = await worldContract.write.app__move([x, y, z]);
await waitForTransaction(tx);
};

Expand Down
1 change: 1 addition & 0 deletions templates/threejs/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "app",
tables: {
Position: {
schema: {
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function createSystemCalls(
* is in the root namespace, `.increment` can be called directly
* on the World contract.
*/
const tx = await worldContract.write.increment();
const tx = await worldContract.write.app__increment();
await waitForTransaction(tx);
return getComponentValue(Counter, singletonEntity);
};
Expand Down
1 change: 1 addition & 0 deletions templates/vanilla/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "app",
tables: {
Counter: {
schema: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract PostDeploy is Script {
// ------------------ EXAMPLES ------------------

// Call increment on the world via the registered function selector
uint32 newValue = IWorld(worldAddress).increment();
uint32 newValue = IWorld(worldAddress).app__increment();
console.log("Increment via IWorld:", newValue);

vm.stopBroadcast();
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract CounterTest is MudTest {
assertEq(counter, 1);

// Expect the counter to be 2 after calling increment.
IWorld(worldAddress).increment();
IWorld(worldAddress).app__increment();
counter = Counter.get();
assertEq(counter, 2);
}
Expand Down

0 comments on commit 1836024

Please sign in to comment.