Exemplo n.º 1
0
 def load_from_file(self, file):
     source = open(file, 'r')
     loaded_layer_stack = LayerStack(32)
     loaded_layer_stack.del_layer(0)
     for line in source:
         layer_data = line.split("*")
         layer_name = layer_data[0]
         layer_tileset = layer_data[1]
         layer_size = make_tuple(layer_data[2])
         layer_res = int(layer_data[3])
         if layer_data[4][0] == "(":
             layer_grid_data = layer_data[4][0:-2].split("$")
             layer_grid = {}
             for cell in layer_grid_data:
                 kv_pair = cell.split(":")
                 layer_grid[make_tuple(kv_pair[0])] = make_tuple(kv_pair[1])
             loaded_layer = Layer("ts", (1, 1), 32, "seed")
             loaded_layer.grid = layer_grid
             loaded_layer.size = layer_size
             loaded_layer.tileset = layer_tileset
             loaded_layer.grid_res = layer_res
             loaded_layer.name = layer_name
             loaded_layer_stack.grid_resolution = layer_res
         else:
             byte_string = layer_data[4][0:]
             bytes64 = byte_string.encode()
             bytes = base64.b64decode(bytes64)
             fauxfile = io.BytesIO(bytes)
             layer_image = Image.open(fauxfile)
             loaded_layer = ImageLayer(layer_image, layer_tileset,
                                       layer_name, layer_res)
         loaded_layer_stack.stack.append(loaded_layer)
     self.layerlist = loaded_layer_stack
     self.active_layer = 1