1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
@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")
}
}
}
}
|