Skip to content

Commit

Permalink
feat: new systems pattern (#63)
Browse files Browse the repository at this point in the history
* feat: add systems interface, systemsComponent, registerSystem

* chore: clean up

* feat: add client mappings for componentComponent, systemComponent

* fix: fix hot reloading react

* feat: wip MoveSystem

* feat: remove diamond

* feat: add createSystemExecutor

* feat: autogenerate system abis and types

* refactor: move from facets to systems, remove persona

* refactor: integrate LibStamina, GameConfigSystem

* chore: clean up

* refactor: port LibECS

* refactor: split up DebugFacets into ComponentDevSystem and BulkUploadSystem

* chore: remove unused params from deploy script

* fix: self review

* fix: remove unused console log in Component.sol

Co-authored-by: Andy Cernera <kooshaba@gmail.com>

* build(cli): gitignore build files, build on prepare

* fix: typos

Co-authored-by: Andy Cernera <kooshaba@gmail.com>
  • Loading branch information
alvrs and Kooshaba committed Jul 8, 2022
1 parent 1d93ed7 commit fb6197b
Show file tree
Hide file tree
Showing 116 changed files with 1,410 additions and 3,075 deletions.
1 change: 1 addition & 0 deletions packages/cli/.gitignore
@@ -0,0 +1 @@
build
15 changes: 0 additions & 15 deletions packages/cli/build/cli.js

This file was deleted.

47 changes: 0 additions & 47 deletions packages/cli/build/commands/create.js

This file was deleted.

413 changes: 0 additions & 413 deletions packages/cli/build/commands/deploy.js

This file was deleted.

56 changes: 0 additions & 56 deletions packages/cli/build/commands/diamond-abi.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/cli/build/commands/hello.js

This file was deleted.

48 changes: 0 additions & 48 deletions packages/cli/build/utils.js

This file was deleted.

11 changes: 5 additions & 6 deletions packages/cli/package.json
Expand Up @@ -13,11 +13,9 @@
"directory": "packages/cli"
},
"scripts": {
"prepare": "chmod u+x build/cli.js",
"globalinstall": "yarn build && yarn prepare && yarn link && yarn global add @latticexyz/cli@link:./",
"build": "rimraf build && tsc -p . && yarn prepare",
"start": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/cli.ts",
"link:bin": "export PATH=\"$(yarn global bin):$PATH\""
"prepare": "yarn build",
"globalinstall": "yarn build && yarn prepare && npm link",
"build": "rimraf build && tsc -p . && chmod u+x build/cli.js"
},
"devDependencies": {
"@types/clear": "^0.1.2",
Expand Down Expand Up @@ -50,7 +48,8 @@
"openurl": "^1.1.1",
"path": "^0.12.7",
"uuid": "^8.3.2",
"yargs": "^17.5.1"
"yargs": "^17.5.1",
"typechain": "^8.1.0"
},
"pkg": {
"scripts": "build/**/*.js"
Expand Down
97 changes: 20 additions & 77 deletions packages/cli/src/commands/deploy.ts
Expand Up @@ -23,11 +23,8 @@ interface Options {
chainSpec?: string;
chainId?: number;
rpc?: string;
personaMirror?: string;
personaAllMinter?: string;
persona?: string;
wsRpc?: string;
world?: string;
diamond?: string;
reuseComponents?: boolean;
deployerPrivateKey?: string;
deployClient?: boolean;
Expand All @@ -45,11 +42,8 @@ export const builder: CommandBuilder<Options, Options> = (yargs) =>
chainSpec: { type: "string" },
chainId: { type: "number" },
rpc: { type: "string" },
personaMirror: { type: "string" },
persona: { type: "string" },
personaAllMinter: { type: "string" },
wsRpc: { type: "string" },
world: { type: "string" },
diamond: { type: "string" },
reuseComponents: { type: "boolean" },
deployerPrivateKey: { type: "string" },
deployClient: { type: "boolean" },
Expand Down Expand Up @@ -107,6 +101,7 @@ const getDeployInfo: (args: Arguments<Options>) => Promise<Options> = async (arg
chainSpec: "chainSpec.json",
chainId: 31337,
rpc: "http://localhost:8545",
wsRpc: "ws://localhost:8545",
reuseComponents: false,
deployClient: false,
clientUrl: "http://localhost:3000",
Expand All @@ -128,6 +123,13 @@ const getDeployInfo: (args: Arguments<Options>) => Promise<Options> = async (arg
message: "Provide a chainId for the deployment",
when: (answers) => answers.chainSpec == null && args.chainId == null && config.chainSpec == null,
},
{
type: "input",
name: "wsRpc",
default: defaultOptions.wsRpc,
message: "Provide a WebSocket RPC endpoint for your deployment",
when: (answers) => answers.chainSpec == null && args.wsRpc == null && config.wsRpc == null,
},
{
type: "input",
name: "rpc",
Expand All @@ -139,49 +141,6 @@ const getDeployInfo: (args: Arguments<Options>) => Promise<Options> = async (arg
return "Invalid URL";
},
},
{
type: "input",
name: "personaMirror",
message:
"Provide the address of an existing PersonaMirror contract. (If none is given, PersonaMirror will be deployed.)",
when: (answers) => answers.chainSpec == null && args.personaMirror == null && config.personaMirror == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42)) return true;
return "Invalid address";
},
},
{
type: "input",
name: "persona",
message: "Provide the address of an existing Persona contract. (If none is given, Persona will be deployed.)",
when: (answers) => answers.chainSpec == null && args.persona == null && config.persona == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42)) return true;
return "Invalid address";
},
},
{
type: "input",
name: "personaAllMinter",
message:
"Provide the address of an existing PersonaAllMinter contract. (If none is given, PersonaAllMinter will be deployed.)",
when: (answers) => answers.chainSpec == null && args.persona == null && config.persona == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42)) return true;
return "Invalid address";
},
},
{
type: "input",
name: "diamond",
message:
"Provide the address of an existing Diamond contract that should be updated. (If none is given, a new Diamond will be deployed.)",
when: () => args.diamond == null && config.diamond == null,
validate: (i) => {
if (!i || (i[0] == "0" && i[1] == "x" && i.length === 42)) return true;
return "Invalid address";
},
},
{
type: "input",
name: "world",
Expand Down Expand Up @@ -277,16 +236,8 @@ const getDeployInfo: (args: Arguments<Options>) => Promise<Options> = async (arg
chainSpec: args.chainSpec ?? config.chainSpec ?? answers.chainSpec ?? defaultOptions.chainSpec,
chainId: args.chainId ?? chainSpec?.chainId ?? config.chainId ?? answers.chainId ?? defaultOptions.chainId,
rpc: args.rpc ?? chainSpec?.rpc ?? config.rpc ?? answers.rpc ?? defaultOptions.rpc,
personaMirror:
args.personaMirror ?? chainSpec?.personaMirrorAddress ?? config.personaMirror ?? answers.personaMirror,
personaAllMinter:
args.personaAllMinter ??
chainSpec?.personaAllMinterAddress ??
config.personaAllMinter ??
answers.personaAllMinter,
persona: args.persona ?? chainSpec?.personaAddress ?? config.persona ?? answers.persona,
wsRpc: args.wsRpc ?? chainSpec?.wsRpc ?? config.wsRpc ?? answers.wsRpc ?? defaultOptions.wsRpc,
world: args.world ?? chainSpec?.world ?? config.world ?? answers.world,
diamond: args.diamond ?? config.diamond ?? answers.diamond,
reuseComponents:
args.reuseComponents ?? config.reuseComponents ?? answers.reuseComponents ?? defaultOptions.reuseComponents,
deployerPrivateKey: args.deployerPrivateKey ?? config.deployerPrivateKey ?? answers.deployerPrivateKey,
Expand Down Expand Up @@ -318,7 +269,7 @@ export const deploy = async (options: Options) => {
const id = v4().substring(0, 6);

let launcherUrl;
let gameContractAddress;
let worldAddress;

try {
const tasks = new Listr([
Expand All @@ -337,10 +288,8 @@ export const deploy = async (options: Options) => {
"--private-keys",
wallet.privateKey,
"--sig",
"deployEmber(address,address,address,address,bool)",
"deployEmber(address,address,bool)",
wallet.address,
options.personaMirror || constants.AddressZero,
options.diamond || constants.AddressZero,
options.world || constants.AddressZero,
options.reuseComponents ? "true" : "false",
"--fork-url",
Expand All @@ -350,12 +299,8 @@ export const deploy = async (options: Options) => {
const { stdout } = await child;
const lines = stdout.split("\n");

ctx.gameContractAddress = gameContractAddress = findLog(lines, "diamond: address");
ctx.personaAddress = findLog(lines, "persona: address");
ctx.personaMirrorAddress = findLog(lines, "personaMirror: address");
ctx.personaAllMinterAddress = findLog(lines, "personaAllMinter: address");

task.output = chalk.yellow(`Game deployed at: ${chalk.bgYellow.black(gameContractAddress)}`);
ctx.worldAddress = worldAddress = findLog(lines, "world: address");
task.output = chalk.yellow(`World deployed at: ${chalk.bgYellow.black(ctx.worldAddress)}`);
},
options: { bottomBar: 3 },
},
Expand Down Expand Up @@ -420,13 +365,11 @@ export const deploy = async (options: Options) => {
title: "Open Launcher",
task: async (ctx) => {
const clientUrl = options.deployClient ? ctx.clientUrl : options.clientUrl;
launcherUrl = `https://play.lattice.xyz?address=${
ctx.gameContractAddress || ""
}&personaMirrorAddress=${ctx.personaMirrorAddress || ""}&personaAddress=${
options.persona || ctx.personaAddress || ""
}&personaAllMinterAddress=${options.personaAllMinter || ctx.personaAllMinterAddress || ""}&client=${
launcherUrl = `https://play.lattice.xyz?worldAddress=${ctx.worldAddress || ""}&client=${
clientUrl || ""
}&rpc=${options.rpc || ""}&chainId=${options.chainId || ""}&dev=${options.chainId === 31337 || ""}`;
}&rpc=${options.rpc || ""}&wsRpc=${options.wsRpc || ""}&chainId=${options.chainId || ""}&dev=${
options.chainId === 31337 || ""
}`;
openurl.open(launcherUrl);
},
options: { bottomBar: 3 },
Expand All @@ -440,7 +383,7 @@ export const deploy = async (options: Options) => {
await tasks.run();
console.log(chalk.bgGreen.black.bold(" Congratulations! Deployment successful"));
console.log();
console.log(chalk.green(`Contract deployed to ${gameContractAddress}`));
console.log(chalk.green(`World address ${worldAddress}`));
console.log(chalk.green(`Open launcher at ${launcherUrl}`));
console.log();
} catch (e) {
Expand Down

0 comments on commit fb6197b

Please sign in to comment.