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