def inject_land(units_parent=None): """run over all counters and put them in the right place""" # init global BF, GPID, HEADER, SHEET print "INJECT LAND" if units_parent is None: units_parent = get_units_parent(False) # fill containers print "reading counters", for u in gen_filtered_rowset(sheet=SHEET["L"], header=HEADER["L"]): try: # init print_item = "." u_type = get_type(u) print_item = "({})".format(u_type) tag, col_symb, col_symb_text, col_left, col_top, col_right = ENTITY_COLOURS[u.home or "Partisan"] hook, is_minor = get_hook(u, units_parent) # piece slot, trait order in R E V E R S E !! ps = PieceSlot(u.name or u.year, GPID.get()) ps.add_trait("prototype", ("ROTATE", "")) # last! # game values and info ps.add_trait("mark", ("val_info", ",".join(u.info or []))) ps.add_trait("mark", ("val_kit", get_kit(u))) ps.add_trait("mark", ("val_year", u.year)) ps.add_trait("mark", ("val_class", u.clas)) ps.add_trait("mark", ("val_type", u_type)) ps.add_trait("mark", ("val_cost", u.cost)) ps.add_trait("mark", ("val_time", u.time)) # land values ps.add_trait("mark", ("val_mv", u.mov)) if u.rog: ps.add_trait("mark", ("val_ro", u.rog)) ps.add_trait("mark", ("val_cf", u.str or 0)) # labels if u.name is not None and "siberian" in u.name: col_left = col_top = "whi" if u.name is not None and u.name == "GGFF": col_left = col_right = col_top = col_symb = "yel" if not is_minor: col_left = col_right = col_top = "blk" if u.info is not None and "SS" in u.info: col_left = col_right = col_top = "whi" if is_minor is True: if u_type == "PART": ps.add_trait("mark", ("val_right", u.name)) else: ps.add_trait("mark", ("val_left", tag)) ps.add_trait("mark", ("col_left", get_col(col_left))) if u.name: ps.add_trait("mark", ("val_right", u.name)) ps.add_trait("mark", ("col_right", get_col(col_right))) else: if u.name: ps.add_trait("mark", ("val_left", u.name)) ps.add_trait("mark", ("col_left", get_col(col_left))) if get_size(u): ps.add_trait("mark", ("val_top", get_size(u))) ps.add_trait("mark", ("col_top", get_col(col_top))) # counter background and symbol ps.add_trait("mark", ("cntr_back_num", CNTR_BACK_COL_NUM.get(u.color.lower(), 1))) ps.add_trait("mark", ("symb_back_num", CNTR_FORE_COL_NUM.get(u.color2.lower(), 1))) if u_type == "Ski": col_symb = "blu" if u.home == "Comm China" and u.clas == "SUPP": col_symb = "red" if u.info is not None: if "SS" in u.info: col_symb = "whi" if "CBV" in u.info and str(u.name) in CBV_COLOURS: col_symb = CBV_COLOURS[u.name][0] col_symb_text = CBV_COLOURS[u.name][1] if "mot" in map(unicode.lower, u.info) or u_type.lower() == "mot": ps.add_trait("mark", ("symb_wheels_num", COL_NUM[col_symb])) if u.size == "H": ps.add_trait("mark", ("symb_heavy_num", COL_NUM[col_symb])) if u_type in ["MIL", "TER", "WAR", "PART"]: ps.add_trait("mark", ("symb_text", u_type[0].upper())) if u.color2 == "white" and col_symb_text == "whi": col_symb_text = "red" if "red" in u.color2.lower() and col_symb_text == "red": col_symb_text = "whi" ps.add_trait("mark", ("col_symb_text", get_col(col_symb_text))) else: if u_type.lower() in ["arm", "mech", "mot", "inf"]: if u.home in ["AUS", "CAN", "IND"]: ps.add_trait("mark", ("symb_text", u.home[:1].upper())) ps.add_trait("mark", ("col_symb_text", get_col(col_symb_text))) if u.home in ["NZ", "SA"]: ps.add_trait("mark", ("symb_text", u.home[:2].upper())) ps.add_trait("mark", ("col_symb_text", get_col(col_symb_text))) # style and colour val1 = "#000000" val2 = "#000000" if u.color.lower() == "black": val1 = "#ff0000" val2 = "#ff0000" if u.info is not None: if "WP" in u.info: val1 = "#ffffff" val2 = "#ffffff" if u.color.lower() == "white": val1 = "#eeeeee" val2 = "#eeeeee" if u.clas == "ART": if "hvy" in map(unicode.lower, u.info): ps.add_trait("mark", ("symb_aa_hvy_num", 1)) val1 = "#ffffff" if "grey" in u.info: ps.add_trait("mark", ("art_num", 1)) elif "pink" in u.info: ps.add_trait("mark", ("art_num", 2)) elif "red" in u.info: ps.add_trait("mark", ("art_num", 3)) else: val1 = "#000000" ps.add_trait("mark", ("col_valL", val1)) ps.add_trait("mark", ("col_valR", val2)) ps.add_trait("prototype", ("UNITlendlease", "")) ps.add_trait("prototype", ("LANDvalues", "")) if u.clas == "ART": ps.add_trait("prototype", ("LANDart", "")) if u.home == "Comm China" and u.clas == "SUPP": col_symb = "red" ps.add_trait("prototype", ("LAND" + col_symb, "")) ps.add_trait("prototype", ("LANDbase", "")) # add to xml tree hook.append(ps.get_xml()) except Exception, ex: print_item = "!" raise finally:
def inject_air(units_parent=None): # init global BF, GPID, HEADER, SHEET print "INJECT AIR" if units_parent is None: units_parent = get_units_parent(False) # fill containers print "reading counters", for u in gen_filtered_rowset(sheet=SHEET["A"], header=HEADER["A"], filt=lambda x: x.type not in ["PILOT"]): try: # init print_item = "." u_type = get_type(u) print_item = "({})".format(u_type) tag, col_symb, col_symb_text, col_left, col_top, col_right = ENTITY_COLOURS[u.home] hook, is_minor = get_hook(u, units_parent) # piece slot, trait order in R E V E R S E !! ps = PieceSlot(u.name or u.year, GPID.get()) ps.add_trait("prototype", ("ROTATE", "")) # last! # game values and info ps.add_trait("mark", ("val_info", ",".join(u.info or []))) ps.add_trait("mark", ("val_kit", get_kit(u))) ps.add_trait("mark", ("val_year", u.year)) ps.add_trait("mark", ("val_class", u.clas)) ps.add_trait("mark", ("val_type", u_type)) ps.add_trait("mark", ("val_cost", u.cost)) ps.add_trait("mark", ("val_time", u.time)) # air values ps.add_trait("mark", ("val_ata", u.ata if u.ata is not None else "*")) ps.add_trait("mark", ("val_ats", u.ats if u.ats is not None else "*")) ps.add_trait("mark", ("val_tac", u.tac if u.tac is not None else "*")) ps.add_trait("mark", ("val_str", u.str if u.str is not None else "*")) ps.add_trait("mark", ("val_rng", u.rng)) if u_type == "CVP": if u.cvp_y1 is not None: ps.add_trait("mark", ("sz1,yr1", u.cvp_s1, u.cvp_y1)) if u.cvp_y2 is not None: ps.add_trait("mark", ("sz2,yr2", u.cvp_s2, u.cvp_y2)) if u.cvp_y3 is not None: ps.add_trait("mark", ("sz3,yr3", u.cvp_s3, u.cvp_y3)) # labels if u_type == "FTR": name = break_name(u.name) if not is_minor: ps.add_trait("mark", ("val_top", name[0])) if len(name) > 1: ps.add_trait("mark", ("val_top2", name[1])) if u.name2 is not None: ps.add_trait("mark", ("val_center3", u.name2)) else: ps.add_trait("mark", ("val_top", tag)) ps.add_trait("mark", ("col_top", get_col(col_left))) ps.add_trait("mark", ("val_center3", u.name)) if u.info is not None: if "2E" in u.info: ps.add_trait("mark", ("col_valTL", "#fbc834")) ps.add_trait("mark", ("col_valTL_bg", "#808080")) if "NF" in u.info: ps.add_trait("mark", ("valTL_bg_num", 2)) if not "2E" in u.info: ps.add_trait("mark", ("col_valTL", "#ffffff")) if u_type in ["ATR", "LND"]: name = break_name(u.name) if len(name) == 1: ps.add_trait("mark", ("val_bottom", name[0])) if len(name) == 2: ps.add_trait("mark", ("val_bottom", name[0])) ps.add_trait("mark", ("val_center2", name[1])) if u.name2 is not None: name2 = break_name(u.name2) if len(name2) == 1: ps.add_trait("mark", ("val_center2", name2[0])) if len(name2) == 2: ps.add_trait("mark", ("val_center1", name2[0])) ps.add_trait("mark", ("val_center2", name2[1])) if u.color.lower() == "black": ps.add_trait("mark", ("col_text", "#ff0000")) ps.add_trait("mark", ("col_valTL", "#ff0000")) ps.add_trait("mark", ("col_valTR", "#ff0000")) ps.add_trait("mark", ("col_valBL", "#ff0000")) if u_type in ["NAV", "CVP"]: name = break_name(u.name) if len(name) > 1: ps.add_trait("mark", ("val_top2", name[0])) ps.add_trait("mark", ("val_bottom", name[1])) if u.name2 is not None: ps.add_trait("mark", ("val_top", u.name2)) else: ps.add_trait("mark", ("val_bottom", name[0])) if u.name2 is not None: ps.add_trait("mark", ("val_top2", u.name2)) if tag is not None: try: col = { "AUS": "#ff0000", "CAN": "#00a2ff", "IND": "#99cc33", "NZ": "#ffffff", "SA": "#fbc834", }[tag] ps.add_trait("mark", ("col_tag", col)) ps.add_trait("mark", ("val_center1", tag)) except: col = get_col(col_left) ps.add_trait("mark", ("col_tag_top", col)) ps.add_trait("mark", ("val_top", tag)) # range and extras rng_num = 1 if u.info is not None and ("ATR" in u.info or "XATR" in u.info): rng_num = 3 if u.info is not None and "EX" in u.info: rng_num = 5 if len(str(u.rng)) > 1: rng_num += 1 ps.add_trait("mark", ("val_rng_num", rng_num)) # counter background and stripes ps.add_trait("mark", ("cntr_back_num", CNTR_BACK_COL_NUM.get(u.color.lower(), 1))) if u.info is not None and "FB" in u.info: ps.add_trait("mark", ("h_stripe_num", 2)) is_ll = False if u.info is not None: for item in u.info: if item.startswith("LL-"): rec = item[3:] ps.add_trait("mark", ("ll_stripe_num", CONTROL_NUM[rec])) is_ll = True break # air prototypes base = { "FTR": "FTR", "LND": "LND", "ATR": "LND", "NAV": "NAV", "CVP": "NAV", "ABOMB": "FTR", "VWEAP": "NAV", }[u_type] if not is_ll: ps.add_trait("prototype", ("UNITlendlease", "")) ps.add_trait("prototype", ("AIRrng" + base, "")) ps.add_trait("prototype", ("AIRvalues", "")) ps.add_trait("prototype", ("AIRbase", "")) # add to xml tree hook.append(ps.get_xml()) except Exception, ex: print_item = "!" raise finally:
def inject_naval(units_parent=None): # init global BF, GPID, HEADER, SHEET print "INJECT NAVAL" if units_parent is None: units_parent = get_units_parent(False) # fill containers print "reading counters", for u in gen_filtered_rowset(sheet=SHEET["N"], header=HEADER["N"], filt=lambda x: x.type not in ["CONV", "TANK"]): try: # init print_item = "." u_type = get_type(u) print_item = "({})".format(u_type) tag, col_symb, col_symb_text, col_left, col_top, col_right = ENTITY_COLOURS[u.home] hook, is_minor = get_hook(u, units_parent) # piece slot, trait order in R E V E R S E !! ps = PieceSlot(u.name or u.year, GPID.get()) ps.add_trait("prototype", ("ROTATE", "")) # last! # game values and info ps.add_trait("mark", ("val_info", ",".join(u.info or []))) ps.add_trait("mark", ("val_kit", get_kit(u))) ps.add_trait("mark", ("val_year", u.year)) ps.add_trait("mark", ("val_class", u.clas)) ps.add_trait("mark", ("val_type", u_type)) ps.add_trait("mark", ("val_cost", u.cost)) ps.add_trait("mark", ("val_time", u.time)) # naval values ps.add_trait("mark", ("val_mov", u.mov if u.aa is not None else "0")) ps.add_trait("mark", ("val_rng", u.rng if u.aa is not None else "0")) ps.add_trait("mark", ("val_atk", u.atk if u.atk is not None else "0")) ps.add_trait("mark", ("val_dfs", u.dfs if u.dfs is not None else "0")) ps.add_trait("mark", ("val_aa", u.aa if u.aa is not None else "0")) if u.cv is not None: ps.add_trait("mark", ("val_sb", u.cv)) if u_type == "FROG": if "Blue" in u.name2: ps.add_trait("mark", ("val_cv_num", 8)) if "Violet" in u.name2: ps.add_trait("mark", ("val_cv_num", 9)) else: ps.add_trait("mark", ("val_cv_num", u.cv)) else: ps.add_trait("mark", ("val_sb", u.sb or "0")) # labels if u.name is not None: ps.add_trait("mark", ("val_name", u.name)) if u.color.lower() == "black": ps.add_trait("mark", ("col_text", "#ff0000")) if tag is not None: try: col = { "AUS": "#ff0000", "CAN": "#00a2ff", "IND": "#99cc33", "NZ": "#ffffff", "SA": "#fbc834", }[tag] except: col = get_col(col_left) ps.add_trait("mark", ("col_tag", col)) ps.add_trait("mark", ("val_tag", tag)) # range and extras if u_type == "ASW": if "pink" in u.info: ps.add_trait("mark", ("val_asw_num", 1)) if "red" in u.info: ps.add_trait("mark", ("val_asw_num", 2)) # counter background and stripes ps.add_trait("mark", ("cntr_back_num", CNTR_BACK_COL_NUM.get(u.color.lower(), 1))) # naval prototypes if u.name2 is not None and "LL-FR" in u.name2: ps.add_trait("mark", ("ll_stripe_num", "4")) else: ps.add_trait("prototype", ("UNITlendlease", "")) ps.add_trait("prototype", ("NAVALvalues", "")) ps.add_trait("prototype", ("NAVALbase", "")) # add to xml tree hook.append(ps.get_xml()) except Exception, ex: print_item = "!" raise finally: