Setting Up the Cooking Catalogs #
In this section, we’ll define the item catalog, crafting catalog, and associated type definitions.
Define item types with protobufs #
The structure of instanced and stackable items are defined in protobuf files defined by the engine. Custom protobuf definitions can be added to extension (ext
) fields. These are predefined protobuf types that can be modified to extend engine functionality.
Run the following commands in the terminal from the platform
directory:
make skip-tests protos engine
make ext
Edit the inventory content ext file #
- Open
5-ext/ext-protos/src/main/proto/shared/inventoryContentExt.proto
. - Edit
extInstancedSpec
by inserting the following:
message ExtInstancedSpec {
oneof data {
IncompleteFoodSpec incomplete_food_spec = 1;
}
}
- Define an
IncompleteFoodSpec
message belowextInstancedSpec
:
message IncompleteFoodSpec {
}
- Edit
ExtPurchaseRequirements
by inserting the following:
message ExtPurchaseRequirements {
oneof data {
CookingCompleteRequirements cooking_complete_requirements = 1;
}
}
- Define a
CookingCompleteRequirements
message belowExtPurchaseRequirements
:
message CookingCompleteRequirements {
string consumed_catalog_id = 1;
}
- Edit
ExtCraftingEntry
by inserting the following:
message ExtCraftingEntry {
oneof data {
CookingSpec cooking_spec = 1;
CookingCompleteSpec cooking_complete_spec = 2;
}
}
- Define
CookingSpec
andCookingCompleteSpec
messages belowExtCraftingEntry
:
message CookingSpec {
int64 cook_time_in_seconds = 1;
string catalog_id_to_create = 2;
}
message CookingCompleteSpec {
string catalog_id_to_create = 1;
}
Edit the inventory ext file: #
- Open
5-ext/ext-protos/src/main/proto/shared/inventoryExt.proto
. - Edit
ExtInstancedItem
by inserting the following:
message ExtInstancedItem {
oneof data {
IncompleteFood incomplete_food = 2;
}
}
- Create an
IncompleteFood
message belowExtInstancedItem
:
message IncompleteFood {
int64 timestamp_millis = 1;
}
Edit the inventory RPC ext file: #
- Import the following files by adding the following code near the top of the file, next to the existing import(s):
import "shared/inventoryExt.proto";
- Edit
ExtInstancedItemServerGrant
by inserting the following:
message ExtInstancedItemServerGrant {
oneof data {
ext.IncompleteFood incomplete_food = 1;
}
}
Building protos #
Run make ext
using a terminal from the platform
directory.
Define the item catalog #
The ItemCatalog defines shared identifiers and configurations for all game content managed by the platform. This is where designers create player inventory specifications. This section will cover creating instanced and stackable item specs, along with the crafting catalog. Note: The format for the item specs currently requires duplicating the catalogId field as both the key in the dictionary and the value within the object.
Define instanced specs #
Cooking is a two step process. The first step is exchanging flour
, milk
, and eggs
for an incompletePlainMuffin
. This is an instanced item, as the incompletePlainMuffin
has a time stamp stored in the ext
field.
Add to the contents of platform/5-ext/content/src/InstancedSpecs.json
with the following code:
[
{
"catalogId": "incompletePlainMuffin",
"name": "incompletePlainMuffin",
"tags": ["cooking_token"],
"ext": {
"incompleteFoodSpec": {
}
}
}
]
Define stackable item specs #
Stackables are simple items that don’t have custom per-item data. Cooking ingredients and the completed muffin are implemented as stackable items.
Add to the contents of platform/5-ext/content/src/StackableSpecs.json
with the following code:
[
{
"catalogId": "flour",
"name": "flour",
"limit": 10000,
"tags": ["material", "cooking"]
},
{
"catalogId": "milk",
"name": "milk",
"limit": 10000,
"tags": ["material", "cooking"]
},
{
"catalogId": "eggs",
"name": "eggs",
"limit": 10000,
"tags": ["material", "cooking"]
},
{
"catalogId": "plainMuffin",
"name": "plainMuffin",
"limit": 1000,
"tags": ["food"]
}
]
Define the crafting catalog #
The crafting catalog is where all crafting recipes are defined. We have defined each step of the cooking process as individual entries in the crafting catalog.
Add to the contents of platform/5-ext/content/src/5-ext/content/shared/CraftingEntries.json
with the following code:
[
{
"id": "plainMuffinRecipe",
"stackableCostByCatalogId": {
"flour": {
"cost": 10
},
"milk": {
"cost": 1
},
"eggs": {
"cost": 1
}
},
"ext": {
"cookingSpec": {
"cookTimeInSeconds": 3,
"catalogIdToCreate": "incompletePlainMuffin"
}
}
},
{
"id": "completePlainMuffin",
"ext": {
"cookingCompleteSpec": {
"catalogIdToCreate": "plainMuffin"
}
},
"requirements": {
"ext": {
"cookingCompleteRequirements": {
"consumedCatalogId": "incompletePlainMuffin"
}
}
}
}
]
Apply content data #
In order to register the instanced items, stackable items, and store you just defined with Pragma Engine, you must apply your content data changes.
In a terminal with platform
as the working directory, run:
java -jar 5-ext/target/pragma.jar contentdata apply -d 5-ext/content
At the prompt, confirm that you wish to apply content changes.