├── .commitlintrc ├── .devcontainer └── devcontainer.json ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .husky ├── .gitignore ├── commit-msg └── pre-commit ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── lerna.json ├── package.json ├── packages ├── client │ ├── .eslintignore │ ├── .eslintrc │ ├── .gitignore │ ├── .hg │ ├── .parcelrc │ ├── CHANGELOG.md │ ├── README.md │ ├── __mocks__ │ │ └── fileMock.js │ ├── jest.config.js │ ├── modules.d.ts │ ├── package.json │ ├── src │ │ ├── boot.tsx │ │ ├── constants.ts │ │ ├── index.html │ │ ├── index.ts │ │ ├── layers │ │ │ ├── network │ │ │ │ ├── components │ │ │ │ │ ├── LoadingStateComponent.ts │ │ │ │ │ └── index.ts │ │ │ │ ├── config.ts │ │ │ │ ├── createNetworkLayer.ts │ │ │ │ ├── index.ts │ │ │ │ ├── setup │ │ │ │ │ ├── index.ts │ │ │ │ │ └── setupDevSystems.ts │ │ │ │ └── types.ts │ │ │ ├── phaser │ │ │ │ ├── assets │ │ │ │ │ └── tilesets │ │ │ │ │ │ ├── .gitkeep │ │ │ │ │ │ ├── mountain-tileset.png │ │ │ │ │ │ ├── moutainTileset.ts │ │ │ │ │ │ ├── overworld-tileset.png │ │ │ │ │ │ └── overworldTileset.ts │ │ │ │ ├── config.ts │ │ │ │ ├── constants.ts │ │ │ │ ├── createPhaserLayer.ts │ │ │ │ ├── index.ts │ │ │ │ └── types.ts │ │ │ └── react │ │ │ │ ├── README.md │ │ │ │ ├── components │ │ │ │ ├── ActionQueue.tsx │ │ │ │ ├── ComponentBrowser.tsx │ │ │ │ ├── LoadingState.tsx │ │ │ │ └── index.ts │ │ │ │ └── engine │ │ │ │ ├── Engine.tsx │ │ │ │ ├── components │ │ │ │ ├── BootScreen.tsx │ │ │ │ ├── Cell.tsx │ │ │ │ ├── ComponentRenderer.tsx │ │ │ │ ├── MainWindow.tsx │ │ │ │ └── index.ts │ │ │ │ ├── constants.ts │ │ │ │ ├── context.ts │ │ │ │ ├── hooks │ │ │ │ ├── index.ts │ │ │ │ ├── useEngineStore.ts │ │ │ │ └── useLayers.ts │ │ │ │ ├── index.ts │ │ │ │ ├── store.ts │ │ │ │ └── types.ts │ │ ├── public │ │ │ ├── atlases │ │ │ │ ├── FILES_AUTOGENERATED_DONT_CHANGE.txt │ │ │ │ └── sprites │ │ │ │ │ ├── atlas.json │ │ │ │ │ └── atlas.png │ │ │ └── img │ │ │ │ └── mud.png │ │ ├── types.ts │ │ └── utils │ │ │ ├── components.ts │ │ │ ├── coords.ts │ │ │ ├── directions.ts │ │ │ ├── distance.ts │ │ │ ├── pathfinding.ts │ │ │ ├── rx.ts │ │ │ ├── sleep.ts │ │ │ └── time.ts │ ├── tsconfig.json │ └── vite.config.ts └── contracts │ ├── .gitignore │ ├── .prettierrc │ ├── .solhint.json │ ├── CHANGELOG.md │ ├── README.md │ ├── chainSpec.json │ ├── deploy.json │ ├── exports.sh │ ├── foundry.toml │ ├── git-install.sh │ ├── hardhat.config.ts │ ├── package.json │ ├── remappings.txt │ ├── src │ ├── components │ │ └── ExampleComponent.sol │ ├── libraries │ │ ├── LibDeploy.ejs │ │ └── TODO.md │ ├── systems │ │ ├── ComponentDevSystem.sol │ │ └── README.md │ └── test │ │ ├── BulkUpload.t.sol │ │ ├── Deploy.t.sol │ │ ├── MudTest.t.sol │ │ ├── systems │ │ └── GameConfigSystem.t.sol │ │ └── utils │ │ ├── BroadcastDeploy.sol │ │ ├── Cheats.sol │ │ ├── Deploy.sol │ │ └── Utilities.sol │ └── tsconfig.json └── yarn.lock /.commitlintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["@commitlint/config-conventional"] 3 | } 4 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "onCreateCommand": "curl -L https://foundry.paradigm.xyz | bash && /home/codespace/.foundry/bin/foundryup && yarn" 3 | } 4 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": [ 6 | "eslint:recommended", 7 | "plugin:@typescript-eslint/eslint-recommended", 8 | "plugin:@typescript-eslint/recommended" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .eslintcache 3 | .DS_STORE -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx --no -- commitlint --edit "${1}" 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx lint-staged 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "semi": true, 4 | "tabWidth": 2, 5 | "useTabs": false 6 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "solidity.remappings": [ 3 | "memmove/=node_modules/memmove/src/", 4 | "ds-test/=node_modules/ds-test/src/", 5 | "@openzeppelin/=node_modules/openzeppelin-solidity/", 6 | "forge-std/=node_modules/forge-std/src/", 7 | "solmate/=node_modules/@rari-capital/solmate/src", 8 | "persona/=node_modules/@latticexyz/persona/src/", 9 | "gsn/=node_modules/@opengsn/contracts/src/", 10 | "ds-test/=node_modules/ds-test/src/", 11 | "solecs/=node_modules/@latticexyz/solecs/src/", 12 | "royalty-registry/=node_modules/@manifoldxzy/royalty-registry/contracts/", 13 | "std-contracts/=node_modules/@latticexyz/std-contracts/src/", 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Lattice Labs Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mudbasics 2 | 3 | A simple mud reference implementation 4 | 5 | ## Getting started 6 | For a simple tutorial on how to use MUD, check out the slides of the [MUD workshop](https://www.figma.com/file/n4Ld4tpaiymotp9mRH5Te9/Mud-Workshop?node-id=0%3A1). Solutions for Quest 1 and Quest 2 can be found at [#1](https://github.com/latticexyz/mudbasics/pull/1) and [#2](https://github.com/latticexyz/mudbasics/pull/2). 7 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": ["packages/*"], 3 | "version": "0.0.0", 4 | "npmClient": "yarn", 5 | "useWorkspaces": true 6 | } 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mudbasics", 3 | "version": "0.0.0", 4 | "description": "A simple mud reference implementation", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/latticexyz/mudbasics.git" 8 | }, 9 | "private": true, 10 | "workspaces": { 11 | "packages": [ 12 | "packages/*" 13 | ] 14 | }, 15 | "devDependencies": { 16 | "@commitlint/cli": "^16.2.4", 17 | "@commitlint/config-conventional": "^16.2.4", 18 | "@typescript-eslint/eslint-plugin": "^5.23.0", 19 | "@typescript-eslint/parser": "^5.23.0", 20 | "commitizen": "^4.2.4", 21 | "cz-conventional-changelog": "3.3.0", 22 | "eslint": "^8.15.0", 23 | "husky": ">=6", 24 | "lerna": "^4.0.0", 25 | "lint-staged": ">=10", 26 | "prettier": "^2.6.2", 27 | "run-pty": "^3.0.0" 28 | }, 29 | "config": { 30 | "commitizen": { 31 | "path": "./node_modules/cz-conventional-changelog" 32 | } 33 | }, 34 | "scripts": { 35 | "prepare": "husky install && yarn lerna run prepare", 36 | "commit": "cz", 37 | "prettier:check": "prettier --check 'src/**/*.ts'", 38 | "prettier": "prettier --write 'packages/**/*.ts'", 39 | "lint": "eslint . --ext .ts", 40 | "lerna:release": "lerna version --conventional-commits --yes", 41 | "lerna:publish": "lerna publish --no-private --force-publish", 42 | "foundryup": "curl -L https://foundry.paradigm.xyz | bash && exec \"$SHELL\" && foundryup", 43 | "start": "run-pty % yarn start:contracts % yarn start:client", 44 | "start:client": "wait-on tcp:8545 && yarn workspace client run start", 45 | "start:contracts": "yarn workspace contracts run start", 46 | "link:mud": "for i in node_modules/@latticexyz/*; do yarn link @latticexyz/$(basename $i); done", 47 | "unlink:mud": "for i in node_modules/@latticexyz/*; do yarn unlink @latticexyz/$(basename $i); done && yarn install --force" 48 | }, 49 | "lint-staged": { 50 | "*.ts": "eslint --cache --fix", 51 | "*.{ts,css,md,sol}": "prettier --write" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /packages/client/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist -------------------------------------------------------------------------------- /packages/client/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": ["@typescript-eslint"], 5 | "extends": [ 6 | "eslint:recommended", 7 | "plugin:@typescript-eslint/eslint-recommended", 8 | "plugin:@typescript-eslint/recommended" 9 | ], 10 | "rules": { 11 | "no-restricted-imports": [ 12 | "error", 13 | { 14 | "paths": [ 15 | { 16 | "importNames": ["delay"], 17 | "name": "rxjs", 18 | "message": "Use delayTime from utils/rx instead." 19 | } 20 | ] 21 | } 22 | ] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/client/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .parcel-cache 4 | cypress/videos 5 | cypress/screenshots 6 | cypress/reports 7 | .yarn/install-state.gz 8 | .DS_Store -------------------------------------------------------------------------------- /packages/client/.hg: -------------------------------------------------------------------------------- 1 | this file is here to tell parcel this is the project root 2 | https://github.com/parcel-bundler/parcel/issues/7206#issuecomment-954127065 -------------------------------------------------------------------------------- /packages/client/.parcelrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@parcel/config-default" 4 | ], 5 | "reporters": [ 6 | "...", 7 | "parcel-reporter-static-files-copy" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /packages/client/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.1.7](https://github.com/latticexyz/mud/compare/v0.1.6...v0.1.7) (2022-05-25) 7 | 8 | **Note:** Version bump only for package client 9 | 10 | # 0.1.0 (2022-05-23) 11 | 12 | ### Bug Fixes 13 | 14 | - **client:** fix assuming component value is not undefined when using updateQuery ([f93ee23](https://github.com/latticexyz/mud/commit/f93ee233d1a2d4a1ef38d946cc241cc75b81e5a9)) 15 | - **client:** integrate client with new contract-side component ids ([78bbdfb](https://github.com/latticexyz/mud/commit/78bbdfb87f7e19964550315696fba080a2056ab8)) 16 | - **client:** type game contracts using combined facet abi ([6bc48a8](https://github.com/latticexyz/mud/commit/6bc48a89dfe9058b5505fcc07aedaf476fae1477)) 17 | 18 | ### Features 19 | 20 | - **client:** add client reference implementation ([10a33cb](https://github.com/latticexyz/mud/commit/10a33cba983fb56e23af3d1baf68ceafb5325503)) 21 | 22 | ### Performance Improvements 23 | 24 | - **client:** throttle ECS event processing to 12000 per second ([88726ec](https://github.com/latticexyz/mud/commit/88726ec559ff5707b84f2eae1d570510fb3ae358)) 25 | - **client:** use json rpc provider to send transactions and load block events ([2455aeb](https://github.com/latticexyz/mud/commit/2455aebca5c021c5b9dfa9227be85d2497eb5df9)) 26 | -------------------------------------------------------------------------------- /packages/client/README.md: -------------------------------------------------------------------------------- 1 | # Reference Implementation Client 2 | -------------------------------------------------------------------------------- /packages/client/__mocks__/fileMock.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | module.exports = ""; 3 | -------------------------------------------------------------------------------- /packages/client/jest.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-undef */ 2 | /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ 3 | module.exports = { 4 | preset: "ts-jest", 5 | // testEnvironment: "node", 6 | roots: ["src"], 7 | moduleNameMapper: { 8 | "\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": 9 | "/__mocks__/fileMock.js", 10 | }, 11 | setupFiles: ["jest-canvas-mock"], 12 | }; 13 | -------------------------------------------------------------------------------- /packages/client/modules.d.ts: -------------------------------------------------------------------------------- 1 | declare module "*.png"; 2 | -------------------------------------------------------------------------------- /packages/client/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "version": "0.2.0", 4 | "private": "true", 5 | "dependencies": { 6 | "@ethersproject/providers": "^5.7.0", 7 | "@improbable-eng/grpc-web": "^0.15.0", 8 | "@latticexyz/ecs-browser": "1.5.1", 9 | "@latticexyz/network": "1.5.1", 10 | "@latticexyz/phaserx": "1.5.1", 11 | "@latticexyz/recs": "1.5.1", 12 | "@latticexyz/services": "1.5.1", 13 | "@latticexyz/solecs": "1.5.1", 14 | "@latticexyz/std-client": "1.5.1", 15 | "@latticexyz/utils": "1.5.1", 16 | "@protobuf-ts/grpcweb-transport": "^2.8.1", 17 | "@protobuf-ts/runtime": "^2.8.1", 18 | "@protobuf-ts/runtime-rpc": "^2.8.1", 19 | "async-mutex": "^0.3.2", 20 | "contracts": "^0.2.0", 21 | "ethers": "^5.7.1", 22 | "heap-js": "^2.2.0", 23 | "lodash": "^4.17.21", 24 | "mobx": "^6.4.2", 25 | "mobx-react-lite": "^3.3.0", 26 | "mobx-utils": "^6.0.4", 27 | "nice-grpc-web": "^2.0.0", 28 | "phaser": "3.60.0-beta.4", 29 | "protobufjs": "^7.1.2", 30 | "proxy-deep": "^3.1.1", 31 | "react": "^18.0.0", 32 | "react-collapse": "^5.1.1", 33 | "react-dom": "^18.0.0", 34 | "react-is": "^18.0.0", 35 | "rxjs": "^7.5.5", 36 | "styled-components": "^5.3.5", 37 | "threads": "^1.7.0", 38 | "uuid": "^8.3.2" 39 | }, 40 | "devDependencies": { 41 | "@originjs/vite-plugin-commonjs": "^1.0.3", 42 | "@types/jest": "^27.4.1", 43 | "@types/react": "^17.0.43", 44 | "@types/react-dom": "^18.0.4", 45 | "@types/styled-components": "^5.1.24", 46 | "@types/uuid": "^8.3.4", 47 | "@typescript-eslint/eslint-plugin": "^5.12.1", 48 | "@typescript-eslint/parser": "^5.12.1", 49 | "cypress": "^9.5.0", 50 | "cypress-wait-until": "^1.7.2", 51 | "dpdm": "^3.9.0", 52 | "eslint": "^8.9.0", 53 | "jest": "^27.5.1", 54 | "jest-canvas-mock": "^2.3.1", 55 | "lodash": "^4.17.21", 56 | "netlify": "^11.0.2", 57 | "netlify-cli": "^10.10.2", 58 | "parcel": "^2.7.0", 59 | "parcel-reporter-static-files-copy": "^1.4.0", 60 | "prettier": "^2.5.1", 61 | "process": "^0.11.10", 62 | "serve": "^14.0.1", 63 | "ts-jest": "^27.1.3", 64 | "typescript": "^4.5.5", 65 | "vite": "^2.8.4" 66 | }, 67 | "scripts": { 68 | "test": "jest", 69 | "lint": "eslint . --fix --ext .ts", 70 | "prettier": "prettier --write '**/*.{ts,tsx}'", 71 | "// use yarn dev when developing with a locally linked version of MUD": "", 72 | "dev": "vite --force", 73 | "// use yarn start when developing with MUD packages from npm or yalc": "", 74 | "start": "rimraf ../../.parcel-cache && rimraf .parcel-cache && yarn parcel src/index.html --port 3000", 75 | "// note: must use MUD packages from npm or yalc to build for production": "", 76 | "build": "rimraf dist && rimraf ../../.parcel-cache && rimraf .parcel-cache && parcel build src/index.html", 77 | "prod": "yarn serve dist", 78 | "test:performance": "cypress run", 79 | "test:performance:record": "cypress run --record --key 6920b67f-6bc2-46cd-9d9a-ee402330517d", 80 | "test:performance:dashboard": "cypress open", 81 | "check:circdepen": "dpdm ./src/index.ts" 82 | }, 83 | "staticFiles": { 84 | "staticPath": "src/public" 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /packages/client/src/boot.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | import { getComponentValue, removeComponent, setComponent } from "@latticexyz/recs"; 3 | import React from "react"; 4 | import ReactDOM from "react-dom/client"; 5 | import { Time } from "./utils/time"; 6 | import { createNetworkLayer as createNetworkLayerImport } from "./layers/network"; 7 | import { createPhaserLayer as createPhaserLayerImport } from "./layers/phaser"; 8 | import { Layers } from "./types"; 9 | import { Engine as EngineImport } from "./layers/react/engine/Engine"; 10 | import { registerUIComponents as registerUIComponentsImport } from "./layers/react/components"; 11 | import { Wallet } from "ethers"; 12 | 13 | // Assign variables that can be overridden by HMR 14 | let createNetworkLayer = createNetworkLayerImport; 15 | let createPhaserLayer = createPhaserLayerImport; 16 | let registerUIComponents = registerUIComponentsImport; 17 | let Engine = EngineImport; 18 | 19 | /** 20 | * This function is called once when the game boots up. 21 | * It creates all the layers and their hierarchy. 22 | * Add new layers here. 23 | */ 24 | async function bootGame() { 25 | const layers: Partial = {}; 26 | let initialBoot = true; 27 | 28 | async function rebootGame(): Promise { 29 | // Remove react when starting to reboot layers, reboot react once layers are rebooted 30 | mountReact.current(false); 31 | 32 | const params = new URLSearchParams(window.location.search); 33 | const worldAddress = params.get("worldAddress"); 34 | let privateKey = params.get("burnerWalletPrivateKey"); 35 | const chainIdString = params.get("chainId"); 36 | const jsonRpc = params.get("rpc") || undefined; 37 | const wsRpc = params.get("wsRpc") || undefined; // || (jsonRpc && jsonRpc.replace("http", "ws")); 38 | const checkpointUrl = params.get("checkpoint") || undefined; 39 | const devMode = params.get("dev") === "true"; 40 | const initialBlockNumberString = params.get("initialBlockNumber"); 41 | const initialBlockNumber = initialBlockNumberString ? parseInt(initialBlockNumberString) : 0; 42 | 43 | if (!privateKey) { 44 | privateKey = localStorage.getItem("burnerWallet") || Wallet.createRandom().privateKey; 45 | localStorage.setItem("burnerWallet", privateKey); 46 | } 47 | 48 | let networkLayerConfig; 49 | if (worldAddress && privateKey && chainIdString && jsonRpc) { 50 | networkLayerConfig = { 51 | worldAddress, 52 | privateKey, 53 | chainId: parseInt(chainIdString), 54 | jsonRpc, 55 | wsRpc, 56 | checkpointUrl, 57 | devMode, 58 | initialBlockNumber, 59 | }; 60 | } 61 | 62 | if (!networkLayerConfig) throw new Error("Invalid config"); 63 | 64 | if (!layers.network) layers.network = await createNetworkLayer(networkLayerConfig); 65 | if (!layers.phaser) layers.phaser = await createPhaserLayer(layers.network); 66 | 67 | // Sync global time with phaser clock 68 | Time.time.setPacemaker((setTimestamp) => { 69 | layers.phaser?.game.events.on("poststep", (time: number) => { 70 | setTimestamp(time); 71 | }); 72 | }); 73 | 74 | // Make sure there is only one canvas. 75 | // Ideally HMR should handle this, but in some cases it fails. 76 | // If there are two canvas elements, do a full reload. 77 | if (document.querySelectorAll("#phaser-game canvas").length > 1) { 78 | console.log("Detected two canvas elements, full reload"); 79 | import.meta.hot?.invalidate(); 80 | } 81 | 82 | // Start syncing once all systems have booted 83 | if (initialBoot) { 84 | initialBoot = false; 85 | layers.network.startSync(); 86 | } 87 | 88 | // Reboot react if layers have changed 89 | mountReact.current(true); 90 | 91 | return layers as Layers; 92 | } 93 | 94 | function dispose(layer: keyof Layers) { 95 | layers[layer]?.world.dispose(); 96 | layers[layer] = undefined; 97 | } 98 | 99 | await rebootGame(); 100 | 101 | const ecs = { 102 | setComponent, 103 | removeComponent, 104 | getComponentValue, 105 | }; 106 | 107 | (window as any).layers = layers; 108 | (window as any).ecs = ecs; 109 | (window as any).time = Time.time; 110 | 111 | let reloadingNetwork = false; 112 | let reloadingPhaser = false; 113 | 114 | if (import.meta.hot) { 115 | import.meta.hot.accept("./layers/network/index.ts", async (module) => { 116 | if (reloadingNetwork) return; 117 | reloadingNetwork = true; 118 | createNetworkLayer = module.createNetworkLayer; 119 | dispose("network"); 120 | dispose("phaser"); 121 | await rebootGame(); 122 | console.log("HMR Network"); 123 | layers.network?.startSync(); 124 | reloadingNetwork = false; 125 | }); 126 | 127 | import.meta.hot.accept("./layers/phaser/index.ts", async (module) => { 128 | if (reloadingPhaser) return; 129 | reloadingPhaser = true; 130 | createPhaserLayer = module.createPhaserLayer; 131 | dispose("phaser"); 132 | await rebootGame(); 133 | console.log("HMR Phaser"); 134 | reloadingPhaser = false; 135 | }); 136 | } 137 | console.log("booted"); 138 | 139 | return { layers, ecs }; 140 | } 141 | 142 | const mountReact: { current: (mount: boolean) => void } = { current: () => void 0 }; 143 | const setLayers: { current: (layers: Layers) => void } = { current: () => void 0 }; 144 | 145 | function bootReact() { 146 | const rootElement = document.getElementById("react-root"); 147 | if (!rootElement) return console.warn("React root not found"); 148 | 149 | const root = ReactDOM.createRoot(rootElement); 150 | 151 | function renderEngine() { 152 | root.render(); 153 | } 154 | 155 | renderEngine(); 156 | registerUIComponents(); 157 | 158 | if (import.meta.hot) { 159 | // HMR React engine 160 | import.meta.hot.accept("./layers/Renderer/React/engine/Engine.tsx", async (module) => { 161 | Engine = module.Engine; 162 | renderEngine(); 163 | }); 164 | } 165 | 166 | if (import.meta.hot) { 167 | // HMR React components 168 | import.meta.hot.accept("./layers/Renderer/React/components/index.ts", async (module) => { 169 | registerUIComponents = module.registerUIComponents; 170 | registerUIComponents(); 171 | }); 172 | } 173 | } 174 | 175 | export async function boot() { 176 | bootReact(); 177 | const game = await bootGame(); 178 | setLayers.current(game.layers as Layers); 179 | } 180 | -------------------------------------------------------------------------------- /packages/client/src/constants.ts: -------------------------------------------------------------------------------- 1 | export enum Direction { 2 | Top, 3 | Right, 4 | Bottom, 5 | Left, 6 | } 7 | 8 | export const Directions = { 9 | [Direction.Top]: { x: 0, y: -1 }, 10 | [Direction.Right]: { x: 1, y: 0 }, 11 | [Direction.Bottom]: { x: 0, y: 1 }, 12 | [Direction.Left]: { x: -1, y: 0 }, 13 | }; 14 | -------------------------------------------------------------------------------- /packages/client/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Phaser Renderer for next-client 4 | 12 | 13 | 14 | 15 | 16 |
17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /packages/client/src/index.ts: -------------------------------------------------------------------------------- 1 | import { boot } from "./boot"; 2 | 3 | boot(); 4 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/components/LoadingStateComponent.ts: -------------------------------------------------------------------------------- 1 | import { defineComponent, Type, World } from "@latticexyz/recs"; 2 | 3 | export function defineLoadingStateComponent(world: World) { 4 | return defineComponent( 5 | world, 6 | { 7 | state: Type.Number, 8 | msg: Type.String, 9 | percentage: Type.Number, 10 | }, 11 | { 12 | id: "LoadingState", 13 | metadata: { 14 | contractId: "component.LoadingState", 15 | }, 16 | } 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/components/index.ts: -------------------------------------------------------------------------------- 1 | export { defineLoadingStateComponent } from "./LoadingStateComponent"; 2 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/config.ts: -------------------------------------------------------------------------------- 1 | import { SetupContractConfig } from "@latticexyz/std-client"; 2 | 3 | export type GameConfig = { 4 | worldAddress: string; 5 | privateKey: string; 6 | chainId: number; 7 | jsonRpc: string; 8 | wsRpc?: string; 9 | checkpointUrl?: string; 10 | devMode: boolean; 11 | initialBlockNumber: number; 12 | }; 13 | 14 | export const getNetworkConfig: (networkConfig: GameConfig) => SetupContractConfig = (config) => ({ 15 | clock: { 16 | period: 1000, 17 | initialTime: 0, 18 | syncInterval: 5000, 19 | }, 20 | provider: { 21 | jsonRpcUrl: config.jsonRpc, 22 | wsRpcUrl: config.wsRpc, 23 | chainId: config.chainId, 24 | options: { 25 | batch: false, 26 | }, 27 | }, 28 | privateKey: config.privateKey, 29 | chainId: config.chainId, 30 | checkpointServiceUrl: config.checkpointUrl, 31 | initialBlockNumber: config.initialBlockNumber, 32 | worldAddress: config.worldAddress, 33 | devMode: config.devMode, 34 | }); 35 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/createNetworkLayer.ts: -------------------------------------------------------------------------------- 1 | import { createWorld } from "@latticexyz/recs"; 2 | import { setupDevSystems } from "./setup"; 3 | import { createActionSystem, setupMUDNetwork } from "@latticexyz/std-client"; 4 | import { defineLoadingStateComponent } from "./components"; 5 | import { SystemTypes } from "contracts/types/SystemTypes"; 6 | import { SystemAbis } from "contracts/types/SystemAbis.mjs"; 7 | import { GameConfig, getNetworkConfig } from "./config"; 8 | 9 | /** 10 | * The Network layer is the lowest layer in the client architecture. 11 | * Its purpose is to synchronize the client components with the contract components. 12 | */ 13 | export async function createNetworkLayer(config: GameConfig) { 14 | console.log("Network config", config); 15 | 16 | // --- WORLD ---------------------------------------------------------------------- 17 | const world = createWorld(); 18 | 19 | // --- COMPONENTS ----------------------------------------------------------------- 20 | const components = { 21 | LoadingState: defineLoadingStateComponent(world), 22 | }; 23 | 24 | // --- SETUP ---------------------------------------------------------------------- 25 | const { txQueue, systems, txReduced$, network, startSync, encoders } = await setupMUDNetwork< 26 | typeof components, 27 | SystemTypes 28 | >(getNetworkConfig(config), world, components, SystemAbis); 29 | 30 | // --- ACTION SYSTEM -------------------------------------------------------------- 31 | const actions = createActionSystem(world, txReduced$); 32 | 33 | // --- API ------------------------------------------------------------------------ 34 | 35 | // --- CONTEXT -------------------------------------------------------------------- 36 | const context = { 37 | world, 38 | components, 39 | txQueue, 40 | systems, 41 | txReduced$, 42 | startSync, 43 | network, 44 | actions, 45 | api: {}, 46 | dev: setupDevSystems(world, encoders, systems), 47 | }; 48 | 49 | return context; 50 | } 51 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/index.ts: -------------------------------------------------------------------------------- 1 | export { createNetworkLayer } from "./createNetworkLayer"; 2 | export type { NetworkLayer } from "./types"; 3 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/setup/index.ts: -------------------------------------------------------------------------------- 1 | export { setupDevSystems } from "./setupDevSystems"; 2 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/setup/setupDevSystems.ts: -------------------------------------------------------------------------------- 1 | import { TxQueue } from "@latticexyz/network"; 2 | import { Component, ComponentValue, defineComponent, EntityIndex, Schema, Type, World } from "@latticexyz/recs"; 3 | import { keccak256 } from "@latticexyz/utils"; 4 | import { BigNumber } from "ethers"; 5 | import { SystemTypes } from "contracts/types/SystemTypes"; 6 | 7 | export function setupDevSystems( 8 | world: World, 9 | encodersPromise: Promise string>>, 10 | systems: TxQueue 11 | ) { 12 | const DevHighlightComponent = defineComponent(world, { value: Type.OptionalNumber }); 13 | 14 | const HoverHighlightComponent = defineComponent(world, { 15 | x: Type.OptionalNumber, 16 | y: Type.OptionalNumber, 17 | }); 18 | 19 | async function setContractComponentValue( 20 | entity: EntityIndex, 21 | component: Component, 22 | newValue: ComponentValue 23 | ) { 24 | if (!component.metadata.contractId) 25 | throw new Error( 26 | `Attempted to set the contract value of Component ${component.id} without a deployed contract backing it.` 27 | ); 28 | const encoders = await encodersPromise; 29 | const data = encoders[keccak256(component.metadata.contractId)](newValue); 30 | const entityId = world.entities[entity]; 31 | console.log(`Sent transaction to edit networked Component ${component.id} for Entity ${entityId}`); 32 | await systems["mudwar.system.ComponentDev"].executeTyped( 33 | keccak256(component.metadata.contractId), 34 | BigNumber.from(entityId), 35 | data 36 | ); 37 | } 38 | 39 | return { setContractComponentValue, DevHighlightComponent, HoverHighlightComponent }; 40 | } 41 | -------------------------------------------------------------------------------- /packages/client/src/layers/network/types.ts: -------------------------------------------------------------------------------- 1 | import { createNetworkLayer } from "./createNetworkLayer"; 2 | 3 | export type NetworkLayer = Awaited>; 4 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/assets/tilesets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/layers/phaser/assets/tilesets/.gitkeep -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/assets/tilesets/mountain-tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/layers/phaser/assets/tilesets/mountain-tileset.png -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/assets/tilesets/moutainTileset.ts: -------------------------------------------------------------------------------- 1 | export enum WangSetKey { 2 | Mountain = "Mountain", 3 | } 4 | export const WangSets: { [key in WangSetKey]: { [key: number]: number } } = { 5 | [WangSetKey.Mountain]: { 6 | 4: 92, 7 | 68: 93, 8 | 64: 94, 9 | 16: 100, 10 | 28: 101, 11 | 124: 102, 12 | 112: 103, 13 | 20: 104, 14 | 84: 105, 15 | 80: 106, 16 | 17: 109, 17 | 31: 110, 18 | 255: 111, 19 | 241: 112, 20 | 21: 113, 21 | 85: 114, 22 | 81: 115, 23 | 1: 118, 24 | 7: 119, 25 | 199: 120, 26 | 193: 121, 27 | 5: 122, 28 | 69: 123, 29 | 65: 124, 30 | 247: 131, 31 | 215: 132, 32 | 223: 133, 33 | 245: 140, 34 | 95: 142, 35 | 253: 149, 36 | 125: 150, 37 | 127: 151, 38 | }, 39 | }; 40 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/assets/tilesets/overworld-tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/layers/phaser/assets/tilesets/overworld-tileset.png -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/assets/tilesets/overworldTileset.ts: -------------------------------------------------------------------------------- 1 | export enum Tileset { 2 | Tree1 = 23, 3 | Tree2 = 24, 4 | Tree3 = 25, 5 | Tree4 = 26, 6 | Tree5 = 27, 7 | Tree6 = 28, 8 | Tree7 = 29, 9 | Tree8 = 30, 10 | Plain = 38, 11 | Grass = 40, 12 | Brick1 = 42, 13 | Tron = 43, 14 | SnowTree1 = 45, 15 | SnowTree2 = 46, 16 | SnowTree3 = 47, 17 | SnowTree4 = 48, 18 | SnowTree5 = 49, 19 | SnowTree6 = 50, 20 | SnowTree7 = 51, 21 | SnowTree8 = 52, 22 | Hill1 = 59, 23 | Hill2 = 60, 24 | Hill3 = 61, 25 | PlainRock1 = 62, 26 | PlainRock2 = 63, 27 | Brick2 = 64, 28 | Water = 683, 29 | } 30 | export enum TileAnimationKey { 31 | Water = "Water", 32 | } 33 | export const TileAnimations: { [key in TileAnimationKey]: number[] } = { 34 | [TileAnimationKey.Water]: [683, 684, 685, 686, 687, 688, 689, 690], 35 | }; 36 | export enum WangSetKey { 37 | Road = "Road", 38 | Wall = "Wall", 39 | Hill = "Hill", 40 | Water = "Water", 41 | } 42 | export const WangSets: { [key in WangSetKey]: { [key: number]: number } } = { 43 | [WangSetKey.Road]: { 44 | 1: 596, 45 | 4: 597, 46 | 5: 598, 47 | 16: 599, 48 | 17: 600, 49 | 20: 601, 50 | 21: 602, 51 | 64: 603, 52 | 65: 604, 53 | 68: 605, 54 | 69: 606, 55 | 80: 607, 56 | 81: 608, 57 | 84: 609, 58 | 85: 610, 59 | }, 60 | [WangSetKey.Wall]: { 61 | 1: 640, 62 | 5: 641, 63 | 16: 643, 64 | 17: 644, 65 | 20: 645, 66 | 21: 646, 67 | 64: 647, 68 | 65: 648, 69 | 68: 649, 70 | 69: 650, 71 | 81: 651, 72 | 84: 653, 73 | 85: 654, 74 | }, 75 | [WangSetKey.Hill]: { 76 | 255: 98, 77 | 127: 99, 78 | 253: 100, 79 | 125: 101, 80 | 247: 102, 81 | 119: 103, 82 | 245: 104, 83 | 117: 105, 84 | 223: 120, 85 | 95: 121, 86 | 221: 122, 87 | 93: 123, 88 | 215: 124, 89 | 87: 125, 90 | 213: 126, 91 | 85: 127, 92 | 31: 142, 93 | 29: 143, 94 | 23: 144, 95 | 21: 145, 96 | 124: 146, 97 | 116: 147, 98 | 92: 148, 99 | 84: 149, 100 | 241: 164, 101 | 209: 165, 102 | 113: 166, 103 | 81: 167, 104 | 199: 168, 105 | 71: 169, 106 | 197: 170, 107 | 69: 171, 108 | 17: 186, 109 | 68: 187, 110 | 28: 188, 111 | 20: 189, 112 | 112: 190, 113 | 80: 191, 114 | 193: 192, 115 | 65: 193, 116 | 7: 208, 117 | 5: 209, 118 | 16: 210, 119 | 4: 211, 120 | 1: 212, 121 | 64: 213, 122 | }, 123 | [WangSetKey.Water]: { 124 | 255: 450, 125 | 127: 451, 126 | 253: 452, 127 | 125: 453, 128 | 247: 454, 129 | 119: 455, 130 | 245: 456, 131 | 117: 457, 132 | 223: 472, 133 | 95: 473, 134 | 221: 474, 135 | 93: 475, 136 | 215: 476, 137 | 87: 477, 138 | 213: 478, 139 | 85: 479, 140 | 31: 494, 141 | 29: 495, 142 | 23: 496, 143 | 21: 497, 144 | 124: 498, 145 | 116: 499, 146 | 92: 500, 147 | 84: 501, 148 | 241: 516, 149 | 209: 517, 150 | 113: 518, 151 | 81: 519, 152 | 199: 520, 153 | 71: 521, 154 | 197: 522, 155 | 69: 523, 156 | 17: 538, 157 | 68: 539, 158 | 28: 540, 159 | 20: 541, 160 | 112: 542, 161 | 80: 543, 162 | 193: 544, 163 | 65: 545, 164 | 7: 560, 165 | 5: 561, 166 | 16: 562, 167 | 4: 563, 168 | 1: 564, 169 | 64: 565, 170 | }, 171 | }; 172 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/config.ts: -------------------------------------------------------------------------------- 1 | import { 2 | defineSceneConfig, 3 | AssetType, 4 | defineScaleConfig, 5 | defineMapConfig, 6 | defineCameraConfig, 7 | } from "@latticexyz/phaserx"; 8 | import { Sprites, Assets, Maps, Scenes, TILE_HEIGHT, TILE_WIDTH } from "./constants"; 9 | import { 10 | Tileset as OverworldTileset, 11 | TileAnimations as OverworldTileAnimations, 12 | } from "../phaser/assets/tilesets/overworldTileset"; 13 | import overworldTileset from "./assets/tilesets/overworld-tileset.png"; 14 | import mountainTileset from "./assets/tilesets/mountain-tileset.png"; 15 | const ANIMATION_INTERVAL = 200; 16 | 17 | export const phaserConfig = { 18 | sceneConfig: { 19 | [Scenes.Main]: defineSceneConfig({ 20 | assets: { 21 | [Assets.OverworldTileset]: { type: AssetType.Image, key: Assets.OverworldTileset, path: overworldTileset }, 22 | [Assets.MountainTileset]: { type: AssetType.Image, key: Assets.MountainTileset, path: mountainTileset }, 23 | [Assets.MainAtlas]: { 24 | type: AssetType.MultiAtlas, 25 | key: Assets.MainAtlas, 26 | path: "/atlases/sprites/atlas.json", 27 | options: { 28 | imagePath: "/atlases/sprites/", 29 | }, 30 | }, 31 | }, 32 | maps: { 33 | [Maps.Main]: defineMapConfig({ 34 | chunkSize: TILE_WIDTH * 64, // tile size * tile amount 35 | tileWidth: TILE_WIDTH, 36 | tileHeight: TILE_HEIGHT, 37 | backgroundTile: [OverworldTileset.Tron], 38 | animationInterval: ANIMATION_INTERVAL, 39 | tileAnimations: OverworldTileAnimations, 40 | layers: { 41 | layers: { 42 | Background: { tilesets: ["Default"], hasHueTintShader: true }, 43 | Foreground: { tilesets: ["Default"], hasHueTintShader: true }, 44 | }, 45 | defaultLayer: "Background", 46 | }, 47 | }), 48 | }, 49 | sprites: { 50 | [Sprites.Settlement]: { 51 | assetKey: Assets.MainAtlas, 52 | frame: "sprites/resources/crystal.png", 53 | }, 54 | [Sprites.Gold]: { 55 | assetKey: Assets.MainAtlas, 56 | frame: "sprites/resources/gold.png", 57 | }, 58 | [Sprites.Container]: { 59 | assetKey: Assets.MainAtlas, 60 | frame: "sprites/resources/chest.png", 61 | }, 62 | [Sprites.GoldShrine]: { 63 | assetKey: Assets.MainAtlas, 64 | frame: "sprites/resources/gold.png", 65 | }, 66 | [Sprites.EscapePortal]: { 67 | assetKey: Assets.MainAtlas, 68 | frame: "sprites/resources/wood.png", 69 | }, 70 | [Sprites.EmberCrown]: { 71 | assetKey: Assets.MainAtlas, 72 | frame: "sprites/resources/wood.png", 73 | }, 74 | [Sprites.Donkey]: { 75 | assetKey: Assets.MainAtlas, 76 | frame: "sprites/workers/donkey.png", 77 | }, 78 | [Sprites.Soldier]: { 79 | assetKey: Assets.MainAtlas, 80 | frame: "sprites/warriors/hero.png", 81 | }, 82 | }, 83 | animations: [], 84 | tilesets: { 85 | Default: { assetKey: Assets.OverworldTileset, tileWidth: TILE_WIDTH, tileHeight: TILE_HEIGHT }, 86 | }, 87 | }), 88 | }, 89 | scale: defineScaleConfig({ 90 | parent: "phaser-game", 91 | zoom: 2, 92 | mode: Phaser.Scale.NONE, 93 | }), 94 | cameraConfig: defineCameraConfig({ 95 | phaserSelector: "phaser-game", 96 | pinchSpeed: 1, 97 | wheelSpeed: 1, 98 | maxZoom: 4, 99 | minZoom: 1, 100 | }), 101 | cullingChunkSize: TILE_HEIGHT * 16, 102 | }; 103 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/constants.ts: -------------------------------------------------------------------------------- 1 | export const TILE_WIDTH = 16; 2 | export const TILE_HEIGHT = 16; 3 | 4 | export enum Scenes { 5 | Main = "Main", 6 | } 7 | 8 | export enum Maps { 9 | Main = "Main", 10 | Pixel = "Pixel", 11 | Tactic = "Tactic", 12 | Strategic = "Strategic", 13 | } 14 | 15 | export enum Assets { 16 | OverworldTileset = "OverworldTileset", 17 | MountainTileset = "MountainTileset", 18 | MainAtlas = "MainAtlas", 19 | } 20 | 21 | export enum Sprites { 22 | Hero, 23 | Settlement, 24 | Gold, 25 | Inventory, 26 | GoldShrine, 27 | EmberCrown, 28 | EscapePortal, 29 | Donkey, 30 | } 31 | 32 | export enum Animations {} 33 | 34 | export const UnitTypeSprites: Record = {}; 35 | 36 | export const ItemTypeSprites: Record = {}; 37 | 38 | export const StructureTypeSprites: Record = {}; 39 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/createPhaserLayer.ts: -------------------------------------------------------------------------------- 1 | import { namespaceWorld } from "@latticexyz/recs"; 2 | import { createPhaserEngine } from "@latticexyz/phaserx"; 3 | import { phaserConfig } from "./config"; 4 | import { NetworkLayer } from "../network"; 5 | 6 | /** 7 | * The Phaser layer is responsible for rendering game objects to the screen. 8 | */ 9 | export async function createPhaserLayer(network: NetworkLayer) { 10 | // --- WORLD ---------------------------------------------------------------------- 11 | const world = namespaceWorld(network.world, "phaser"); 12 | 13 | // --- COMPONENTS ----------------------------------------------------------------- 14 | const components = {}; 15 | 16 | // --- PHASER ENGINE SETUP -------------------------------------------------------- 17 | const { game, scenes, dispose: disposePhaser } = await createPhaserEngine(phaserConfig); 18 | world.registerDisposer(disposePhaser); 19 | 20 | // --- LAYER CONTEXT -------------------------------------------------------------- 21 | const context = { 22 | world, 23 | components, 24 | network, 25 | game, 26 | scenes, 27 | }; 28 | 29 | // --- SYSTEMS -------------------------------------------------------------------- 30 | 31 | return context; 32 | } 33 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/index.ts: -------------------------------------------------------------------------------- 1 | export { createPhaserLayer } from "./createPhaserLayer"; 2 | export type { PhaserLayer } from "./types"; 3 | -------------------------------------------------------------------------------- /packages/client/src/layers/phaser/types.ts: -------------------------------------------------------------------------------- 1 | import { createPhaserLayer } from "./createPhaserLayer"; 2 | 3 | export type PhaserLayer = Awaited>; 4 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/layers/react/README.md -------------------------------------------------------------------------------- /packages/client/src/layers/react/components/ActionQueue.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { registerUIComponent } from "../engine"; 3 | import { getComponentEntities, getComponentValueStrict } from "@latticexyz/recs"; 4 | import { map } from "rxjs"; 5 | import { ActionStateString, ActionState } from "@latticexyz/std-client"; 6 | 7 | export function registerActionQueue() { 8 | registerUIComponent( 9 | "ActionQueue", 10 | { 11 | rowStart: 4, 12 | rowEnd: 12, 13 | colStart: 1, 14 | colEnd: 3, 15 | }, 16 | (layers) => { 17 | const { 18 | network: { 19 | actions: { Action }, 20 | }, 21 | } = layers; 22 | 23 | return Action.update$.pipe( 24 | map(() => ({ 25 | Action, 26 | })) 27 | ); 28 | }, 29 | ({ Action }) => { 30 | return ( 31 |
32 |

Actions:

33 | {[...getComponentEntities(Action)].map((e) => { 34 | const actionData = getComponentValueStrict(Action, e); 35 | const state = ActionStateString[actionData.state as ActionState]; 36 | return ( 37 |

38 | {Action.world.entities[e]}: {state} 39 |

40 | ); 41 | })} 42 |
43 | ); 44 | } 45 | ); 46 | } 47 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/components/ComponentBrowser.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Browser } from "@latticexyz/ecs-browser"; 3 | import { registerUIComponent } from "../engine"; 4 | import { of } from "rxjs"; 5 | export function registerComponentBrowser() { 6 | registerUIComponent( 7 | "ComponentBrowser", 8 | { 9 | colStart: 10, 10 | colEnd: 13, 11 | rowStart: 1, 12 | rowEnd: 13, 13 | }, 14 | (layers) => of({ layers }), 15 | ({ layers }) => { 16 | const { 17 | network: { world, dev }, 18 | } = layers; 19 | return ( 20 | 28 | ); 29 | } 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/components/LoadingState.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { BootScreen, registerUIComponent } from "../engine"; 3 | import { concat, map } from "rxjs"; 4 | import { getComponentValue } from "@latticexyz/recs"; 5 | import { GodID, SyncState } from "@latticexyz/network"; 6 | 7 | export function registerLoadingState() { 8 | registerUIComponent( 9 | "LoadingState", 10 | { 11 | rowStart: 1, 12 | rowEnd: 13, 13 | colStart: 1, 14 | colEnd: 13, 15 | }, 16 | (layers) => { 17 | const { 18 | components: { LoadingState }, 19 | world, 20 | } = layers.network; 21 | 22 | return concat([1], LoadingState.update$).pipe( 23 | map(() => ({ 24 | LoadingState, 25 | world, 26 | })) 27 | ); 28 | }, 29 | 30 | ({ LoadingState, world }) => { 31 | const GodEntityIndex = world.entityToIndex.get(GodID); 32 | 33 | const loadingState = GodEntityIndex == null ? null : getComponentValue(LoadingState, GodEntityIndex); 34 | if (loadingState == null) { 35 | return Connecting; 36 | } 37 | 38 | if (loadingState.state !== SyncState.LIVE) { 39 | return {loadingState.msg}; 40 | } 41 | 42 | return null; 43 | } 44 | ); 45 | } 46 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/components/index.ts: -------------------------------------------------------------------------------- 1 | import { registerComponentBrowser } from "./ComponentBrowser"; 2 | import { registerActionQueue } from "./ActionQueue"; 3 | import { registerLoadingState } from "./LoadingState"; 4 | 5 | export function registerUIComponents() { 6 | registerLoadingState(); 7 | registerComponentBrowser(); 8 | registerActionQueue(); 9 | } 10 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/Engine.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { LayerContext, EngineContext } from "./context"; 3 | import { EngineStore } from "./store"; 4 | import { BootScreen, MainWindow } from "./components"; 5 | import { observer } from "mobx-react-lite"; 6 | import { useEffect } from "react"; 7 | import { useState } from "react"; 8 | import { Layers } from "../../../types"; 9 | 10 | export const Engine: React.FC<{ 11 | setLayers: { current: (layers: Layers) => void }; 12 | mountReact: { current: (mount: boolean) => void }; 13 | customBootScreen?: React.ReactElement; 14 | }> = observer(({ mountReact, setLayers, customBootScreen }) => { 15 | const [mounted, setMounted] = useState(true); 16 | const [layers, _setLayers] = useState(); 17 | 18 | useEffect(() => { 19 | mountReact.current = (mounted: boolean) => setMounted(mounted); 20 | setLayers.current = (layers: Layers) => _setLayers(layers); 21 | }, []); 22 | 23 | if (!mounted || !layers) return customBootScreen || ; 24 | 25 | return ( 26 | 27 | 28 | 29 | 30 | 31 | ); 32 | }); 33 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/components/BootScreen.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import styled from "styled-components"; 3 | 4 | export const BootScreen: React.FC<{ initialOpacity?: number }> = ({ children, initialOpacity }) => { 5 | const [opacity, setOpacity] = useState(initialOpacity ?? 0); 6 | 7 | useEffect(() => setOpacity(1), []); 8 | 9 | return ( 10 | 11 | 12 |
{children || <> }
13 |
14 | ); 15 | }; 16 | 17 | const Container = styled.div` 18 | width: 100%; 19 | height: 100%; 20 | position: absolute; 21 | background-color: #000; 22 | display: grid; 23 | align-content: center; 24 | align-items: center; 25 | justify-content: center; 26 | justify-items: center; 27 | transition: all 2s ease; 28 | grid-gap: 50px; 29 | z-index: 100; 30 | pointer-events: all; 31 | 32 | div { 33 | font-family: "Space Grotesk", sans-serif; 34 | } 35 | 36 | img { 37 | transition: all 2s ease; 38 | width: 100px; 39 | } 40 | `; 41 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/components/Cell.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import styled from "styled-components"; 3 | import { observer } from "mobx-react-lite"; 4 | import { useLayers } from "../hooks"; 5 | import { filter, fromEvent } from "rxjs"; 6 | 7 | const WINDOW_CLASSNAME = "react-ui-window"; 8 | 9 | export const Cell: React.FC<{ style: React.CSSProperties }> = observer(({ children, style }) => { 10 | // const { 11 | // phaser: { 12 | // scenes: { 13 | // Main: { input }, 14 | // }, 15 | // }, 16 | // } = useLayers(); 17 | 18 | // useEffect(() => { 19 | // // Enable input if pointer is not over window 20 | // const sub = fromEvent(document, "mousemove") 21 | // .pipe( 22 | // filter(() => !input.enabled.current), // Only if input is currently disabled 23 | // filter(() => document.querySelectorAll(`.${WINDOW_CLASSNAME}:hover`).length === 0) // Only if mouse is not over window 24 | // ) 25 | // .subscribe(() => input.enableInput()); 26 | 27 | // return () => sub?.unsubscribe(); 28 | // }, []); 29 | 30 | return ( 31 | 37 | {children} 38 | 39 | ); 40 | }); 41 | 42 | const Container = styled.div` 43 | width: 100%; 44 | height: 100%; 45 | color: #fff; 46 | `; 47 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/components/ComponentRenderer.tsx: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from "react"; 2 | import { observer } from "mobx-react-lite"; 3 | import { useLayers, useEngineStore } from "../hooks"; 4 | import { filterNullishValues } from "@latticexyz/utils"; 5 | import { Cell } from "./Cell"; 6 | import styled from "styled-components"; 7 | import { GridConfiguration, UIComponent } from "../types"; 8 | import { useStream } from "@latticexyz/std-client"; 9 | import { Layers } from "../../../../types"; 10 | 11 | const UIGrid = styled.div` 12 | display: grid; 13 | grid-template-columns: repeat(12, 8.33%); 14 | grid-template-rows: repeat(12, 8.33%); 15 | position: absolute; 16 | left: 0; 17 | top: 0; 18 | height: 100vh; 19 | width: 100vw; 20 | pointer-events: none; 21 | z-index: 100; 22 | `; 23 | 24 | const UIComponentContainer: React.FC<{ gridConfig: GridConfiguration }> = React.memo(({ children, gridConfig }) => { 25 | const { colStart, colEnd, rowStart, rowEnd } = gridConfig; 26 | 27 | return ( 28 | 36 | {children} 37 | 38 | ); 39 | }); 40 | 41 | export const UIComponentRenderer: React.FC<{ layers: Layers; id: string; uiComponent: UIComponent }> = React.memo( 42 | ({ layers, id, uiComponent: { requirement, Render, gridConfig } }) => { 43 | const req = useMemo(() => requirement(layers), [requirement, layers]); 44 | const state = useStream(req); 45 | if (!state) return null; 46 | 47 | return ( 48 | 49 | {} 50 | 51 | ); 52 | } 53 | ); 54 | 55 | export const ComponentRenderer: React.FC = observer(() => { 56 | const { UIComponents } = useEngineStore(); 57 | const layers = useLayers(); 58 | if (!layers) return null; 59 | 60 | return ( 61 | 62 | {filterNullishValues( 63 | // Iterate through all registered UIComponents 64 | // and return those whose requirements are fulfilled 65 | [...UIComponents.entries()].map(([id, uiComponent]) => { 66 | return ( 67 | 68 | ); 69 | }) 70 | )} 71 | 72 | ); 73 | }); 74 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/components/MainWindow.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { observer } from "mobx-react-lite"; 3 | import { ComponentRenderer } from "./ComponentRenderer"; 4 | 5 | export const MainWindow: React.FC = observer(() => { 6 | return ; 7 | }); 8 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/components/index.ts: -------------------------------------------------------------------------------- 1 | export { Cell } from "./Cell"; 2 | export { ComponentRenderer } from "./ComponentRenderer"; 3 | export { MainWindow } from "./MainWindow"; 4 | export { BootScreen } from "./BootScreen"; 5 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/constants.ts: -------------------------------------------------------------------------------- 1 | export const ReloadEvent = new Event("reload:react"); 2 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/context.ts: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Layers } from "../../../types"; 3 | import { EngineStore } from "./store"; 4 | 5 | export const LayerContext = React.createContext({} as Layers); 6 | export const EngineContext = React.createContext(EngineStore); 7 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export { useLayers as useLayers } from "./useLayers"; 2 | export { useEngineStore } from "./useEngineStore"; 3 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/hooks/useEngineStore.ts: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | import { EngineContext } from "../context"; 3 | 4 | export function useEngineStore() { 5 | return useContext(EngineContext); 6 | } 7 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/hooks/useLayers.ts: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | import { LayerContext } from "../context"; 3 | 4 | export function useLayers() { 5 | return useContext(LayerContext); 6 | } 7 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/index.ts: -------------------------------------------------------------------------------- 1 | export { Engine } from "./Engine"; 2 | export { registerUIComponent } from "./store"; 3 | export { useLayers } from "./hooks"; 4 | export { BootScreen } from "./components"; 5 | export { ReloadEvent } from "./constants"; 6 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/store.ts: -------------------------------------------------------------------------------- 1 | import { observable, action } from "mobx"; 2 | import { Observable } from "rxjs"; 3 | import { Layers } from "../../../types"; 4 | import { GridConfiguration, UIComponent } from "./types"; 5 | 6 | export const EngineStore = observable({ 7 | UIComponents: new Map(), 8 | }); 9 | 10 | export const registerUIComponent = action( 11 | ( 12 | id: string, 13 | gridConfig: GridConfiguration, 14 | requirement: (layers: Layers) => Observable, 15 | Render: React.FC> 16 | ) => { 17 | EngineStore.UIComponents.set(id, { requirement, Render: Render as React.FC, gridConfig }); 18 | } 19 | ); 20 | -------------------------------------------------------------------------------- /packages/client/src/layers/react/engine/types.ts: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Observable } from "rxjs"; 3 | import { Layers } from "../../../types"; 4 | 5 | export type GridConfiguration = { colStart: number; colEnd: number; rowStart: number; rowEnd: number }; 6 | 7 | export interface UIComponent { 8 | gridConfig: GridConfiguration; 9 | requirement(layers: Layers): Observable; 10 | Render: React.FC>; 11 | } 12 | -------------------------------------------------------------------------------- /packages/client/src/public/atlases/FILES_AUTOGENERATED_DONT_CHANGE.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/public/atlases/FILES_AUTOGENERATED_DONT_CHANGE.txt -------------------------------------------------------------------------------- /packages/client/src/public/atlases/sprites/atlas.json: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "app": "", 4 | "version": "1.0.0" 5 | }, 6 | "textures": [ 7 | { 8 | "image": "atlas.png", 9 | "format": "RGBA8888", 10 | "size": { 11 | "w": 2048, 12 | "h": 2048 13 | }, 14 | "scale": 1, 15 | "frames": [ 16 | { 17 | "filename": "sprites/base/big-base.png", 18 | "rotated": false, 19 | "trimmed": false, 20 | "sourceSize": { 21 | "w": 48, 22 | "h": 32 23 | }, 24 | "spriteSourceSize": { 25 | "x": 0, 26 | "y": 0, 27 | "w": 48, 28 | "h": 32 29 | }, 30 | "frame": { 31 | "x": 0, 32 | "y": 0, 33 | "w": 48, 34 | "h": 32 35 | } 36 | }, 37 | { 38 | "filename": "sprites/portraits/Clothes/0.png", 39 | "rotated": false, 40 | "trimmed": false, 41 | "sourceSize": { 42 | "w": 48, 43 | "h": 48 44 | }, 45 | "spriteSourceSize": { 46 | "x": 0, 47 | "y": 0, 48 | "w": 48, 49 | "h": 48 50 | }, 51 | "frame": { 52 | "x": 0, 53 | "y": 32, 54 | "w": 48, 55 | "h": 48 56 | } 57 | }, 58 | { 59 | "filename": "sprites/portraits/Eyes/0.png", 60 | "rotated": false, 61 | "trimmed": false, 62 | "sourceSize": { 63 | "w": 48, 64 | "h": 48 65 | }, 66 | "spriteSourceSize": { 67 | "x": 0, 68 | "y": 0, 69 | "w": 48, 70 | "h": 48 71 | }, 72 | "frame": { 73 | "x": 48, 74 | "y": 0, 75 | "w": 48, 76 | "h": 48 77 | } 78 | }, 79 | { 80 | "filename": "sprites/portraits/Eyes/1.png", 81 | "rotated": false, 82 | "trimmed": false, 83 | "sourceSize": { 84 | "w": 48, 85 | "h": 48 86 | }, 87 | "spriteSourceSize": { 88 | "x": 0, 89 | "y": 0, 90 | "w": 48, 91 | "h": 48 92 | }, 93 | "frame": { 94 | "x": 48, 95 | "y": 48, 96 | "w": 48, 97 | "h": 48 98 | } 99 | }, 100 | { 101 | "filename": "sprites/portraits/Eyes/10.png", 102 | "rotated": false, 103 | "trimmed": false, 104 | "sourceSize": { 105 | "w": 48, 106 | "h": 48 107 | }, 108 | "spriteSourceSize": { 109 | "x": 0, 110 | "y": 0, 111 | "w": 48, 112 | "h": 48 113 | }, 114 | "frame": { 115 | "x": 0, 116 | "y": 80, 117 | "w": 48, 118 | "h": 48 119 | } 120 | }, 121 | { 122 | "filename": "sprites/portraits/Eyes/11.png", 123 | "rotated": false, 124 | "trimmed": false, 125 | "sourceSize": { 126 | "w": 48, 127 | "h": 48 128 | }, 129 | "spriteSourceSize": { 130 | "x": 0, 131 | "y": 0, 132 | "w": 48, 133 | "h": 48 134 | }, 135 | "frame": { 136 | "x": 96, 137 | "y": 0, 138 | "w": 48, 139 | "h": 48 140 | } 141 | }, 142 | { 143 | "filename": "sprites/portraits/Eyes/12.png", 144 | "rotated": false, 145 | "trimmed": false, 146 | "sourceSize": { 147 | "w": 48, 148 | "h": 48 149 | }, 150 | "spriteSourceSize": { 151 | "x": 0, 152 | "y": 0, 153 | "w": 48, 154 | "h": 48 155 | }, 156 | "frame": { 157 | "x": 96, 158 | "y": 48, 159 | "w": 48, 160 | "h": 48 161 | } 162 | }, 163 | { 164 | "filename": "sprites/portraits/Eyes/13.png", 165 | "rotated": false, 166 | "trimmed": false, 167 | "sourceSize": { 168 | "w": 48, 169 | "h": 48 170 | }, 171 | "spriteSourceSize": { 172 | "x": 0, 173 | "y": 0, 174 | "w": 48, 175 | "h": 48 176 | }, 177 | "frame": { 178 | "x": 0, 179 | "y": 128, 180 | "w": 48, 181 | "h": 48 182 | } 183 | }, 184 | { 185 | "filename": "sprites/portraits/Eyes/2.png", 186 | "rotated": false, 187 | "trimmed": false, 188 | "sourceSize": { 189 | "w": 48, 190 | "h": 48 191 | }, 192 | "spriteSourceSize": { 193 | "x": 0, 194 | "y": 0, 195 | "w": 48, 196 | "h": 48 197 | }, 198 | "frame": { 199 | "x": 48, 200 | "y": 96, 201 | "w": 48, 202 | "h": 48 203 | } 204 | }, 205 | { 206 | "filename": "sprites/portraits/Eyes/3.png", 207 | "rotated": false, 208 | "trimmed": false, 209 | "sourceSize": { 210 | "w": 48, 211 | "h": 48 212 | }, 213 | "spriteSourceSize": { 214 | "x": 0, 215 | "y": 0, 216 | "w": 48, 217 | "h": 48 218 | }, 219 | "frame": { 220 | "x": 96, 221 | "y": 96, 222 | "w": 48, 223 | "h": 48 224 | } 225 | }, 226 | { 227 | "filename": "sprites/portraits/Eyes/4.png", 228 | "rotated": false, 229 | "trimmed": false, 230 | "sourceSize": { 231 | "w": 48, 232 | "h": 48 233 | }, 234 | "spriteSourceSize": { 235 | "x": 0, 236 | "y": 0, 237 | "w": 48, 238 | "h": 48 239 | }, 240 | "frame": { 241 | "x": 144, 242 | "y": 0, 243 | "w": 48, 244 | "h": 48 245 | } 246 | }, 247 | { 248 | "filename": "sprites/portraits/Eyes/5.png", 249 | "rotated": false, 250 | "trimmed": false, 251 | "sourceSize": { 252 | "w": 48, 253 | "h": 48 254 | }, 255 | "spriteSourceSize": { 256 | "x": 0, 257 | "y": 0, 258 | "w": 48, 259 | "h": 48 260 | }, 261 | "frame": { 262 | "x": 144, 263 | "y": 48, 264 | "w": 48, 265 | "h": 48 266 | } 267 | }, 268 | { 269 | "filename": "sprites/portraits/Eyes/6.png", 270 | "rotated": false, 271 | "trimmed": false, 272 | "sourceSize": { 273 | "w": 48, 274 | "h": 48 275 | }, 276 | "spriteSourceSize": { 277 | "x": 0, 278 | "y": 0, 279 | "w": 48, 280 | "h": 48 281 | }, 282 | "frame": { 283 | "x": 144, 284 | "y": 96, 285 | "w": 48, 286 | "h": 48 287 | } 288 | }, 289 | { 290 | "filename": "sprites/portraits/Eyes/7.png", 291 | "rotated": false, 292 | "trimmed": false, 293 | "sourceSize": { 294 | "w": 48, 295 | "h": 48 296 | }, 297 | "spriteSourceSize": { 298 | "x": 0, 299 | "y": 0, 300 | "w": 48, 301 | "h": 48 302 | }, 303 | "frame": { 304 | "x": 0, 305 | "y": 176, 306 | "w": 48, 307 | "h": 48 308 | } 309 | }, 310 | { 311 | "filename": "sprites/portraits/Eyes/9.png", 312 | "rotated": false, 313 | "trimmed": false, 314 | "sourceSize": { 315 | "w": 48, 316 | "h": 48 317 | }, 318 | "spriteSourceSize": { 319 | "x": 0, 320 | "y": 0, 321 | "w": 48, 322 | "h": 48 323 | }, 324 | "frame": { 325 | "x": 48, 326 | "y": 144, 327 | "w": 48, 328 | "h": 48 329 | } 330 | }, 331 | { 332 | "filename": "sprites/portraits/Hair/0.png", 333 | "rotated": false, 334 | "trimmed": false, 335 | "sourceSize": { 336 | "w": 48, 337 | "h": 48 338 | }, 339 | "spriteSourceSize": { 340 | "x": 0, 341 | "y": 0, 342 | "w": 48, 343 | "h": 48 344 | }, 345 | "frame": { 346 | "x": 96, 347 | "y": 144, 348 | "w": 48, 349 | "h": 48 350 | } 351 | }, 352 | { 353 | "filename": "sprites/portraits/Hair/1.png", 354 | "rotated": false, 355 | "trimmed": false, 356 | "sourceSize": { 357 | "w": 48, 358 | "h": 48 359 | }, 360 | "spriteSourceSize": { 361 | "x": 0, 362 | "y": 0, 363 | "w": 48, 364 | "h": 48 365 | }, 366 | "frame": { 367 | "x": 144, 368 | "y": 144, 369 | "w": 48, 370 | "h": 48 371 | } 372 | }, 373 | { 374 | "filename": "sprites/portraits/Hair/2.png", 375 | "rotated": false, 376 | "trimmed": false, 377 | "sourceSize": { 378 | "w": 48, 379 | "h": 48 380 | }, 381 | "spriteSourceSize": { 382 | "x": 0, 383 | "y": 0, 384 | "w": 48, 385 | "h": 48 386 | }, 387 | "frame": { 388 | "x": 192, 389 | "y": 0, 390 | "w": 48, 391 | "h": 48 392 | } 393 | }, 394 | { 395 | "filename": "sprites/portraits/Hair/3.png", 396 | "rotated": false, 397 | "trimmed": false, 398 | "sourceSize": { 399 | "w": 48, 400 | "h": 48 401 | }, 402 | "spriteSourceSize": { 403 | "x": 0, 404 | "y": 0, 405 | "w": 48, 406 | "h": 48 407 | }, 408 | "frame": { 409 | "x": 192, 410 | "y": 48, 411 | "w": 48, 412 | "h": 48 413 | } 414 | }, 415 | { 416 | "filename": "sprites/portraits/Hair/4.png", 417 | "rotated": false, 418 | "trimmed": false, 419 | "sourceSize": { 420 | "w": 48, 421 | "h": 48 422 | }, 423 | "spriteSourceSize": { 424 | "x": 0, 425 | "y": 0, 426 | "w": 48, 427 | "h": 48 428 | }, 429 | "frame": { 430 | "x": 192, 431 | "y": 96, 432 | "w": 48, 433 | "h": 48 434 | } 435 | }, 436 | { 437 | "filename": "sprites/portraits/Hair/5.png", 438 | "rotated": false, 439 | "trimmed": false, 440 | "sourceSize": { 441 | "w": 48, 442 | "h": 48 443 | }, 444 | "spriteSourceSize": { 445 | "x": 0, 446 | "y": 0, 447 | "w": 48, 448 | "h": 48 449 | }, 450 | "frame": { 451 | "x": 192, 452 | "y": 144, 453 | "w": 48, 454 | "h": 48 455 | } 456 | }, 457 | { 458 | "filename": "sprites/portraits/Head/0.png", 459 | "rotated": false, 460 | "trimmed": false, 461 | "sourceSize": { 462 | "w": 48, 463 | "h": 48 464 | }, 465 | "spriteSourceSize": { 466 | "x": 0, 467 | "y": 0, 468 | "w": 48, 469 | "h": 48 470 | }, 471 | "frame": { 472 | "x": 0, 473 | "y": 224, 474 | "w": 48, 475 | "h": 48 476 | } 477 | }, 478 | { 479 | "filename": "sprites/portraits/Head/1.png", 480 | "rotated": false, 481 | "trimmed": false, 482 | "sourceSize": { 483 | "w": 48, 484 | "h": 48 485 | }, 486 | "spriteSourceSize": { 487 | "x": 0, 488 | "y": 0, 489 | "w": 48, 490 | "h": 48 491 | }, 492 | "frame": { 493 | "x": 48, 494 | "y": 192, 495 | "w": 48, 496 | "h": 48 497 | } 498 | }, 499 | { 500 | "filename": "sprites/portraits/Head/2.png", 501 | "rotated": false, 502 | "trimmed": false, 503 | "sourceSize": { 504 | "w": 48, 505 | "h": 48 506 | }, 507 | "spriteSourceSize": { 508 | "x": 0, 509 | "y": 0, 510 | "w": 48, 511 | "h": 48 512 | }, 513 | "frame": { 514 | "x": 96, 515 | "y": 192, 516 | "w": 48, 517 | "h": 48 518 | } 519 | }, 520 | { 521 | "filename": "sprites/portraits/Head/3.png", 522 | "rotated": false, 523 | "trimmed": false, 524 | "sourceSize": { 525 | "w": 48, 526 | "h": 48 527 | }, 528 | "spriteSourceSize": { 529 | "x": 0, 530 | "y": 0, 531 | "w": 48, 532 | "h": 48 533 | }, 534 | "frame": { 535 | "x": 144, 536 | "y": 192, 537 | "w": 48, 538 | "h": 48 539 | } 540 | }, 541 | { 542 | "filename": "sprites/portraits/Head/4.png", 543 | "rotated": false, 544 | "trimmed": false, 545 | "sourceSize": { 546 | "w": 48, 547 | "h": 48 548 | }, 549 | "spriteSourceSize": { 550 | "x": 0, 551 | "y": 0, 552 | "w": 48, 553 | "h": 48 554 | }, 555 | "frame": { 556 | "x": 192, 557 | "y": 192, 558 | "w": 48, 559 | "h": 48 560 | } 561 | }, 562 | { 563 | "filename": "sprites/portraits/Head/5.png", 564 | "rotated": false, 565 | "trimmed": false, 566 | "sourceSize": { 567 | "w": 48, 568 | "h": 48 569 | }, 570 | "spriteSourceSize": { 571 | "x": 0, 572 | "y": 0, 573 | "w": 48, 574 | "h": 48 575 | }, 576 | "frame": { 577 | "x": 240, 578 | "y": 0, 579 | "w": 48, 580 | "h": 48 581 | } 582 | }, 583 | { 584 | "filename": "sprites/portraits/Nose/0.png", 585 | "rotated": false, 586 | "trimmed": false, 587 | "sourceSize": { 588 | "w": 48, 589 | "h": 48 590 | }, 591 | "spriteSourceSize": { 592 | "x": 0, 593 | "y": 0, 594 | "w": 48, 595 | "h": 48 596 | }, 597 | "frame": { 598 | "x": 240, 599 | "y": 48, 600 | "w": 48, 601 | "h": 48 602 | } 603 | }, 604 | { 605 | "filename": "sprites/portraits/Nose/1.png", 606 | "rotated": false, 607 | "trimmed": false, 608 | "sourceSize": { 609 | "w": 48, 610 | "h": 48 611 | }, 612 | "spriteSourceSize": { 613 | "x": 0, 614 | "y": 0, 615 | "w": 48, 616 | "h": 48 617 | }, 618 | "frame": { 619 | "x": 240, 620 | "y": 96, 621 | "w": 48, 622 | "h": 48 623 | } 624 | }, 625 | { 626 | "filename": "sprites/portraits/Nose/10.png", 627 | "rotated": false, 628 | "trimmed": false, 629 | "sourceSize": { 630 | "w": 48, 631 | "h": 48 632 | }, 633 | "spriteSourceSize": { 634 | "x": 0, 635 | "y": 0, 636 | "w": 48, 637 | "h": 48 638 | }, 639 | "frame": { 640 | "x": 240, 641 | "y": 144, 642 | "w": 48, 643 | "h": 48 644 | } 645 | }, 646 | { 647 | "filename": "sprites/portraits/Nose/11.png", 648 | "rotated": false, 649 | "trimmed": false, 650 | "sourceSize": { 651 | "w": 48, 652 | "h": 48 653 | }, 654 | "spriteSourceSize": { 655 | "x": 0, 656 | "y": 0, 657 | "w": 48, 658 | "h": 48 659 | }, 660 | "frame": { 661 | "x": 240, 662 | "y": 192, 663 | "w": 48, 664 | "h": 48 665 | } 666 | }, 667 | { 668 | "filename": "sprites/portraits/Nose/12.png", 669 | "rotated": false, 670 | "trimmed": false, 671 | "sourceSize": { 672 | "w": 48, 673 | "h": 48 674 | }, 675 | "spriteSourceSize": { 676 | "x": 0, 677 | "y": 0, 678 | "w": 48, 679 | "h": 48 680 | }, 681 | "frame": { 682 | "x": 0, 683 | "y": 272, 684 | "w": 48, 685 | "h": 48 686 | } 687 | }, 688 | { 689 | "filename": "sprites/portraits/Nose/2.png", 690 | "rotated": false, 691 | "trimmed": false, 692 | "sourceSize": { 693 | "w": 48, 694 | "h": 48 695 | }, 696 | "spriteSourceSize": { 697 | "x": 0, 698 | "y": 0, 699 | "w": 48, 700 | "h": 48 701 | }, 702 | "frame": { 703 | "x": 48, 704 | "y": 240, 705 | "w": 48, 706 | "h": 48 707 | } 708 | }, 709 | { 710 | "filename": "sprites/portraits/Nose/3.png", 711 | "rotated": false, 712 | "trimmed": false, 713 | "sourceSize": { 714 | "w": 48, 715 | "h": 48 716 | }, 717 | "spriteSourceSize": { 718 | "x": 0, 719 | "y": 0, 720 | "w": 48, 721 | "h": 48 722 | }, 723 | "frame": { 724 | "x": 96, 725 | "y": 240, 726 | "w": 48, 727 | "h": 48 728 | } 729 | }, 730 | { 731 | "filename": "sprites/portraits/Nose/4.png", 732 | "rotated": false, 733 | "trimmed": false, 734 | "sourceSize": { 735 | "w": 48, 736 | "h": 48 737 | }, 738 | "spriteSourceSize": { 739 | "x": 0, 740 | "y": 0, 741 | "w": 48, 742 | "h": 48 743 | }, 744 | "frame": { 745 | "x": 144, 746 | "y": 240, 747 | "w": 48, 748 | "h": 48 749 | } 750 | }, 751 | { 752 | "filename": "sprites/portraits/Nose/5.png", 753 | "rotated": false, 754 | "trimmed": false, 755 | "sourceSize": { 756 | "w": 48, 757 | "h": 48 758 | }, 759 | "spriteSourceSize": { 760 | "x": 0, 761 | "y": 0, 762 | "w": 48, 763 | "h": 48 764 | }, 765 | "frame": { 766 | "x": 192, 767 | "y": 240, 768 | "w": 48, 769 | "h": 48 770 | } 771 | }, 772 | { 773 | "filename": "sprites/portraits/Nose/6.png", 774 | "rotated": false, 775 | "trimmed": false, 776 | "sourceSize": { 777 | "w": 48, 778 | "h": 48 779 | }, 780 | "spriteSourceSize": { 781 | "x": 0, 782 | "y": 0, 783 | "w": 48, 784 | "h": 48 785 | }, 786 | "frame": { 787 | "x": 240, 788 | "y": 240, 789 | "w": 48, 790 | "h": 48 791 | } 792 | }, 793 | { 794 | "filename": "sprites/portraits/Nose/7.png", 795 | "rotated": false, 796 | "trimmed": false, 797 | "sourceSize": { 798 | "w": 48, 799 | "h": 48 800 | }, 801 | "spriteSourceSize": { 802 | "x": 0, 803 | "y": 0, 804 | "w": 48, 805 | "h": 48 806 | }, 807 | "frame": { 808 | "x": 288, 809 | "y": 0, 810 | "w": 48, 811 | "h": 48 812 | } 813 | }, 814 | { 815 | "filename": "sprites/portraits/Nose/8.png", 816 | "rotated": false, 817 | "trimmed": false, 818 | "sourceSize": { 819 | "w": 48, 820 | "h": 48 821 | }, 822 | "spriteSourceSize": { 823 | "x": 0, 824 | "y": 0, 825 | "w": 48, 826 | "h": 48 827 | }, 828 | "frame": { 829 | "x": 288, 830 | "y": 48, 831 | "w": 48, 832 | "h": 48 833 | } 834 | }, 835 | { 836 | "filename": "sprites/portraits/Nose/9.png", 837 | "rotated": false, 838 | "trimmed": false, 839 | "sourceSize": { 840 | "w": 48, 841 | "h": 48 842 | }, 843 | "spriteSourceSize": { 844 | "x": 0, 845 | "y": 0, 846 | "w": 48, 847 | "h": 48 848 | }, 849 | "frame": { 850 | "x": 288, 851 | "y": 96, 852 | "w": 48, 853 | "h": 48 854 | } 855 | }, 856 | { 857 | "filename": "sprites/portraits/accessory/0.png", 858 | "rotated": false, 859 | "trimmed": false, 860 | "sourceSize": { 861 | "w": 48, 862 | "h": 48 863 | }, 864 | "spriteSourceSize": { 865 | "x": 0, 866 | "y": 0, 867 | "w": 48, 868 | "h": 48 869 | }, 870 | "frame": { 871 | "x": 288, 872 | "y": 144, 873 | "w": 48, 874 | "h": 48 875 | } 876 | }, 877 | { 878 | "filename": "sprites/portraits/accessory/1.png", 879 | "rotated": false, 880 | "trimmed": false, 881 | "sourceSize": { 882 | "w": 48, 883 | "h": 48 884 | }, 885 | "spriteSourceSize": { 886 | "x": 0, 887 | "y": 0, 888 | "w": 48, 889 | "h": 48 890 | }, 891 | "frame": { 892 | "x": 288, 893 | "y": 192, 894 | "w": 48, 895 | "h": 48 896 | } 897 | }, 898 | { 899 | "filename": "sprites/portraits/accessory/2.png", 900 | "rotated": false, 901 | "trimmed": false, 902 | "sourceSize": { 903 | "w": 48, 904 | "h": 48 905 | }, 906 | "spriteSourceSize": { 907 | "x": 0, 908 | "y": 0, 909 | "w": 48, 910 | "h": 48 911 | }, 912 | "frame": { 913 | "x": 288, 914 | "y": 240, 915 | "w": 48, 916 | "h": 48 917 | } 918 | }, 919 | { 920 | "filename": "sprites/portraits/accessory/3.png", 921 | "rotated": false, 922 | "trimmed": false, 923 | "sourceSize": { 924 | "w": 48, 925 | "h": 48 926 | }, 927 | "spriteSourceSize": { 928 | "x": 0, 929 | "y": 0, 930 | "w": 48, 931 | "h": 48 932 | }, 933 | "frame": { 934 | "x": 0, 935 | "y": 320, 936 | "w": 48, 937 | "h": 48 938 | } 939 | }, 940 | { 941 | "filename": "sprites/portraits/accessory/4.png", 942 | "rotated": false, 943 | "trimmed": false, 944 | "sourceSize": { 945 | "w": 48, 946 | "h": 48 947 | }, 948 | "spriteSourceSize": { 949 | "x": 0, 950 | "y": 0, 951 | "w": 48, 952 | "h": 48 953 | }, 954 | "frame": { 955 | "x": 48, 956 | "y": 288, 957 | "w": 48, 958 | "h": 48 959 | } 960 | }, 961 | { 962 | "filename": "sprites/portraits/accessory/5.png", 963 | "rotated": false, 964 | "trimmed": false, 965 | "sourceSize": { 966 | "w": 48, 967 | "h": 48 968 | }, 969 | "spriteSourceSize": { 970 | "x": 0, 971 | "y": 0, 972 | "w": 48, 973 | "h": 48 974 | }, 975 | "frame": { 976 | "x": 96, 977 | "y": 288, 978 | "w": 48, 979 | "h": 48 980 | } 981 | }, 982 | { 983 | "filename": "sprites/portraits/accessory/6.png", 984 | "rotated": false, 985 | "trimmed": false, 986 | "sourceSize": { 987 | "w": 48, 988 | "h": 48 989 | }, 990 | "spriteSourceSize": { 991 | "x": 0, 992 | "y": 0, 993 | "w": 48, 994 | "h": 48 995 | }, 996 | "frame": { 997 | "x": 144, 998 | "y": 288, 999 | "w": 48, 1000 | "h": 48 1001 | } 1002 | }, 1003 | { 1004 | "filename": "sprites/portraits/clothes/1.png", 1005 | "rotated": false, 1006 | "trimmed": false, 1007 | "sourceSize": { 1008 | "w": 48, 1009 | "h": 48 1010 | }, 1011 | "spriteSourceSize": { 1012 | "x": 0, 1013 | "y": 0, 1014 | "w": 48, 1015 | "h": 48 1016 | }, 1017 | "frame": { 1018 | "x": 192, 1019 | "y": 288, 1020 | "w": 48, 1021 | "h": 48 1022 | } 1023 | }, 1024 | { 1025 | "filename": "sprites/portraits/clothes/12.png", 1026 | "rotated": false, 1027 | "trimmed": false, 1028 | "sourceSize": { 1029 | "w": 48, 1030 | "h": 48 1031 | }, 1032 | "spriteSourceSize": { 1033 | "x": 0, 1034 | "y": 0, 1035 | "w": 48, 1036 | "h": 48 1037 | }, 1038 | "frame": { 1039 | "x": 240, 1040 | "y": 288, 1041 | "w": 48, 1042 | "h": 48 1043 | } 1044 | }, 1045 | { 1046 | "filename": "sprites/portraits/clothes/13.png", 1047 | "rotated": false, 1048 | "trimmed": false, 1049 | "sourceSize": { 1050 | "w": 48, 1051 | "h": 48 1052 | }, 1053 | "spriteSourceSize": { 1054 | "x": 0, 1055 | "y": 0, 1056 | "w": 48, 1057 | "h": 48 1058 | }, 1059 | "frame": { 1060 | "x": 288, 1061 | "y": 288, 1062 | "w": 48, 1063 | "h": 48 1064 | } 1065 | }, 1066 | { 1067 | "filename": "sprites/portraits/clothes/14.png", 1068 | "rotated": false, 1069 | "trimmed": false, 1070 | "sourceSize": { 1071 | "w": 48, 1072 | "h": 48 1073 | }, 1074 | "spriteSourceSize": { 1075 | "x": 0, 1076 | "y": 0, 1077 | "w": 48, 1078 | "h": 48 1079 | }, 1080 | "frame": { 1081 | "x": 336, 1082 | "y": 0, 1083 | "w": 48, 1084 | "h": 48 1085 | } 1086 | }, 1087 | { 1088 | "filename": "sprites/portraits/clothes/15.png", 1089 | "rotated": false, 1090 | "trimmed": false, 1091 | "sourceSize": { 1092 | "w": 48, 1093 | "h": 48 1094 | }, 1095 | "spriteSourceSize": { 1096 | "x": 0, 1097 | "y": 0, 1098 | "w": 48, 1099 | "h": 48 1100 | }, 1101 | "frame": { 1102 | "x": 336, 1103 | "y": 48, 1104 | "w": 48, 1105 | "h": 48 1106 | } 1107 | }, 1108 | { 1109 | "filename": "sprites/portraits/clothes/16.png", 1110 | "rotated": false, 1111 | "trimmed": false, 1112 | "sourceSize": { 1113 | "w": 48, 1114 | "h": 48 1115 | }, 1116 | "spriteSourceSize": { 1117 | "x": 0, 1118 | "y": 0, 1119 | "w": 48, 1120 | "h": 48 1121 | }, 1122 | "frame": { 1123 | "x": 336, 1124 | "y": 96, 1125 | "w": 48, 1126 | "h": 48 1127 | } 1128 | }, 1129 | { 1130 | "filename": "sprites/portraits/clothes/17.png", 1131 | "rotated": false, 1132 | "trimmed": false, 1133 | "sourceSize": { 1134 | "w": 48, 1135 | "h": 48 1136 | }, 1137 | "spriteSourceSize": { 1138 | "x": 0, 1139 | "y": 0, 1140 | "w": 48, 1141 | "h": 48 1142 | }, 1143 | "frame": { 1144 | "x": 336, 1145 | "y": 144, 1146 | "w": 48, 1147 | "h": 48 1148 | } 1149 | }, 1150 | { 1151 | "filename": "sprites/portraits/clothes/18.png", 1152 | "rotated": false, 1153 | "trimmed": false, 1154 | "sourceSize": { 1155 | "w": 48, 1156 | "h": 48 1157 | }, 1158 | "spriteSourceSize": { 1159 | "x": 0, 1160 | "y": 0, 1161 | "w": 48, 1162 | "h": 48 1163 | }, 1164 | "frame": { 1165 | "x": 336, 1166 | "y": 192, 1167 | "w": 48, 1168 | "h": 48 1169 | } 1170 | }, 1171 | { 1172 | "filename": "sprites/portraits/clothes/19.png", 1173 | "rotated": false, 1174 | "trimmed": false, 1175 | "sourceSize": { 1176 | "w": 48, 1177 | "h": 48 1178 | }, 1179 | "spriteSourceSize": { 1180 | "x": 0, 1181 | "y": 0, 1182 | "w": 48, 1183 | "h": 48 1184 | }, 1185 | "frame": { 1186 | "x": 336, 1187 | "y": 240, 1188 | "w": 48, 1189 | "h": 48 1190 | } 1191 | }, 1192 | { 1193 | "filename": "sprites/portraits/eyes/14.png", 1194 | "rotated": false, 1195 | "trimmed": false, 1196 | "sourceSize": { 1197 | "w": 48, 1198 | "h": 48 1199 | }, 1200 | "spriteSourceSize": { 1201 | "x": 0, 1202 | "y": 0, 1203 | "w": 48, 1204 | "h": 48 1205 | }, 1206 | "frame": { 1207 | "x": 336, 1208 | "y": 288, 1209 | "w": 48, 1210 | "h": 48 1211 | } 1212 | }, 1213 | { 1214 | "filename": "sprites/portraits/eyes/15.png", 1215 | "rotated": false, 1216 | "trimmed": false, 1217 | "sourceSize": { 1218 | "w": 48, 1219 | "h": 48 1220 | }, 1221 | "spriteSourceSize": { 1222 | "x": 0, 1223 | "y": 0, 1224 | "w": 48, 1225 | "h": 48 1226 | }, 1227 | "frame": { 1228 | "x": 0, 1229 | "y": 368, 1230 | "w": 48, 1231 | "h": 48 1232 | } 1233 | }, 1234 | { 1235 | "filename": "sprites/portraits/eyes/16.png", 1236 | "rotated": false, 1237 | "trimmed": false, 1238 | "sourceSize": { 1239 | "w": 48, 1240 | "h": 48 1241 | }, 1242 | "spriteSourceSize": { 1243 | "x": 0, 1244 | "y": 0, 1245 | "w": 48, 1246 | "h": 48 1247 | }, 1248 | "frame": { 1249 | "x": 48, 1250 | "y": 336, 1251 | "w": 48, 1252 | "h": 48 1253 | } 1254 | }, 1255 | { 1256 | "filename": "sprites/portraits/eyes/17.png", 1257 | "rotated": false, 1258 | "trimmed": false, 1259 | "sourceSize": { 1260 | "w": 48, 1261 | "h": 48 1262 | }, 1263 | "spriteSourceSize": { 1264 | "x": 0, 1265 | "y": 0, 1266 | "w": 48, 1267 | "h": 48 1268 | }, 1269 | "frame": { 1270 | "x": 96, 1271 | "y": 336, 1272 | "w": 48, 1273 | "h": 48 1274 | } 1275 | }, 1276 | { 1277 | "filename": "sprites/portraits/eyes/18.png", 1278 | "rotated": false, 1279 | "trimmed": false, 1280 | "sourceSize": { 1281 | "w": 48, 1282 | "h": 48 1283 | }, 1284 | "spriteSourceSize": { 1285 | "x": 0, 1286 | "y": 0, 1287 | "w": 48, 1288 | "h": 48 1289 | }, 1290 | "frame": { 1291 | "x": 144, 1292 | "y": 336, 1293 | "w": 48, 1294 | "h": 48 1295 | } 1296 | }, 1297 | { 1298 | "filename": "sprites/portraits/eyes/19.png", 1299 | "rotated": false, 1300 | "trimmed": false, 1301 | "sourceSize": { 1302 | "w": 48, 1303 | "h": 48 1304 | }, 1305 | "spriteSourceSize": { 1306 | "x": 0, 1307 | "y": 0, 1308 | "w": 48, 1309 | "h": 48 1310 | }, 1311 | "frame": { 1312 | "x": 192, 1313 | "y": 336, 1314 | "w": 48, 1315 | "h": 48 1316 | } 1317 | }, 1318 | { 1319 | "filename": "sprites/portraits/hair-background/0.png", 1320 | "rotated": false, 1321 | "trimmed": false, 1322 | "sourceSize": { 1323 | "w": 48, 1324 | "h": 48 1325 | }, 1326 | "spriteSourceSize": { 1327 | "x": 0, 1328 | "y": 0, 1329 | "w": 48, 1330 | "h": 48 1331 | }, 1332 | "frame": { 1333 | "x": 240, 1334 | "y": 336, 1335 | "w": 48, 1336 | "h": 48 1337 | } 1338 | }, 1339 | { 1340 | "filename": "sprites/portraits/hair-background/1.png", 1341 | "rotated": false, 1342 | "trimmed": false, 1343 | "sourceSize": { 1344 | "w": 48, 1345 | "h": 48 1346 | }, 1347 | "spriteSourceSize": { 1348 | "x": 0, 1349 | "y": 0, 1350 | "w": 48, 1351 | "h": 48 1352 | }, 1353 | "frame": { 1354 | "x": 288, 1355 | "y": 336, 1356 | "w": 48, 1357 | "h": 48 1358 | } 1359 | }, 1360 | { 1361 | "filename": "sprites/portraits/hair-background/2.png", 1362 | "rotated": false, 1363 | "trimmed": false, 1364 | "sourceSize": { 1365 | "w": 48, 1366 | "h": 48 1367 | }, 1368 | "spriteSourceSize": { 1369 | "x": 0, 1370 | "y": 0, 1371 | "w": 48, 1372 | "h": 48 1373 | }, 1374 | "frame": { 1375 | "x": 336, 1376 | "y": 336, 1377 | "w": 48, 1378 | "h": 48 1379 | } 1380 | }, 1381 | { 1382 | "filename": "sprites/portraits/hair-background/3.png", 1383 | "rotated": false, 1384 | "trimmed": false, 1385 | "sourceSize": { 1386 | "w": 48, 1387 | "h": 48 1388 | }, 1389 | "spriteSourceSize": { 1390 | "x": 0, 1391 | "y": 0, 1392 | "w": 48, 1393 | "h": 48 1394 | }, 1395 | "frame": { 1396 | "x": 384, 1397 | "y": 0, 1398 | "w": 48, 1399 | "h": 48 1400 | } 1401 | }, 1402 | { 1403 | "filename": "sprites/portraits/hair-background/4.png", 1404 | "rotated": false, 1405 | "trimmed": false, 1406 | "sourceSize": { 1407 | "w": 48, 1408 | "h": 48 1409 | }, 1410 | "spriteSourceSize": { 1411 | "x": 0, 1412 | "y": 0, 1413 | "w": 48, 1414 | "h": 48 1415 | }, 1416 | "frame": { 1417 | "x": 384, 1418 | "y": 48, 1419 | "w": 48, 1420 | "h": 48 1421 | } 1422 | }, 1423 | { 1424 | "filename": "sprites/portraits/hair-background/5.png", 1425 | "rotated": false, 1426 | "trimmed": false, 1427 | "sourceSize": { 1428 | "w": 48, 1429 | "h": 48 1430 | }, 1431 | "spriteSourceSize": { 1432 | "x": 0, 1433 | "y": 0, 1434 | "w": 48, 1435 | "h": 48 1436 | }, 1437 | "frame": { 1438 | "x": 384, 1439 | "y": 96, 1440 | "w": 48, 1441 | "h": 48 1442 | } 1443 | }, 1444 | { 1445 | "filename": "sprites/portraits/hair/10.png", 1446 | "rotated": false, 1447 | "trimmed": false, 1448 | "sourceSize": { 1449 | "w": 48, 1450 | "h": 48 1451 | }, 1452 | "spriteSourceSize": { 1453 | "x": 0, 1454 | "y": 0, 1455 | "w": 48, 1456 | "h": 48 1457 | }, 1458 | "frame": { 1459 | "x": 384, 1460 | "y": 144, 1461 | "w": 48, 1462 | "h": 48 1463 | } 1464 | }, 1465 | { 1466 | "filename": "sprites/portraits/hair/6.png", 1467 | "rotated": false, 1468 | "trimmed": false, 1469 | "sourceSize": { 1470 | "w": 48, 1471 | "h": 48 1472 | }, 1473 | "spriteSourceSize": { 1474 | "x": 0, 1475 | "y": 0, 1476 | "w": 48, 1477 | "h": 48 1478 | }, 1479 | "frame": { 1480 | "x": 384, 1481 | "y": 192, 1482 | "w": 48, 1483 | "h": 48 1484 | } 1485 | }, 1486 | { 1487 | "filename": "sprites/portraits/hair/7.png", 1488 | "rotated": false, 1489 | "trimmed": false, 1490 | "sourceSize": { 1491 | "w": 48, 1492 | "h": 48 1493 | }, 1494 | "spriteSourceSize": { 1495 | "x": 0, 1496 | "y": 0, 1497 | "w": 48, 1498 | "h": 48 1499 | }, 1500 | "frame": { 1501 | "x": 384, 1502 | "y": 240, 1503 | "w": 48, 1504 | "h": 48 1505 | } 1506 | }, 1507 | { 1508 | "filename": "sprites/portraits/hair/8.png", 1509 | "rotated": false, 1510 | "trimmed": false, 1511 | "sourceSize": { 1512 | "w": 48, 1513 | "h": 48 1514 | }, 1515 | "spriteSourceSize": { 1516 | "x": 0, 1517 | "y": 0, 1518 | "w": 48, 1519 | "h": 48 1520 | }, 1521 | "frame": { 1522 | "x": 384, 1523 | "y": 288, 1524 | "w": 48, 1525 | "h": 48 1526 | } 1527 | }, 1528 | { 1529 | "filename": "sprites/portraits/hair/9.png", 1530 | "rotated": false, 1531 | "trimmed": false, 1532 | "sourceSize": { 1533 | "w": 48, 1534 | "h": 48 1535 | }, 1536 | "spriteSourceSize": { 1537 | "x": 0, 1538 | "y": 0, 1539 | "w": 48, 1540 | "h": 48 1541 | }, 1542 | "frame": { 1543 | "x": 384, 1544 | "y": 336, 1545 | "w": 48, 1546 | "h": 48 1547 | } 1548 | }, 1549 | { 1550 | "filename": "sprites/portraits/head/6.png", 1551 | "rotated": false, 1552 | "trimmed": false, 1553 | "sourceSize": { 1554 | "w": 48, 1555 | "h": 48 1556 | }, 1557 | "spriteSourceSize": { 1558 | "x": 0, 1559 | "y": 0, 1560 | "w": 48, 1561 | "h": 48 1562 | }, 1563 | "frame": { 1564 | "x": 0, 1565 | "y": 416, 1566 | "w": 48, 1567 | "h": 48 1568 | } 1569 | }, 1570 | { 1571 | "filename": "sprites/portraits/head/7.png", 1572 | "rotated": false, 1573 | "trimmed": false, 1574 | "sourceSize": { 1575 | "w": 48, 1576 | "h": 48 1577 | }, 1578 | "spriteSourceSize": { 1579 | "x": 0, 1580 | "y": 0, 1581 | "w": 48, 1582 | "h": 48 1583 | }, 1584 | "frame": { 1585 | "x": 48, 1586 | "y": 384, 1587 | "w": 48, 1588 | "h": 48 1589 | } 1590 | }, 1591 | { 1592 | "filename": "sprites/portraits/head/8.png", 1593 | "rotated": false, 1594 | "trimmed": false, 1595 | "sourceSize": { 1596 | "w": 48, 1597 | "h": 48 1598 | }, 1599 | "spriteSourceSize": { 1600 | "x": 0, 1601 | "y": 0, 1602 | "w": 48, 1603 | "h": 48 1604 | }, 1605 | "frame": { 1606 | "x": 96, 1607 | "y": 384, 1608 | "w": 48, 1609 | "h": 48 1610 | } 1611 | }, 1612 | { 1613 | "filename": "sprites/portraits/head/9.png", 1614 | "rotated": false, 1615 | "trimmed": false, 1616 | "sourceSize": { 1617 | "w": 48, 1618 | "h": 48 1619 | }, 1620 | "spriteSourceSize": { 1621 | "x": 0, 1622 | "y": 0, 1623 | "w": 48, 1624 | "h": 48 1625 | }, 1626 | "frame": { 1627 | "x": 144, 1628 | "y": 384, 1629 | "w": 48, 1630 | "h": 48 1631 | } 1632 | }, 1633 | { 1634 | "filename": "sprites/portraits/mouth/0.png", 1635 | "rotated": false, 1636 | "trimmed": false, 1637 | "sourceSize": { 1638 | "w": 48, 1639 | "h": 48 1640 | }, 1641 | "spriteSourceSize": { 1642 | "x": 0, 1643 | "y": 0, 1644 | "w": 48, 1645 | "h": 48 1646 | }, 1647 | "frame": { 1648 | "x": 192, 1649 | "y": 384, 1650 | "w": 48, 1651 | "h": 48 1652 | } 1653 | }, 1654 | { 1655 | "filename": "sprites/portraits/mouth/1.png", 1656 | "rotated": false, 1657 | "trimmed": false, 1658 | "sourceSize": { 1659 | "w": 48, 1660 | "h": 48 1661 | }, 1662 | "spriteSourceSize": { 1663 | "x": 0, 1664 | "y": 0, 1665 | "w": 48, 1666 | "h": 48 1667 | }, 1668 | "frame": { 1669 | "x": 240, 1670 | "y": 384, 1671 | "w": 48, 1672 | "h": 48 1673 | } 1674 | }, 1675 | { 1676 | "filename": "sprites/portraits/mouth/10.png", 1677 | "rotated": false, 1678 | "trimmed": false, 1679 | "sourceSize": { 1680 | "w": 48, 1681 | "h": 48 1682 | }, 1683 | "spriteSourceSize": { 1684 | "x": 0, 1685 | "y": 0, 1686 | "w": 48, 1687 | "h": 48 1688 | }, 1689 | "frame": { 1690 | "x": 288, 1691 | "y": 384, 1692 | "w": 48, 1693 | "h": 48 1694 | } 1695 | }, 1696 | { 1697 | "filename": "sprites/portraits/mouth/11.png", 1698 | "rotated": false, 1699 | "trimmed": false, 1700 | "sourceSize": { 1701 | "w": 48, 1702 | "h": 48 1703 | }, 1704 | "spriteSourceSize": { 1705 | "x": 0, 1706 | "y": 0, 1707 | "w": 48, 1708 | "h": 48 1709 | }, 1710 | "frame": { 1711 | "x": 336, 1712 | "y": 384, 1713 | "w": 48, 1714 | "h": 48 1715 | } 1716 | }, 1717 | { 1718 | "filename": "sprites/portraits/mouth/12.png", 1719 | "rotated": false, 1720 | "trimmed": false, 1721 | "sourceSize": { 1722 | "w": 48, 1723 | "h": 48 1724 | }, 1725 | "spriteSourceSize": { 1726 | "x": 0, 1727 | "y": 0, 1728 | "w": 48, 1729 | "h": 48 1730 | }, 1731 | "frame": { 1732 | "x": 384, 1733 | "y": 384, 1734 | "w": 48, 1735 | "h": 48 1736 | } 1737 | }, 1738 | { 1739 | "filename": "sprites/portraits/mouth/13.png", 1740 | "rotated": false, 1741 | "trimmed": false, 1742 | "sourceSize": { 1743 | "w": 48, 1744 | "h": 48 1745 | }, 1746 | "spriteSourceSize": { 1747 | "x": 0, 1748 | "y": 0, 1749 | "w": 48, 1750 | "h": 48 1751 | }, 1752 | "frame": { 1753 | "x": 432, 1754 | "y": 0, 1755 | "w": 48, 1756 | "h": 48 1757 | } 1758 | }, 1759 | { 1760 | "filename": "sprites/portraits/mouth/14.png", 1761 | "rotated": false, 1762 | "trimmed": false, 1763 | "sourceSize": { 1764 | "w": 48, 1765 | "h": 48 1766 | }, 1767 | "spriteSourceSize": { 1768 | "x": 0, 1769 | "y": 0, 1770 | "w": 48, 1771 | "h": 48 1772 | }, 1773 | "frame": { 1774 | "x": 432, 1775 | "y": 48, 1776 | "w": 48, 1777 | "h": 48 1778 | } 1779 | }, 1780 | { 1781 | "filename": "sprites/portraits/mouth/15.png", 1782 | "rotated": false, 1783 | "trimmed": false, 1784 | "sourceSize": { 1785 | "w": 48, 1786 | "h": 48 1787 | }, 1788 | "spriteSourceSize": { 1789 | "x": 0, 1790 | "y": 0, 1791 | "w": 48, 1792 | "h": 48 1793 | }, 1794 | "frame": { 1795 | "x": 432, 1796 | "y": 96, 1797 | "w": 48, 1798 | "h": 48 1799 | } 1800 | }, 1801 | { 1802 | "filename": "sprites/portraits/mouth/16.png", 1803 | "rotated": false, 1804 | "trimmed": false, 1805 | "sourceSize": { 1806 | "w": 48, 1807 | "h": 48 1808 | }, 1809 | "spriteSourceSize": { 1810 | "x": 0, 1811 | "y": 0, 1812 | "w": 48, 1813 | "h": 48 1814 | }, 1815 | "frame": { 1816 | "x": 432, 1817 | "y": 144, 1818 | "w": 48, 1819 | "h": 48 1820 | } 1821 | }, 1822 | { 1823 | "filename": "sprites/portraits/mouth/17.png", 1824 | "rotated": false, 1825 | "trimmed": false, 1826 | "sourceSize": { 1827 | "w": 48, 1828 | "h": 48 1829 | }, 1830 | "spriteSourceSize": { 1831 | "x": 0, 1832 | "y": 0, 1833 | "w": 48, 1834 | "h": 48 1835 | }, 1836 | "frame": { 1837 | "x": 432, 1838 | "y": 192, 1839 | "w": 48, 1840 | "h": 48 1841 | } 1842 | }, 1843 | { 1844 | "filename": "sprites/portraits/mouth/18.png", 1845 | "rotated": false, 1846 | "trimmed": false, 1847 | "sourceSize": { 1848 | "w": 48, 1849 | "h": 48 1850 | }, 1851 | "spriteSourceSize": { 1852 | "x": 0, 1853 | "y": 0, 1854 | "w": 48, 1855 | "h": 48 1856 | }, 1857 | "frame": { 1858 | "x": 432, 1859 | "y": 240, 1860 | "w": 48, 1861 | "h": 48 1862 | } 1863 | }, 1864 | { 1865 | "filename": "sprites/portraits/mouth/19.png", 1866 | "rotated": false, 1867 | "trimmed": false, 1868 | "sourceSize": { 1869 | "w": 48, 1870 | "h": 48 1871 | }, 1872 | "spriteSourceSize": { 1873 | "x": 0, 1874 | "y": 0, 1875 | "w": 48, 1876 | "h": 48 1877 | }, 1878 | "frame": { 1879 | "x": 432, 1880 | "y": 288, 1881 | "w": 48, 1882 | "h": 48 1883 | } 1884 | }, 1885 | { 1886 | "filename": "sprites/portraits/mouth/2.png", 1887 | "rotated": false, 1888 | "trimmed": false, 1889 | "sourceSize": { 1890 | "w": 48, 1891 | "h": 48 1892 | }, 1893 | "spriteSourceSize": { 1894 | "x": 0, 1895 | "y": 0, 1896 | "w": 48, 1897 | "h": 48 1898 | }, 1899 | "frame": { 1900 | "x": 432, 1901 | "y": 336, 1902 | "w": 48, 1903 | "h": 48 1904 | } 1905 | }, 1906 | { 1907 | "filename": "sprites/portraits/mouth/3.png", 1908 | "rotated": false, 1909 | "trimmed": false, 1910 | "sourceSize": { 1911 | "w": 48, 1912 | "h": 48 1913 | }, 1914 | "spriteSourceSize": { 1915 | "x": 0, 1916 | "y": 0, 1917 | "w": 48, 1918 | "h": 48 1919 | }, 1920 | "frame": { 1921 | "x": 432, 1922 | "y": 384, 1923 | "w": 48, 1924 | "h": 48 1925 | } 1926 | }, 1927 | { 1928 | "filename": "sprites/portraits/mouth/4.png", 1929 | "rotated": false, 1930 | "trimmed": false, 1931 | "sourceSize": { 1932 | "w": 48, 1933 | "h": 48 1934 | }, 1935 | "spriteSourceSize": { 1936 | "x": 0, 1937 | "y": 0, 1938 | "w": 48, 1939 | "h": 48 1940 | }, 1941 | "frame": { 1942 | "x": 0, 1943 | "y": 464, 1944 | "w": 48, 1945 | "h": 48 1946 | } 1947 | }, 1948 | { 1949 | "filename": "sprites/portraits/mouth/5.png", 1950 | "rotated": false, 1951 | "trimmed": false, 1952 | "sourceSize": { 1953 | "w": 48, 1954 | "h": 48 1955 | }, 1956 | "spriteSourceSize": { 1957 | "x": 0, 1958 | "y": 0, 1959 | "w": 48, 1960 | "h": 48 1961 | }, 1962 | "frame": { 1963 | "x": 48, 1964 | "y": 432, 1965 | "w": 48, 1966 | "h": 48 1967 | } 1968 | }, 1969 | { 1970 | "filename": "sprites/portraits/mouth/6.png", 1971 | "rotated": false, 1972 | "trimmed": false, 1973 | "sourceSize": { 1974 | "w": 48, 1975 | "h": 48 1976 | }, 1977 | "spriteSourceSize": { 1978 | "x": 0, 1979 | "y": 0, 1980 | "w": 48, 1981 | "h": 48 1982 | }, 1983 | "frame": { 1984 | "x": 96, 1985 | "y": 432, 1986 | "w": 48, 1987 | "h": 48 1988 | } 1989 | }, 1990 | { 1991 | "filename": "sprites/portraits/mouth/7.png", 1992 | "rotated": false, 1993 | "trimmed": false, 1994 | "sourceSize": { 1995 | "w": 48, 1996 | "h": 48 1997 | }, 1998 | "spriteSourceSize": { 1999 | "x": 0, 2000 | "y": 0, 2001 | "w": 48, 2002 | "h": 48 2003 | }, 2004 | "frame": { 2005 | "x": 144, 2006 | "y": 432, 2007 | "w": 48, 2008 | "h": 48 2009 | } 2010 | }, 2011 | { 2012 | "filename": "sprites/portraits/mouth/8.png", 2013 | "rotated": false, 2014 | "trimmed": false, 2015 | "sourceSize": { 2016 | "w": 48, 2017 | "h": 48 2018 | }, 2019 | "spriteSourceSize": { 2020 | "x": 0, 2021 | "y": 0, 2022 | "w": 48, 2023 | "h": 48 2024 | }, 2025 | "frame": { 2026 | "x": 192, 2027 | "y": 432, 2028 | "w": 48, 2029 | "h": 48 2030 | } 2031 | }, 2032 | { 2033 | "filename": "sprites/portraits/mouth/9.png", 2034 | "rotated": false, 2035 | "trimmed": false, 2036 | "sourceSize": { 2037 | "w": 48, 2038 | "h": 48 2039 | }, 2040 | "spriteSourceSize": { 2041 | "x": 0, 2042 | "y": 0, 2043 | "w": 48, 2044 | "h": 48 2045 | }, 2046 | "frame": { 2047 | "x": 240, 2048 | "y": 432, 2049 | "w": 48, 2050 | "h": 48 2051 | } 2052 | }, 2053 | { 2054 | "filename": "sprites/portraits/nose/13.png", 2055 | "rotated": false, 2056 | "trimmed": false, 2057 | "sourceSize": { 2058 | "w": 48, 2059 | "h": 48 2060 | }, 2061 | "spriteSourceSize": { 2062 | "x": 0, 2063 | "y": 0, 2064 | "w": 48, 2065 | "h": 48 2066 | }, 2067 | "frame": { 2068 | "x": 288, 2069 | "y": 432, 2070 | "w": 48, 2071 | "h": 48 2072 | } 2073 | }, 2074 | { 2075 | "filename": "sprites/portraits/nose/14.png", 2076 | "rotated": false, 2077 | "trimmed": false, 2078 | "sourceSize": { 2079 | "w": 48, 2080 | "h": 48 2081 | }, 2082 | "spriteSourceSize": { 2083 | "x": 0, 2084 | "y": 0, 2085 | "w": 48, 2086 | "h": 48 2087 | }, 2088 | "frame": { 2089 | "x": 336, 2090 | "y": 432, 2091 | "w": 48, 2092 | "h": 48 2093 | } 2094 | }, 2095 | { 2096 | "filename": "sprites/base/building-base.png", 2097 | "rotated": false, 2098 | "trimmed": false, 2099 | "sourceSize": { 2100 | "w": 32, 2101 | "h": 32 2102 | }, 2103 | "spriteSourceSize": { 2104 | "x": 0, 2105 | "y": 0, 2106 | "w": 32, 2107 | "h": 32 2108 | }, 2109 | "frame": { 2110 | "x": 48, 2111 | "y": 480, 2112 | "w": 32, 2113 | "h": 32 2114 | } 2115 | }, 2116 | { 2117 | "filename": "sprites/base/medium-base.png", 2118 | "rotated": false, 2119 | "trimmed": false, 2120 | "sourceSize": { 2121 | "w": 32, 2122 | "h": 32 2123 | }, 2124 | "spriteSourceSize": { 2125 | "x": 0, 2126 | "y": 0, 2127 | "w": 32, 2128 | "h": 32 2129 | }, 2130 | "frame": { 2131 | "x": 80, 2132 | "y": 480, 2133 | "w": 32, 2134 | "h": 32 2135 | } 2136 | }, 2137 | { 2138 | "filename": "sprites/buildings/ruins.png", 2139 | "rotated": false, 2140 | "trimmed": false, 2141 | "sourceSize": { 2142 | "w": 32, 2143 | "h": 32 2144 | }, 2145 | "spriteSourceSize": { 2146 | "x": 0, 2147 | "y": 0, 2148 | "w": 32, 2149 | "h": 32 2150 | }, 2151 | "frame": { 2152 | "x": 112, 2153 | "y": 480, 2154 | "w": 32, 2155 | "h": 32 2156 | } 2157 | }, 2158 | { 2159 | "filename": "sprites/buildings/settlements.png", 2160 | "rotated": false, 2161 | "trimmed": false, 2162 | "sourceSize": { 2163 | "w": 32, 2164 | "h": 32 2165 | }, 2166 | "spriteSourceSize": { 2167 | "x": 0, 2168 | "y": 0, 2169 | "w": 32, 2170 | "h": 32 2171 | }, 2172 | "frame": { 2173 | "x": 144, 2174 | "y": 480, 2175 | "w": 32, 2176 | "h": 32 2177 | } 2178 | }, 2179 | { 2180 | "filename": "sprites/base/small-base.png", 2181 | "rotated": false, 2182 | "trimmed": false, 2183 | "sourceSize": { 2184 | "w": 16, 2185 | "h": 16 2186 | }, 2187 | "spriteSourceSize": { 2188 | "x": 0, 2189 | "y": 0, 2190 | "w": 16, 2191 | "h": 16 2192 | }, 2193 | "frame": { 2194 | "x": 176, 2195 | "y": 480, 2196 | "w": 16, 2197 | "h": 16 2198 | } 2199 | }, 2200 | { 2201 | "filename": "sprites/resources/chest.png", 2202 | "rotated": false, 2203 | "trimmed": false, 2204 | "sourceSize": { 2205 | "w": 16, 2206 | "h": 16 2207 | }, 2208 | "spriteSourceSize": { 2209 | "x": 0, 2210 | "y": 0, 2211 | "w": 16, 2212 | "h": 16 2213 | }, 2214 | "frame": { 2215 | "x": 176, 2216 | "y": 496, 2217 | "w": 16, 2218 | "h": 16 2219 | } 2220 | }, 2221 | { 2222 | "filename": "sprites/resources/crystal.png", 2223 | "rotated": false, 2224 | "trimmed": false, 2225 | "sourceSize": { 2226 | "w": 16, 2227 | "h": 16 2228 | }, 2229 | "spriteSourceSize": { 2230 | "x": 0, 2231 | "y": 0, 2232 | "w": 16, 2233 | "h": 16 2234 | }, 2235 | "frame": { 2236 | "x": 192, 2237 | "y": 480, 2238 | "w": 16, 2239 | "h": 16 2240 | } 2241 | }, 2242 | { 2243 | "filename": "sprites/resources/dai-coin.png", 2244 | "rotated": false, 2245 | "trimmed": false, 2246 | "sourceSize": { 2247 | "w": 16, 2248 | "h": 16 2249 | }, 2250 | "spriteSourceSize": { 2251 | "x": 0, 2252 | "y": 0, 2253 | "w": 16, 2254 | "h": 16 2255 | }, 2256 | "frame": { 2257 | "x": 192, 2258 | "y": 496, 2259 | "w": 16, 2260 | "h": 16 2261 | } 2262 | }, 2263 | { 2264 | "filename": "sprites/resources/dai.png", 2265 | "rotated": false, 2266 | "trimmed": false, 2267 | "sourceSize": { 2268 | "w": 16, 2269 | "h": 16 2270 | }, 2271 | "spriteSourceSize": { 2272 | "x": 0, 2273 | "y": 0, 2274 | "w": 16, 2275 | "h": 16 2276 | }, 2277 | "frame": { 2278 | "x": 208, 2279 | "y": 480, 2280 | "w": 16, 2281 | "h": 16 2282 | } 2283 | }, 2284 | { 2285 | "filename": "sprites/resources/gems.png", 2286 | "rotated": false, 2287 | "trimmed": false, 2288 | "sourceSize": { 2289 | "w": 16, 2290 | "h": 16 2291 | }, 2292 | "spriteSourceSize": { 2293 | "x": 0, 2294 | "y": 0, 2295 | "w": 16, 2296 | "h": 16 2297 | }, 2298 | "frame": { 2299 | "x": 208, 2300 | "y": 496, 2301 | "w": 16, 2302 | "h": 16 2303 | } 2304 | }, 2305 | { 2306 | "filename": "sprites/resources/gold.png", 2307 | "rotated": false, 2308 | "trimmed": false, 2309 | "sourceSize": { 2310 | "w": 16, 2311 | "h": 16 2312 | }, 2313 | "spriteSourceSize": { 2314 | "x": 0, 2315 | "y": 0, 2316 | "w": 16, 2317 | "h": 16 2318 | }, 2319 | "frame": { 2320 | "x": 224, 2321 | "y": 480, 2322 | "w": 16, 2323 | "h": 16 2324 | } 2325 | }, 2326 | { 2327 | "filename": "sprites/resources/oil.png", 2328 | "rotated": false, 2329 | "trimmed": false, 2330 | "sourceSize": { 2331 | "w": 16, 2332 | "h": 16 2333 | }, 2334 | "spriteSourceSize": { 2335 | "x": 0, 2336 | "y": 0, 2337 | "w": 16, 2338 | "h": 16 2339 | }, 2340 | "frame": { 2341 | "x": 224, 2342 | "y": 496, 2343 | "w": 16, 2344 | "h": 16 2345 | } 2346 | }, 2347 | { 2348 | "filename": "sprites/resources/rock.png", 2349 | "rotated": false, 2350 | "trimmed": false, 2351 | "sourceSize": { 2352 | "w": 16, 2353 | "h": 16 2354 | }, 2355 | "spriteSourceSize": { 2356 | "x": 0, 2357 | "y": 0, 2358 | "w": 16, 2359 | "h": 16 2360 | }, 2361 | "frame": { 2362 | "x": 240, 2363 | "y": 480, 2364 | "w": 16, 2365 | "h": 16 2366 | } 2367 | }, 2368 | { 2369 | "filename": "sprites/resources/sulfur.png", 2370 | "rotated": false, 2371 | "trimmed": false, 2372 | "sourceSize": { 2373 | "w": 16, 2374 | "h": 16 2375 | }, 2376 | "spriteSourceSize": { 2377 | "x": 0, 2378 | "y": 0, 2379 | "w": 16, 2380 | "h": 16 2381 | }, 2382 | "frame": { 2383 | "x": 240, 2384 | "y": 496, 2385 | "w": 16, 2386 | "h": 16 2387 | } 2388 | }, 2389 | { 2390 | "filename": "sprites/resources/wood.png", 2391 | "rotated": false, 2392 | "trimmed": false, 2393 | "sourceSize": { 2394 | "w": 16, 2395 | "h": 16 2396 | }, 2397 | "spriteSourceSize": { 2398 | "x": 0, 2399 | "y": 0, 2400 | "w": 16, 2401 | "h": 16 2402 | }, 2403 | "frame": { 2404 | "x": 256, 2405 | "y": 480, 2406 | "w": 16, 2407 | "h": 16 2408 | } 2409 | }, 2410 | { 2411 | "filename": "sprites/warriors/archer.png", 2412 | "rotated": false, 2413 | "trimmed": false, 2414 | "sourceSize": { 2415 | "w": 16, 2416 | "h": 16 2417 | }, 2418 | "spriteSourceSize": { 2419 | "x": 0, 2420 | "y": 0, 2421 | "w": 16, 2422 | "h": 16 2423 | }, 2424 | "frame": { 2425 | "x": 256, 2426 | "y": 496, 2427 | "w": 16, 2428 | "h": 16 2429 | } 2430 | }, 2431 | { 2432 | "filename": "sprites/warriors/hero.png", 2433 | "rotated": false, 2434 | "trimmed": false, 2435 | "sourceSize": { 2436 | "w": 16, 2437 | "h": 16 2438 | }, 2439 | "spriteSourceSize": { 2440 | "x": 0, 2441 | "y": 0, 2442 | "w": 16, 2443 | "h": 16 2444 | }, 2445 | "frame": { 2446 | "x": 272, 2447 | "y": 480, 2448 | "w": 16, 2449 | "h": 16 2450 | } 2451 | }, 2452 | { 2453 | "filename": "sprites/workers/bridge-builder-imp.png", 2454 | "rotated": false, 2455 | "trimmed": false, 2456 | "sourceSize": { 2457 | "w": 16, 2458 | "h": 16 2459 | }, 2460 | "spriteSourceSize": { 2461 | "x": 0, 2462 | "y": 0, 2463 | "w": 16, 2464 | "h": 16 2465 | }, 2466 | "frame": { 2467 | "x": 272, 2468 | "y": 496, 2469 | "w": 16, 2470 | "h": 16 2471 | } 2472 | }, 2473 | { 2474 | "filename": "sprites/workers/crypto-picker-imp.png", 2475 | "rotated": false, 2476 | "trimmed": false, 2477 | "sourceSize": { 2478 | "w": 16, 2479 | "h": 16 2480 | }, 2481 | "spriteSourceSize": { 2482 | "x": 0, 2483 | "y": 0, 2484 | "w": 16, 2485 | "h": 16 2486 | }, 2487 | "frame": { 2488 | "x": 288, 2489 | "y": 480, 2490 | "w": 16, 2491 | "h": 16 2492 | } 2493 | }, 2494 | { 2495 | "filename": "sprites/workers/donkey.png", 2496 | "rotated": false, 2497 | "trimmed": false, 2498 | "sourceSize": { 2499 | "w": 16, 2500 | "h": 16 2501 | }, 2502 | "spriteSourceSize": { 2503 | "x": 0, 2504 | "y": 0, 2505 | "w": 16, 2506 | "h": 16 2507 | }, 2508 | "frame": { 2509 | "x": 288, 2510 | "y": 496, 2511 | "w": 16, 2512 | "h": 16 2513 | } 2514 | }, 2515 | { 2516 | "filename": "sprites/workers/fortify-imp.png", 2517 | "rotated": false, 2518 | "trimmed": false, 2519 | "sourceSize": { 2520 | "w": 16, 2521 | "h": 16 2522 | }, 2523 | "spriteSourceSize": { 2524 | "x": 0, 2525 | "y": 0, 2526 | "w": 16, 2527 | "h": 16 2528 | }, 2529 | "frame": { 2530 | "x": 304, 2531 | "y": 480, 2532 | "w": 16, 2533 | "h": 16 2534 | } 2535 | }, 2536 | { 2537 | "filename": "sprites/workers/mining-imp.png", 2538 | "rotated": false, 2539 | "trimmed": false, 2540 | "sourceSize": { 2541 | "w": 16, 2542 | "h": 16 2543 | }, 2544 | "spriteSourceSize": { 2545 | "x": 0, 2546 | "y": 0, 2547 | "w": 16, 2548 | "h": 16 2549 | }, 2550 | "frame": { 2551 | "x": 304, 2552 | "y": 496, 2553 | "w": 16, 2554 | "h": 16 2555 | } 2556 | }, 2557 | { 2558 | "filename": "sprites/workers/road-builder-imp.png", 2559 | "rotated": false, 2560 | "trimmed": false, 2561 | "sourceSize": { 2562 | "w": 16, 2563 | "h": 16 2564 | }, 2565 | "spriteSourceSize": { 2566 | "x": 0, 2567 | "y": 0, 2568 | "w": 16, 2569 | "h": 16 2570 | }, 2571 | "frame": { 2572 | "x": 320, 2573 | "y": 480, 2574 | "w": 16, 2575 | "h": 16 2576 | } 2577 | }, 2578 | { 2579 | "filename": "sprites/digits/0.png", 2580 | "rotated": false, 2581 | "trimmed": false, 2582 | "sourceSize": { 2583 | "w": 5, 2584 | "h": 5 2585 | }, 2586 | "spriteSourceSize": { 2587 | "x": 0, 2588 | "y": 0, 2589 | "w": 5, 2590 | "h": 5 2591 | }, 2592 | "frame": { 2593 | "x": 320, 2594 | "y": 496, 2595 | "w": 5, 2596 | "h": 5 2597 | } 2598 | }, 2599 | { 2600 | "filename": "sprites/digits/1.png", 2601 | "rotated": false, 2602 | "trimmed": false, 2603 | "sourceSize": { 2604 | "w": 5, 2605 | "h": 5 2606 | }, 2607 | "spriteSourceSize": { 2608 | "x": 0, 2609 | "y": 0, 2610 | "w": 5, 2611 | "h": 5 2612 | }, 2613 | "frame": { 2614 | "x": 320, 2615 | "y": 501, 2616 | "w": 5, 2617 | "h": 5 2618 | } 2619 | }, 2620 | { 2621 | "filename": "sprites/digits/2.png", 2622 | "rotated": false, 2623 | "trimmed": false, 2624 | "sourceSize": { 2625 | "w": 5, 2626 | "h": 5 2627 | }, 2628 | "spriteSourceSize": { 2629 | "x": 0, 2630 | "y": 0, 2631 | "w": 5, 2632 | "h": 5 2633 | }, 2634 | "frame": { 2635 | "x": 320, 2636 | "y": 506, 2637 | "w": 5, 2638 | "h": 5 2639 | } 2640 | }, 2641 | { 2642 | "filename": "sprites/digits/3.png", 2643 | "rotated": false, 2644 | "trimmed": false, 2645 | "sourceSize": { 2646 | "w": 5, 2647 | "h": 5 2648 | }, 2649 | "spriteSourceSize": { 2650 | "x": 0, 2651 | "y": 0, 2652 | "w": 5, 2653 | "h": 5 2654 | }, 2655 | "frame": { 2656 | "x": 325, 2657 | "y": 496, 2658 | "w": 5, 2659 | "h": 5 2660 | } 2661 | }, 2662 | { 2663 | "filename": "sprites/digits/4.png", 2664 | "rotated": false, 2665 | "trimmed": false, 2666 | "sourceSize": { 2667 | "w": 5, 2668 | "h": 5 2669 | }, 2670 | "spriteSourceSize": { 2671 | "x": 0, 2672 | "y": 0, 2673 | "w": 5, 2674 | "h": 5 2675 | }, 2676 | "frame": { 2677 | "x": 325, 2678 | "y": 501, 2679 | "w": 5, 2680 | "h": 5 2681 | } 2682 | }, 2683 | { 2684 | "filename": "sprites/digits/5.png", 2685 | "rotated": false, 2686 | "trimmed": false, 2687 | "sourceSize": { 2688 | "w": 5, 2689 | "h": 5 2690 | }, 2691 | "spriteSourceSize": { 2692 | "x": 0, 2693 | "y": 0, 2694 | "w": 5, 2695 | "h": 5 2696 | }, 2697 | "frame": { 2698 | "x": 325, 2699 | "y": 506, 2700 | "w": 5, 2701 | "h": 5 2702 | } 2703 | }, 2704 | { 2705 | "filename": "sprites/digits/6.png", 2706 | "rotated": false, 2707 | "trimmed": false, 2708 | "sourceSize": { 2709 | "w": 5, 2710 | "h": 5 2711 | }, 2712 | "spriteSourceSize": { 2713 | "x": 0, 2714 | "y": 0, 2715 | "w": 5, 2716 | "h": 5 2717 | }, 2718 | "frame": { 2719 | "x": 330, 2720 | "y": 496, 2721 | "w": 5, 2722 | "h": 5 2723 | } 2724 | }, 2725 | { 2726 | "filename": "sprites/digits/7.png", 2727 | "rotated": false, 2728 | "trimmed": false, 2729 | "sourceSize": { 2730 | "w": 5, 2731 | "h": 5 2732 | }, 2733 | "spriteSourceSize": { 2734 | "x": 0, 2735 | "y": 0, 2736 | "w": 5, 2737 | "h": 5 2738 | }, 2739 | "frame": { 2740 | "x": 330, 2741 | "y": 501, 2742 | "w": 5, 2743 | "h": 5 2744 | } 2745 | }, 2746 | { 2747 | "filename": "sprites/digits/8.png", 2748 | "rotated": false, 2749 | "trimmed": false, 2750 | "sourceSize": { 2751 | "w": 5, 2752 | "h": 5 2753 | }, 2754 | "spriteSourceSize": { 2755 | "x": 0, 2756 | "y": 0, 2757 | "w": 5, 2758 | "h": 5 2759 | }, 2760 | "frame": { 2761 | "x": 330, 2762 | "y": 506, 2763 | "w": 5, 2764 | "h": 5 2765 | } 2766 | }, 2767 | { 2768 | "filename": "sprites/digits/9.png", 2769 | "rotated": false, 2770 | "trimmed": false, 2771 | "sourceSize": { 2772 | "w": 5, 2773 | "h": 5 2774 | }, 2775 | "spriteSourceSize": { 2776 | "x": 0, 2777 | "y": 0, 2778 | "w": 5, 2779 | "h": 5 2780 | }, 2781 | "frame": { 2782 | "x": 335, 2783 | "y": 496, 2784 | "w": 5, 2785 | "h": 5 2786 | } 2787 | }, 2788 | { 2789 | "filename": "sprites/portraits/clothes/10.png", 2790 | "rotated": false, 2791 | "trimmed": false, 2792 | "sourceSize": { 2793 | "w": 48, 2794 | "h": 48 2795 | }, 2796 | "spriteSourceSize": { 2797 | "x": 0, 2798 | "y": 0, 2799 | "w": 48, 2800 | "h": 48 2801 | }, 2802 | "frame": { 2803 | "x": 0, 2804 | "y": 32, 2805 | "w": 48, 2806 | "h": 48 2807 | } 2808 | }, 2809 | { 2810 | "filename": "sprites/portraits/Eyes/8.png", 2811 | "rotated": false, 2812 | "trimmed": false, 2813 | "sourceSize": { 2814 | "w": 48, 2815 | "h": 48 2816 | }, 2817 | "spriteSourceSize": { 2818 | "x": 0, 2819 | "y": 0, 2820 | "w": 48, 2821 | "h": 48 2822 | }, 2823 | "frame": { 2824 | "x": 48, 2825 | "y": 48, 2826 | "w": 48, 2827 | "h": 48 2828 | } 2829 | }, 2830 | { 2831 | "filename": "sprites/portraits/clothes/11.png", 2832 | "rotated": false, 2833 | "trimmed": false, 2834 | "sourceSize": { 2835 | "w": 48, 2836 | "h": 48 2837 | }, 2838 | "spriteSourceSize": { 2839 | "x": 0, 2840 | "y": 0, 2841 | "w": 48, 2842 | "h": 48 2843 | }, 2844 | "frame": { 2845 | "x": 192, 2846 | "y": 288, 2847 | "w": 48, 2848 | "h": 48 2849 | } 2850 | }, 2851 | { 2852 | "filename": "sprites/portraits/clothes/2.png", 2853 | "rotated": false, 2854 | "trimmed": false, 2855 | "sourceSize": { 2856 | "w": 48, 2857 | "h": 48 2858 | }, 2859 | "spriteSourceSize": { 2860 | "x": 0, 2861 | "y": 0, 2862 | "w": 48, 2863 | "h": 48 2864 | }, 2865 | "frame": { 2866 | "x": 240, 2867 | "y": 288, 2868 | "w": 48, 2869 | "h": 48 2870 | } 2871 | }, 2872 | { 2873 | "filename": "sprites/portraits/clothes/3.png", 2874 | "rotated": false, 2875 | "trimmed": false, 2876 | "sourceSize": { 2877 | "w": 48, 2878 | "h": 48 2879 | }, 2880 | "spriteSourceSize": { 2881 | "x": 0, 2882 | "y": 0, 2883 | "w": 48, 2884 | "h": 48 2885 | }, 2886 | "frame": { 2887 | "x": 288, 2888 | "y": 288, 2889 | "w": 48, 2890 | "h": 48 2891 | } 2892 | }, 2893 | { 2894 | "filename": "sprites/portraits/clothes/4.png", 2895 | "rotated": false, 2896 | "trimmed": false, 2897 | "sourceSize": { 2898 | "w": 48, 2899 | "h": 48 2900 | }, 2901 | "spriteSourceSize": { 2902 | "x": 0, 2903 | "y": 0, 2904 | "w": 48, 2905 | "h": 48 2906 | }, 2907 | "frame": { 2908 | "x": 336, 2909 | "y": 0, 2910 | "w": 48, 2911 | "h": 48 2912 | } 2913 | }, 2914 | { 2915 | "filename": "sprites/portraits/clothes/5.png", 2916 | "rotated": false, 2917 | "trimmed": false, 2918 | "sourceSize": { 2919 | "w": 48, 2920 | "h": 48 2921 | }, 2922 | "spriteSourceSize": { 2923 | "x": 0, 2924 | "y": 0, 2925 | "w": 48, 2926 | "h": 48 2927 | }, 2928 | "frame": { 2929 | "x": 336, 2930 | "y": 48, 2931 | "w": 48, 2932 | "h": 48 2933 | } 2934 | }, 2935 | { 2936 | "filename": "sprites/portraits/clothes/6.png", 2937 | "rotated": false, 2938 | "trimmed": false, 2939 | "sourceSize": { 2940 | "w": 48, 2941 | "h": 48 2942 | }, 2943 | "spriteSourceSize": { 2944 | "x": 0, 2945 | "y": 0, 2946 | "w": 48, 2947 | "h": 48 2948 | }, 2949 | "frame": { 2950 | "x": 336, 2951 | "y": 96, 2952 | "w": 48, 2953 | "h": 48 2954 | } 2955 | }, 2956 | { 2957 | "filename": "sprites/portraits/clothes/7.png", 2958 | "rotated": false, 2959 | "trimmed": false, 2960 | "sourceSize": { 2961 | "w": 48, 2962 | "h": 48 2963 | }, 2964 | "spriteSourceSize": { 2965 | "x": 0, 2966 | "y": 0, 2967 | "w": 48, 2968 | "h": 48 2969 | }, 2970 | "frame": { 2971 | "x": 336, 2972 | "y": 144, 2973 | "w": 48, 2974 | "h": 48 2975 | } 2976 | }, 2977 | { 2978 | "filename": "sprites/portraits/clothes/8.png", 2979 | "rotated": false, 2980 | "trimmed": false, 2981 | "sourceSize": { 2982 | "w": 48, 2983 | "h": 48 2984 | }, 2985 | "spriteSourceSize": { 2986 | "x": 0, 2987 | "y": 0, 2988 | "w": 48, 2989 | "h": 48 2990 | }, 2991 | "frame": { 2992 | "x": 336, 2993 | "y": 192, 2994 | "w": 48, 2995 | "h": 48 2996 | } 2997 | }, 2998 | { 2999 | "filename": "sprites/portraits/clothes/9.png", 3000 | "rotated": false, 3001 | "trimmed": false, 3002 | "sourceSize": { 3003 | "w": 48, 3004 | "h": 48 3005 | }, 3006 | "spriteSourceSize": { 3007 | "x": 0, 3008 | "y": 0, 3009 | "w": 48, 3010 | "h": 48 3011 | }, 3012 | "frame": { 3013 | "x": 336, 3014 | "y": 240, 3015 | "w": 48, 3016 | "h": 48 3017 | } 3018 | } 3019 | ] 3020 | } 3021 | ] 3022 | } -------------------------------------------------------------------------------- /packages/client/src/public/atlases/sprites/atlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/public/atlases/sprites/atlas.png -------------------------------------------------------------------------------- /packages/client/src/public/img/mud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/latticexyz/mudbasics/28e39c05745200d78475d573118fdf1fed09775e/packages/client/src/public/img/mud.png -------------------------------------------------------------------------------- /packages/client/src/types.ts: -------------------------------------------------------------------------------- 1 | import { boot } from "./boot"; 2 | import { NetworkLayer } from "./layers/network"; 3 | import { PhaserLayer } from "./layers/phaser"; 4 | 5 | export type EmberWindow = Awaited>; 6 | 7 | export type Layers = { network: NetworkLayer; phaser: PhaserLayer }; 8 | -------------------------------------------------------------------------------- /packages/client/src/utils/components.ts: -------------------------------------------------------------------------------- 1 | import { Component, Schema, ComponentValue, componentValueEquals, EntityIndex } from "@latticexyz/recs"; 2 | import { deferred } from "@latticexyz/utils"; 3 | import { filter } from "rxjs"; 4 | 5 | export function waitForComponentValueIn( 6 | component: Component, 7 | entity: EntityIndex, 8 | values: Partial>[] 9 | ): Promise { 10 | const [resolve, , promise] = deferred(); 11 | 12 | let dispose = resolve; 13 | const subscription = component.update$ 14 | .pipe( 15 | filter((e) => e.entity === entity && Boolean(values.find((value) => componentValueEquals(value, e.value[0])))) 16 | ) 17 | .subscribe(() => { 18 | resolve(); 19 | dispose(); 20 | }); 21 | 22 | dispose = () => subscription?.unsubscribe(); 23 | 24 | return promise; 25 | } 26 | 27 | export async function waitForComponentValue( 28 | component: Component, 29 | entity: EntityIndex, 30 | value: Partial> 31 | ): Promise { 32 | await waitForComponentValueIn(component, entity, [value]); 33 | } 34 | -------------------------------------------------------------------------------- /packages/client/src/utils/coords.ts: -------------------------------------------------------------------------------- 1 | import { WorldCoord } from "../types"; 2 | 3 | export function worldCoordEq(a?: WorldCoord, b?: WorldCoord): boolean { 4 | if (!a || !b) return false; 5 | return a.x === b.x && a.y === b.y; 6 | } 7 | -------------------------------------------------------------------------------- /packages/client/src/utils/directions.ts: -------------------------------------------------------------------------------- 1 | import { Direction, Directions } from "../constants"; 2 | import { WorldCoord } from "../types"; 3 | import { random } from "@latticexyz/utils"; 4 | 5 | /** 6 | * @param coord Initial coordinate 7 | * @param translation Relative translation of the initial coordinate 8 | * @returns New coordinate after translating 9 | */ 10 | export function translate(coord: WorldCoord, translation: WorldCoord): WorldCoord { 11 | return { x: coord.x + translation.x, y: coord.y + translation.y }; 12 | } 13 | 14 | /** 15 | * @param coord Initial coordinate 16 | * @param direction Direction to move to 17 | * @returns New coordiante after moving in the specified direction 18 | */ 19 | export function translateDirection(coord: WorldCoord, direction: Direction): WorldCoord { 20 | return translate(coord, Directions[direction]); 21 | } 22 | 23 | /** 24 | * @returns Random direction (Top, Right, Bottom or Left) 25 | */ 26 | export function randomDirection(): Direction { 27 | return random(3, 0); 28 | } 29 | 30 | export function getSurroundingCoords(coord: WorldCoord, distance = 1): WorldCoord[] { 31 | const surroundingCoords: WorldCoord[] = []; 32 | 33 | for (let x = -1 * distance; x <= distance; x++) { 34 | for (let y = -1 * distance; y <= distance; y++) { 35 | if (!(x === 0 && y === 0)) surroundingCoords.push(translate(coord, { x, y })); 36 | } 37 | } 38 | 39 | return surroundingCoords; 40 | } 41 | -------------------------------------------------------------------------------- /packages/client/src/utils/distance.ts: -------------------------------------------------------------------------------- 1 | import { WorldCoord } from "../types"; 2 | 3 | /** 4 | * @param a Coordinate A 5 | * @param b Coordinate B 6 | * @returns Manhattan distance from A to B (https://xlinux.nist.gov/dads/HTML/manhattanDistance.html) 7 | */ 8 | export function manhattan(a: WorldCoord, b: WorldCoord) { 9 | return Math.abs(a.x - b.x) + Math.abs(a.y - b.y); 10 | } 11 | -------------------------------------------------------------------------------- /packages/client/src/utils/pathfinding.ts: -------------------------------------------------------------------------------- 1 | import { WorldCoord } from "../types"; 2 | import { worldCoordEq } from "./coords"; 3 | import { manhattan } from "./distance"; 4 | import { CoordMap } from "@latticexyz/utils"; 5 | import { Heap } from "heap-js"; 6 | 7 | interface gridNode { 8 | x: number; 9 | y: number; 10 | f: number; 11 | g: number; 12 | h: number; 13 | cost: number; 14 | visited: boolean; 15 | closed: boolean; 16 | parent: gridNode | null; 17 | } 18 | interface bfsNode { 19 | f: number; 20 | cost: number; 21 | visited: boolean; 22 | } 23 | 24 | function getVisitableNeighbor(currentPosition: WorldCoord, isUntraversable: (arg0: WorldCoord) => boolean) { 25 | const neighbors = [ 26 | { x: currentPosition.x, y: currentPosition.y - 1 }, // Up 27 | { x: currentPosition.x + 1, y: currentPosition.y }, // Right 28 | { x: currentPosition.x, y: currentPosition.y + 1 }, // Down 29 | { x: currentPosition.x - 1, y: currentPosition.y }, // Left 30 | ]; 31 | const visitableNeighbors: WorldCoord[] = []; 32 | for (const neighbor of neighbors) { 33 | if (!isUntraversable(neighbor)) { 34 | visitableNeighbors.push(neighbor); 35 | } 36 | } 37 | return visitableNeighbors; 38 | } 39 | 40 | /** 41 | * @param from Coordinate to start from (included in the path) 42 | * @param to Coordinate to go to (included in the path) 43 | * @param maxDistance The maximum distance that can be traveled in the path 44 | * @param isUntraversable A function that takes in a coordinate and returns true if it cannot be traversed 45 | * @returns Finds shortest path between the from and to coordinates 46 | */ 47 | export function aStar( 48 | from: WorldCoord, 49 | to: WorldCoord, 50 | maxDistance: number, 51 | isUntraversable: (arg0: WorldCoord) => boolean 52 | ): WorldCoord[] { 53 | if (manhattan(from, to) > maxDistance) return []; // early out if destination is further than stamina allows 54 | 55 | const path: WorldCoord[] = []; 56 | const nodeMap = new CoordMap(); 57 | 58 | const start = { 59 | x: from.x, 60 | y: from.y, 61 | f: 0, 62 | g: 0, 63 | h: 0, 64 | cost: 1, // TODO: change cost to reflect terrain 65 | visited: false, 66 | closed: false, 67 | parent: null, 68 | }; 69 | 70 | nodeMap.set(from, start); 71 | 72 | const customPriorityComparator = (a: gridNode, b: gridNode) => a.f - b.f; 73 | const openHeap = new Heap(customPriorityComparator); 74 | 75 | openHeap.push(start); 76 | 77 | while (openHeap.size() > 0) { 78 | const currentNode = openHeap.pop()!; 79 | 80 | if (worldCoordEq(currentNode, to)) { 81 | let curr = currentNode; 82 | while (curr && curr.parent) { 83 | path.push({ x: curr.x, y: curr.y }); 84 | curr = curr.parent; 85 | } 86 | return path.reverse(); 87 | } 88 | 89 | currentNode.closed = true; 90 | 91 | const neighborCoords = getVisitableNeighbor(currentNode, isUntraversable); 92 | 93 | for (let i = 0; i < neighborCoords.length; i++) { 94 | let neighbor = nodeMap.get(neighborCoords[i]); 95 | if (!neighbor) { 96 | neighbor = { 97 | x: neighborCoords[i].x, 98 | y: neighborCoords[i].y, 99 | f: 0, 100 | g: 0, 101 | h: 0, 102 | cost: 1, // TODO: get terrain travel cost 103 | visited: false, 104 | closed: false, 105 | parent: null, 106 | }; 107 | nodeMap.set(neighborCoords[i], neighbor); 108 | } 109 | if (neighbor.closed) { 110 | continue; 111 | } 112 | 113 | const gScore = currentNode.g + neighbor.cost; 114 | const beenVisited = neighbor.visited; 115 | 116 | if (gScore <= maxDistance && (!beenVisited || gScore < neighbor.g)) { 117 | neighbor.visited = true; 118 | neighbor.parent = currentNode; 119 | neighbor.h = neighbor.h || manhattan({ x: neighbor.x, y: neighbor.y }, to); 120 | neighbor.g = gScore; 121 | neighbor.f = neighbor.g + neighbor.h; 122 | 123 | if (!beenVisited) { 124 | openHeap.push(neighbor); 125 | } 126 | } 127 | } 128 | } 129 | 130 | return []; 131 | } 132 | 133 | /** 134 | * @param from Coordinate to start from (included in the path) 135 | * @param maxDistance The maximum distance that can be traveled 136 | * @param isUntraversable A function that takes in a coordinate and returns true if it cannot be traversed 137 | * @returns Finds all traversable paths up to maxDistance 138 | */ 139 | export function BFS( 140 | from: WorldCoord, 141 | maxDistance: number, 142 | isUntraversable: (arg0: WorldCoord) => boolean 143 | ): WorldCoord[] { 144 | const path: WorldCoord[] = []; 145 | const nodeMap = new CoordMap(); 146 | 147 | const unvisitedCoords: WorldCoord[] = []; 148 | const start = { 149 | f: 0, 150 | cost: 1, 151 | visited: false, 152 | }; 153 | nodeMap.set(from, start); 154 | unvisitedCoords.push(from); 155 | 156 | while (unvisitedCoords.length > 0) { 157 | const currentCoord = unvisitedCoords.shift()!; 158 | const currentNode = nodeMap.get(currentCoord)!; 159 | 160 | const neighborCoords = getVisitableNeighbor(currentCoord, isUntraversable); 161 | 162 | for (let i = 0; i < neighborCoords.length; i++) { 163 | let neighbor = nodeMap.get(neighborCoords[i]); 164 | if (!neighbor) { 165 | neighbor = { 166 | f: 0, 167 | cost: 1, 168 | visited: false, 169 | }; 170 | nodeMap.set(neighborCoords[i], neighbor); 171 | } 172 | 173 | const totalCost = currentNode.f + neighbor.cost; 174 | const beenVisited = neighbor.visited; 175 | 176 | if (totalCost <= maxDistance) { 177 | neighbor.f = totalCost; 178 | 179 | if (!beenVisited) { 180 | unvisitedCoords.push(neighborCoords[i]); 181 | path.push(neighborCoords[i]); 182 | neighbor.visited = true; 183 | } 184 | } 185 | } 186 | } 187 | 188 | return path; 189 | } 190 | 191 | /** 192 | * @param from Coordinate to start from (included in the path) 193 | * @param to Coordinate to go to (included in the path) 194 | * @returns Finds a path between the from and to coordinates, used in some cases when aStar fails 195 | */ 196 | export function directionalPathfind(from: WorldCoord, to: WorldCoord): WorldCoord[] { 197 | const path: WorldCoord[] = []; 198 | const directionX = from.x < to.x ? 1 : -1; 199 | const directionY = from.y < to.y ? 1 : -1; 200 | 201 | for (let x = from.x + directionX; directionX * x <= directionX * to.x; x = x + directionX) { 202 | path.push({ x, y: from.y }); 203 | } 204 | 205 | for (let y = from.y + directionY; directionY * y <= directionY * to.y; y = y + directionY) { 206 | path.push({ x: to.x, y }); 207 | } 208 | 209 | return path; 210 | } 211 | -------------------------------------------------------------------------------- /packages/client/src/utils/rx.ts: -------------------------------------------------------------------------------- 1 | import { Time } from "./time"; 2 | import { MonoTypeOperatorFunction, Subject, delayWhen } from "rxjs"; 3 | 4 | export function delayTime(due: number): MonoTypeOperatorFunction { 5 | const duration = new Subject<0>(); 6 | Time.time.setTimeout(() => duration.next(0), due); 7 | return delayWhen(() => duration); 8 | } 9 | -------------------------------------------------------------------------------- /packages/client/src/utils/sleep.ts: -------------------------------------------------------------------------------- 1 | import { deferred } from "@latticexyz/utils"; 2 | import { Time } from "./time"; 3 | 4 | /** 5 | * @param miliseconds Time until the promise resolves. 6 | * @returns A promise that resolves after the specified time. 7 | */ 8 | export async function sleep(miliseconds: number) { 9 | const [resolve, , promise] = deferred(); 10 | Time.time.setTimeout(resolve, miliseconds); 11 | return promise; 12 | } 13 | -------------------------------------------------------------------------------- /packages/client/src/utils/time.ts: -------------------------------------------------------------------------------- 1 | import { makeAutoObservable, reaction } from "mobx"; 2 | 3 | /** 4 | * A static time class that allows us to play time in the speed we want to. 5 | * Using this instead of setTimeout allows us to synchronize the system loops with the phaser time 6 | * (eg. don't run the strolling system when the window is inactive) and simplifies testing systems as we 7 | * have control over the time. 8 | */ 9 | export class Time { 10 | private static instance: Time; 11 | private nonce = 0; 12 | timestamp = 0; 13 | 14 | constructor() { 15 | makeAutoObservable(this); 16 | } 17 | 18 | public static get time(): Time { 19 | if (!this.instance) this.instance = new Time(); 20 | return this.instance; 21 | } 22 | 23 | /** 24 | * Sets the internal timestamp to the given number. 25 | * Use with caution, should not be called directly in most cases. 26 | * Use setPacemaker instead. 27 | * @param timestamp 28 | */ 29 | public setTimestamp(timestamp: number) { 30 | this.timestamp = timestamp; 31 | } 32 | 33 | /** 34 | * Allows to register a function that sets the current timestamp in regular intervals. 35 | * Makes sure only the last call to setPacemaker actually sets the time. 36 | * @param pacemaker Callback with a reference to setTimestamp 37 | */ 38 | public setPacemaker(pacemaker: (setTimestamp: (timestamp: number) => void) => void) { 39 | this.nonce++; 40 | const currentNonce = this.nonce; 41 | pacemaker((timestamp: number) => { 42 | // Only the most recent pacemaker actually sets the timestamp 43 | if (this.nonce === currentNonce) this.setTimestamp(timestamp); 44 | }); 45 | } 46 | 47 | /** 48 | * Use as a replacement of the native setTimeout 49 | * @param callback Callback to be called after delay 50 | * @param delay Delay after which to call thecallback 51 | * @returns 52 | */ 53 | public setTimeout(callback: () => unknown, delay: number) { 54 | if (delay === 0) return callback(); 55 | 56 | const dueTime = this.timestamp + delay; 57 | const dispose = reaction( 58 | () => this.timestamp, 59 | (currentTime) => { 60 | if (currentTime >= dueTime) { 61 | // Calling the callback in a setTimeout makes it be executed in the next event loop, 62 | // so exactly the same behavior as when calling the native setTimeout 63 | setTimeout(callback); 64 | dispose(); 65 | } 66 | } 67 | ); 68 | } 69 | 70 | /** 71 | * Use as a replacement of the native setInterval 72 | * @param callback Callback to be called once in every interval 73 | * @param interval Interval in which to call the callback 74 | * @returns Disposer to stop the interval 75 | */ 76 | public setInterval(callback: () => unknown, interval: number) { 77 | if (interval === 0) throw new Error("Interval must be greater than 0"); 78 | 79 | let lastInvocation = this.timestamp; 80 | 81 | const dispose = reaction( 82 | () => this.timestamp, 83 | (currentTime) => { 84 | if (currentTime >= lastInvocation + interval) { 85 | // Calling the callback in a setTimeout makes it be executed in the next event loop, 86 | // so exactly the same behavior as when calling the native setInterval 87 | setTimeout(callback); 88 | lastInvocation = currentTime; 89 | } 90 | } 91 | ); 92 | 93 | return dispose; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /packages/client/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "esnext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | "jsx": "preserve" /* Specify what JSX code is generated. */, 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 22 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | "useDefineForClassFields": true /* Emit ECMAScript-standard-compliant class fields. */, 25 | /* Modules */ 26 | "module": "esnext" /* Specify what module code is generated. */, 27 | // "rootDir": "./", /* Specify the root folder within your source files. */ 28 | "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, 29 | // "baseUrl": "./" /* Specify the base directory to resolve non-relative module names. */, 30 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 31 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 32 | // "typeRoots": [] /* Specify multiple folders that act like `./node_modules/@types`. */, 33 | "types": [ 34 | "vite/client", 35 | "jest" 36 | ] /* Specify type package names to be included without being referenced in a source file. */, 37 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 38 | "resolveJsonModule": true /* Enable importing .json files */, 39 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 40 | 41 | /* JavaScript Support */ 42 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ 43 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 44 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 45 | 46 | /* Emit */ 47 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 48 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 49 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 50 | "sourceMap": true /* Create source map files for emitted JavaScript files. */, 51 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ 52 | "outDir": "dist" /* Specify an output folder for all emitted files. */, 53 | // "removeComments": true, /* Disable emitting comments. */ 54 | // "noEmit": true, /* Disable emitting files from a compilation. */ 55 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 56 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 57 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 58 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 59 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 60 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 61 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 62 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 63 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 64 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 65 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 66 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 67 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 68 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 69 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 70 | 71 | /* Interop Constraints */ 72 | "isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */, 73 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 74 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, 75 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 76 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 77 | 78 | /* Type Checking */ 79 | "strict": true /* Enable all strict type-checking options. */, 80 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 81 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 82 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 83 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 84 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 85 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 86 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 87 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 88 | // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ 89 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ 90 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 91 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 92 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 93 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 94 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 95 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 96 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 97 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 98 | 99 | /* Completeness */ 100 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 101 | "skipLibCheck": true /* Skip type checking all .d.ts files. */ 102 | }, 103 | "exclude": ["dist", "packages"] 104 | } 105 | -------------------------------------------------------------------------------- /packages/client/vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | 3 | export default defineConfig({ 4 | root: "src", 5 | build: { 6 | outDir: "../dist", 7 | emptyOutDir: true, 8 | sourcemap: true, 9 | assetsInlineLimit: 0, 10 | }, 11 | preview: { 12 | port: 3000, 13 | }, 14 | resolve: { 15 | dedupe: ["proxy-deep"], 16 | }, 17 | optimizeDeps: { 18 | esbuildOptions: { 19 | target: "es2020", 20 | }, 21 | }, 22 | server: { 23 | fs: { 24 | strict: false, 25 | }, 26 | }, 27 | }); 28 | -------------------------------------------------------------------------------- /packages/contracts/.gitignore: -------------------------------------------------------------------------------- 1 | out/ 2 | /cache/ 3 | node_modules/ 4 | .env 5 | bindings/ 6 | artifacts/ 7 | deployments 8 | abi/ 9 | types/ 10 | broadcast/ 11 | src/libraries/LibDeploy.sol -------------------------------------------------------------------------------- /packages/contracts/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "semi": true, 4 | "tabWidth": 2, 5 | "useTabs": false, 6 | "bracketSpacing": true 7 | } 8 | -------------------------------------------------------------------------------- /packages/contracts/.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "rules": { 4 | "compiler-version": ["error", ">=0.8.0"], 5 | "avoid-low-level-calls": "off", 6 | "no-inline-assembly": "off", 7 | "func-visibility": ["warn", { "ignoreConstructors": true }], 8 | "no-empty-blocks": "off", 9 | "no-complex-fallback": "off" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/contracts/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [0.1.7](https://github.com/latticexyz/mud/compare/v0.1.6...v0.1.7) (2022-05-25) 7 | 8 | **Note:** Version bump only for package ri-contracts 9 | 10 | # 0.1.0 (2022-05-23) 11 | 12 | ### Features 13 | 14 | - **contracts:** add contracts reference implementation ([8709568](https://github.com/latticexyz/mud/commit/87095681dcde69b63063ab9ca08587d801f66b7b)) 15 | -------------------------------------------------------------------------------- /packages/contracts/README.md: -------------------------------------------------------------------------------- 1 | # Reference Implementation Contracts 2 | 3 | ### Upgrading Facets 4 | 5 | Run `yarn hardhat:deploy:upgrade` to only upgrade Diamond contracts. 6 | 7 | ### Adding new functions 8 | 9 | When adding new facets or new functions to existing facets, make sure to add the function selectors in `src/test/utils/Deploy.sol`. 10 | -------------------------------------------------------------------------------- /packages/contracts/chainSpec.json: -------------------------------------------------------------------------------- 1 | { 2 | "chainId": 31337, 3 | "rpc": "http://localhost:8545", 4 | "wsRpc": "ws://localhost:8545" 5 | } 6 | -------------------------------------------------------------------------------- /packages/contracts/deploy.json: -------------------------------------------------------------------------------- 1 | { 2 | "components": ["ExampleComponent"], 3 | "systems": [{ "name": "ComponentDevSystem", "writeAccess": ["*"] }] 4 | } 5 | -------------------------------------------------------------------------------- /packages/contracts/exports.sh: -------------------------------------------------------------------------------- 1 | #! usr/bin/bash 2 | ABIS=( 3 | # Add greps to export here 4 | *Component 5 | *System 6 | World 7 | LibQuery 8 | ) 9 | 10 | EXCLUDE=( 11 | # Add files not to export here 12 | Component 13 | IComponent 14 | ) 15 | 16 | for file in ${ABIS[@]}; do 17 | cp out/$file.sol/*.json abi/; 18 | done 19 | 20 | for file in ${EXCLUDE[@]}; do 21 | rm abi/$file.json; 22 | done 23 | -------------------------------------------------------------------------------- /packages/contracts/foundry.toml: -------------------------------------------------------------------------------- 1 | [default] 2 | ffi = false 3 | fuzz_runs = 256 4 | optimizer = true 5 | optimizer_runs = 1000000 6 | verbosity = 1 7 | libs = ["../../node_modules", "../../../mud"] 8 | src = "src" 9 | out = "out" 10 | -------------------------------------------------------------------------------- /packages/contracts/git-install.sh: -------------------------------------------------------------------------------- 1 | #! usr/bin/bash 2 | giturl=https://github.com/$1.git 3 | head=$(git ls-remote $giturl HEAD | head -n1 | awk '{print $1;}') 4 | yarn add $giturl#$head $2 5 | echo "Installed $giturl#$head" -------------------------------------------------------------------------------- /packages/contracts/hardhat.config.ts: -------------------------------------------------------------------------------- 1 | import { HardhatUserConfig } from "hardhat/config"; 2 | 3 | const degen = { 4 | live: true, 5 | url: "https://follower.super-degen-chain.lattice.xyz", 6 | accounts: ["0x26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48"], 7 | chainId: 4242, 8 | }; 9 | 10 | // this is when connecting to a localhost hh instance, it doesn't actually configure the hh network. for this setup stuff in the 'hardhat' key. 11 | const localhost = { 12 | url: "http://localhost:8545/", 13 | accounts: [ 14 | "0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF", 15 | "0x523170AAE57904F24FFE1F61B7E4FF9E9A0CE7557987C2FC034EACB1C267B4AE", 16 | "0x67195c963ff445314e667112ab22f4a7404bad7f9746564eb409b9bb8c6aed32", 17 | ], 18 | chainId: 31337, 19 | }; 20 | 21 | const hardhat = { 22 | initialDate: "1993-11-19", 23 | mining: { 24 | auto: false, 25 | interval: 1000, 26 | }, 27 | gasPrice: 0, 28 | initialBaseFeePerGas: 0, 29 | blockGasLimit: 100_000_000, 30 | accounts: [ 31 | // from/deployer is default the first address in accounts 32 | { 33 | privateKey: "0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF", 34 | balance: "100000000000000000000", 35 | }, 36 | // user1 in tests 37 | { 38 | privateKey: "0x523170AAE57904F24FFE1F61B7E4FF9E9A0CE7557987C2FC034EACB1C267B4AE", 39 | balance: "100000000000000000000", 40 | }, 41 | // user2 in tests 42 | { 43 | privateKey: "0x67195c963ff445314e667112ab22f4a7404bad7f9746564eb409b9bb8c6aed32", 44 | balance: "100000000000000000000", 45 | }, 46 | ], 47 | }; 48 | 49 | const config: HardhatUserConfig = { 50 | defaultNetwork: "hardhat", 51 | networks: { 52 | degen, 53 | localhost, 54 | hardhat, 55 | }, 56 | solidity: { 57 | version: "0.8.13", 58 | settings: { 59 | optimizer: { 60 | enabled: true, 61 | runs: 200, 62 | }, 63 | }, 64 | }, 65 | }; 66 | 67 | export default config; 68 | -------------------------------------------------------------------------------- /packages/contracts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contracts", 3 | "license": "MIT", 4 | "version": "0.2.0", 5 | "private": true, 6 | "scripts": { 7 | "----- DEV -----": "---------------------------", 8 | "prepare": "yarn build && chmod u+x git-install.sh && chmod u+x exports.sh", 9 | "git:install": "bash git-install.sh", 10 | "lint": "yarn prettier && yarn solhint", 11 | "prettier": "prettier --write 'src/**/*.sol'", 12 | "solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix", 13 | "test": "forge test", 14 | "----- BUILD/DEPLOY -----": "---------------------------", 15 | "start": "yarn start:anvil", 16 | "start:hardhat": "run-p -l hardhat:node deploy:hardhat", 17 | "start:anvil": "run-p -l anvil:node deploy:anvil", 18 | "build:force": "yarn codegen && rimraf out && forge build --force && yarn dist && yarn types", 19 | "build": "yarn codegen && forge build && yarn dist && yarn types && mud system-types && cp types/SystemAbis.mts types/SystemAbis.mjs", 20 | "dist": "rimraf abi && mkdir abi && bash exports.sh && rimraf abi/*.metadata.json", 21 | "deploy:anvil": "wait-on tcp:8545 && mud deploy --deployerPrivateKey 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", 22 | "deploy:hardhat": "wait-on tcp:8545 && yarn hardhat:resetfee && mud deploy --deployerPrivateKey 0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF && yarn hardhat:resetfee && yarn types", 23 | "deploy:degen": "mud deploy -i --deployerPrivateKey 0x26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48", 24 | "deploy:prod": "mud deploy --deployerPrivateKey 0x26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48 --chainSpec https://mud-config.pages.dev/chainSpec.json --deployClient --netlifySlug mud --netlifyPersonalToken q49-wyrS2OGAMk60KsCyfyQGD0QgCcjfqKmtiu8RtQc", 25 | "upgrade:anvil": "wait-on tcp:8545 && mud deploy --deployerPrivateKey 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --upgradeSystems", 26 | "upgrade:hardhat": "wait-on tcp:8545 && yarn hardhat:resetfee && mud deploy --deployerPrivateKey 0x044C7963E9A89D4F8B64AB23E02E97B2E00DD57FCB60F316AC69B77135003AEF --upgradeSystems && yarn hardhat:resetfee && yarn types", 27 | "upgrade:degen": "mud deploy -i --deployerPrivateKey 0x26e86e45f6fc45ec6e2ecd128cec80fa1d1505e5507dcd2ae58c3130a7a97b48 --upgradeSystems", 28 | "types": "rimraf types && yarn removebytecode && typechain --target=ethers-v5 abi/*.json && mud system-types", 29 | "anvil:node": "anvil -b 1 --block-base-fee-per-gas 0", 30 | "hardhat:node": "hardhat node", 31 | "hardhat:resetfee": "curl -X POST localhost:8545 -H \"Content-Type: application/json\" --data '{\"jsonrpc\": \"2.0\", \"method\": \"hardhat_setNextBlockBaseFeePerGas\", \"params\": [\"0x0\"], \"id\": 1 }'", 32 | "forge:deploy": "yarn build && forge script ./src/test/utils/BroadcastDeploy.sol --target-contract Deploy -vvv", 33 | "codegen": "yarn ejs src/libraries/LibDeploy.ejs -f deploy.json -o src/libraries/LibDeploy.sol", 34 | "removebytecode": "for i in abi/*; do jq 'del(.bytecode) | del(.deployedBytecode) | del(.ast)' \"$i\" > \"$i\".tmp && mv \"$i\".tmp \"$i\"; done" 35 | }, 36 | "devDependencies": { 37 | "@ethersproject/abi": "^5.7.0", 38 | "@ethersproject/bytes": "^5.7.0", 39 | "@ethersproject/providers": "^5.7.0", 40 | "@latticexyz/cli": "1.5.1", 41 | "@latticexyz/solecs": "1.5.1", 42 | "@latticexyz/std-contracts": "1.5.1", 43 | "@manifoldxyz/royalty-registry-solidity": "https://github.com/manifoldxyz/royalty-registry-solidity.git#c5ad6269d37e180fbf449a1f5ba2d2ff6c441efc", 44 | "@opengsn/contracts": "^2.2.6", 45 | "@rari-capital/solmate": "https://github.com/rari-capital/solmate.git#851ea3baa4327f453da723df75b1093b58b964dc", 46 | "@typechain/ethers-v5": "^9.0.0", 47 | "@types/glob": "^7.2.0", 48 | "@types/node": "^17.0.21", 49 | "base64-sol": "https://github.com/Brechtpd/base64.git#4d85607b18d981acff392d2e99ba654305552a97", 50 | "copyfiles": "^2.4.1", 51 | "ds-test": "https://github.com/dapphub/ds-test.git#c7a36fb236f298e04edf28e2fee385b80f53945f", 52 | "ejs": "^3.1.8", 53 | "ethers": "^5.7.1", 54 | "forge-std": "https://github.com/foundry-rs/forge-std.git#4d36e3f7e2168c8155c641eb0f80e85cd584bd1c", 55 | "glob": "^8.0.3", 56 | "hardhat": "https://gitpkg.now.sh/latticexyz/hardhat/packages/hardhat-core?build", 57 | "memmove": "https://github.com/brockelmore/memmove.git#d577ecd1bc43656f4032edf4daa9797f756a8ad2", 58 | "npm-run-all": "^4.1.5", 59 | "openzeppelin-solidity": "https://github.com/OpenZeppelin/openzeppelin-contracts.git#57725120581e27ec469e1c7e497a4008aafff818", 60 | "prettier": "^2.6.2", 61 | "prettier-plugin-solidity": "^1.0.0-beta.19", 62 | "rimraf": "^3.0.2", 63 | "run-pty": "^3.0.0", 64 | "solhint": "^3.3.7", 65 | "ts-node": "^10.7.0", 66 | "typechain": "^7.0.1", 67 | "typescript": "^4.6.2", 68 | "wait-on": "^6.0.1" 69 | }, 70 | "dependencies": {} 71 | } 72 | -------------------------------------------------------------------------------- /packages/contracts/remappings.txt: -------------------------------------------------------------------------------- 1 | memmove/=../../node_modules/memmove/src/ 2 | gsn=../../node_modules/@opengsn/contracts/src/ 3 | ds-test/=../../node_modules/ds-test/src/ 4 | solmate/=../../node_modules/@rari-capital/solmate/src/ 5 | forge-std/=../../node_modules/forge-std/src/ 6 | solecs/=../../node_modules/@latticexyz/solecs/src/ 7 | royalty-registry/=../../node_modules/@manifoldxyz/royalty-registry-solidity/contracts/ 8 | @openzeppelin/=../../node_modules/openzeppelin-solidity/ 9 | base64/=../../node_modules/base64-sol/ 10 | std-contracts/=../../node_modules/@latticexyz/std-contracts/src/ -------------------------------------------------------------------------------- /packages/contracts/src/components/ExampleComponent.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | import "std-contracts/components/Uint256Component.sol"; 4 | 5 | uint256 constant ID = uint256(keccak256("ember.component.example")); 6 | 7 | contract ExampleComponent is Uint256Component { 8 | constructor(address world) Uint256Component(world, ID) {} 9 | } 10 | -------------------------------------------------------------------------------- /packages/contracts/src/libraries/LibDeploy.ejs: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | // Foundry 5 | import { DSTest } from "ds-test/test.sol"; 6 | import { console } from "forge-std/console.sol"; 7 | import { Cheats } from "../test/utils/Cheats.sol"; 8 | 9 | // Solecs 10 | import { World } from "solecs/World.sol"; 11 | import { Component } from "solecs/Component.sol"; 12 | import { getAddressById } from "solecs/utils.sol"; 13 | import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; 14 | import { ISystem } from "solecs/interfaces/ISystem.sol"; 15 | 16 | // Components 17 | <% components.forEach(component => { -%> 18 | import { <%= component %>, ID as <%= component %>ID } from "../components/<%- component %>.sol"; 19 | <% }); -%> 20 | 21 | // Systems 22 | <% systems.forEach(system => { -%> 23 | import { <%= system.name %>, ID as <%= system.name %>ID } from "../systems/<%- system.name %>.sol"; 24 | <% }); -%> 25 | 26 | struct DeployResult { 27 | World world; 28 | address deployer; 29 | } 30 | 31 | library LibDeploy { 32 | 33 | function deploy( 34 | address _deployer, 35 | address _world, 36 | bool _reuseComponents 37 | ) internal returns (DeployResult memory result) { 38 | result.deployer = _deployer; 39 | 40 | // ------------------------ 41 | // Deploy 42 | // ------------------------ 43 | 44 | // Deploy world 45 | result.world = _world == address(0) ? new World() : World(_world); 46 | if(_world == address(0)) result.world.init(); // Init if it's a fresh world 47 | 48 | // Deploy components 49 | if(!_reuseComponents) { 50 | Component comp; 51 | <% components.forEach(component => { %> 52 | console.log("Deploying <%= component %>"); 53 | comp = new <%= component %>(address(result.world)); 54 | console.log(address(comp)); 55 | <% });%> 56 | } 57 | 58 | deploySystems(address(result.world), true); 59 | } 60 | 61 | 62 | function authorizeWriter(IUint256Component components, uint256 componentId, address writer) internal { 63 | Component(getAddressById(components, componentId)).authorizeWriter(writer); 64 | } 65 | 66 | function deploySystems(address _world, bool init) internal { 67 | World world = World(_world); 68 | // Deploy systems 69 | ISystem system; 70 | IUint256Component components = world.components(); 71 | <% systems.forEach(system => { %> 72 | console.log("Deploying <%= system.name %>"); 73 | system = new <%= system.name %>(world, address(components)); 74 | world.registerSystem(address(system), <%= system.name %>ID); 75 | <% system.writeAccess?.forEach(component => { -%> 76 | <% if(component === "*") { -%> 77 | <% components.forEach(comp=> { -%> 78 | authorizeWriter(components, <%= comp %>ID, address(system)); 79 | <% });-%> 80 | <% } else { -%> 81 | authorizeWriter(components, <%= component %>ID, address(system)); 82 | <% } -%> 83 | <% });-%> 84 | <% if(system.initialize) { -%> 85 | if(init) system.execute(<%= system.initialize -%>); 86 | <% } -%> 87 | console.log(address(system)); 88 | <% });%> 89 | } 90 | } -------------------------------------------------------------------------------- /packages/contracts/src/libraries/TODO.md: -------------------------------------------------------------------------------- 1 | - move deploy scripts to one central location in this folder 2 | - LibDeploy, BroadcastDeploy, Deploy etc 3 | -------------------------------------------------------------------------------- /packages/contracts/src/systems/ComponentDevSystem.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | import "solecs/System.sol"; 4 | import { IWorld } from "solecs/interfaces/IWorld.sol"; 5 | import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; 6 | import { IComponent } from "solecs/interfaces/IComponent.sol"; 7 | import { getAddressById } from "solecs/utils.sol"; 8 | 9 | uint256 constant ID = uint256(keccak256("mudwar.system.ComponentDev")); 10 | 11 | contract ComponentDevSystem is System { 12 | constructor(IWorld _world, address _components) System(_world, _components) {} 13 | 14 | function requirement(bytes memory) public view returns (bytes memory) { 15 | // NOTE: Make sure to not include this system in a production deployment, as anyone can change all component values 16 | } 17 | 18 | function execute(bytes memory arguments) public returns (bytes memory) { 19 | (uint256 componentId, uint256 entity, bytes memory value) = abi.decode(arguments, (uint256, uint256, bytes)); 20 | IComponent c = IComponent(getAddressById(components, componentId)); 21 | if (value.length == 0) { 22 | c.remove(entity); 23 | } else { 24 | c.set(entity, value); 25 | } 26 | } 27 | 28 | function executeTyped( 29 | uint256 componentId, 30 | uint256 entity, 31 | bytes memory value // If value has length 0, the component is removed 32 | ) public returns (bytes memory) { 33 | return execute(abi.encode(componentId, entity, value)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/contracts/src/systems/README.md: -------------------------------------------------------------------------------- 1 | # Systems 2 | 3 | In order to automatically generate system abi and type maps (using `mud system-types`), systems must follow some rules: 4 | 5 | - Systems must implement the `ISystem` interface. 6 | - Systems must declare an ID following this pattern: `uint256 constant ID = uint256(keccak256(""));` 7 | - System contracts must be named exactly the same as the file containing them. 8 | -------------------------------------------------------------------------------- /packages/contracts/src/test/BulkUpload.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | // import { World } from "solecs/World.sol"; 5 | // import { ECSEvent } from "../facets/DebugFacet.sol"; 6 | import { MudTest } from "./MudTest.t.sol"; 7 | 8 | // import { ID as PositionComponentID } from "../components/PositionComponent.sol"; 9 | // import { console } from "forge-std/console.sol"; 10 | 11 | contract BulkUploadTest is MudTest { 12 | // function testInitMap() public { 13 | // uint256 sizeX = 100; 14 | // uint256 sizeY = 100; 15 | // uint256[] memory components = new uint256[](1); 16 | // components[0] = PositionComponentID; 17 | // uint256[] memory entities = new uint256[](sizeX * sizeY); 18 | // ECSEvent[] memory state = new ECSEvent[](sizeX * sizeY); 19 | // for (uint256 y; y < sizeY; y++) { 20 | // for (uint256 x; x < sizeY; x++) { 21 | // uint256 index = y * sizeX + x; 22 | // entities[index] = index; 23 | // state[index] = ECSEvent(0, 0, new bytes(0)); 24 | // } 25 | // } 26 | // debugFacet.bulkSetState(components, entities, state); 27 | // } 28 | } 29 | -------------------------------------------------------------------------------- /packages/contracts/src/test/Deploy.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | import { DSTest } from "ds-test/test.sol"; 5 | import { Utilities } from "./utils/Utilities.sol"; 6 | import { Deploy } from "./utils/Deploy.sol"; 7 | import { Cheats } from "./utils/Cheats.sol"; 8 | 9 | contract DeployTest is DSTest { 10 | Deploy internal deploy = new Deploy(); 11 | 12 | function testDeploy() public { 13 | deploy.deploy(address(0), address(0), false); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/contracts/src/test/MudTest.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | import { DSTest } from "ds-test/test.sol"; 5 | import { World } from "solecs/World.sol"; 6 | import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; 7 | import { Cheats } from "./utils/Cheats.sol"; 8 | import { Utilities } from "./utils/Utilities.sol"; 9 | import { Deploy } from "./utils/Deploy.sol"; 10 | import { componentsComponentId, systemsComponentId } from "solecs/constants.sol"; 11 | import { getAddressById } from "solecs/utils.sol"; 12 | import { console } from "forge-std/console.sol"; 13 | 14 | contract MudTest is DSTest { 15 | Cheats internal immutable vm = Cheats(HEVM_ADDRESS); 16 | Utilities internal immutable utils = new Utilities(); 17 | 18 | address payable internal alice; 19 | address payable internal bob; 20 | address payable internal eve; 21 | address internal deployer; 22 | 23 | World internal world; 24 | IUint256Component components; 25 | IUint256Component systems; 26 | Deploy internal deploy = new Deploy(); 27 | 28 | function component(uint256 id) public view returns (address) { 29 | return getAddressById(components, id); 30 | } 31 | 32 | function system(uint256 id) public view returns (address) { 33 | return getAddressById(systems, id); 34 | } 35 | 36 | function setUp() public { 37 | world = deploy.deploy(address(0), address(0), false); 38 | components = world.components(); 39 | systems = world.systems(); 40 | deployer = deploy.deployer(); 41 | alice = utils.getNextUserAddress(); 42 | bob = utils.getNextUserAddress(); 43 | eve = utils.getNextUserAddress(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /packages/contracts/src/test/systems/GameConfigSystem.t.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | import "../MudTest.t.sol"; 5 | 6 | contract GameConfigSystemTest is MudTest { 7 | function testExecute() public { 8 | vm.startPrank(deployer); 9 | console.log("Depiloyer"); 10 | console.log(deployer); 11 | // GameConfigSystem(system(sysID)).execute(new bytes(0)); 12 | // GameConfigComponent gameConfigComponent = GameConfigComponent(component(compID)); 13 | // assertTrue(gameConfigComponent.getRawValue(GodID).length != 0); 14 | vm.stopPrank(); 15 | } 16 | 17 | function testRequirement() public { 18 | vm.startPrank(deployer); 19 | // GameConfigSystem(system(sysID)).requirement(new bytes(0)); 20 | vm.stopPrank(); 21 | } 22 | 23 | function testFailRequirement() public { 24 | vm.startPrank(alice); 25 | // GameConfigSystem(system(sysID)).requirement(new bytes(0)); 26 | vm.stopPrank(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/contracts/src/test/utils/BroadcastDeploy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | // Foundry 5 | import { DSTest } from "ds-test/test.sol"; 6 | import { Vm } from "forge-std/Vm.sol"; 7 | import { console } from "forge-std/console.sol"; 8 | import { Utilities } from "./Utilities.sol"; 9 | import { Cheats } from "./Cheats.sol"; 10 | 11 | // Libraries 12 | import { LibDeploy, DeployResult } from "../../libraries/LibDeploy.sol"; 13 | 14 | contract Deploy is DSTest { 15 | Cheats internal immutable vm = Cheats(HEVM_ADDRESS); 16 | 17 | function deploy( 18 | address _deployer, 19 | address _world, 20 | bool _reuseComponents 21 | ) public returns (address world, uint256 initialBlockNumber) { 22 | vm.startBroadcast(_deployer); 23 | initialBlockNumber = block.number; 24 | DeployResult memory result = LibDeploy.deploy(_deployer, _world, _reuseComponents); 25 | vm.stopBroadcast(); 26 | world = address(result.world); 27 | } 28 | 29 | function upgradeSystems(address _deployer, address _world) 30 | public 31 | returns (address world, uint256 initialBlockNumber) 32 | { 33 | vm.startBroadcast(_deployer); 34 | initialBlockNumber = block.number; 35 | world = _world; 36 | LibDeploy.deploySystems(_world, false); 37 | vm.stopBroadcast(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/contracts/src/test/utils/Cheats.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | interface Cheats { 5 | // Set block.timestamp (newTimestamp) 6 | function warp(uint256) external; 7 | 8 | // Set block.height (newHeight) 9 | function roll(uint256) external; 10 | 11 | // Set block.basefee (newBasefee) 12 | function fee(uint256) external; 13 | 14 | // Set block.coinbase (who) 15 | function coinbase(address) external; 16 | 17 | // Loads a storage slot from an address (who, slot) 18 | function load(address, bytes32) external returns (bytes32); 19 | 20 | // Stores a value to an address' storage slot, (who, slot, value) 21 | function store( 22 | address, 23 | bytes32, 24 | bytes32 25 | ) external; 26 | 27 | // Signs data, (privateKey, digest) => (v, r, s) 28 | function sign(uint256, bytes32) 29 | external 30 | returns ( 31 | uint8, 32 | bytes32, 33 | bytes32 34 | ); 35 | 36 | // Gets address for a given private key, (privateKey) => (address) 37 | function addr(uint256) external returns (address); 38 | 39 | // Performs a foreign function call via terminal, (stringInputs) => (result) 40 | function ffi(string[] calldata) external returns (bytes memory); 41 | 42 | // Sets the *next* call's msg.sender to be the input address 43 | function prank(address) external; 44 | 45 | // Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called 46 | function startPrank(address) external; 47 | 48 | // Sets the *next* call's msg.sender to be the input address, and the tx.origin to be the second input 49 | function prank(address, address) external; 50 | 51 | // Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called, and the tx.origin to be the second input 52 | function startPrank(address, address) external; 53 | 54 | // Resets subsequent calls' msg.sender to be `address(this)` 55 | function stopPrank() external; 56 | 57 | // Sets an address' balance, (who, newBalance) 58 | function deal(address, uint256) external; 59 | 60 | // Sets an address' code, (who, newCode) 61 | function etch(address, bytes calldata) external; 62 | 63 | // Expects an error on next call 64 | function expectRevert() external; 65 | 66 | function expectRevert(bytes calldata) external; 67 | 68 | function expectRevert(bytes4) external; 69 | 70 | // Record all storage reads and writes 71 | function record() external; 72 | 73 | // Gets all accessed reads and write slot from a recording session, for a given address 74 | function accesses(address) external returns (bytes32[] memory reads, bytes32[] memory writes); 75 | 76 | // Prepare an expected log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData). 77 | // Call this function, then emit an event, then call a function. Internally after the call, we check if 78 | // logs were emitted in the expected order with the expected topics and data (as specified by the booleans). 79 | // Second form also checks supplied address against emitting contract. 80 | function expectEmit( 81 | bool, 82 | bool, 83 | bool, 84 | bool 85 | ) external; 86 | 87 | function expectEmit( 88 | bool, 89 | bool, 90 | bool, 91 | bool, 92 | address 93 | ) external; 94 | 95 | // Mocks a call to an address, returning specified data. 96 | // Calldata can either be strict or a partial match, e.g. if you only 97 | // pass a Solidity selector to the expected calldata, then the entire Solidity 98 | // function will be mocked. 99 | function mockCall( 100 | address, 101 | bytes calldata, 102 | bytes calldata 103 | ) external; 104 | 105 | // Clears all mocked calls 106 | function clearMockedCalls() external; 107 | 108 | // Expect a call to an address with the specified calldata. 109 | // Calldata can either be strict or a partial match 110 | function expectCall(address, bytes calldata) external; 111 | 112 | // Gets the code from an artifact file. Takes in the relative path to the json file 113 | function getCode(string calldata) external returns (bytes memory); 114 | 115 | // Labels an address in call traces 116 | function label(address, string calldata) external; 117 | 118 | // If the condition is false, discard this run's fuzz inputs and generate new ones 119 | function assume(bool) external; 120 | 121 | // Set nonce for an account 122 | function setNonce(address, uint64) external; 123 | 124 | // Get nonce for an account 125 | function getNonce(address) external returns (uint64); 126 | 127 | // Set block.chainid (newChainId) 128 | function chainId(uint256) external; 129 | 130 | // Using the address that deploys the test contract, has the next call (at this call depth only) create a transaction, that can later be signed and sent onchain 131 | function broadcast() external; 132 | 133 | // Has the next call (at this call depth only) create a transaction with the address provided as the sender, that can later be signed and sent onchain 134 | function broadcast(address) external; 135 | 136 | // Has the all subsequent calls (at tis call depth only) create transactions, that can later be signed and sent onchain 137 | function startBroadcast(address) external; 138 | 139 | // Stops generating onchain transactions 140 | function stopBroadcast() external; 141 | } 142 | -------------------------------------------------------------------------------- /packages/contracts/src/test/utils/Deploy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | // TODO: Refactor to use LibDeploy 5 | 6 | // Foundry 7 | import { DSTest } from "ds-test/test.sol"; 8 | import { Vm } from "forge-std/Vm.sol"; 9 | import { console } from "forge-std/console.sol"; 10 | import { Utilities } from "./Utilities.sol"; 11 | import { Cheats } from "./Cheats.sol"; 12 | import { World } from "solecs/World.sol"; 13 | 14 | // Libraries 15 | import { LibDeploy, DeployResult } from "../../libraries/LibDeploy.sol"; 16 | 17 | contract Deploy is DSTest { 18 | Cheats internal immutable vm = Cheats(HEVM_ADDRESS); 19 | Utilities internal immutable utils = new Utilities(); 20 | address public deployer; 21 | World public world; 22 | 23 | function deploy( 24 | address _deployer, 25 | address _world, 26 | bool _reuseComponents 27 | ) public returns (World) { 28 | deployer = _deployer == address(0) ? utils.getNextUserAddress() : _deployer; 29 | vm.startPrank(_deployer); 30 | DeployResult memory result = LibDeploy.deploy(deployer, _world, _reuseComponents); 31 | vm.stopPrank(); 32 | world = result.world; 33 | return world; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/contracts/src/test/utils/Utilities.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Unlicense 2 | pragma solidity >=0.8.0; 3 | 4 | import { DSTest } from "ds-test/test.sol"; 5 | import { Vm } from "forge-std/Vm.sol"; 6 | 7 | //common utilities for forge tests 8 | contract Utilities is DSTest { 9 | Vm internal immutable vm = Vm(HEVM_ADDRESS); 10 | bytes32 internal nextUser = keccak256(abi.encodePacked("user address")); 11 | 12 | function getNextUserAddress() external returns (address payable) { 13 | //bytes32 to address conversion 14 | address payable user = payable(address(uint160(uint256(nextUser)))); 15 | nextUser = keccak256(abi.encodePacked(nextUser)); 16 | return user; 17 | } 18 | 19 | //create users with 100 ether balance 20 | function createUsers(uint256 userNum) external returns (address payable[] memory) { 21 | address payable[] memory users = new address payable[](userNum); 22 | for (uint256 i = 0; i < userNum; i++) { 23 | address payable user = this.getNextUserAddress(); 24 | vm.deal(user, 100 ether); 25 | users[i] = user; 26 | } 27 | return users; 28 | } 29 | 30 | //move block.number forward by a given number of blocks 31 | function mineBlocks(uint256 numBlocks) external { 32 | uint256 targetBlock = block.number + numBlocks; 33 | vm.roll(targetBlock); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/contracts/tsconfig.json: -------------------------------------------------------------------------------- 1 | // Visit https://aka.ms/tsconfig.json for all config options 2 | { 3 | "compilerOptions": { 4 | "target": "ES2020", 5 | "module": "commonjs", 6 | "strict": true, 7 | "resolveJsonModule": true, 8 | "esModuleInterop": true, 9 | "skipLibCheck": true, 10 | "forceConsistentCasingInFileNames": true 11 | } 12 | } --------------------------------------------------------------------------------