import os import json import dataclasses from utils.logger import Warn from game_server.resource.base_resource import BaseResource from game_server.resource.decorators import GameResource,LoadPriority from game_server.resource.configdb.sub_type.floor_info import FloorInfo,parse_floor_info from game_server.resource.configdb.sub_type.group_info import parse_group_info floor_dir = './resources/Config/LevelOutput/RuntimeFloor/' @dataclasses.dataclass @GameResource("resources/ExcelOutput/MapEntrance.json", load_priority=LoadPriority.LOW) class MapEntranceData(BaseResource): ID: int PlaneID: int FloorID: int StartAnchorID: int StartGroupID: int EntranceType: str floor_infos: dict[int, FloorInfo] = dataclasses.field(default_factory=dict) def on_load(self) -> bool: name = f"P{self.PlaneID}_F{self.FloorID}" file_path = os.path.join(floor_dir, f"{name}.json") if not os.path.exists(file_path): Warn(f"Missing floor info: {name}") return False with open(file_path, 'r', encoding='utf-8') as file: raw_data = json.load(file) self.floor_infos = {} floor_data = parse_floor_info(raw_data) self.floor_infos[self.ID] = floor_data floor = self.floor_infos[self.ID] for simpleGroup in floor.GroupInstanceList: if simpleGroup.IsDelete: continue group_file_path = os.path.join('./resources/', simpleGroup.GroupPath) if not os.path.exists(group_file_path): Warn(f"Missing GroupPath info: {simpleGroup.GroupPath}") continue try: with open(group_file_path, 'r', encoding='utf-8') as group_file: content = group_file.read().strip() if not content: Warn(f"File is empty: {group_file_path}") continue group_raw_data = json.loads(content) except json.JSONDecodeError as e: Warn(f"Error decoding JSON in file {group_file_path}: {e}") continue except Exception as e: Warn(f"Unexpected error occurred while processing file {group_file_path}: {e}") continue group_info = parse_group_info(group_raw_data) group_info.id = simpleGroup.ID if group_info.OwnerMainMissionID and group_info.OwnerMainMissionID > 0: continue floor.groups[simpleGroup.ID] = group_info return True def check_floor_dir(self) -> bool: if not os.path.exists(floor_dir): Warn(f"Floor infos are missing, please check your resources folder: {floor_dir}. Teleports and natural world spawns may not work!") return return True def get_index(self) -> str: return str(self.ID)