Пример #1
0
    def parseScenes(self, storyPath):
        dom = xml.dom.minidom.parse(storyPath)
        scenes = dom.getElementsByTagName("scene")
        for x in scenes:
            idscene = x.getAttribute("id")
            fondo = x.getElementsByTagName("background")[0]
            background = fondo.getAttribute("value")
            if len(x.getElementsByTagName("escena_opcion1")) != 0:
                escena_opcion1 = x.getElementsByTagName("escena_opcion1")[0].getAttribute("value")
            if len(x.getElementsByTagName("escena_opcion2")) != 0:
                escena_opcion2 = x.getElementsByTagName("escena_opcion2")[0].getAttribute("value")
            if len(x.getElementsByTagName("escena_opcion3")) != 0:
                escena_opcion3 = x.getElementsByTagName("escena_opcion3")[0].getAttribute("value")
                 
            audio = x.getElementsByTagName("audio")[0].getAttribute("value")
            relato = x.getElementsByTagName("relato")[0].getAttribute("value")
            opciones = x.getElementsByTagName("option")
            parsedOptions = []
            for opcion in opciones:
                print "parsing option"
                optionId = opcion.getAttribute("id")
                optionImage = opcion.getElementsByTagName("image")[0].getAttribute("value")
                optionPosX = opcion.getElementsByTagName("position")[0].getAttribute("x")
                optionPosY = opcion.getElementsByTagName("position")[0].getAttribute("y")
                action_verb = opcion.getElementsByTagName("action")[0].getAttribute("verb")
                action_resource = opcion.getElementsByTagName("action")[0].getAttribute("resource")
                action_x = opcion.getElementsByTagName("action")[0].getAttribute("x")
                action_y = opcion.getElementsByTagName("action")[0].getAttribute("y")
                action_speed = opcion.getElementsByTagName("action")[0].getAttribute("x")
                personajeId = opcion.getElementsByTagName("character")[0].getAttribute("charid")
                act = Action(action_verb,action_resource,action_x,action_y,action_speed)

                newOpt = Option(optionId,optionImage,optionPosX, optionPosY,act,personajeId)
                parsedOptions.append(newOpt)
            scene = Scene(self._surf_display, background, escena_opcion1 , escena_opcion2, escena_opcion3, audio, relato, parsedOptions)
            characters_xml = x.getElementsByTagName("scene_character")
            print "personajes " + str(len(characters_xml))
            for charxml in characters_xml:
                charid = charxml.getAttribute("id")
                print "IdEscena= " + idscene + ". Personaje " + charid
                charx = charxml.getElementsByTagName("position")[0].getAttribute("x")
                chary = charxml.getElementsByTagName("position")[0].getAttribute("y")
                if charid != "guzman":
                    toAdd = Character(charid, self.character_sprites[charid], charx, chary)
                    scene.addCharacter(toAdd)
                    print "[Main] se agrego un personaje a la escena. Personaje " + charid

            print "se creo escena con" + str(len(parsedOptions)) + " opciones"
            self.scenes[idscene] = scene
            self.scenes[self.current_scene].setearDatos(self._surf_display, self.current_scene)
            self.imprimir.setearDatos(self._surf_display)