From 3fa2506971bae9054a89c676dd0f0eebc6ba6b66 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 22 Jan 2025 10:29:49 +0000 Subject: [PATCH 01/11] move old template aside --- templates/{react-ecs => react-ecs-old}/.eslintrc | 0 templates/{react-ecs => react-ecs-old}/.gitattributes | 0 templates/{react-ecs => react-ecs-old}/.gitignore | 0 .../.vscode/extensions.json | 0 .../.vscode/settings.json | 0 templates/{react-ecs => react-ecs-old}/mprocs.yaml | 0 templates/{react-ecs => react-ecs-old}/package.json | 0 .../packages/client/.eslintrc | 0 .../packages/client/.gitignore | 0 .../packages/client/index.html | 0 .../packages/client/package.json | 0 .../packages/client/src/App.tsx | 0 .../packages/client/src/MUDContext.tsx | 0 .../packages/client/src/index.tsx | 0 .../packages/client/src/mud/createClientComponents.ts | 0 .../packages/client/src/mud/createSystemCalls.ts | 0 .../packages/client/src/mud/getNetworkConfig.ts | 0 .../packages/client/src/mud/setup.ts | 0 .../packages/client/src/mud/setupNetwork.ts | 0 .../packages/client/src/mud/supportedChains.ts | 0 .../packages/client/src/mud/world.ts | 0 .../packages/client/tsconfig.json | 0 .../packages/client/vite.config.ts | 0 .../packages/contracts/.gitignore | 0 .../packages/contracts/.prettierrc | 0 .../packages/contracts/.solhint.json | 0 .../packages/contracts/foundry.toml | 0 .../packages/contracts/mud.config.ts | 0 .../packages/contracts/package.json | 0 .../packages/contracts/remappings.txt | 0 .../packages/contracts/script/PostDeploy.s.sol | 0 .../packages/contracts/src/codegen/index.sol | 0 .../packages/contracts/src/codegen/tables/Counter.sol | 0 .../contracts/src/codegen/world/IIncrementSystem.sol | 0 .../packages/contracts/src/codegen/world/IWorld.sol | 0 .../contracts/src/systems/IncrementSystem.sol | 0 .../packages/contracts/test/CounterTest.t.sol | 0 .../packages/contracts/tsconfig.json | 0 .../packages/contracts/worlds.json | 0 .../packages/contracts/worlds.json.d.ts | 0 .../{react-ecs => react-ecs-old}/pnpm-workspace.yaml | 0 templates/{react-ecs => react-ecs-old}/tsconfig.json | 0 templates/react-ecs/packages/client/.env | 1 - templates/react-ecs/packages/contracts/.env | 11 ----------- 44 files changed, 12 deletions(-) rename templates/{react-ecs => react-ecs-old}/.eslintrc (100%) rename templates/{react-ecs => react-ecs-old}/.gitattributes (100%) rename templates/{react-ecs => react-ecs-old}/.gitignore (100%) rename templates/{react-ecs => react-ecs-old}/.vscode/extensions.json (100%) rename templates/{react-ecs => react-ecs-old}/.vscode/settings.json (100%) rename templates/{react-ecs => react-ecs-old}/mprocs.yaml (100%) rename templates/{react-ecs => react-ecs-old}/package.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/.eslintrc (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/.gitignore (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/index.html (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/package.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/App.tsx (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/MUDContext.tsx (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/index.tsx (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/createClientComponents.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/createSystemCalls.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/getNetworkConfig.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/setup.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/setupNetwork.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/supportedChains.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/src/mud/world.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/tsconfig.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/client/vite.config.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/.gitignore (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/.prettierrc (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/.solhint.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/foundry.toml (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/mud.config.ts (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/package.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/remappings.txt (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/script/PostDeploy.s.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/src/codegen/index.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/src/codegen/tables/Counter.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/src/codegen/world/IIncrementSystem.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/src/codegen/world/IWorld.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/src/systems/IncrementSystem.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/test/CounterTest.t.sol (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/tsconfig.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/worlds.json (100%) rename templates/{react-ecs => react-ecs-old}/packages/contracts/worlds.json.d.ts (100%) rename templates/{react-ecs => react-ecs-old}/pnpm-workspace.yaml (100%) rename templates/{react-ecs => react-ecs-old}/tsconfig.json (100%) delete mode 100644 templates/react-ecs/packages/client/.env delete mode 100644 templates/react-ecs/packages/contracts/.env diff --git a/templates/react-ecs/.eslintrc b/templates/react-ecs-old/.eslintrc similarity index 100% rename from templates/react-ecs/.eslintrc rename to templates/react-ecs-old/.eslintrc diff --git a/templates/react-ecs/.gitattributes b/templates/react-ecs-old/.gitattributes similarity index 100% rename from templates/react-ecs/.gitattributes rename to templates/react-ecs-old/.gitattributes diff --git a/templates/react-ecs/.gitignore b/templates/react-ecs-old/.gitignore similarity index 100% rename from templates/react-ecs/.gitignore rename to templates/react-ecs-old/.gitignore diff --git a/templates/react-ecs/.vscode/extensions.json b/templates/react-ecs-old/.vscode/extensions.json similarity index 100% rename from templates/react-ecs/.vscode/extensions.json rename to templates/react-ecs-old/.vscode/extensions.json diff --git a/templates/react-ecs/.vscode/settings.json b/templates/react-ecs-old/.vscode/settings.json similarity index 100% rename from templates/react-ecs/.vscode/settings.json rename to templates/react-ecs-old/.vscode/settings.json diff --git a/templates/react-ecs/mprocs.yaml b/templates/react-ecs-old/mprocs.yaml similarity index 100% rename from templates/react-ecs/mprocs.yaml rename to templates/react-ecs-old/mprocs.yaml diff --git a/templates/react-ecs/package.json b/templates/react-ecs-old/package.json similarity index 100% rename from templates/react-ecs/package.json rename to templates/react-ecs-old/package.json diff --git a/templates/react-ecs/packages/client/.eslintrc b/templates/react-ecs-old/packages/client/.eslintrc similarity index 100% rename from templates/react-ecs/packages/client/.eslintrc rename to templates/react-ecs-old/packages/client/.eslintrc diff --git a/templates/react-ecs/packages/client/.gitignore b/templates/react-ecs-old/packages/client/.gitignore similarity index 100% rename from templates/react-ecs/packages/client/.gitignore rename to templates/react-ecs-old/packages/client/.gitignore diff --git a/templates/react-ecs/packages/client/index.html b/templates/react-ecs-old/packages/client/index.html similarity index 100% rename from templates/react-ecs/packages/client/index.html rename to templates/react-ecs-old/packages/client/index.html diff --git a/templates/react-ecs/packages/client/package.json b/templates/react-ecs-old/packages/client/package.json similarity index 100% rename from templates/react-ecs/packages/client/package.json rename to templates/react-ecs-old/packages/client/package.json diff --git a/templates/react-ecs/packages/client/src/App.tsx b/templates/react-ecs-old/packages/client/src/App.tsx similarity index 100% rename from templates/react-ecs/packages/client/src/App.tsx rename to templates/react-ecs-old/packages/client/src/App.tsx diff --git a/templates/react-ecs/packages/client/src/MUDContext.tsx b/templates/react-ecs-old/packages/client/src/MUDContext.tsx similarity index 100% rename from templates/react-ecs/packages/client/src/MUDContext.tsx rename to templates/react-ecs-old/packages/client/src/MUDContext.tsx diff --git a/templates/react-ecs/packages/client/src/index.tsx b/templates/react-ecs-old/packages/client/src/index.tsx similarity index 100% rename from templates/react-ecs/packages/client/src/index.tsx rename to templates/react-ecs-old/packages/client/src/index.tsx diff --git a/templates/react-ecs/packages/client/src/mud/createClientComponents.ts b/templates/react-ecs-old/packages/client/src/mud/createClientComponents.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/createClientComponents.ts rename to templates/react-ecs-old/packages/client/src/mud/createClientComponents.ts diff --git a/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts b/templates/react-ecs-old/packages/client/src/mud/createSystemCalls.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/createSystemCalls.ts rename to templates/react-ecs-old/packages/client/src/mud/createSystemCalls.ts diff --git a/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts b/templates/react-ecs-old/packages/client/src/mud/getNetworkConfig.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts rename to templates/react-ecs-old/packages/client/src/mud/getNetworkConfig.ts diff --git a/templates/react-ecs/packages/client/src/mud/setup.ts b/templates/react-ecs-old/packages/client/src/mud/setup.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/setup.ts rename to templates/react-ecs-old/packages/client/src/mud/setup.ts diff --git a/templates/react-ecs/packages/client/src/mud/setupNetwork.ts b/templates/react-ecs-old/packages/client/src/mud/setupNetwork.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/setupNetwork.ts rename to templates/react-ecs-old/packages/client/src/mud/setupNetwork.ts diff --git a/templates/react-ecs/packages/client/src/mud/supportedChains.ts b/templates/react-ecs-old/packages/client/src/mud/supportedChains.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/supportedChains.ts rename to templates/react-ecs-old/packages/client/src/mud/supportedChains.ts diff --git a/templates/react-ecs/packages/client/src/mud/world.ts b/templates/react-ecs-old/packages/client/src/mud/world.ts similarity index 100% rename from templates/react-ecs/packages/client/src/mud/world.ts rename to templates/react-ecs-old/packages/client/src/mud/world.ts diff --git a/templates/react-ecs/packages/client/tsconfig.json b/templates/react-ecs-old/packages/client/tsconfig.json similarity index 100% rename from templates/react-ecs/packages/client/tsconfig.json rename to templates/react-ecs-old/packages/client/tsconfig.json diff --git a/templates/react-ecs/packages/client/vite.config.ts b/templates/react-ecs-old/packages/client/vite.config.ts similarity index 100% rename from templates/react-ecs/packages/client/vite.config.ts rename to templates/react-ecs-old/packages/client/vite.config.ts diff --git a/templates/react-ecs/packages/contracts/.gitignore b/templates/react-ecs-old/packages/contracts/.gitignore similarity index 100% rename from templates/react-ecs/packages/contracts/.gitignore rename to templates/react-ecs-old/packages/contracts/.gitignore diff --git a/templates/react-ecs/packages/contracts/.prettierrc b/templates/react-ecs-old/packages/contracts/.prettierrc similarity index 100% rename from templates/react-ecs/packages/contracts/.prettierrc rename to templates/react-ecs-old/packages/contracts/.prettierrc diff --git a/templates/react-ecs/packages/contracts/.solhint.json b/templates/react-ecs-old/packages/contracts/.solhint.json similarity index 100% rename from templates/react-ecs/packages/contracts/.solhint.json rename to templates/react-ecs-old/packages/contracts/.solhint.json diff --git a/templates/react-ecs/packages/contracts/foundry.toml b/templates/react-ecs-old/packages/contracts/foundry.toml similarity index 100% rename from templates/react-ecs/packages/contracts/foundry.toml rename to templates/react-ecs-old/packages/contracts/foundry.toml diff --git a/templates/react-ecs/packages/contracts/mud.config.ts b/templates/react-ecs-old/packages/contracts/mud.config.ts similarity index 100% rename from templates/react-ecs/packages/contracts/mud.config.ts rename to templates/react-ecs-old/packages/contracts/mud.config.ts diff --git a/templates/react-ecs/packages/contracts/package.json b/templates/react-ecs-old/packages/contracts/package.json similarity index 100% rename from templates/react-ecs/packages/contracts/package.json rename to templates/react-ecs-old/packages/contracts/package.json diff --git a/templates/react-ecs/packages/contracts/remappings.txt b/templates/react-ecs-old/packages/contracts/remappings.txt similarity index 100% rename from templates/react-ecs/packages/contracts/remappings.txt rename to templates/react-ecs-old/packages/contracts/remappings.txt diff --git a/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol b/templates/react-ecs-old/packages/contracts/script/PostDeploy.s.sol similarity index 100% rename from templates/react-ecs/packages/contracts/script/PostDeploy.s.sol rename to templates/react-ecs-old/packages/contracts/script/PostDeploy.s.sol diff --git a/templates/react-ecs/packages/contracts/src/codegen/index.sol b/templates/react-ecs-old/packages/contracts/src/codegen/index.sol similarity index 100% rename from templates/react-ecs/packages/contracts/src/codegen/index.sol rename to templates/react-ecs-old/packages/contracts/src/codegen/index.sol diff --git a/templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol b/templates/react-ecs-old/packages/contracts/src/codegen/tables/Counter.sol similarity index 100% rename from templates/react-ecs/packages/contracts/src/codegen/tables/Counter.sol rename to templates/react-ecs-old/packages/contracts/src/codegen/tables/Counter.sol diff --git a/templates/react-ecs/packages/contracts/src/codegen/world/IIncrementSystem.sol b/templates/react-ecs-old/packages/contracts/src/codegen/world/IIncrementSystem.sol similarity index 100% rename from templates/react-ecs/packages/contracts/src/codegen/world/IIncrementSystem.sol rename to templates/react-ecs-old/packages/contracts/src/codegen/world/IIncrementSystem.sol diff --git a/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol b/templates/react-ecs-old/packages/contracts/src/codegen/world/IWorld.sol similarity index 100% rename from templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol rename to templates/react-ecs-old/packages/contracts/src/codegen/world/IWorld.sol diff --git a/templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol b/templates/react-ecs-old/packages/contracts/src/systems/IncrementSystem.sol similarity index 100% rename from templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol rename to templates/react-ecs-old/packages/contracts/src/systems/IncrementSystem.sol diff --git a/templates/react-ecs/packages/contracts/test/CounterTest.t.sol b/templates/react-ecs-old/packages/contracts/test/CounterTest.t.sol similarity index 100% rename from templates/react-ecs/packages/contracts/test/CounterTest.t.sol rename to templates/react-ecs-old/packages/contracts/test/CounterTest.t.sol diff --git a/templates/react-ecs/packages/contracts/tsconfig.json b/templates/react-ecs-old/packages/contracts/tsconfig.json similarity index 100% rename from templates/react-ecs/packages/contracts/tsconfig.json rename to templates/react-ecs-old/packages/contracts/tsconfig.json diff --git a/templates/react-ecs/packages/contracts/worlds.json b/templates/react-ecs-old/packages/contracts/worlds.json similarity index 100% rename from templates/react-ecs/packages/contracts/worlds.json rename to templates/react-ecs-old/packages/contracts/worlds.json diff --git a/templates/react-ecs/packages/contracts/worlds.json.d.ts b/templates/react-ecs-old/packages/contracts/worlds.json.d.ts similarity index 100% rename from templates/react-ecs/packages/contracts/worlds.json.d.ts rename to templates/react-ecs-old/packages/contracts/worlds.json.d.ts diff --git a/templates/react-ecs/pnpm-workspace.yaml b/templates/react-ecs-old/pnpm-workspace.yaml similarity index 100% rename from templates/react-ecs/pnpm-workspace.yaml rename to templates/react-ecs-old/pnpm-workspace.yaml diff --git a/templates/react-ecs/tsconfig.json b/templates/react-ecs-old/tsconfig.json similarity index 100% rename from templates/react-ecs/tsconfig.json rename to templates/react-ecs-old/tsconfig.json diff --git a/templates/react-ecs/packages/client/.env b/templates/react-ecs/packages/client/.env deleted file mode 100644 index 3528db8807..0000000000 --- a/templates/react-ecs/packages/client/.env +++ /dev/null @@ -1 +0,0 @@ -VITE_CHAIN_ID=31337 diff --git a/templates/react-ecs/packages/contracts/.env b/templates/react-ecs/packages/contracts/.env deleted file mode 100644 index 84889c8ef2..0000000000 --- a/templates/react-ecs/packages/contracts/.env +++ /dev/null @@ -1,11 +0,0 @@ -# This .env file is for demonstration purposes only. -# -# This should usually be excluded via .gitignore and the env vars attached to -# your deployment environment, but we're including this here for ease of local -# development. Please do not commit changes to this file! -# -# Enable debug logs for MUD CLI -DEBUG=mud:* -# -# Anvil default private key: -PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 From 9f71f8b2c23fc0e43df8a9bb4695748c8ed26350 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 22 Jan 2025 10:35:25 +0000 Subject: [PATCH 02/11] copy react template --- templates/react-ecs/.eslintrc | 10 + templates/react-ecs/.gitattributes | 3 + templates/react-ecs/.gitignore | 16 + templates/react-ecs/.vscode/extensions.json | 3 + templates/react-ecs/.vscode/settings.json | 3 + templates/react-ecs/mprocs.yaml | 21 + templates/react-ecs/package.json | 38 + templates/react-ecs/packages/client/.eslintrc | 7 + .../react-ecs/packages/client/.gitignore | 1 + .../react-ecs/packages/client/index.html | 12 + .../react-ecs/packages/client/package.json | 44 + .../packages/client/postcss.config.cjs | 6 + .../react-ecs/packages/client/src/App.tsx | 46 + .../packages/client/src/Providers.tsx | 35 + .../react-ecs/packages/client/src/common.ts | 26 + .../packages/client/src/game/GameMap.tsx | 102 + .../client/src/game/useKeyboardMovement.ts | 26 + .../react-ecs/packages/client/src/index.tsx | 19 + .../packages/client/src/mud/Explorer.tsx | 32 + .../packages/client/src/mud/Synced.tsx | 14 + .../packages/client/src/mud/stash.ts | 4 + .../packages/client/src/mud/useSyncStatus.ts | 21 + .../client/src/mud/useWorldContract.ts | 44 + .../packages/client/src/ui/AsyncButton.tsx | 41 + .../packages/client/src/ui/ErrorFallback.tsx | 58 + .../client/src/ui/icons/ArrowDownIcon.tsx | 22 + .../packages/client/src/ui/icons/MUDIcon.tsx | 25 + .../packages/client/src/wagmiConfig.ts | 49 + .../packages/client/tailwind.config.ts | 10 + .../react-ecs/packages/client/tsconfig.json | 11 + .../react-ecs/packages/client/vite.config.ts | 12 + .../react-ecs/packages/contracts/.gitignore | 13 + .../react-ecs/packages/contracts/.prettierrc | 8 + .../packages/contracts/.solhint.json | 12 + .../react-ecs/packages/contracts/foundry.toml | 29 + .../packages/contracts/mud.config.ts | 21 + .../contracts/out/IWorld.sol/IWorld.abi.json | 2021 +++++++++++++++++ .../react-ecs/packages/contracts/package.json | 35 + .../packages/contracts/remappings.txt | 3 + .../contracts/script/PostDeploy.s.sol | 25 + .../packages/contracts/src/MoveSystem.sol | 26 + .../packages/contracts/src/codegen/common.sol | 11 + .../packages/contracts/src/codegen/index.sol | 6 + .../contracts/src/codegen/tables/Position.sol | 318 +++ .../src/codegen/world/IMoveSystem.sol | 15 + .../contracts/src/codegen/world/IWorld.sol | 16 + .../packages/contracts/test/MoveTest.t.sol | 27 + .../packages/contracts/test/WorldTest.t.sol | 21 + .../packages/contracts/tsconfig.json | 3 + .../react-ecs/packages/contracts/worlds.json | 5 + .../packages/contracts/worlds.json.d.ts | 2 + templates/react-ecs/pnpm-workspace.yaml | 2 + templates/react-ecs/tsconfig.json | 6 + 53 files changed, 3386 insertions(+) create mode 100644 templates/react-ecs/.eslintrc create mode 100644 templates/react-ecs/.gitattributes create mode 100644 templates/react-ecs/.gitignore create mode 100644 templates/react-ecs/.vscode/extensions.json create mode 100644 templates/react-ecs/.vscode/settings.json create mode 100644 templates/react-ecs/mprocs.yaml create mode 100644 templates/react-ecs/package.json create mode 100644 templates/react-ecs/packages/client/.eslintrc create mode 100644 templates/react-ecs/packages/client/.gitignore create mode 100644 templates/react-ecs/packages/client/index.html create mode 100644 templates/react-ecs/packages/client/package.json create mode 100644 templates/react-ecs/packages/client/postcss.config.cjs create mode 100644 templates/react-ecs/packages/client/src/App.tsx create mode 100644 templates/react-ecs/packages/client/src/Providers.tsx create mode 100644 templates/react-ecs/packages/client/src/common.ts create mode 100644 templates/react-ecs/packages/client/src/game/GameMap.tsx create mode 100644 templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts create mode 100644 templates/react-ecs/packages/client/src/index.tsx create mode 100644 templates/react-ecs/packages/client/src/mud/Explorer.tsx create mode 100644 templates/react-ecs/packages/client/src/mud/Synced.tsx create mode 100644 templates/react-ecs/packages/client/src/mud/stash.ts create mode 100644 templates/react-ecs/packages/client/src/mud/useSyncStatus.ts create mode 100644 templates/react-ecs/packages/client/src/mud/useWorldContract.ts create mode 100644 templates/react-ecs/packages/client/src/ui/AsyncButton.tsx create mode 100644 templates/react-ecs/packages/client/src/ui/ErrorFallback.tsx create mode 100644 templates/react-ecs/packages/client/src/ui/icons/ArrowDownIcon.tsx create mode 100644 templates/react-ecs/packages/client/src/ui/icons/MUDIcon.tsx create mode 100644 templates/react-ecs/packages/client/src/wagmiConfig.ts create mode 100644 templates/react-ecs/packages/client/tailwind.config.ts create mode 100644 templates/react-ecs/packages/client/tsconfig.json create mode 100644 templates/react-ecs/packages/client/vite.config.ts create mode 100644 templates/react-ecs/packages/contracts/.gitignore create mode 100644 templates/react-ecs/packages/contracts/.prettierrc create mode 100644 templates/react-ecs/packages/contracts/.solhint.json create mode 100644 templates/react-ecs/packages/contracts/foundry.toml create mode 100644 templates/react-ecs/packages/contracts/mud.config.ts create mode 100644 templates/react-ecs/packages/contracts/out/IWorld.sol/IWorld.abi.json create mode 100644 templates/react-ecs/packages/contracts/package.json create mode 100644 templates/react-ecs/packages/contracts/remappings.txt create mode 100644 templates/react-ecs/packages/contracts/script/PostDeploy.s.sol create mode 100644 templates/react-ecs/packages/contracts/src/MoveSystem.sol create mode 100644 templates/react-ecs/packages/contracts/src/codegen/common.sol create mode 100644 templates/react-ecs/packages/contracts/src/codegen/index.sol create mode 100644 templates/react-ecs/packages/contracts/src/codegen/tables/Position.sol create mode 100644 templates/react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol create mode 100644 templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol create mode 100644 templates/react-ecs/packages/contracts/test/MoveTest.t.sol create mode 100644 templates/react-ecs/packages/contracts/test/WorldTest.t.sol create mode 100644 templates/react-ecs/packages/contracts/tsconfig.json create mode 100644 templates/react-ecs/packages/contracts/worlds.json create mode 100644 templates/react-ecs/packages/contracts/worlds.json.d.ts create mode 100644 templates/react-ecs/pnpm-workspace.yaml create mode 100644 templates/react-ecs/tsconfig.json diff --git a/templates/react-ecs/.eslintrc b/templates/react-ecs/.eslintrc new file mode 100644 index 0000000000..79bd6ef23f --- /dev/null +++ b/templates/react-ecs/.eslintrc @@ -0,0 +1,10 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ] +} diff --git a/templates/react-ecs/.gitattributes b/templates/react-ecs/.gitattributes new file mode 100644 index 0000000000..9c70dc52f0 --- /dev/null +++ b/templates/react-ecs/.gitattributes @@ -0,0 +1,3 @@ +# suppress diffs for generated files +**/pnpm-lock.yaml linguist-generated=true +**/codegen/**/*.sol linguist-generated=true diff --git a/templates/react-ecs/.gitignore b/templates/react-ecs/.gitignore new file mode 100644 index 0000000000..b05d373f12 --- /dev/null +++ b/templates/react-ecs/.gitignore @@ -0,0 +1,16 @@ +.DS_Store +logs +*.log + +node_modules + +.env.* + +# foundry +cache +broadcast +out/* +!out/IWorld.sol +out/IWorld.sol/* +!out/IWorld.sol/IWorld.abi.json +!out/IWorld.sol/IWorld.abi.d.json.ts diff --git a/templates/react-ecs/.vscode/extensions.json b/templates/react-ecs/.vscode/extensions.json new file mode 100644 index 0000000000..f015de2761 --- /dev/null +++ b/templates/react-ecs/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["NomicFoundation.hardhat-solidity", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] +} diff --git a/templates/react-ecs/.vscode/settings.json b/templates/react-ecs/.vscode/settings.json new file mode 100644 index 0000000000..25fa6215fd --- /dev/null +++ b/templates/react-ecs/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib" +} diff --git a/templates/react-ecs/mprocs.yaml b/templates/react-ecs/mprocs.yaml new file mode 100644 index 0000000000..f5be11254f --- /dev/null +++ b/templates/react-ecs/mprocs.yaml @@ -0,0 +1,21 @@ +scrollback: 10000 +procs: + client: + cwd: packages/client + shell: pnpm run dev + contracts: + cwd: packages/contracts + shell: pnpm mud dev-contracts --rpc http://127.0.0.1:8545 + deploy-prereqs: + cwd: packages/contracts + shell: pnpm deploy-local-prereqs + env: + DEBUG: "mud:*" + # Anvil default account (0x70997970C51812dc3A010C7d01b50e0d17dc79C8) + PRIVATE_KEY: "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d" + anvil: + cwd: packages/contracts + shell: anvil --block-time 2 + explorer: + cwd: packages/contracts + shell: pnpm explorer diff --git a/templates/react-ecs/package.json b/templates/react-ecs/package.json new file mode 100644 index 0000000000..661fc6e32f --- /dev/null +++ b/templates/react-ecs/package.json @@ -0,0 +1,38 @@ +{ + "name": "mud-template-react", + "private": true, + "scripts": { + "build": "pnpm recursive run build", + "dev": "mprocs", + "dev:client": "pnpm --filter 'client' run dev", + "dev:contracts": "pnpm --filter 'contracts' dev", + "foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup", + "mud:up": "pnpm mud set-version --tag main && pnpm install", + "prepare": "(forge --version || pnpm foundry:up)", + "test": "pnpm recursive run test" + }, + "devDependencies": { + "@latticexyz/cli": "link:../../packages/cli", + "@latticexyz/common": "link:../../packages/common", + "@latticexyz/explorer": "link:../../packages/explorer", + "@latticexyz/store-indexer": "link:../../packages/store-indexer", + "@types/debug": "4.1.7", + "@typescript-eslint/eslint-plugin": "7.1.1", + "@typescript-eslint/parser": "7.1.1", + "eslint": "8.57.0", + "mprocs": "^0.7.1", + "shx": "^0.3.4", + "typescript": "5.4.2" + }, + "engines": { + "node": "^18", + "pnpm": "^8 || ^9" + }, + "pnpm": { + "overrides": { + "@tanstack/react-query": "link:../../packages/entrykit/node_modules/@tanstack/react-query", + "@types/react": "link:../../packages/entrykit/node_modules/@types/react", + "wagmi": "link:../../packages/entrykit/node_modules/wagmi" + } + } +} diff --git a/templates/react-ecs/packages/client/.eslintrc b/templates/react-ecs/packages/client/.eslintrc new file mode 100644 index 0000000000..930af95967 --- /dev/null +++ b/templates/react-ecs/packages/client/.eslintrc @@ -0,0 +1,7 @@ +{ + "extends": ["../../.eslintrc", "plugin:react/recommended", "plugin:react-hooks/recommended"], + "plugins": ["react", "react-hooks"], + "rules": { + "react/react-in-jsx-scope": "off" + } +} diff --git a/templates/react-ecs/packages/client/.gitignore b/templates/react-ecs/packages/client/.gitignore new file mode 100644 index 0000000000..1521c8b765 --- /dev/null +++ b/templates/react-ecs/packages/client/.gitignore @@ -0,0 +1 @@ +dist diff --git a/templates/react-ecs/packages/client/index.html b/templates/react-ecs/packages/client/index.html new file mode 100644 index 0000000000..ccf1b76fb2 --- /dev/null +++ b/templates/react-ecs/packages/client/index.html @@ -0,0 +1,12 @@ + + + + + + a MUD app + + +
+ + + diff --git a/templates/react-ecs/packages/client/package.json b/templates/react-ecs/packages/client/package.json new file mode 100644 index 0000000000..f9b2d4dee2 --- /dev/null +++ b/templates/react-ecs/packages/client/package.json @@ -0,0 +1,44 @@ +{ + "name": "client", + "version": "0.0.0", + "private": true, + "license": "MIT", + "type": "module", + "scripts": { + "build": "vite build", + "dev": "vite", + "preview": "vite preview", + "test": "tsc --noEmit" + }, + "dependencies": { + "@latticexyz/common": "link:../../../../packages/common", + "@latticexyz/entrykit": "link:../../../../packages/entrykit", + "@latticexyz/explorer": "link:../../../../packages/explorer", + "@latticexyz/react": "link:../../../../packages/react", + "@latticexyz/schema-type": "link:../../../../packages/schema-type", + "@latticexyz/stash": "link:../../../../packages/stash", + "@latticexyz/store-sync": "link:../../../../packages/store-sync", + "@latticexyz/utils": "link:../../../../packages/utils", + "@latticexyz/world": "link:../../../../packages/world", + "@tanstack/react-query": "^5.63.0", + "contracts": "workspace:*", + "react": "18.2.0", + "react-dom": "18.2.0", + "react-error-boundary": "5.0.0", + "tailwind-merge": "^2.6.0", + "viem": "2.21.19", + "wagmi": "2.12.11" + }, + "devDependencies": { + "@types/react": "18.2.22", + "@types/react-dom": "18.2.7", + "@vitejs/plugin-react": "^4.3.4", + "autoprefixer": "^10.4.20", + "eslint-plugin-react": "7.31.11", + "eslint-plugin-react-hooks": "4.6.0", + "postcss": "^8.4.49", + "tailwindcss": "^3.4.17", + "vite": "^6.0.7", + "vite-plugin-mud": "link:../../../../packages/vite-plugin-mud" + } +} diff --git a/templates/react-ecs/packages/client/postcss.config.cjs b/templates/react-ecs/packages/client/postcss.config.cjs new file mode 100644 index 0000000000..12a703d900 --- /dev/null +++ b/templates/react-ecs/packages/client/postcss.config.cjs @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; diff --git a/templates/react-ecs/packages/client/src/App.tsx b/templates/react-ecs/packages/client/src/App.tsx new file mode 100644 index 0000000000..ddc7bae21c --- /dev/null +++ b/templates/react-ecs/packages/client/src/App.tsx @@ -0,0 +1,46 @@ +import { stash } from "./mud/stash"; +import { useRecords } from "@latticexyz/stash/react"; +import { AccountButton } from "@latticexyz/entrykit/internal"; +import { Direction } from "./common"; +import mudConfig from "contracts/mud.config"; +import { useMemo } from "react"; +import { GameMap } from "./game/GameMap"; +import { useWorldContract } from "./mud/useWorldContract"; +import { Synced } from "./mud/Synced"; +import { useSync } from "@latticexyz/store-sync/react"; + +export function App() { + const players = useRecords({ stash, table: mudConfig.tables.app__Position }); + + const sync = useSync(); + const worldContract = useWorldContract(); + const onMove = useMemo( + () => + sync.data && worldContract + ? async (direction: Direction) => { + const tx = await worldContract.write.app__move([mudConfig.enums.Direction.indexOf(direction)]); + await sync.data.waitForTransaction(tx); + } + : undefined, + [sync.data, worldContract], + ); + + return ( + <> +
+ ( +
+ {message} ({percentage.toFixed(1)}%)… +
+ )} + > + +
+
+
+ +
+ + ); +} diff --git a/templates/react-ecs/packages/client/src/Providers.tsx b/templates/react-ecs/packages/client/src/Providers.tsx new file mode 100644 index 0000000000..ed96171dbb --- /dev/null +++ b/templates/react-ecs/packages/client/src/Providers.tsx @@ -0,0 +1,35 @@ +import { WagmiProvider } from "wagmi"; +import { QueryClientProvider, QueryClient } from "@tanstack/react-query"; +import { ReactNode } from "react"; +import { createSyncAdapter } from "@latticexyz/store-sync/internal"; +import { SyncProvider } from "@latticexyz/store-sync/react"; +import { stash } from "./mud/stash"; +import { defineConfig, EntryKitProvider } from "@latticexyz/entrykit/internal"; +import { wagmiConfig } from "./wagmiConfig"; +import { chainId, getWorldAddress, startBlock } from "./common"; + +const queryClient = new QueryClient(); + +export type Props = { + children: ReactNode; +}; + +export function Providers({ children }: Props) { + const worldAddress = getWorldAddress(); + return ( + + + + + {children} + + + + + ); +} diff --git a/templates/react-ecs/packages/client/src/common.ts b/templates/react-ecs/packages/client/src/common.ts new file mode 100644 index 0000000000..6caa86136c --- /dev/null +++ b/templates/react-ecs/packages/client/src/common.ts @@ -0,0 +1,26 @@ +import mudConfig from "contracts/mud.config"; +import { chains } from "./wagmiConfig"; +import { Chain } from "viem"; + +export const chainId = import.meta.env.CHAIN_ID; +export const worldAddress = import.meta.env.WORLD_ADDRESS; +export const startBlock = import.meta.env.START_BLOCK; + +export const url = new URL(window.location.href); + +export type Direction = (typeof mudConfig.enums.Direction)[number]; + +export function getWorldAddress() { + if (!worldAddress) { + throw new Error("No world address configured. Is the world still deploying?"); + } + return worldAddress; +} + +export function getChain(): Chain { + const chain = chains.find((c) => c.id === chainId); + if (!chain) { + throw new Error(`No chain configured for chain ID ${chainId}.`); + } + return chain; +} diff --git a/templates/react-ecs/packages/client/src/game/GameMap.tsx b/templates/react-ecs/packages/client/src/game/GameMap.tsx new file mode 100644 index 0000000000..04d7d24d4f --- /dev/null +++ b/templates/react-ecs/packages/client/src/game/GameMap.tsx @@ -0,0 +1,102 @@ +import { serialize, useAccount } from "wagmi"; +import { useKeyboardMovement } from "./useKeyboardMovement"; +import { Address, Hex, hexToBigInt, keccak256 } from "viem"; +import { ArrowDownIcon } from "../ui/icons/ArrowDownIcon"; +import { twMerge } from "tailwind-merge"; +import { Direction } from "../common"; +import mudConfig from "contracts/mud.config"; +import { AsyncButton } from "../ui/AsyncButton"; +import { useAccountModal } from "@latticexyz/entrykit/internal"; + +export type Props = { + readonly players?: readonly { + readonly player: Address; + readonly x: number; + readonly y: number; + }[]; + + readonly onMove?: (direction: Direction) => Promise; +}; + +const size = 40; +const scale = 100 / size; + +function getColorAngle(seed: Hex) { + return Number(hexToBigInt(keccak256(seed)) % 360n); +} + +const rotateClassName = { + North: "rotate-0", + East: "rotate-90", + South: "rotate-180", + West: "-rotate-90", +} as const satisfies Record; + +export function GameMap({ players = [], onMove }: Props) { + const { openAccountModal } = useAccountModal(); + const { address: userAddress } = useAccount(); + const currentPlayer = players.find((player) => player.player.toLowerCase() === userAddress?.toLowerCase()); + useKeyboardMovement(onMove); + return ( +
+
+ {onMove + ? mudConfig.enums.Direction.map((direction) => ( + + )) + : null} + + {players.map((player) => ( +
+ {player === currentPlayer ?
: null} +
+ ))} + + {!currentPlayer ? ( + onMove ? ( +
+ onMove("North")} + > + Spawning… + +
+ ) : ( +
+ +
+ ) + ) : null} +
+
+ ); +} diff --git a/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts b/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts new file mode 100644 index 0000000000..7e9074290f --- /dev/null +++ b/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts @@ -0,0 +1,26 @@ +import { useEffect } from "react"; +import { Direction } from "../common"; + +const keys = new Map([ + ["ArrowUp", "North"], + ["ArrowRight", "East"], + ["ArrowDown", "South"], + ["ArrowLeft", "West"], +]); + +export const useKeyboardMovement = (move: undefined | ((direction: Direction) => void)) => { + useEffect(() => { + if (!move) return; + + const listener = (event: KeyboardEvent) => { + const direction = keys.get(event.key); + if (direction == null) return; + + event.preventDefault(); + move(direction); + }; + + window.addEventListener("keydown", listener); + return () => window.removeEventListener("keydown", listener); + }, [move]); +}; diff --git a/templates/react-ecs/packages/client/src/index.tsx b/templates/react-ecs/packages/client/src/index.tsx new file mode 100644 index 0000000000..995e6ec9fd --- /dev/null +++ b/templates/react-ecs/packages/client/src/index.tsx @@ -0,0 +1,19 @@ +import "tailwindcss/tailwind.css"; +import { StrictMode } from "react"; +import { createRoot } from "react-dom/client"; +import { Providers } from "./Providers"; +import { App } from "./App"; +import { Explorer } from "./mud/Explorer"; +import { ErrorBoundary } from "react-error-boundary"; +import { ErrorFallback } from "./ui/ErrorFallback"; + +createRoot(document.getElementById("react-root")!).render( + + + + + + + + , +); diff --git a/templates/react-ecs/packages/client/src/mud/Explorer.tsx b/templates/react-ecs/packages/client/src/mud/Explorer.tsx new file mode 100644 index 0000000000..fe59d58c57 --- /dev/null +++ b/templates/react-ecs/packages/client/src/mud/Explorer.tsx @@ -0,0 +1,32 @@ +import { useState } from "react"; +import { getChain, getWorldAddress } from "../common"; +import { MUDIcon } from "../ui/icons/MUDIcon"; + +export function Explorer() { + const [open, setOpen] = useState(false); + + const chain = getChain(); + const worldAddress = getWorldAddress(); + + const explorerUrl = chain.blockExplorers?.worldsExplorer?.url; + if (!explorerUrl) return null; + + return ( +
+ + {open ?