Example #1
0
 def parse(self, sexpr):
     self.name = get_value_from_tree(["name", "_"], sexpr, "default")
     self.x_offset = get_value_from_tree(["x-offset", "_"], sexpr, 0)
     self.y_offset = get_value_from_tree(["y-offset", "_"], sexpr, 0)
     # we only parse the first image for now as we don't have support for
     # animation in flexlay anyway
     self.image = get_value_from_tree(["images", "_"], sexpr, 0)
Example #2
0
    def read(self, sexpr, obj):
        self.nodes = []

        sexpr = get_value_from_tree([self.identifier], sexpr, [])
        for node in sexpr:
            if node[0] == 'node':
                x = get_value_from_tree(["x", "_"], node[1:], 0)
                y = get_value_from_tree(["y", "_"], node[1:], 0)
                time = get_value_from_tree(["time", "_"], node[1:], 1)
                self.nodes.append(PathProperty.Node(x, y, time))
            elif node[0] == 'mode':
                if node[1] in PathProperty.Node.mode_values:
                    self.mode = PathProperty.Node.mode_values.index(node[1])
                else:
                    raise RuntimeError("unknown enum value %r" % node[1])
            else:
                raise RuntimeError("unknown tag %r" % node[0])
Example #3
0
 def parse_v2(self, data):
     self.id = get_value_from_tree(["id", "_"], data, "")
     self.version = get_value_from_tree(["version", "_"], data, "")
     self.type = get_value_from_tree(["type", "_"], data, "")
     self.title = get_value_from_tree(["title", "_"], data, "")
     self.author = get_value_from_tree(["author", "_"], data, "")
     self.license = get_value_from_tree(["license", "_"], data, "")
Example #4
0
    def from_file(filename):
        addon = Addon()

        # if filename.endswith(".stwm"):
        #    level.is_worldmap = True
        # else:
        #    level.is_worldmap = False

        # level.filename = filename

        tree = load_lisp(addon.filename, "supertux-addoninfo")
        data = tree[1:]

        addon.id = get_value_from_tree(["id", "_"], data, "")
        addon.version = get_value_from_tree(["version", "_"], data, "")
        addon.type = get_value_from_tree(["type", "_"], data, "")
        addon.title = get_value_from_tree(["title", "_"], data, "")
        addon.author = get_value_from_tree(["author", "_"], data, "")
        addon.license = get_value_from_tree(["license", "_"], data, "")

        # print("VERSION:", level.filename, " ", level.version)

        # if level.version == 1:
        #    raise Exception("version 1 levels not supported at the moment")
        # else:
        #    level.parse_v2(data)

        return addon
Example #5
0
    def from_file(filename):
        level = Level()

        if filename.endswith(".stwm"):
            level.is_worldmap = True
        else:
            level.is_worldmap = False

        level.filename = filename

        tree = load_lisp(level.filename, "supertux-level")
        data = tree[1:]

        level.version = get_value_from_tree(["version", "_"], data, 0)

        # print("VERSION:", level.filename, " ", level.version)

        if level.version == 1:
            raise Exception("version 1 levels not supported at the moment")
        else:
            level.parse_v2(data)

        return level
Example #6
0
    def parse_v2(self, data):
        self.name = get_value_from_tree(["name", "_"], data, "")
        self.author = get_value_from_tree(["author", "_"], data, "")
        self.contact = get_value_from_tree(["contact", "_"], data, "")
        self.license = get_value_from_tree(["license", "_"], data, "")
        self.target_time = get_value_from_tree(["target-time", "_"], data, 0)
        self.tileset_path = get_value_from_tree(["tileset", "_"], data,
                                                os.path.join(
                                                    "images", "tiles.strf"))
        # self.tileset_path = get_value_from_tree(["tileset", "_"], data, "images/tiles.strf")
        # self.tileset_path = os.path.join(Config.current.datadir, self.tileset_path)

        # Check tileset path is somewhat valid
        if len(self.tileset_path) < 1:
            self.tileset_path = os.path.join("images", "tiles.strf")

        # Sort out tileset path beginning with os.sep
        if self.tileset_path[0] == os.sep:
            if len(self.tileset_path) > 1:
                self.tileset_path = self.tileset_path[1:]  # Remove os.sep
            else:
                self.tileset_path = os.path.join(
                    "images", "tiles.strf")  # Reset to default

        self.current_sector = None
        self.sectors = []
        for sec in sexpr_filter("sector", data):
            sector = Sector(self)
            sector.load_v2(sec)
            self.sectors.append(sector)
            if sector.name == "main":
                self.current_sector = sector

        if self.current_sector is None:
            logging.error("Error: No main sector defined: " +
                          str(self.sectors))
            self.current_sector = self.sectors[0]
Example #7
0
    def from_sexpr(data):
        # Load position from path, node and then x, ys
        x = 0
        y = 0
        path = get_value_from_tree(["path"], data, None)
        if path:
            node = get_value_from_tree(["node"], path, None)
            if node:
                x = get_value_from_tree(["x", "_"], node, None)
                y = get_value_from_tree(["y", "_"], node, None)

        name = get_value_from_tree(["name", "_"], data, "")
        z_pos = get_value_from_tree(["z-pos", "_"], data, 0)
        solid = get_value_from_tree(["solid", "_"], data, False)

        result = SuperTuxTileMap(z_pos, solid)

        width = get_value_from_tree(["width", "_"], data, 20)
        height = get_value_from_tree(["height", "_"], data, 15)
        result.draw_target = get_value_from_tree(["draw-target", "_"], data,
                                                 "")
        result.speed = get_value_from_tree(["speed", "_"], data, 1.0)
        result.speed_y = get_value_from_tree(["speed-y", "_"], data, 1.0)
        result.alpha = get_value_from_tree(["alpha", "_"], data, 1.0)

        result.tilemap_layer = TilemapLayer(SuperTuxTileset.current, width,
                                            height)
        result.tilemap_layer.set_data(get_value_from_tree(["tiles"], data, []))
        result.tilemap_layer.metadata = result
        result.pos = Point(x, y)
        result.tilemap_layer.name = name

        return result
Example #8
0
 def read(self, sexpr, obj):
     obj.pos.x = get_value_from_tree(["x", "_"], sexpr, 0.0)
     obj.pos.y = get_value_from_tree(["y", "_"], sexpr, 0.0)
     obj.size.width = get_value_from_tree(["width", "_"], sexpr, 0.0)
     obj.size.height = get_value_from_tree(["height", "_"], sexpr, 0.0)
Example #9
0
 def read(self, sexpr, obj):
     obj.pos.x = get_value_from_tree(["x", "_"], sexpr, 0.0) * 32
     obj.pos.y = get_value_from_tree(["y", "_"], sexpr, 0.0) * 32
Example #10
0
 def read(self, sexpr, obj):
     self.value = get_value_from_tree([self.identifier, "_"], sexpr,
                                      self.default)
Example #11
0
 def read(self, sexpr, obj):
     self.value = Colorf(
         *get_value_from_tree([self.identifier], sexpr, [1.0, 1.0, 1.0]))
Example #12
0
    def load(self, filename):
        logging.info("Loading Tileset: %s" % filename)
        self.filename = filename
        tree = load_lisp(filename, "supertux-tiles")

        tree = tree[1:]

        for i in tree:
            if i[0] == "tiles":
                data = i[1:]
                width = get_value_from_tree(['width', '_'], data, 1)
                # height = get_value_from_tree(['height', '_'], data, 1)
                ids = get_value_from_tree(['ids'], data, [])
                # attributes = get_value_from_tree(['attributes'], data, [])
                image = get_value_from_tree(['image', '_'], data, None)

                if not image:
                    image = get_value_from_tree(['images', '_'], data, None)

                if not image:
                    image = get_value_from_tree(['editor-images', '_'], data, "tiles/auxiliary/notile.png")

                x = 0
                y = 0
                for tile_id in ids:
                    pixelbuffer = PixelBuffer.subregion_from_file(os.path.join(Config.current.datadir, "images", image),
                                                                  x * 32, y * 32, 32, 32)
                    self.add_tile(tile_id, Tile(pixelbuffer))
                    x += 1
                    if x == width:
                        x = 0
                        y += 1

            elif i[0] == "tile":
                data = i[1:]
                tile_id = get_value_from_tree(['id', '_'], data, -1)
                image = get_value_from_tree(['editor-images', '_'], data, False)
                hidden = get_value_from_tree(['hidden', '_'], data, False)

                if not image:
                    image = get_value_from_tree(['images', '_'], data, "tiles/auxiliary/notile.png")

                if isinstance(image, str):
                    pixelbuffer = PixelBuffer.from_file(
                        os.path.join(Config.current.datadir, "images", image))
                elif isinstance(image, list):
                    if image[0] == "region":
                        pixelbuffer = PixelBuffer.subregion_from_file(
                            os.path.join(Config.current.datadir, "images", image[1]),
                            image[2], image[3], image[4], image[5])

                if not hidden:
                    if tile_id == 0 or not pixelbuffer:
                        self.add_tile(tile_id, None)
                    else:
                        self.add_tile(tile_id, Tile(pixelbuffer))

            elif i[0] == "tilegroup":
                data = i[1:]
                name = get_value_from_tree(['name', '_'], data, "Unnamed")
                tiles = get_value_from_tree(['tiles'], data, [])

                if not self.tilegroups:
                    self.tilegroups = []
                self.tilegroups.append(TileGroup(name, tiles))