def handle_tile_layer(layer: minidom.Node, builder: flatbuffers.Builder) -> int: width = int(layer.getAttribute('width')) height = int(layer.getAttribute('height')) tilewidth = float(layer.parentNode.getAttribute('tilewidth')) tileheight = float(layer.parentNode.getAttribute('tileheight')) dataNode = layer.getElementsByTagName('data')[0] if dataNode.firstChild is None: return dataString = dataNode.firstChild.nodeValue rows = dataString.splitlines() data = [] for row in rows: for tile in row.split(','): if tile == '': continue data.append(int(tile)) FlatBuffGenerated.Tilelayer.TilelayerStartTiledataVector( builder, len(data)) for tile in reversed(data): builder.PrependInt16(tile) dataOffset = builder.EndVector(len(data)) FlatBuffGenerated.Tilelayer.TilelayerStart(builder) FlatBuffGenerated.Tilelayer.TilelayerAddWidth(builder, width) FlatBuffGenerated.Tilelayer.TilelayerAddHeight(builder, height) tilesize = FlatBuffGenerated.Vec2.CreateVec2(builder, tilewidth, tileheight) FlatBuffGenerated.Tilelayer.TilelayerAddTilesize(builder, tilesize) FlatBuffGenerated.Tilelayer.TilelayerAddTiledata(builder, dataOffset) return FlatBuffGenerated.Tilelayer.TilelayerEnd(builder)
def _serialise_shortarray(builder: flatbuffers.Builder, data: np.ndarray, source: int): ArrayShortStartValueVector(builder, len(data)) for single_value in reversed(data): builder.PrependInt16(single_value) array_offset = builder.EndVector(len(data)) ArrayShortStart(builder) ArrayShortAddValue(builder, array_offset) value_position = ArrayShortEnd(builder) LogData.LogDataStart(builder) LogData.LogDataAddSourceName(builder, source) LogData.LogDataAddValue(builder, value_position) LogData.LogDataAddValueType(builder, Value.ArrayShort)