Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jun 5, 2024
1 parent 2f196e2 commit 5a07319
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 45 deletions.
45 changes: 23 additions & 22 deletions examples/multiple-namespaces/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import { defineWorld } from "@latticexyz/world";

export default defineWorld({
namespace: "game",
tables: {
Health: {
schema: {
player: "address",
value: "uint32",
},
key: ["player"],
},
Position: {
schema: {
player: "address",
x: "int32",
y: "int32",
},
key: ["player"],
},
},
namespaces: {
"some-plugin": {
game: {
tables: {
Score: {
Health: {
schema: {
player: "address",
value: "uint256",
value: "uint32",
},
key: ["player"],
},
Position: {
schema: {
player: "address",
x: "int32",
y: "int32",
},
key: ["player"],
},
},
},
"game-fork": {
gameFork: {
tables: {
Health: {
schema: {
Expand All @@ -50,5 +40,16 @@ export default defineWorld({
},
},
},
somePlugin: {
tables: {
Score: {
schema: {
player: "address",
value: "uint256",
},
key: ["player"],
},
},
},
},
});

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.

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.

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.

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 @@ -3,7 +3,7 @@ pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
import { Health } from "../codegen/game/tables/Health.sol";

contract HealSystem is System {
contract game__HealSystem is System {
function heal(address player) public {
Health.set(player, Health.get(player) + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
import { Position } from "../codegen/game/tables/Position.sol";

contract MoveSystem is System {
contract game__MoveSystem is System {
function move(address player, int32 x, int32 y) public {
Position.set(player, x, y);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
import { Score } from "../codegen/some-plugin/tables/Score.sol";
import { Score } from "../codegen/somePlugin/tables/Score.sol";

contract ScoreSystem is System {
contract game__ScoreSystem is System {
function score(address player) public {
Score.set(player, Score.get(player) + 1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
import { Score } from "../codegen/somePlugin/tables/Score.sol";

contract somePlugin__ScoreSystem is System {
function score(address player) public {
Score.set(player, Score.get(player) + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { Score } from "../src/codegen/some-plugin/tables/Score.sol";
import { Score } from "../src/codegen/somePlugin/tables/Score.sol";

contract ScoreTest is MudTest {
contract ScoreGameTest is MudTest {
using WorldResourceIdInstance for ResourceId;

function testScore(address player) public {
Expand All @@ -18,7 +18,7 @@ contract ScoreTest is MudTest {
abi.encodeWithSelector(
IWorldErrors.World_AccessDenied.selector,
Score._tableId.toString(),
0xb02f49Cccf3e20302446FD8124d27c3f70AeC7C9
0x06a818A2c007BA5E3F26d00Fc2FCB9d4ff03f18B
)
);
IWorld(worldAddress).game__score(player);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
import { IWorldErrors } from "@latticexyz/world/src/IWorldErrors.sol";
import { ResourceId, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { Score } from "../src/codegen/somePlugin/tables/Score.sol";

contract ScoreSomePluginTest is MudTest {
using WorldResourceIdInstance for ResourceId;

function testScore(address player) public {
IWorld(worldAddress).somePlugin__score(player);

uint256 score = Score.get(player);
assertEq(score, 1);
}
}

0 comments on commit 5a07319

Please sign in to comment.