Ejemplo n.º 1
0
    def fromelement(cls, maptree, terrainmap=None, tokenmap=None):
        
        # get the size
        esize = maptree.find("size")
        if esize is None:
            raise MapError("A map must have a size")
        else:
            evec = esize[0]
            size = Vector.fromelement(evec)

        # and the origin
        eorigin = maptree.find("origin")
        if eorigin is not None:
            evec = eorigin[0]
            origin = Vector.fromelement(evec) 
        else:
            origin = Vector.ORIGIN

        # and the name, game and copyright
        hm = cls(size, origin)

        # add the terrains
        for eterrain in maptree.findall("terrain"):
            tname = eterrain.get("type")
            if tname in terrainmap:
                terrain = terrainmap[tname].fromelement(eterrain, hm)
                hm.addTerrain(terrain)
            else:
                print "terrain name %s not in terrain map %s" % (tname, terrainmap)

        return hm
Ejemplo n.º 2
0
    def fromelement(cls, eterrain, hm=None):
        logger = logging.getLogger(cls.__name__ + ".fromelement")
        t = cls(eterrain.tag)
        depth = eterrain.get("depth") or 0
        eloclist = eterrain.find("locations")
        if eloclist.get("all") == "true":
            t._locations=map.AllHexes(hm)
        else:
            logger.debug("Not all hexes")
            for eloc in eloclist:
                logger.debug("new location %s" % eloc)
                vloc = Vector.fromelement(eloc)
                t.locations.append(vloc)

            logger.debug("locations: %s" % t.locations)

        return t