Skip to content

Commit

Permalink
separate configs
Browse files Browse the repository at this point in the history
  • Loading branch information
frolic committed Feb 7, 2025
1 parent 64301f5 commit f38cd84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
37 changes: 24 additions & 13 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineWorld } from "./ts/config/v2/world";

/**
* @internal
*/
export const configInput = {
namespace: "world", // NOTE: this namespace is only used for tables, the core system is deployed in the root namespace.
codegen: {
worldImportPath: "./src",
worldgenDirectory: "interfaces",
worldInterfaceName: "IBaseWorld",
generateSystemLibraries: true,
},
// Ideally we'd use a single multi-namespace config here, but we don't want
// to break imports from this package because the source location changed.
//
// Once we have more nuanced control over source paths and codegen for each
// namespace, then we could probably migrate to multi-namespace config.
//
// Or some way to deeply merge multiple configs while retaining strong types.

/** @internal */
export const tablesConfig = defineWorld({
namespace: "world",
userTypes: {
ResourceId: { filePath: "@latticexyz/store/src/ResourceId.sol", type: "bytes32" },
},
Expand Down Expand Up @@ -111,6 +111,17 @@ export const configInput = {
key: [],
},
},
});

/** @internal */
export const systemsConfig = defineWorld({
namespace: "",
codegen: {
worldImportPath: "./src",
worldgenDirectory: "interfaces",
worldInterfaceName: "IBaseWorld",
generateSystemLibraries: true,
},
systems: {
AccessManagementSystem: {
name: "AccessManagement",
Expand All @@ -135,6 +146,6 @@ export const configInput = {
name: "Registration",
},
},
} as const;
});

export default defineWorld(configInput);
export default tablesConfig;
12 changes: 5 additions & 7 deletions packages/world/ts/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import path from "node:path";
import { resolveConfigPath } from "@latticexyz/config/node";
import { tablegen } from "@latticexyz/store/codegen";
import { defineWorld } from "../config/v2/world";
import { worldgen } from "../node";
import config, { configInput } from "../../mud.config";
import config, { systemsConfig } from "../../mud.config";

/**
* To avoid circular dependencies, we run a very similar `build` step as `cli` package here.
Expand All @@ -17,9 +16,8 @@ const rootDir = path.dirname(configPath);

await Promise.all([
tablegen({ rootDir, config }),
worldgen({
rootDir,
// use root namespace to generate the core system interfaces
config: defineWorld({ ...configInput, namespace: "" }),
}),
// until we get finer-grained control of for namespaces (source path, codegen)
// or being able to merge configs with strong types, we need to use a separate
// config for systems to maintain source locations
worldgen({ rootDir, config: systemsConfig }),
]);

0 comments on commit f38cd84

Please sign in to comment.