Prototype Configs

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#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#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#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
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);
}