1// automatically generated by the FlatBuffers compiler, do not modify 2// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable 3 4library my_game.sample; 5 6import 'dart:typed_data' show Uint8List; 7import 'package:flat_buffers/flat_buffers.dart' as fb; 8 9 10class Color { 11 final int value; 12 const Color._(this.value); 13 14 factory Color.fromValue(int value) { 15 final result = values[value]; 16 if (result == null) { 17 throw StateError('Invalid value $value for bit flag enum Color'); 18 } 19 return result; 20 } 21 22 static Color? _createOrNull(int? value) => 23 value == null ? null : Color.fromValue(value); 24 25 static const int minValue = 0; 26 static const int maxValue = 2; 27 static bool containsValue(int value) => values.containsKey(value); 28 29 static const Color Red = Color._(0); 30 static const Color Green = Color._(1); 31 static const Color Blue = Color._(2); 32 static const Map<int, Color> values = { 33 0: Red, 34 1: Green, 35 2: Blue}; 36 37 static const fb.Reader<Color> reader = _ColorReader(); 38 39 @override 40 String toString() { 41 return 'Color{value: $value}'; 42 } 43} 44 45class _ColorReader extends fb.Reader<Color> { 46 const _ColorReader(); 47 48 @override 49 int get size => 1; 50 51 @override 52 Color read(fb.BufferContext bc, int offset) => 53 Color.fromValue(const fb.Int8Reader().read(bc, offset)); 54} 55 56class EquipmentTypeId { 57 final int value; 58 const EquipmentTypeId._(this.value); 59 60 factory EquipmentTypeId.fromValue(int value) { 61 final result = values[value]; 62 if (result == null) { 63 throw StateError('Invalid value $value for bit flag enum EquipmentTypeId'); 64 } 65 return result; 66 } 67 68 static EquipmentTypeId? _createOrNull(int? value) => 69 value == null ? null : EquipmentTypeId.fromValue(value); 70 71 static const int minValue = 0; 72 static const int maxValue = 1; 73 static bool containsValue(int value) => values.containsKey(value); 74 75 static const EquipmentTypeId NONE = EquipmentTypeId._(0); 76 static const EquipmentTypeId Weapon = EquipmentTypeId._(1); 77 static const Map<int, EquipmentTypeId> values = { 78 0: NONE, 79 1: Weapon}; 80 81 static const fb.Reader<EquipmentTypeId> reader = _EquipmentTypeIdReader(); 82 83 @override 84 String toString() { 85 return 'EquipmentTypeId{value: $value}'; 86 } 87} 88 89class _EquipmentTypeIdReader extends fb.Reader<EquipmentTypeId> { 90 const _EquipmentTypeIdReader(); 91 92 @override 93 int get size => 1; 94 95 @override 96 EquipmentTypeId read(fb.BufferContext bc, int offset) => 97 EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset)); 98} 99 100class Vec3 { 101 Vec3._(this._bc, this._bcOffset); 102 103 static const fb.Reader<Vec3> reader = _Vec3Reader(); 104 105 final fb.BufferContext _bc; 106 final int _bcOffset; 107 108 double get x => const fb.Float32Reader().read(_bc, _bcOffset + 0); 109 double get y => const fb.Float32Reader().read(_bc, _bcOffset + 4); 110 double get z => const fb.Float32Reader().read(_bc, _bcOffset + 8); 111 112 @override 113 String toString() { 114 return 'Vec3{x: $x, y: $y, z: $z}'; 115 } 116} 117 118class _Vec3Reader extends fb.StructReader<Vec3> { 119 const _Vec3Reader(); 120 121 @override 122 int get size => 12; 123 124 @override 125 Vec3 createObject(fb.BufferContext bc, int offset) => 126 Vec3._(bc, offset); 127} 128 129class Vec3Builder { 130 Vec3Builder(this.fbBuilder); 131 132 final fb.Builder fbBuilder; 133 134 int finish(double x, double y, double z) { 135 fbBuilder.putFloat32(z); 136 fbBuilder.putFloat32(y); 137 fbBuilder.putFloat32(x); 138 return fbBuilder.offset; 139 } 140 141} 142 143class Vec3ObjectBuilder extends fb.ObjectBuilder { 144 final double _x; 145 final double _y; 146 final double _z; 147 148 Vec3ObjectBuilder({ 149 required double x, 150 required double y, 151 required double z, 152 }) 153 : _x = x, 154 _y = y, 155 _z = z; 156 157 /// Finish building, and store into the [fbBuilder]. 158 @override 159 int finish(fb.Builder fbBuilder) { 160 fbBuilder.putFloat32(_z); 161 fbBuilder.putFloat32(_y); 162 fbBuilder.putFloat32(_x); 163 return fbBuilder.offset; 164 } 165 166 /// Convenience method to serialize to byte list. 167 @override 168 Uint8List toBytes([String? fileIdentifier]) { 169 final fbBuilder = fb.Builder(deduplicateTables: false); 170 fbBuilder.finish(finish(fbBuilder), fileIdentifier); 171 return fbBuilder.buffer; 172 } 173} 174class Monster { 175 Monster._(this._bc, this._bcOffset); 176 factory Monster(List<int> bytes) { 177 final rootRef = fb.BufferContext.fromBytes(bytes); 178 return reader.read(rootRef, 0); 179 } 180 181 static const fb.Reader<Monster> reader = _MonsterReader(); 182 183 final fb.BufferContext _bc; 184 final int _bcOffset; 185 186 Vec3? get pos => Vec3.reader.vTableGetNullable(_bc, _bcOffset, 4); 187 int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150); 188 int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100); 189 String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10); 190 List<int>? get inventory => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14); 191 Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2)); 192 List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18); 193 EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20)); 194 dynamic get equipped { 195 switch (equippedType?.value) { 196 case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22); 197 default: return null; 198 } 199 } 200 List<Vec3>? get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGetNullable(_bc, _bcOffset, 24); 201 202 @override 203 String toString() { 204 return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, weapons: $weapons, equippedType: $equippedType, equipped: $equipped, path: $path}'; 205 } 206} 207 208class _MonsterReader extends fb.TableReader<Monster> { 209 const _MonsterReader(); 210 211 @override 212 Monster createObject(fb.BufferContext bc, int offset) => 213 Monster._(bc, offset); 214} 215 216class MonsterBuilder { 217 MonsterBuilder(this.fbBuilder); 218 219 final fb.Builder fbBuilder; 220 221 void begin() { 222 fbBuilder.startTable(10); 223 } 224 225 int addPos(int offset) { 226 fbBuilder.addStruct(0, offset); 227 return fbBuilder.offset; 228 } 229 int addMana(int? mana) { 230 fbBuilder.addInt16(1, mana); 231 return fbBuilder.offset; 232 } 233 int addHp(int? hp) { 234 fbBuilder.addInt16(2, hp); 235 return fbBuilder.offset; 236 } 237 int addNameOffset(int? offset) { 238 fbBuilder.addOffset(3, offset); 239 return fbBuilder.offset; 240 } 241 int addInventoryOffset(int? offset) { 242 fbBuilder.addOffset(5, offset); 243 return fbBuilder.offset; 244 } 245 int addColor(Color? color) { 246 fbBuilder.addInt8(6, color?.value); 247 return fbBuilder.offset; 248 } 249 int addWeaponsOffset(int? offset) { 250 fbBuilder.addOffset(7, offset); 251 return fbBuilder.offset; 252 } 253 int addEquippedType(EquipmentTypeId? equippedType) { 254 fbBuilder.addUint8(8, equippedType?.value); 255 return fbBuilder.offset; 256 } 257 int addEquippedOffset(int? offset) { 258 fbBuilder.addOffset(9, offset); 259 return fbBuilder.offset; 260 } 261 int addPathOffset(int? offset) { 262 fbBuilder.addOffset(10, offset); 263 return fbBuilder.offset; 264 } 265 266 int finish() { 267 return fbBuilder.endTable(); 268 } 269} 270 271class MonsterObjectBuilder extends fb.ObjectBuilder { 272 final Vec3ObjectBuilder? _pos; 273 final int? _mana; 274 final int? _hp; 275 final String? _name; 276 final List<int>? _inventory; 277 final Color? _color; 278 final List<WeaponObjectBuilder>? _weapons; 279 final EquipmentTypeId? _equippedType; 280 final dynamic _equipped; 281 final List<Vec3ObjectBuilder>? _path; 282 283 MonsterObjectBuilder({ 284 Vec3ObjectBuilder? pos, 285 int? mana, 286 int? hp, 287 String? name, 288 List<int>? inventory, 289 Color? color, 290 List<WeaponObjectBuilder>? weapons, 291 EquipmentTypeId? equippedType, 292 dynamic equipped, 293 List<Vec3ObjectBuilder>? path, 294 }) 295 : _pos = pos, 296 _mana = mana, 297 _hp = hp, 298 _name = name, 299 _inventory = inventory, 300 _color = color, 301 _weapons = weapons, 302 _equippedType = equippedType, 303 _equipped = equipped, 304 _path = path; 305 306 /// Finish building, and store into the [fbBuilder]. 307 @override 308 int finish(fb.Builder fbBuilder) { 309 final int? nameOffset = _name == null ? null 310 : fbBuilder.writeString(_name!); 311 final int? inventoryOffset = _inventory == null ? null 312 : fbBuilder.writeListUint8(_inventory!); 313 final int? weaponsOffset = _weapons == null ? null 314 : fbBuilder.writeList(_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList()); 315 final int? equippedOffset = _equipped?.getOrCreateOffset(fbBuilder); 316 final int? pathOffset = _path == null ? null 317 : fbBuilder.writeListOfStructs(_path!); 318 fbBuilder.startTable(10); 319 if (_pos != null) { 320 fbBuilder.addStruct(0, _pos!.finish(fbBuilder)); 321 } 322 fbBuilder.addInt16(1, _mana); 323 fbBuilder.addInt16(2, _hp); 324 fbBuilder.addOffset(3, nameOffset); 325 fbBuilder.addOffset(5, inventoryOffset); 326 fbBuilder.addInt8(6, _color?.value); 327 fbBuilder.addOffset(7, weaponsOffset); 328 fbBuilder.addUint8(8, _equippedType?.value); 329 fbBuilder.addOffset(9, equippedOffset); 330 fbBuilder.addOffset(10, pathOffset); 331 return fbBuilder.endTable(); 332 } 333 334 /// Convenience method to serialize to byte list. 335 @override 336 Uint8List toBytes([String? fileIdentifier]) { 337 final fbBuilder = fb.Builder(deduplicateTables: false); 338 fbBuilder.finish(finish(fbBuilder), fileIdentifier); 339 return fbBuilder.buffer; 340 } 341} 342class Weapon { 343 Weapon._(this._bc, this._bcOffset); 344 factory Weapon(List<int> bytes) { 345 final rootRef = fb.BufferContext.fromBytes(bytes); 346 return reader.read(rootRef, 0); 347 } 348 349 static const fb.Reader<Weapon> reader = _WeaponReader(); 350 351 final fb.BufferContext _bc; 352 final int _bcOffset; 353 354 String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 4); 355 int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 0); 356 357 @override 358 String toString() { 359 return 'Weapon{name: $name, damage: $damage}'; 360 } 361} 362 363class _WeaponReader extends fb.TableReader<Weapon> { 364 const _WeaponReader(); 365 366 @override 367 Weapon createObject(fb.BufferContext bc, int offset) => 368 Weapon._(bc, offset); 369} 370 371class WeaponBuilder { 372 WeaponBuilder(this.fbBuilder); 373 374 final fb.Builder fbBuilder; 375 376 void begin() { 377 fbBuilder.startTable(2); 378 } 379 380 int addNameOffset(int? offset) { 381 fbBuilder.addOffset(0, offset); 382 return fbBuilder.offset; 383 } 384 int addDamage(int? damage) { 385 fbBuilder.addInt16(1, damage); 386 return fbBuilder.offset; 387 } 388 389 int finish() { 390 return fbBuilder.endTable(); 391 } 392} 393 394class WeaponObjectBuilder extends fb.ObjectBuilder { 395 final String? _name; 396 final int? _damage; 397 398 WeaponObjectBuilder({ 399 String? name, 400 int? damage, 401 }) 402 : _name = name, 403 _damage = damage; 404 405 /// Finish building, and store into the [fbBuilder]. 406 @override 407 int finish(fb.Builder fbBuilder) { 408 final int? nameOffset = _name == null ? null 409 : fbBuilder.writeString(_name!); 410 fbBuilder.startTable(2); 411 fbBuilder.addOffset(0, nameOffset); 412 fbBuilder.addInt16(1, _damage); 413 return fbBuilder.endTable(); 414 } 415 416 /// Convenience method to serialize to byte list. 417 @override 418 Uint8List toBytes([String? fileIdentifier]) { 419 final fbBuilder = fb.Builder(deduplicateTables: false); 420 fbBuilder.finish(finish(fbBuilder), fileIdentifier); 421 return fbBuilder.buffer; 422 } 423} 424