def _readNationConfigSection(xmlCtx, section): config = {} firstNames = {} lastNames = {} icons = {} for kindName in component_constants.TANKMEN_GROUPS: groups = [] totalWeight = 0.0 for sname, subsection in _xml.getChildren(xmlCtx, section, kindName): ctx = (xmlCtx, kindName + '/' + sname) group = _readTankmenGroup(ctx, subsection, firstNames, lastNames, icons) totalWeight += group.weight groups.append(group) totalWeight = max(0.001, totalWeight) for group in groups: group.weight /= totalWeight config[kindName] = tuple(groups) ranks = _readRanks((xmlCtx, 'ranks'), _xml.getChildren(xmlCtx, section, 'ranks')) config['roleRanks'] = _readRoleRanks((xmlCtx, 'roleRanks'), _xml.getSubsection(xmlCtx, section, 'roleRanks'), ranks) if IS_CLIENT or IS_WEB: config['firstNames'] = firstNames config['lastNames'] = lastNames config['icons'] = icons config['ranks'] = ranks else: config['firstNames'] = frozenset(firstNames) config['lastNames'] = frozenset(lastNames) config['icons'] = frozenset(icons) return tankmen_components.NationConfig(xmlCtx[1], **config)
def getNationConfig(nationID): global _g_nationsConfig if _g_nationsConfig[nationID] is None: nationName = nations.NAMES[nationID] if nationName not in nations.AVAILABLE_NAMES: _g_nationsConfig[nationID] = tankmen_components.NationConfig('stub') else: _g_nationsConfig[nationID] = tankmen_readers.readNationConfig(ITEM_DEFS_PATH + 'tankmen/' + nationName + '.xml') return _g_nationsConfig[nationID]
def getNationConfig(nationID): """Gets nation-specific configuration (names, ranks, etc.) of tankmen by ID of nation. For more information about configuration see class tankmen_components.NationConfig. :param nationID: integer containing ID of nation. :return: instance of NationConfig. """ global _g_nationsConfig if _g_nationsConfig[nationID] is None: nationName = nations.NAMES[nationID] if nationName not in nations.AVAILABLE_NAMES: _g_nationsConfig[nationID] = tankmen_components.NationConfig('stub') else: _g_nationsConfig[nationID] = tankmen_readers.readNationConfig(ITEM_DEFS_PATH + 'tankmen/' + nationName + '.xml') return _g_nationsConfig[nationID]