mirror of
git://jb55.com/damus
synced 2024-09-19 11:43:44 +00:00
48 lines
2.2 KiB
Plaintext
48 lines
2.2 KiB
Plaintext
@Tutorial(time: 2) {
|
|
@Intro(title: "Creating a schema") {
|
|
You will need to have the FlatBuffer compiler to be installed on your device
|
|
}
|
|
|
|
@Section(title: "Creating a schema") {
|
|
@ContentAndMedia {}
|
|
@Steps {
|
|
@Step {
|
|
Start by creating a new empty folder called `monster.fbs`. We want to create a Monster table, that contains
|
|
position, color, and basic information about the monster.
|
|
@Code(name: "monster.fbs", file: "monster_step_1.fbs")
|
|
}
|
|
@Step {
|
|
We will start by adding our Color object. We will be using an enumerate, to represent this object
|
|
@Code(name: "monster.fbs", file: "monster_step_2.fbs")
|
|
}
|
|
@Step {
|
|
We will add a position object and will use a struct to represent that type of data. Where we will need the monsters
|
|
x and y positions.
|
|
@Code(name: "monster.fbs", file: "monster_step_3.fbs")
|
|
}
|
|
@Step {
|
|
Then we will be creating our Monster object of type table. This will contain the current position of our
|
|
monster and its color
|
|
@Code(name: "monster.fbs", file: "monster_step_4.fbs")
|
|
}
|
|
@Step {
|
|
Our Monster is missing a name, mana, hp, name, equipped Weapon, weapons, and path. We will be adding these
|
|
fields to our table with a proper data type for each. Example; weapons, and path would be a vector of data.
|
|
@Code(name: "monster.fbs", file: "monster_step_5.fbs")
|
|
}
|
|
@Step {
|
|
Now we are missing two data types here, `Weapon` and `Equipment`. And since Equipment can be a weapon, we will be using
|
|
a `Union` enumerate that can contain all the equipment that you would want your monster to have. And the weapon can simply
|
|
have a name and amount of damage
|
|
@Code(name: "monster.fbs", file: "monster_step_6.fbs")
|
|
}
|
|
@Step {
|
|
And to finalize our monster table, we can add a root type of type Monster.
|
|
Then run the command `flatc --swift monster.fbs`
|
|
Note: Make sure to import the file to your xcode project.
|
|
@Code(name: "monster.fbs", file: "monster_step_7.fbs")
|
|
}
|
|
}
|
|
}
|
|
}
|