Prototype Configs
Prototype Configuration files in Primodium are used to define the game's configuration data. During our game design and balancing processes, we needed to frequently change game data such as resource prices, building costs, and factory production.
Inspired by Sky Strife's (opens in a new tab) templates, we developed internal scripts to generate Foundry scripts (opens in a new tab) from JSON objects and CSV files with TypeScript scripts. This allows us to quickly iterate between play tests without needing to manually update Solidity contracts.
Prototype Config Data
@primodiumxyz/contracts/config/prototypeConfig.ts
(opens in a new tab): The main configuration file that defines game prototype data in Primodium. For example, the following defines the prototype data forCopperMine
, a building that mines copper on an asteroid.
@primodiumxyz/contracts/config/prototypeConfig.ts#L623-L655
{
// ...
CopperMine: {
tables: {
P_Blueprint: { value: getBlueprint(1, 1) },
P_MaxLevel: { value: 15n },
P_RequiredTile: { value: MUDEnums.EResource.indexOf("Iron") },
},
levels: {
1: { P_RequiredBaseLevel: { value: 1n }, P_Production: getResourceValues({ Copper: 0.09 }) },
2: {
P_RequiredBaseLevel: { value: 1n },
P_RequiredResources: getResourceValues({ Iron: 50, Copper: 100 }),
P_Production: getResourceValues({ Copper: 0.12 }),
},
3: {
P_RequiredBaseLevel: { value: 2n },
P_RequiredResources: getResourceValues({ Iron: 100, Copper: 300 }),
P_Production: getResourceValues({ Copper: 0.15 }),
},
4: {
P_RequiredBaseLevel: { value: 3n },
P_RequiredResources: getResourceValues({ Iron: 200, Copper: 1000 }),
P_Production: getResourceValues({ Copper: 0.18 }),
},
5: {
P_RequiredBaseLevel: { value: 4n },
P_RequiredResources: getResourceValues({ Iron: 400, Copper: 1600 }),
P_Production: getResourceValues({ Copper: 0.23 }),
},
6: {
P_RequiredBaseLevel: { value: 6n },
P_RequiredResources: getResourceValues({ Iron: 4000, Alloy: 1000 }),
P_Production: getResourceValues({ Copper: 0.28 }),
},
// ...
}
@primodiumxyz/contracts/config/enums.ts
(opens in a new tab): Solidity Enums that define each building, resource, units, objectives, and related enumerated prototype data. For example, the following enum describes all resources that can be associated with an asteroid in Primodium.
@primodiumxyz/contracts/config/enums.ts#L39-L65
export enum EResource {
Iron = 1,
Copper,
Lithium,
Titanium,
Iridium,
Kimberlite,
Platinum,
// Crafted Items
IronPlate,
Alloy,
PVCell,
// Utilities
U_Electricity,
U_Housing,
U_MaxFleets,
U_Defense,
U_Unraidable,
U_AdvancedUnraidable,
R_HP,
R_Encryption,
// Multipliers
M_DefenseMultiplier,
}
Prototype Config Scripts
@primodiumxyz/contracts/ts/prototypes/prototypeGenUtils.ts
(opens in a new tab): Utility functions for generating prototype data. For example, thegetResourceValue()
function also referenced above converts a resource key and amount into aEResource
enum and aBigInt
, values that can be written to a Solidity contract.
@primodiumxyz/contracts/ts/prototypes/prototypeGenUtils.ts#L63-L66
export const getResourceValue = (resourceValue: { [x: string]: number }) => {
const [resource, amount] = Object.entries(resourceValue)[0];
return {
resource: MUDEnums.EResource.indexOf(resource),
amount: BigInt(Math.round(amount * SCALE)),
};
};
@primodiumxyz/contracts/config/util/blueprints.ts
(opens in a new tab): Contains the utility functiongetBlueprint()
that takes in a building width and height measured in tiles and returns a building blueprint value stored in theP_Blueprint
prototype table.
@primodiumxyz/contracts/config/util/blueprints.ts
export function getIntArray(coords: { x: number; y: number }[]) {
return coords.reduce((prev: number[], { x, y }) => [...prev, x, y], []);
}
export function getBlueprint(width: number, height: number) {
const blueprint = [];
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
blueprint.push({ x: -x, y: -y });
}
}
return getIntArray(blueprint);
}
@primodiumxyz/contracts/ts/terrain/terraingen.ts
(opens in a new tab): Generates a Foundry script for populating terrain ore distribution, described in detail in the prototype generation example.