Set Up Pragma Engine to Handle Parties #
The first step to building out a game flow is the Party flow, and the first step in getting started with parties is setting up the party protos and building the Party plugin.
As this is a simplified tutorial, we are barely exercising the flexibility that Pragma Engine’s Party plugin brings. See our Party Plugin API reference document to learn more about the other methods.
Build Pragma Engine #
You must have Pragma Engine and its associated
protos
A format for efficiently serializing structured data that's cross-platform and compatible with several languages. built and have a boilerplate 5-ext
project ready.
Run the following command in the terminal from the platform
directory:
make skip-tests protos engine ext
Define party functionality with protobufs #
In your 5-ext/ext-protos/src/main/proto/shared/partyRpcExt.proto
file, edit the following existing messages so that they match the code below:
// ext field for player selection state within a party
message ExtPlayerSelections {
// if your character selection is visible, show it here
party.Character visible_character = 1;
int64 team_number = 2;
}
// request ext field for updating a player selection
message ExtUpdatePlayerSelectionsRequest {
oneof update {
party.Character new_character = 1;
}
}
You only need to edit the proto messages covered in the code block. The other messages in partyRpcExt.proto
should remain unmodified.
While still working in partyRpcExt.proto
, create a new proto enum Character
:
enum Character {
UNSPECIFIED = 0;
KNIGHT = 1;
MAGE = 2;
ROGUE = 3;
}
Build the protos so that they’re available for use when implementing the party plugin by running the following command in the terminal from the platform
directory:
make ext-protos
Create the Party Plugin #
Create a new Kotlin file at the following location: 5-ext/ext/src/main/kotlin/party/GameFlowTutorialPartyPlugin.kt
. Create directories as necessary.
In this file, create a GameFlowTutorialPartyPlugin
class that implements the PartyPlugin
interface, then implement the following methods:
override suspend fun updatePlayer(
playerToUpdate: PartyPlayer,
requestExt: ExtUpdatePlayerSelectionsRequest,
party: Party,
partyConfig: PartyConfig
) {
when (requestExt.updateCase) {
ExtUpdatePlayerSelectionsRequest.UpdateCase.NEW_CHARACTER -> {
setNewCharacterSelection(playerToUpdate, requestExt.newCharacter)
}
else -> {
throw Exception("Invalid update case")
}
}
}
private fun setNewCharacterSelection(
playerToUpdate: PartyPlayer,
character: Character,
) {
val updatedSelections: ExtPlayerSelections.Builder =
playerToUpdate.extPlayerSelections.toBuilder()
updatedSelections.visibleCharacter = character
playerToUpdate.ready =
updatedSelections.visibleCharacter != Character.UNSPECIFIED
playerToUpdate.extPlayerSelections = updatedSelections.build()
}
Now that we’ve finished creating the party plugin, we need to compile both our 5-ext
and the Pragma SDK. Run the following command in a terminal from the platform
directory:
make ext pragma-sdks
Enable the Party Plugin #
We need to edit our configuration file so that the engine knows to use our new party plugin. Edit 5-ext/config/common.yml
by inserting the following configuration:
game:
pluginConfigs:
PartyService.partyPlugin:
class: "party.GameFlowTutorialPartyPlugin"