Adding a new Node Type
tip
For troubleshooting go to "help"
Backend (Nakama)
-
Extend
NodeTypeenum:apps/nakama/src/models/workshop.ts -
Implement the node:
apps/nakama/src/workshop/nodes/YourNewNode.tsclass 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;
}
} -
Register in the factory switch:
apps/nakama/src/workshop/workshop_Info.tscase NodeType.YourNewNode:
tempNodeClass = new YourNewNode(tempNode, state, ctx);
break;
Frontend (Next.js)
-
Extend
NodeTypeenum:apps/web/src/models/workshop.ts -
Create component:
apps/web/src/components/nodes/YourNewNode.tsxexport default function YourNewNode({ content, isHost }: { content: any; isHost: boolean }) {
return <div>{/* render your node */}</div>;
} -
Map the node in page switch:
apps/web/src/app/workshop/[id]/page.tsxcase NodeType.YourNewNode:
return <YourNewNode key={index} content={node.nodeData} isHost={workshop.isHost} />; -
Create a sample workshop JSON including your node and test it.