damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

creating_flatbuffer_schema.tutorial (2242B)


      1 @Tutorial(time: 2) {
      2   @Intro(title: "Creating a schema") {
      3     You will need to have the FlatBuffer compiler to be installed on your device
      4     }
      5     
      6     @Section(title: "Creating a schema") {
      7       @ContentAndMedia {}
      8       @Steps {
      9         @Step {
     10           Start by creating a new empty folder called `monster.fbs`. We want to create a Monster table, that contains
     11           position, color, and basic information about the monster.
     12           @Code(name: "monster.fbs", file: "monster_step_1.fbs")
     13         }
     14         @Step {
     15           We will start by adding our Color object. We will be using an enumerate, to represent this object
     16           @Code(name: "monster.fbs", file: "monster_step_2.fbs")
     17         }
     18         @Step {
     19           We will add a position object and will use a struct to represent that type of data. Where we will need the monsters
     20           x and y positions.
     21           @Code(name: "monster.fbs", file: "monster_step_3.fbs")
     22         }
     23         @Step {
     24           Then we will be creating our Monster object of type table. This will contain the current position of our
     25           monster and its color
     26           @Code(name: "monster.fbs", file: "monster_step_4.fbs")
     27         }
     28         @Step {
     29           Our Monster is missing a name, mana, hp, name, equipped Weapon, weapons, and path. We will be adding these 
     30           fields to our table with a proper data type for each. Example; weapons, and path would be a vector of data.
     31           @Code(name: "monster.fbs", file: "monster_step_5.fbs")
     32         }
     33         @Step {
     34           Now we are missing two data types here, `Weapon` and `Equipment`. And since Equipment can be a weapon, we will be using
     35           a `Union` enumerate that can contain all the equipment that you would want your monster to have. And the weapon can simply
     36           have a name and amount of damage
     37           @Code(name: "monster.fbs", file: "monster_step_6.fbs")
     38         }
     39         @Step {
     40           And to finalize our monster table, we can add a root type of type Monster. 
     41           Then run the command `flatc --swift monster.fbs`
     42           Note: Make sure to import the file to your xcode project.
     43           @Code(name: "monster.fbs", file: "monster_step_7.fbs")
     44         }
     45       }
     46     }
     47   }