Skip to main content

Adding a new Node Type

tip

For troubleshooting go to "help"

Backend (Nakama)

  1. Extend NodeType enum: apps/nakama/src/models/workshop.ts

  2. Implement the node: apps/nakama/src/workshop/nodes/YourNewNode.ts

    class YourNewNode extends DefaultNode {
    constructor(node: WorkshopNode_Default, state: workshop_State, ctx: nkruntime.Context) {
    super(node, state, ctx);
    }

    init(workshop: workshopObject, state: workshop_State, goBack?: boolean): workshop_State {
    // initialization logic
    return state;
    }
    }
  3. Register in the factory switch: apps/nakama/src/workshop/workshop_Info.ts

    case NodeType.YourNewNode:
    tempNodeClass = new YourNewNode(tempNode, state, ctx);
    break;

Frontend (Next.js)

  1. Extend NodeType enum: apps/web/src/models/workshop.ts

  2. Create component: apps/web/src/components/nodes/YourNewNode.tsx

    export default function YourNewNode({ content, isHost }: { content: any; isHost: boolean }) {
    return <div>{/* render your node */}</div>;
    }
  3. Map the node in page switch: apps/web/src/app/workshop/[id]/page.tsx

    case NodeType.YourNewNode:
    return <YourNewNode key={index} content={node.nodeData} isHost={workshop.isHost} />;
  4. Create a sample workshop JSON including your node and test it.