Skip to content

Commit

Permalink
feat(world): export world events, organize TS files (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Oct 10, 2023
1 parent f44eed6 commit 63ea7c3
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "MIT",
"type": "module",
"exports": {
".": "./dist/ts/library/index.js",
".": "./dist/ts/index.js",
"./register": "./dist/ts/register/index.js",
"./node": "./dist/ts/node/index.js",
"./out/*": "./out/*",
Expand All @@ -19,7 +19,7 @@
"typesVersions": {
"*": {
"index": [
"./ts/library/index.ts"
"./ts/index.ts"
],
"register": [
"./ts/register/index.ts"
Expand Down Expand Up @@ -50,6 +50,7 @@
"@latticexyz/config": "workspace:*",
"@latticexyz/schema-type": "workspace:*",
"@latticexyz/store": "workspace:*",
"abitype": "0.9.8",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions packages/world/ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./config/defaults";
export * from "./config/resolveWorldConfig";
export * from "./config/types";
export * from "./config/worldConfig";
export * from "./worldEvents";
4 changes: 0 additions & 4 deletions packages/world/ts/library/config/index.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/world/ts/library/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/world/ts/node/render-solidity/worldgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { formatAndWriteSolidity, contractToInterface, type RelativeImportDatum }
import { StoreConfig } from "@latticexyz/store";
import { renderSystemInterface } from "./renderSystemInterface";
import { renderWorld } from "./renderWorld";
import { resolveWorldConfig, WorldConfig } from "../../library/config";
import { resolveWorldConfig } from "../../config/resolveWorldConfig";
import { WorldConfig } from "../../config/types";

export async function worldgen(
config: StoreConfig & WorldConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/register/configExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extendMUDCoreConfig, fromZodErrorCustom } from "@latticexyz/config";
import { ZodError } from "zod";
import { zPluginWorldConfig } from "../library";
import { zPluginWorldConfig } from "../config/worldConfig";

extendMUDCoreConfig((config) => {
// This function gets called within mudConfig.
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/register/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test } from "vitest";
import { mudConfig } from ".";
import { resolveWorldConfig } from "../library";
import { resolveWorldConfig } from "../config/resolveWorldConfig";

test("resolveWorldConfig requires unique table and system names", () => {
expect(() =>
Expand Down
3 changes: 2 additions & 1 deletion packages/world/ts/register/typeExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { OrDefaults } from "@latticexyz/common/type-utils";
import { MUDCoreUserConfig } from "@latticexyz/config";
import { ExpandSystemsConfig, WorldConfig, WorldUserConfig, WORLD_DEFAULTS } from "../library";

import "@latticexyz/store/register";
import { WORLD_DEFAULTS } from "../config/defaults";
import { WorldUserConfig, WorldConfig, ExpandSystemsConfig } from "../config/types";

// Inject the plugin options into the core config.
// Re-exporting an interface of an existing module merges them, adding new options to the interface.
Expand Down
2 changes: 1 addition & 1 deletion packages/world/ts/scripts/worldgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import path, { basename } from "path";
import { rmSync } from "fs";
import { loadConfig } from "@latticexyz/config/node";
import { getSrcDirectory } from "@latticexyz/common/foundry";
import { WorldConfig } from "../library";
import { worldgen } from "../node";
import { StoreConfig } from "@latticexyz/store";
import { WorldConfig } from "../config/types";

// TODO dedupe this and cli's worldgen command
const configPath = undefined;
Expand Down
33 changes: 33 additions & 0 deletions packages/world/ts/worldEvents.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import IWorldFactoryAbi from "../out/IWorldFactory.sol/IWorldFactory.abi.json";
import IBaseWorldAbi from "../out/IBaseWorld.sol/IBaseWorld.abi.json";
import { helloWorldEvent, worldDeployedEvent } from "./worldEvents";
import { parseAbiItem, AbiEvent } from "abitype";

function normalizeAbiEvent(event: AbiEvent) {
return {
type: event.type,
name: event.name,
inputs: event.inputs.map((input) => ({
type: input.type,
name: input.name,
...(input.indexed ? { indexed: true } : null),
})),
} as const;
}

describe("WorldFactory events", () => {
it("should match the ABI", () => {
const forgeAbiItem = IWorldFactoryAbi.find(
(item) => item.type === "event" && item.name === "WorldDeployed"
) as AbiEvent;
expect(normalizeAbiEvent(parseAbiItem(worldDeployedEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem));
});
});

describe("World events", () => {
it("should match the ABI", () => {
const forgeAbiItem = IBaseWorldAbi.find((item) => item.type === "event" && item.name === "HelloWorld") as AbiEvent;
expect(normalizeAbiEvent(parseAbiItem(helloWorldEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem));
});
});
5 changes: 5 additions & 0 deletions packages/world/ts/worldEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// from WorldFactory
export const worldDeployedEvent = "event WorldDeployed(address indexed newContract)";

// from World
export const helloWorldEvent = "event HelloWorld(bytes32 indexed worldVersion)";
3 changes: 1 addition & 2 deletions packages/world/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
"strict": true,
"skipLibCheck": true
},
"include": ["mud.config.ts", "ts"],
"exclude": ["ts/plugins"]
"include": ["mud.config.ts", "ts"]
}
2 changes: 1 addition & 1 deletion packages/world/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["mud.config.ts", "ts/library/index.ts", "ts/register/index.ts", "ts/node/index.ts"],
entry: ["mud.config.ts", "ts/index.ts", "ts/register/index.ts", "ts/node/index.ts"],
target: "esnext",
format: ["esm"],
dts: false,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 63ea7c3

Please sign in to comment.