def __init__(self, game, main_language, score): xml_game_node = game.xml_game_node self.globalvars = game.globalvars # here we create a new game object to play with # thus the original game won't be altered common.Game.__init__(self, self.globalvars, xml_game_node, game.level, score) self.score.enable_count_good() self.score.enable_count_wrong() self.score.enable_record_time() self.xml_game_node = xml_game_node # reading global parameters xml_global_parameters_node = self.xml_game_node.getElementsByTagName( "global_parameters")[0] # first of all, game setup xml_game_setup_node = self.xml_game_node.getElementsByTagName( "game_setup")[0] # possible values for types : # image # image_on_map (only to associate) # text self.type_to_associate = xml_funcs.getText( xml_game_setup_node.getElementsByTagName("type_to_associate")[0]) type_to_drag_node = xml_game_setup_node.getElementsByTagName( "type_to_drag")[0] self.type_to_drag = xml_funcs.getText(type_to_drag_node) sort = type_to_drag_node.getAttribute("sort") if (sort == None): self.sort = False elif (cmp(sort.lower(), "yes") == 0): self.sort = True else: self.sort = False # the min and max amounts of associations (good + bad ones) which will become draggable items self.min_draggable = xml_funcs.getInt( xml_game_setup_node.getElementsByTagName("min_draggable")[0]) self.max_draggable = xml_funcs.getInt( xml_game_setup_node.getElementsByTagName("max_draggable")[0]) item_to_associate_parameters_nodes = xml_global_parameters_node.getElementsByTagName( "item_to_associate") self.item_to_associate_parameters = [] for item_to_associate_parameters_node in item_to_associate_parameters_nodes: self.item_to_associate_parameters.append( xml_funcs.get_box(item_to_associate_parameters_node)) draggable_items_area_nodes = xml_global_parameters_node.getElementsByTagName( "draggable_items_area") self.draggable_items_areas = [] for draggable_items_area_node in draggable_items_area_nodes: spacing_x_nodes = draggable_items_area_node.getElementsByTagName( "spacing_x") spacing_y_nodes = draggable_items_area_node.getElementsByTagName( "spacing_y") if (len(spacing_x_nodes) > 0): spacing_x = xml_funcs.getFloat(spacing_x_nodes[0]) else: spacing_x = 0 if (len(spacing_y_nodes) > 0): spacing_y = xml_funcs.getFloat(spacing_y_nodes[0]) else: spacing_y = 0 draggable_items_area = ( xml_funcs.get_box(draggable_items_area_node), xml_funcs.getInt( draggable_items_area_node.getElementsByTagName("amount_x") [0]), xml_funcs.getInt( draggable_items_area_node.getElementsByTagName("amount_y") [0]), spacing_x, spacing_y) # TODO: make this under each area text_height_nodes = draggable_items_area_node.getElementsByTagName( "font_height") if (len(text_height_nodes) > 0): self.text_height = xml_funcs.getInt(text_height_nodes[0]) else: self.text_height = None self.draggable_items_areas.append(draggable_items_area) # global placeholders where to drag items # only present for non-map associations goal_nodes = xml_global_parameters_node.getElementsByTagName("goal") self.goals = [] for goal_node in goal_nodes: goal = Goal(goal_node) self.goals.append(goal) # space to display text legends text_legend_nodes = xml_global_parameters_node.getElementsByTagName( "text_legend_area") if (len(text_legend_nodes) > 0): self.text_legend_area = xml_funcs.get_box(text_legend_nodes[0]) else: self.text_legend_area = None # Map information (only present if type_to_associate is "on_map") map_nodes = xml_global_parameters_node.getElementsByTagName("map") if (len(map_nodes) > 0): map_node = map_nodes[0] (self.map_pos, self.map_size) = xml_funcs.get_box(map_node) map_filenames = map_node.getElementsByTagName("image") self.map_filename = xml_funcs.getText(map_filenames[0]) # reading associations associations_node = self.xml_game_node.getElementsByTagName( "associations")[0] associations = associations_node.getElementsByTagName("association") self.associations = [] for association_node in associations: association = Association(self) image_nodes = association_node.getElementsByTagName("image") for image_node in image_nodes: if (image_node.parentNode == association_node): # we ignore images which are not direct children # of the association (ie: images inside goal for instance) image_filename = xml_funcs.getText(image_node) if (cmp(image_node.getAttribute("type"), "") == 0): if (cmp(self.type_to_associate, "image") == 0): association.images_to_associate.append( image_filename) if (cmp(self.type_to_drag, "image") == 0): association.images_to_drag.append(image_filename) elif (cmp(image_node.getAttribute("type"), "to_associate") == 0): if ((cmp(self.type_to_associate, "image") == 0) or (cmp(self.type_to_associate, "image_on_map") == 0)): association.images_to_associate.append( image_filename) if (cmp(self.type_to_associate, "image_on_map") == 0): association.image_to_associate_pos_size = xml_funcs.get_box( image_node) else: common.warn( image_filename + " is supposed to be associated, but the game is not supposed to associate images" ) elif (cmp(image_node.getAttribute("type"), "to_drag") == 0): if ((cmp(self.type_to_drag, "image") == 0) or (cmp( self.type_to_associate, "image_on_map") == 0)): association.images_to_drag.append(image_filename) else: common.warn( image_filename + " is supposed to be dragged and dropped, but the game is not supposed to drag an drop images" ) # find potential associated sounds sound_nodes = image_node.getElementsByTagName("sound") for sound_node in sound_nodes: sound_node_lang = sound_node.getAttribute("lang") if ((cmp(sound_node_lang, "") == 0) or (cmp(sound_node_lang, main_language) == 0)): association.append_image_sound( image_filename, xml_funcs.getText(sound_node)) # find potential associated text legends # only texts with no lang tag or with lang tag = main_language are used text_legend_nodes = image_node.getElementsByTagName("text") for text_legend_node in text_legend_nodes: if ((cmp(text_legend_node.getAttribute("lang"), main_language) == 0) or (cmp(text_legend_node.getAttribute("key"), "") != 0)): association.append_image_text_legend( image_filename, xml_funcs.getText(text_legend_node, self.i18n_dict, main_language)) text_nodes = association_node.getElementsByTagName("text") for text_node in text_nodes: if (text_node.parentNode == association_node): text_lang = text_node.getAttribute("lang") text_should_be_added = False if (text_lang == ""): # if no lang attribute defined, the text is included text_should_be_added = True else: # if there is a lang attribute, we add the text only # if this language is the main language if (cmp(text_lang, main_language) == 0): text_should_be_added = True # the text node might be a dictionary key, in this case we also add it : if (cmp(text_node.getAttribute("key"), "") != 0): text_should_be_added = True if (text_should_be_added == True): text = xml_funcs.getText(text_node, self.i18n_dict, main_language) association.texts.append(text) sound_nodes = text_node.getElementsByTagName("sound") for sound_node in sound_nodes: sound_node_lang = sound_node.getAttribute("lang") if ((cmp(sound_node_lang, "") == 0) or (cmp(sound_node_lang, main_language) == 0)): association.append_text_sound( text, xml_funcs.getText(sound_node)) # goals local to only one association goal_nodes = association_node.getElementsByTagName("goal") if (len(goal_nodes) > 0): # TODO : allow for more than a goal ? goal_node = goal_nodes[0] if (cmp(self.type_to_associate, "image_on_map") == 0): goal = Goal(goal_node) # TODO : remove from here ? self.goals.append(goal) # TODO : put more than one goal association.associated_goal = goal else: common.warn( "<goal> found inside an association whereas type to associate is not image_on_map" ) self.associations.append(association) self.associations = common.randomize_list(self.associations)
def __init__(self, game, score): self.globalvars = game.globalvars # creation of a new game common.Game.__init__(self, self.globalvars, game.xml_game_node, game.level, score) self.score.enable_record_time() if (self.xml_game_node != None): # reading global parameters xml_global_parameters_node = self.xml_game_node.getElementsByTagName( "global_parameters")[0] # the amount of identical cards to find self.amount_identical_cards = xml_funcs.getInt( xml_global_parameters_node.getElementsByTagName( "identical_cards")[0]) # Grid setup grid_node = xml_global_parameters_node.getElementsByTagName( "grid")[0] self.grid_box = xml_funcs.get_box(grid_node) self.grid_amount_x = xml_funcs.getInt( grid_node.getElementsByTagName("amount_x")[0]) self.grid_amount_y = xml_funcs.getInt( grid_node.getElementsByTagName("amount_y")[0]) self.amount_different_cards = int( (1.0 * self.grid_amount_x * self.grid_amount_y) / self.amount_identical_cards) if (self.amount_different_cards != round( self.amount_different_cards)): common.error( "the amount of cards is not a multiple of the amount of cards to group" ) raise common.BadXMLException() spacing_x_nodes = grid_node.getElementsByTagName("spacing_x") spacing_y_nodes = grid_node.getElementsByTagName("spacing_y") if (len(spacing_x_nodes) > 0): self.spacing_x = xml_funcs.getFloat(spacing_x_nodes[0]) else: self.spacing_x = 0 if (len(spacing_y_nodes) > 0): self.spacing_y = xml_funcs.getFloat(spacing_y_nodes[0]) else: self.spacing_y = 0 # card setup card_node = xml_global_parameters_node.getElementsByTagName( "card")[0] front_card_node = card_node.getElementsByTagName("front")[0] self.front_card_file = xml_funcs.getText(front_card_node) back_card_node = card_node.getElementsByTagName("back")[0] self.back_card_file = xml_funcs.getText(back_card_node) image_area_nodes = xml_global_parameters_node.getElementsByTagName( "image_area") if (len(image_area_nodes) > 0): image_area_node = image_area_nodes[0] ratio_x_node = image_area_node.getElementsByTagName( "ratio_x")[0] self.ratio_x = xml_funcs.getFloat(ratio_x_node) ratio_y_node = image_area_node.getElementsByTagName( "ratio_y")[0] self.ratio_y = xml_funcs.getFloat(ratio_y_node) else: self.ratio_x = 100.0 self.ratio_y = 100.0 # reading associations # (here, only images with associated sounds are supported) associations_node = self.xml_game_node.getElementsByTagName( "associations")[0] associations = associations_node.getElementsByTagName( "association") self.associations = [] for association_node in associations: association = Association(self) image_nodes = association_node.getElementsByTagName("image") for image_node in image_nodes: image_filename = xml_funcs.getText(image_node) association.images.append(image_filename) sound_nodes = image_node.getElementsByTagName("sound") for sound_node in sound_nodes: association.append_image_sound( image_filename, xml_funcs.getText(sound_node)) self.associations.append(association) if (len(self.associations) < self.amount_different_cards): common.error("The XML file contains " + str(len(self.associations)) + " associations") common.error("But at least " + str(self.amount_different_cards) + " associations are required") raise common.BadXMLException() self.associations = common.randomize_list(self.associations)
def __init__(self) : # default values self.music_on = True self.screen = None self.fonts = None self.force_light = False self.main_language_mode = "system" (self.main_language, self.user_country) = get_user_lang() self.active_languages = copy.copy(constants.supported_languages) self.release = "unknown" self.screen_width = 0 self.screen_height = 0 self.music_volume = constants.music_volume self.congrats_sounds_active = True self.congrats_voices_active = True self.display_igloo = True self.arcade_mode = False self.highscore = True # trying to load options file if available user_options_file = os.path.join(constants.home_dir, constants.user_options_filename) if (os.path.isfile(user_options_file)) : try : xml_data = xml.dom.minidom.parse(user_options_file) # load screen resolution screen_resolution_nodes = xml_data.getElementsByTagName("screen_resolution") if (len(screen_resolution_nodes) > 0) : screen_width_nodes = screen_resolution_nodes[0].getElementsByTagName("width") screen_height_nodes = screen_resolution_nodes[0].getElementsByTagName("height") if ((len(screen_width_nodes) > 0) and (len(screen_height_nodes) > 0)) : width = xml_funcs.getFloat(screen_width_nodes[0]) height = xml_funcs.getFloat(screen_height_nodes[0]) if ((width, height) in pygame.display.list_modes()) : self.screen_width = width self.screen_height = height # load music volume music_volume_nodes = xml_data.getElementsByTagName("music_volume") if (len(music_volume_nodes) > 0) : user_music_volume = xml_funcs.getFloat(music_volume_nodes[0]) if ((user_music_volume >= 0) and (user_music_volume <= 1)) : self.music_volume = user_music_volume # load congratulation sounds mode congrat_sound_nodes = xml_data.getElementsByTagName("congrats_sounds") if (len(congrat_sound_nodes) > 0) : self.congrats_sounds_active = xml_funcs.getBool(congrat_sound_nodes[0].getAttribute("active")) else : self.congrats_sounds_active = True # load congratulation voices mode congrat_voices_nodes = xml_data.getElementsByTagName("congrats_voices") if (len(congrat_voices_nodes) > 0) : self.congrats_voices_active = xml_funcs.getBool(congrat_voices_nodes[0].getAttribute("active")) else : self.congrats_voices_active = True # load display igloo mode igloo_nodes = xml_data.getElementsByTagName("igloo") if (len(igloo_nodes) > 0) : self.display_igloo = xml_funcs.getBool(igloo_nodes[0].getAttribute("display")) # load arcade mode arcade_nodes = xml_data.getElementsByTagName("arcade") if (len(arcade_nodes) > 0) : self.arcade_mode = xml_funcs.getBool(arcade_nodes[0].getAttribute("enabled")) # load default language language_nodes = xml_data.getElementsByTagName("language") if (len(language_nodes) > 0) : main_language = language_nodes[0].getAttribute("default") if (cmp(main_language, "system") != 0) : self.main_language = main_language self.main_language_mode = "user" except Exception, e : error("Can not load user options file ", e, traceback.format_exc())
def __init__(self, game, score) : self.globalvars = game.globalvars # creation of a new game common.Game.__init__(self, self.globalvars, game.xml_game_node, game.level, score) self.score.enable_record_time() if (self.xml_game_node != None) : # reading global parameters xml_global_parameters_node = self.xml_game_node.getElementsByTagName("global_parameters")[0] # the min and max amounts of differences to find self.min_differences = xml_funcs.getInt(xml_global_parameters_node.getElementsByTagName("min_differences")[0]) self.max_differences = xml_funcs.getInt(xml_global_parameters_node.getElementsByTagName("max_differences")[0]) # original image original_node = xml_global_parameters_node.getElementsByTagName("original")[0] self.original_box = xml_funcs.get_box(original_node) original_image_file_node = original_node.getElementsByTagName("image")[0] self.original_image_file = xml_funcs.getText(original_image_file_node) # modified image modified_node = xml_global_parameters_node.getElementsByTagName("modified")[0] self.modified_box = xml_funcs.get_box(modified_node) modified_image_file_node = modified_node.getElementsByTagName("image")[0] self.modified_image_file = xml_funcs.getText(modified_image_file_node) # original image size (useful for resized .light images) image_resolution_nodes = xml_global_parameters_node.getElementsByTagName("image_resolution") if (len(image_resolution_nodes) > 0) : image_resolution_node = image_resolution_nodes[0] self.original_width = float(image_resolution_node.getAttribute("width")) self.original_height = float(image_resolution_node.getAttribute("height")) else : # will be useful in case of an XML file with difference pos and size in percents and not pixels self.original_width = None self.original_height = None # images 'showing' the differences found_nodes = xml_global_parameters_node.getElementsByTagName("found")[0] self.found_file_names = [] found_file_nodes = found_nodes.getElementsByTagName("image") for found_file_node in found_file_nodes : self.found_file_names.append(xml_funcs.getText(found_file_node)) ratio_x_nodes = xml_global_parameters_node.getElementsByTagName("ratio_x") if (len(ratio_x_nodes) > 0) : self.ratio_x = (xml_funcs.getFloat(ratio_x_nodes[0])) / 100.0 else : self.ratio_x = 1.0 ratio_y_nodes = xml_global_parameters_node.getElementsByTagName("ratio_y") if (len(ratio_y_nodes) > 0) : self.ratio_y = (xml_funcs.getFloat(ratio_y_nodes[0])) / 100.0 else : self.ratio_y = 1.0 # reading differences main_differences_node = self.xml_game_node.getElementsByTagName("differences")[0] differences_nodes = main_differences_node.getElementsByTagName("difference") self.differences = [] for difference_node in differences_nodes : difference = Difference(self, difference_node) self.differences.append(difference) if (len(self.differences) < self.max_differences) : common.error("The XML file contains " + str(len(self.differences)) + " differences") common.error("But at least "+self.max_differences + " differences are required") common.error("set up more differences or change the max_differences value") raise common.BadXMLException()
def __init__(self, game, score) : self.globalvars = game.globalvars # creation of a new game common.Game.__init__(self, self.globalvars, game.xml_game_node, game.level, score) self.score.enable_record_time() if (self.xml_game_node != None) : # reading global parameters xml_global_parameters_node = self.xml_game_node.getElementsByTagName("global_parameters")[0] # the amount of identical cards to find self.amount_identical_cards = xml_funcs.getInt(xml_global_parameters_node.getElementsByTagName("identical_cards")[0]) # Grid setup grid_node = xml_global_parameters_node.getElementsByTagName("grid")[0] self.grid_box = xml_funcs.get_box(grid_node) self.grid_amount_x = xml_funcs.getInt(grid_node.getElementsByTagName("amount_x")[0]) self.grid_amount_y = xml_funcs.getInt(grid_node.getElementsByTagName("amount_y")[0]) self.amount_different_cards = int((1.0 * self.grid_amount_x * self.grid_amount_y) / self.amount_identical_cards) if (self.amount_different_cards != round(self.amount_different_cards)) : common.error("the amount of cards is not a multiple of the amount of cards to group") raise common.BadXMLException() spacing_x_nodes = grid_node.getElementsByTagName("spacing_x") spacing_y_nodes = grid_node.getElementsByTagName("spacing_y") if (len(spacing_x_nodes) > 0) : self.spacing_x = xml_funcs.getFloat(spacing_x_nodes[0]) else : self.spacing_x = 0 if (len(spacing_y_nodes) > 0) : self.spacing_y = xml_funcs.getFloat(spacing_y_nodes[0]) else : self.spacing_y = 0 # card setup card_node = xml_global_parameters_node.getElementsByTagName("card")[0] front_card_node = card_node.getElementsByTagName("front")[0] self.front_card_file = xml_funcs.getText(front_card_node) back_card_node = card_node.getElementsByTagName("back")[0] self.back_card_file = xml_funcs.getText(back_card_node) image_area_nodes = xml_global_parameters_node.getElementsByTagName("image_area") if (len(image_area_nodes) > 0) : image_area_node = image_area_nodes[0] ratio_x_node = image_area_node.getElementsByTagName("ratio_x")[0] self.ratio_x = xml_funcs.getFloat(ratio_x_node) ratio_y_node = image_area_node.getElementsByTagName("ratio_y")[0] self.ratio_y = xml_funcs.getFloat(ratio_y_node) else : self.ratio_x = 100.0 self.ratio_y = 100.0 # reading associations # (here, only images with associated sounds are supported) associations_node = self.xml_game_node.getElementsByTagName("associations")[0] associations = associations_node.getElementsByTagName("association") self.associations = [] for association_node in associations : association = Association(self) image_nodes = association_node.getElementsByTagName("image") for image_node in image_nodes : image_filename = xml_funcs.getText(image_node) association.images.append(image_filename) sound_nodes = image_node.getElementsByTagName("sound") for sound_node in sound_nodes : association.append_image_sound(image_filename, xml_funcs.getText(sound_node)) self.associations.append(association) if (len(self.associations) < self.amount_different_cards) : common.error("The XML file contains " + str(len(self.associations)) + " associations") common.error("But at least "+str(self.amount_different_cards) + " associations are required") raise common.BadXMLException() self.associations = common.randomize_list(self.associations)
def __init__(self, game, main_language, score) : xml_game_node = game.xml_game_node self.globalvars = game.globalvars # here we create a new game object to play with # thus the original game won't be altered common.Game.__init__(self, self.globalvars, xml_game_node, game.level, score) self.score.enable_count_good() self.score.enable_count_wrong() self.score.enable_record_time() self.xml_game_node = xml_game_node # reading global parameters xml_global_parameters_node = self.xml_game_node.getElementsByTagName("global_parameters")[0] # first of all, game setup xml_game_setup_node = self.xml_game_node.getElementsByTagName("game_setup")[0] # possible values for types : # image # image_on_map (only to associate) # text self.type_to_associate = xml_funcs.getText(xml_game_setup_node.getElementsByTagName("type_to_associate")[0]) type_to_drag_node = xml_game_setup_node.getElementsByTagName("type_to_drag")[0] self.type_to_drag = xml_funcs.getText(type_to_drag_node) sort = type_to_drag_node.getAttribute("sort") if (sort == None) : self.sort = False elif (cmp(sort.lower(), "yes") == 0) : self.sort = True else : self.sort = False # the min and max amounts of associations (good + bad ones) which will become draggable items self.min_draggable = xml_funcs.getInt(xml_game_setup_node.getElementsByTagName("min_draggable")[0]) self.max_draggable = xml_funcs.getInt(xml_game_setup_node.getElementsByTagName("max_draggable")[0]) item_to_associate_parameters_nodes = xml_global_parameters_node.getElementsByTagName("item_to_associate") self.item_to_associate_parameters = [] for item_to_associate_parameters_node in item_to_associate_parameters_nodes : self.item_to_associate_parameters.append(xml_funcs.get_box(item_to_associate_parameters_node)) draggable_items_area_nodes = xml_global_parameters_node.getElementsByTagName("draggable_items_area") self.draggable_items_areas = [] for draggable_items_area_node in draggable_items_area_nodes : spacing_x_nodes = draggable_items_area_node.getElementsByTagName("spacing_x") spacing_y_nodes = draggable_items_area_node.getElementsByTagName("spacing_y") if (len(spacing_x_nodes) > 0) : spacing_x = xml_funcs.getFloat(spacing_x_nodes[0]) else : spacing_x = 0 if (len(spacing_y_nodes) > 0) : spacing_y = xml_funcs.getFloat(spacing_y_nodes[0]) else : spacing_y = 0 draggable_items_area = (xml_funcs.get_box(draggable_items_area_node), xml_funcs.getInt(draggable_items_area_node.getElementsByTagName("amount_x")[0]), xml_funcs.getInt(draggable_items_area_node.getElementsByTagName("amount_y")[0]), spacing_x, spacing_y) # TODO: make this under each area text_height_nodes = draggable_items_area_node.getElementsByTagName("font_height") if (len(text_height_nodes) > 0) : self.text_height = xml_funcs.getInt(text_height_nodes[0]) else : self.text_height = None self.draggable_items_areas.append(draggable_items_area) # global placeholders where to drag items # only present for non-map associations goal_nodes = xml_global_parameters_node.getElementsByTagName("goal") self.goals = [] for goal_node in goal_nodes : goal = Goal(goal_node) self.goals.append(goal) # space to display text legends text_legend_nodes = xml_global_parameters_node.getElementsByTagName("text_legend_area") if (len(text_legend_nodes) > 0) : self.text_legend_area = xml_funcs.get_box(text_legend_nodes[0]) else : self.text_legend_area = None # Map information (only present if type_to_associate is "on_map") map_nodes = xml_global_parameters_node.getElementsByTagName("map") if (len(map_nodes) > 0) : map_node = map_nodes[0] (self.map_pos, self.map_size) = xml_funcs.get_box(map_node) map_filenames = map_node.getElementsByTagName("image") self.map_filename = xml_funcs.getText(map_filenames[0]) # reading associations associations_node = self.xml_game_node.getElementsByTagName("associations")[0] associations = associations_node.getElementsByTagName("association") self.associations = [] for association_node in associations : association = Association(self) image_nodes = association_node.getElementsByTagName("image") for image_node in image_nodes : if (image_node.parentNode == association_node) : # we ignore images which are not direct children # of the association (ie: images inside goal for instance) image_filename = xml_funcs.getText(image_node) if (cmp(image_node.getAttribute("type"), "") == 0) : if (cmp(self.type_to_associate, "image") == 0) : association.images_to_associate.append(image_filename) if (cmp(self.type_to_drag, "image") == 0) : association.images_to_drag.append(image_filename) elif (cmp(image_node.getAttribute("type"), "to_associate") == 0) : if ((cmp(self.type_to_associate, "image") == 0) or (cmp(self.type_to_associate, "image_on_map") == 0)) : association.images_to_associate.append(image_filename) if (cmp(self.type_to_associate, "image_on_map") == 0) : association.image_to_associate_pos_size = xml_funcs.get_box(image_node) else : common.warn(image_filename + " is supposed to be associated, but the game is not supposed to associate images") elif (cmp(image_node.getAttribute("type"), "to_drag") == 0) : if ((cmp(self.type_to_drag, "image") == 0) or (cmp(self.type_to_associate, "image_on_map") == 0)) : association.images_to_drag.append(image_filename) else : common.warn(image_filename + " is supposed to be dragged and dropped, but the game is not supposed to drag an drop images") # find potential associated sounds sound_nodes = image_node.getElementsByTagName("sound") for sound_node in sound_nodes : sound_node_lang = sound_node.getAttribute("lang") if ((cmp(sound_node_lang, "") == 0) or (cmp(sound_node_lang, main_language) == 0)) : association.append_image_sound(image_filename, xml_funcs.getText(sound_node)) # find potential associated text legends # only texts with no lang tag or with lang tag = main_language are used text_legend_nodes = image_node.getElementsByTagName("text") for text_legend_node in text_legend_nodes : if ((cmp(text_legend_node.getAttribute("lang"), main_language) == 0) or (cmp(text_legend_node.getAttribute("key"), "") != 0)) : association.append_image_text_legend(image_filename, xml_funcs.getText(text_legend_node, self.i18n_dict, main_language)) text_nodes = association_node.getElementsByTagName("text") for text_node in text_nodes : if (text_node.parentNode == association_node) : text_lang = text_node.getAttribute("lang") text_should_be_added = False if (text_lang == "") : # if no lang attribute defined, the text is included text_should_be_added = True else : # if there is a lang attribute, we add the text only # if this language is the main language if (cmp(text_lang, main_language) == 0) : text_should_be_added = True # the text node might be a dictionary key, in this case we also add it : if (cmp(text_node.getAttribute("key"), "") != 0) : text_should_be_added = True if (text_should_be_added == True) : text = xml_funcs.getText(text_node, self.i18n_dict, main_language) association.texts.append(text) sound_nodes = text_node.getElementsByTagName("sound") for sound_node in sound_nodes : sound_node_lang = sound_node.getAttribute("lang") if ((cmp(sound_node_lang, "") == 0) or (cmp(sound_node_lang, main_language) == 0)) : association.append_text_sound(text, xml_funcs.getText(sound_node)) # goals local to only one association goal_nodes = association_node.getElementsByTagName("goal") if (len(goal_nodes) > 0) : # TODO : allow for more than a goal ? goal_node = goal_nodes[0] if (cmp(self.type_to_associate, "image_on_map") == 0) : goal = Goal(goal_node) # TODO : remove from here ? self.goals.append(goal) # TODO : put more than one goal association.associated_goal = goal else : common.warn("<goal> found inside an association whereas type to associate is not image_on_map") self.associations.append(association) self.associations = common.randomize_list(self.associations)
def __init__(self): # default values self.music_on = True self.screen = None self.fonts = None self.force_light = False self.main_language_mode = "system" (self.main_language, self.user_country) = get_user_lang() self.active_languages = copy.copy(constants.supported_languages) self.release = "unknown" self.screen_width = 0 self.screen_height = 0 self.music_volume = constants.music_volume self.congrats_sounds_active = True self.congrats_voices_active = True self.display_igloo = True self.arcade_mode = False self.highscore = True # trying to load options file if available user_options_file = os.path.join(constants.home_dir, constants.user_options_filename) if (os.path.isfile(user_options_file)): try: xml_data = xml.dom.minidom.parse(user_options_file) # load screen resolution screen_resolution_nodes = xml_data.getElementsByTagName( "screen_resolution") if (len(screen_resolution_nodes) > 0): screen_width_nodes = screen_resolution_nodes[ 0].getElementsByTagName("width") screen_height_nodes = screen_resolution_nodes[ 0].getElementsByTagName("height") if ((len(screen_width_nodes) > 0) and (len(screen_height_nodes) > 0)): width = xml_funcs.getFloat(screen_width_nodes[0]) height = xml_funcs.getFloat(screen_height_nodes[0]) if ((width, height) in pygame.display.list_modes()): self.screen_width = width self.screen_height = height # load music volume music_volume_nodes = xml_data.getElementsByTagName( "music_volume") if (len(music_volume_nodes) > 0): user_music_volume = xml_funcs.getFloat( music_volume_nodes[0]) if ((user_music_volume >= 0) and (user_music_volume <= 1)): self.music_volume = user_music_volume # load congratulation sounds mode congrat_sound_nodes = xml_data.getElementsByTagName( "congrats_sounds") if (len(congrat_sound_nodes) > 0): self.congrats_sounds_active = xml_funcs.getBool( congrat_sound_nodes[0].getAttribute("active")) else: self.congrats_sounds_active = True # load congratulation voices mode congrat_voices_nodes = xml_data.getElementsByTagName( "congrats_voices") if (len(congrat_voices_nodes) > 0): self.congrats_voices_active = xml_funcs.getBool( congrat_voices_nodes[0].getAttribute("active")) else: self.congrats_voices_active = True # load display igloo mode igloo_nodes = xml_data.getElementsByTagName("igloo") if (len(igloo_nodes) > 0): self.display_igloo = xml_funcs.getBool( igloo_nodes[0].getAttribute("display")) # load arcade mode arcade_nodes = xml_data.getElementsByTagName("arcade") if (len(arcade_nodes) > 0): self.arcade_mode = xml_funcs.getBool( arcade_nodes[0].getAttribute("enabled")) # load default language language_nodes = xml_data.getElementsByTagName("language") if (len(language_nodes) > 0): main_language = language_nodes[0].getAttribute("default") if (cmp(main_language, "system") != 0): self.main_language = main_language self.main_language_mode = "user" except Exception, e: error("Can not load user options file ", e, traceback.format_exc())