New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new systems pattern #63
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ffd94d2
feat: add systems interface, systemsComponent, registerSystem
alvrs a135d76
chore: clean up
alvrs 35a3a3e
feat: add client mappings for componentComponent, systemComponent
alvrs 262b626
fix: fix hot reloading react
alvrs 59942d9
feat: wip MoveSystem
alvrs 23b0aac
feat: remove diamond
alvrs d410b32
feat: add createSystemExecutor
alvrs 6d86035
feat: autogenerate system abis and types
alvrs 92ac8a7
refactor: move from facets to systems, remove persona
alvrs fcf523d
refactor: integrate LibStamina, GameConfigSystem
alvrs 578eefc
chore: clean up
alvrs 434e405
refactor: port LibECS
alvrs 90ac01b
refactor: split up DebugFacets into ComponentDevSystem and BulkUpload…
alvrs f5d36b2
chore: remove unused params from deploy script
alvrs 96804bd
fix: self review
alvrs ccf07a6
fix: remove unused console log in Component.sol
alvrs 4737c88
build(cli): gitignore build files, build on prepare
alvrs b8ac7cf
fix: typos
alvrs File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handler = exports.builder = exports.desc = exports.command = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const glob_1 = __importDefault(require("glob")); | ||
const utils_1 = require("../utils"); | ||
const IDregex = new RegExp(/(?<=uint256 constant ID = uint256\(keccak256\(")(.*)(?="\))/); | ||
exports.command = "system-types"; | ||
exports.desc = "Generates system type file. Note: assumes ABIs of all systems in ./abi and typechain generated types in ./types/ethers-contracts"; | ||
const builder = (yargs) => yargs.options({ | ||
include: { type: "array" }, | ||
exclude: { type: "array" }, | ||
out: { type: "string" }, | ||
}); | ||
exports.builder = builder; | ||
const handler = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const wd = process.cwd(); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let abis = []; | ||
let systems = []; | ||
let ids = []; | ||
let typePaths = []; | ||
const systemsPath = `${wd}/src/systems/*.sol`; | ||
const [resolve, , promise] = (0, utils_1.deferred)(); | ||
(0, glob_1.default)(systemsPath, {}, (_, matches) => { | ||
systems = matches.map((path) => { | ||
const fragments = path.split("/"); | ||
return fragments[fragments.length - 1].split(".sol")[0]; | ||
}); | ||
ids = matches | ||
.map((path) => fs_1.default.readFileSync(path).toString()) | ||
.map((source, index) => { | ||
const regexResult = IDregex.exec(source); | ||
const id = regexResult && regexResult[0]; | ||
if (!id) { | ||
console.log("Source:", source); | ||
console.log("ID:", id); | ||
console.log("Regex:", IDregex, regexResult); | ||
throw new Error("No ID found for" + | ||
matches[index] + | ||
". Make sure your system source file includes a ID definition (uint256 constant ID = uint256(keccak256(<ID>));)"); | ||
} | ||
return id; | ||
}); | ||
abis = systems.map((system) => `../abi/${system}.json`); | ||
typePaths = systems.map((system) => `./ethers-contracts/${system}.ts`); | ||
resolve(); | ||
}); | ||
// Make the callback synchronous | ||
yield promise; | ||
console.log("Matches", systems); | ||
console.log("Solidity", ids); | ||
console.log("Type paths", typePaths); | ||
console.log("ABIs", abis); | ||
const SystemTypes = `// Autogenerated using mud system-types | ||
${typePaths.map((path, index) => `import { ${systems[index]} } from "${path.replace(".ts", "")}";`).join("\n")} | ||
|
||
export type SystemTypes = { | ||
${systems.map((system, index) => ` "${ids[index]}": ${system};`).join("\n")} | ||
}; | ||
`; | ||
const SystemAbis = `// Autogenerated using mud system-types | ||
${abis.map((path, index) => `import { abi as ${systems[index]} } from "${path}";`).join("\n")} | ||
|
||
export const SystemAbis = { | ||
${systems.map((system, index) => ` "${ids[index]}": ${system},`).join("\n")} | ||
}; | ||
`; | ||
console.log("Generating files:"); | ||
console.log("SystemTypes.ts", SystemTypes); | ||
console.log("SystemAbis.ts", SystemAbis); | ||
fs_1.default.writeFileSync("./types/SystemTypes.ts", SystemTypes); | ||
fs_1.default.writeFileSync("./types/SystemAbis.ts", SystemAbis); | ||
// fs.writeFileSync(out, JSON.stringify({ abi })); | ||
// console.log(`Created diamond abi at ${out}`); | ||
// process.exit(0); | ||
}); | ||
exports.handler = handler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to commit these generated files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Removed them