def to_binary(self): task_protos = [] for t in self.tasks: t_proto = oj_task(**t) task_protos.append(t_proto) msg = oj_add_task_behavior(task=task_protos) return wrap_message(msg)
def cr_topology_init_scene(self, topo_data, root_entity, auto_arrange_root=True): """ 初始化拓扑地图 :param topo_data: oj中的json网络描述 :param root_entity: 定义一个根节点,展开topo :param auto_arrange_root: :return: """ errors = 0 self.topology = XojScene() self.topology.from_json(topo_data) self.topology.make_tree(root_entity, auto_arrange_root) bin_msg = self.topology.to_binary() if bin_msg: message = wrap_message(bin_msg) logging.info(self.topology.to_json()) self.pub_state(WORLD_STATES.INIT_TOPO, topo_data, message) else: logging.error("Generating serialized topology error!") errors += 1 # 发送proto2兼容数据 bin_msg2 = self.topology.to_binary_2() if bin_msg2: message = wrap_message_2(bin_msg2) self.pub_state(WORLD_STATES.INIT_TOPO_PROTO2, topo_data, message) else: logging.error( "Generating proto2 version serialized topology error!") errors += 1 return not bool(errors)
def mk_oj_shipgroup(id, name, members=0, logo="", wrap=True): memb = [] for i in range(1, members + 1): msg_member = oj_behavior_pb2.oj_team_member( team_child_id=str(i), model=oj_enum.EnumVirtualModelType.vir_att_shipgroup) memb.append(msg_member) all_colors = [ oj_enum.EnumOjColors.red, oj_enum.EnumOjColors.yellow, oj_enum.EnumOjColors.blue2, oj_enum.EnumOjColors.orange, oj_enum.EnumOjColors.purple, oj_enum.EnumOjColors.green, oj_enum.EnumOjColors.cyan, oj_enum.EnumOjColors.magenta, oj_enum.EnumOjColors.red2, oj_enum.EnumOjColors.yellow2, oj_enum.EnumOjColors.blue2, oj_enum.EnumOjColors.orange2, oj_enum.EnumOjColors.purple2, oj_enum.EnumOjColors.green2 ] the_color = all_colors[int(id) % len(all_colors)] msg_shipgroup = oj_behavior_pb2.oj_team( team_id=str(id), team_name=name, color=the_color, team_members=memb, logo=logo, model=oj_enum.EnumVirtualModelType.vir_att_shipleader) if wrap: return wrap_message(msg_shipgroup) else: return msg_shipgroup
def mk_focus(obj_id1, obj_id2="", obj_id3="", duration=10, switch=EnumOnoff.on): msg = sysctrl_focus(obj_id1=obj_id1, obj_id2=obj_id2, obj_id3=obj_id3, duration=duration, switch=switch) return wrap_message(msg)
def mk_ad_attack(src_team_id, src_unit_id, dest_team_id, dest_unit_id, intensity=ad_enums.EnumAttackIntensity.attack_moderate, color=ad_enums.EnumColor.blue, gather_action=False, is_defensed=False, is_firstblood=False, src_score=0, dest_score=0, wrap=True): msg = ad_behavior_pb2.ad_attack(src_team_id=str(src_team_id), src_unit_id=str(src_unit_id), dest_team_id=str(dest_team_id), dest_unit_id=str(dest_unit_id), intensity=intensity, color=color, is_puzzle=gather_action, is_defensed=is_defensed, is_firstblood=is_firstblood, src_score=src_score, dest_score=dest_score) if wrap: return wrap_message(msg) else: return msg
def mk_ad_set_ui_bottom(left_message, right_message=""): if right_message: str_message = left_message + '|' + right_message else: str_message = left_message msg = ad_sysctrl_pb2.ad_sysctrl_set_ui_bottom(bottom_text=str_message) return wrap_message(msg)
def mk_ad_team_score_action(team_id, unit_id, score, wrap=True): msg = ad_behavior_pb2.ad_team_score_aciton(team_id=team_id, team_child_id=unit_id, score=score) if wrap: return wrap_message(msg) else: return msg
def mk_set_entity_status(src_obj_id, color, switch, wrap=True): msg = map_behavior_pb2.set_entity_status(id=src_obj_id, show_flag=switch, color=color) if wrap: return wrap_message(msg) else: return msg
def mk_focus(obj_id, obj_id2="", obj_id3="", duration=1000, switch=EnumOnoff.on): msg = map_sysctrl_pb2.sysctrl_focus(obj_id1=obj_id, duration=duration, switch=switch) return wrap_message(msg)
def mk_focus_subnet(subnet_id, duration, switch=EnumOnoff.on, wrap=True): msg_camera_settings = camera_settings(normalY = 150.0, # normal 镜头轨道的Y坐标 roamingFootY = 50.0, # Roaming 镜头轨道低Y坐标 roamingPeakY = 50.0, # Roaming 镜头轨道高Y坐标 trackScale= 4.0) # Track Scale msg = sysctrl_focus_subnet(subnet_id=subnet_id, duration=duration, switch=switch, camera_settings=msg_camera_settings) if wrap: return wrap_message(msg) else: return msg
def mk_sandtable_panel(src_obj_id="", icon=EnumEffectIcon.information, top_text="N/A", per1=0.2, per2=0.3, wrap=True): msg = sandtable_panel(src_obj_id=src_obj_id, icon=icon, top_text=top_text, percentage1=per1, percentage2=per2) if wrap: return wrap_message(msg) else: return msg
def cr_topology_init_multi_scene(self, topo_data_list, root_name): multi_scene = MultiXojScene(root_name) for topo in topo_data_list: logging.info("Generating ", topo[1]) multi_scene.add_subnet(topo[0], topo[1]) bin_msg = multi_scene.to_binary() if bin_msg: message = wrap_message(bin_msg) logging.info(multi_scene.to_json()) return self.pub_state(WORLD_STATES.INIT_TOPO, topo_data_list, message) else: logging.error("Generating serialized multiple topology error!")
def mk_set_message_extend(message="", src_team="", src_ip="", dest_team="", dest_ip=""): msg = sysctrl_set_message(src_team=src_team, src_ip=src_ip, dest_team=dest_team, dest_ip=dest_ip, message_text=message, datetime=time.strftime( '%Y-%m-%d %X', time.localtime())) return wrap_message(msg)
def mk_playback_events(eventlist=[]): """ :param eventlist: [{"position":0.23, "event_title":"", "event_description":"hh", "knob_color":"white"}] """ msg_events = [] for event in eventlist: msg_event = playback_events.event_info(position=event['position'], event_title=event['event_title'], event_description=event['event_description'], knob_color=event['knob_color']) msg_events.append(msg_event) msg_pb_events = playback_events(events=msg_events) return wrap_message(msg_pb_events)
def mk_sync_timing(display_countdown=True, countdown_time=0): # TODO:如果到0点以后,这个信息要更新到第二天 # TODO:在回放时,应当关闭自动倒数 d = datetime.datetime.now() weekday = d.weekday() the_week = u'星期' + [u'一', u'二', u'三', u'四', u'五', u'六', u'日'][weekday] the_date = d.strftime('%Y-%m-%d') server_time = int(time.time()) msg = sysctrl_sync_timing(the_week=the_week, the_date=the_date, countdown_time=countdown_time, server_time=server_time, display_countdown=display_countdown) return wrap_message(msg)
def mk_oj_solv(shipgroup_id, task_id_list, member_seq, result=False, score=0, is_first_blood=False): msg = oj_behavior_pb2.oj_solve_behavior( src_obj_id=str(shipgroup_id), task_id=[str(id) for id in task_id_list], src_obj_child_id=str(member_seq), result=result, score=score, is_first_blood=is_first_blood) return wrap_message(msg)
def mk_entity_panel(src_obj_id, text, duration, switch=map_enums.EnumOnoff.on, wrap=True): msg = map_behavior_pb2.entity_panel( src_obj_id=src_obj_id, describe=text, duration=duration, switch=switch, ) if wrap: return wrap_message(msg) else: return msg
def mk_sandtable_init(): msg_camera_settings = camera_settings(normalY=150.0, # normal 镜头轨道的Y坐标 roamingFootY=50.0, # Roaming 镜头轨道低Y坐标 roamingPeakY=50.0, # Roaming 镜头轨道高Y坐标 trackScale=4.0) # Track Scale msg_init = sandtable_settings(camera_settings=msg_camera_settings) entities = [] for d in sandtable_init_data: entity = sandtable_entity(preset_point_id=d["preset_point"], set_obj_id=d["obj_id"], set_obj_name=d["obj_name"]) entities.append(entity) msg_init.legend = "Red Vs. Blue" msg_init.entities.extend(entities) return wrap_message(msg_init)
def mk_sandtable_guideline(switch=EnumOnoff.on, src_obj_id="NOT_SET", dest_obj_id="NOT_SET", duration=5, color="666666", wrap=True): msg = sandtable_guide_line(switch=switch, src_obj_id=src_obj_id, dest_obj_id=dest_obj_id, duration=duration, color="#" + color) if wrap: return wrap_message(msg) else: return msg
def mk_ad_damages(team_id, unit_id, occupied=False, pwn=False, down=False, wrap=True): msg = ad_behavior_pb2.ad_damages(team_id=team_id, unit_id=unit_id, occupied=occupied, pwn=pwn, down=down) if wrap: return wrap_message(msg) else: return msg
def mk_sync_timing(display_countdown=True, astro_time='', countdown_time=0): d = datetime.datetime.now() weekday = d.weekday() the_week = u'星期' + [u'一', u'二', u'三', u'四', u'五', u'六', u'日'][weekday] the_date = d.strftime('%Y-%m-%d') server_time = int(time.time()) msg = sysctrl_sync_timing(the_week=the_week, the_date=the_date, countdown_time=countdown_time, server_time=server_time, display_countdown=display_countdown, astro_time=astro_time) return wrap_message(msg)
def mk_topology_attack(switch=EnumOnoff.on, intensity=EnumAttackIntensity.attack_moderate, src_obj_id="", dest_obj_id="", color="#FFFFFF", duration=4, wrap=True): msg = topology_attack(switch=switch, intensity=intensity, src_obj_id=src_obj_id, dest_obj_id=dest_obj_id, color="#" + color, duration=duration) if wrap: return wrap_message(msg) else: return msg
def mk_ad_effect(team_id, team_child_id, switch=ad_enums.EnumOnoff.on, effect=ad_enums.EnumAdEffect.defence, color=ad_enums.EnumColor.blue, duration=5, wrap=True): msg = ad_behavior_pb2.ad_effect(team_id=str(team_id), team_child_id=str(team_child_id), effect=effect, switch=switch, color=color, duration=duration) if wrap: return wrap_message(msg) else: return msg
def mk_topology_entity_panel(src_obj_id="", switch=EnumOnoff.on, ip_address="", os_name="", status="", duration=0, wrap=True): msg = topology_entity_panel(src_obj_id=src_obj_id, switch=switch, ip_address=ip_address, os_name=os_name, status=status, duration=duration) if wrap: return wrap_message(msg) else: return msg
def mk_ui_toast(position=Enums.EnumPosition.left, icon=Enums.EnumToastIcon.information, text_title="untitled", text_content="sample content", switch=Enums.EnumOnoff.on, duration=5, color=""): if position == Enums.EnumPosition.top: alpha = 1.0 else: alpha = 0.8 if not color: color = color msg = sysctrl_toast(positon=position, icon=icon, text_title=text_title, text_content=text_content, switch=switch, duration=duration, message_id=str(time.time()), color=color, alpha=alpha) return wrap_message(msg)
def mk_effect(src_obj_id, color1="", color2="", switch=map_enums.EnumOnoff.on, effect=map_enums.EnumSandtableEffect.enhance, icon=map_enums.EnumEffectIcon.information, duration=5, wrap=True): msg = map_behavior_pb2.behavior_effect(src_obj_id=str(src_obj_id), color1=color1, color2=color2, switch=switch, effect=effect, icon=icon, duration=duration) if wrap: return wrap_message(msg) else: return msg
def mk_ui_scoreboard(objects=[], title="The Scoreboard"): """ :param objects: [{"id": "xx", "name":"xx", "score":100, "mvp": "xx", "trend": enum_trend, "country_flag": "", "rank": 1, "fbc": 2, "logo":"http://xx"]} """ score_infos = [] for obj in objects: scoreboard_info = sysctrl_scoreboard.msg_score_info(name=obj.get("name"), score=obj.get("score"), team_mvp=obj.get("mvp"), trend=obj.get("trend"), country_flag=obj.get("country_flag"), rank=obj.get("rank"), first_blood_count=obj.get("fbc"), id=obj.get("id"), logo=obj.get("logo")) score_infos.append(scoreboard_info) scoreboard = sysctrl_scoreboard() scoreboard.score_info.MergeFrom(score_infos) return wrap_message(scoreboard)
def mk_sandtable_attack(intensity=EnumAttackIntensity.attack_extreme, attack_speed=0, src_obj_id="", dest_obj_id="", color="", size=2, tail_duration=2, wrap=True): msg = sandtable_attack(intensity=intensity, attack_speed=attack_speed, src_obj_id=src_obj_id, dest_obj_id=dest_obj_id, color="#" + color, size=size, tail_duration=tail_duration) if wrap: return wrap_message(msg) else: return msg
def mk_guideline(src_obj_id, dest_obj_id, dest_type=map_enums.EnumDestType.entity, description='', switch=map_enums.EnumOnoff.on, duration=5, color='#0099FF', wrap=True): msg = map_behavior_pb2.guide_line( src_id=str(src_obj_id), dest=ModelDestObject(dest_type=dest_type, dest_id=dest_obj_id).to_protobuf(), switch=switch, duration=duration, color=color, description=description, ) if wrap: return wrap_message(msg) else: return msg
def mk_sandtable_effect(switch=EnumOnoff.on, effect=EnumSandtableEffect.blink, src_obj_id="", icon="", color1="NOT_SET", color2="NOT_SET", duration=4, wrap=True): if src_obj_id == "": src_obj_id = random.choice(sandtable_init_data)["obj_id"] msg = sandtable_effects(switch = switch, effect = effect, src_obj_id = src_obj_id, icon=icon, color1 = "#" + color1, color2 = "#" + color2, duration = duration) if wrap: return wrap_message(msg) else: return msg