mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-14 05:44:34 +01:00
Initial commit
This commit is contained in:
60
game_server/resource/__init__.py
Normal file
60
game_server/resource/__init__.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import json
|
||||
import traceback
|
||||
from typing import Dict, Type, TypeVar, Optional, Any, List
|
||||
|
||||
from game_server.config.log import Error, Info
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import resource_registry
|
||||
import game_server.resource.configdb # noqa: F401
|
||||
|
||||
T = TypeVar("T", bound=BaseResource)
|
||||
|
||||
def filter_data(cls: Type, data):
|
||||
valid_fields = cls.__annotations__.keys()
|
||||
return {field: data.get(field, None) for field in valid_fields}
|
||||
|
||||
class ResourceManager:
|
||||
def __init__(self):
|
||||
self.data: Dict[Type[T], Dict[Any, T]] = {}
|
||||
|
||||
def load_resources(self) -> None:
|
||||
Info("[BOOT] [ResourceManager] Loading Resourcses...")
|
||||
sorted_load_priority = dict(
|
||||
sorted(resource_registry.items(), key=lambda item: item[1]["load_priority"])
|
||||
).items()
|
||||
for cls, metadata in sorted_load_priority:
|
||||
path = metadata["path"]
|
||||
try:
|
||||
with open(path, "r", encoding="utf-8") as file:
|
||||
raw_data = json.load(file)
|
||||
except Exception:
|
||||
Error(f"Error when loading resource {path}")
|
||||
traceback.print_exc()
|
||||
continue
|
||||
|
||||
self.data[cls] = {}
|
||||
i = 0
|
||||
for data in raw_data:
|
||||
data = filter_data(cls, data)
|
||||
item: T = cls(**data)
|
||||
if not item.on_load():
|
||||
continue
|
||||
i += 1
|
||||
index_value = item.get_index()
|
||||
self.data[cls][index_value] = item
|
||||
Info(f"[BOOT] [ResourceManager] Loaded {i} config(s) for {cls.__name__}")
|
||||
|
||||
def find_by_index(self, cls: Type[T], value: Any) -> Optional[T]:
|
||||
return self.data.get(cls, {}).get(str(value))
|
||||
|
||||
def has_index(self, cls: Type[T], value: Any) -> bool:
|
||||
return value in self.data.get(cls, {})
|
||||
|
||||
def values(self, cls: Type[T]) -> List[T]:
|
||||
return list(self.data.get(cls, {}).values())
|
||||
|
||||
@staticmethod
|
||||
def instance():
|
||||
return resource_manager
|
||||
|
||||
resource_manager = ResourceManager()
|
||||
15
game_server/resource/base_resource.py
Normal file
15
game_server/resource/base_resource.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T", bound="BaseResource")
|
||||
|
||||
@dataclass
|
||||
class BaseResource(ABC):
|
||||
def on_load(self: T) -> bool:
|
||||
"""returns True by default if item loaded, otherwise will be skipped"""
|
||||
return True
|
||||
|
||||
@abstractmethod
|
||||
def get_index(self) -> str:
|
||||
pass
|
||||
15
game_server/resource/configdb/__init__.py
Normal file
15
game_server/resource/configdb/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import importlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
folder = "game_server/resource/configdb"
|
||||
sys.path.append(os.path.dirname(folder))
|
||||
|
||||
for filename in os.listdir(folder):
|
||||
if filename.endswith(".py") and filename != "__init__.py":
|
||||
module_name = filename[:-3]
|
||||
module_path = f"game_server.resource.configdb.{module_name}"
|
||||
try:
|
||||
importlib.import_module(module_path)
|
||||
except Exception as e:
|
||||
print(f"Error importing module '{module_path}': {e}")
|
||||
12
game_server/resource/configdb/act_challenge_data.py
Normal file
12
game_server/resource/configdb/act_challenge_data.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/ActChallengeData.json")
|
||||
class ActChallengeData(BaseResource):
|
||||
actId: int
|
||||
difficulty: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.actId)
|
||||
11
game_server/resource/configdb/activity_tower.py
Normal file
11
game_server/resource/configdb/activity_tower.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/ActivityTower.json")
|
||||
class ActivityTowerData(BaseResource):
|
||||
ActivityID: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ActivityID)
|
||||
18
game_server/resource/configdb/avatar_data.py
Normal file
18
game_server/resource/configdb/avatar_data.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/AvatarData.json")
|
||||
class AvatarData(BaseResource):
|
||||
avatarID: int
|
||||
DefaultDressId: int
|
||||
unlockStar: int
|
||||
initialWeapon: int
|
||||
skillList: list
|
||||
|
||||
def on_load(self) -> bool:
|
||||
return self.avatarID != 316 and (self.avatarID < 9000 or self.avatarID > 20000)
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.avatarID)
|
||||
14
game_server/resource/configdb/avatar_sub_skill_data.py
Normal file
14
game_server/resource/configdb/avatar_sub_skill_data.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/AvatarSubSkillData.json")
|
||||
class AvatarSubSkillData(BaseResource):
|
||||
skillId: int
|
||||
unlockScoin: int
|
||||
maxLv: int
|
||||
avatarSubSkillId: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.avatarSubSkillId)
|
||||
11
game_server/resource/configdb/avatar_tutorial.py
Normal file
11
game_server/resource/configdb/avatar_tutorial.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/AvatarTutorial.json")
|
||||
class AvatarTutorialData(BaseResource):
|
||||
ActivityID: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ActivityID)
|
||||
11
game_server/resource/configdb/collection.py
Normal file
11
game_server/resource/configdb/collection.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/Collection.json")
|
||||
class CollectionData(BaseResource):
|
||||
ID: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ID)
|
||||
11
game_server/resource/configdb/custom_head_data.py
Normal file
11
game_server/resource/configdb/custom_head_data.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/CustomHeadData.json")
|
||||
class CustomHeadData(BaseResource):
|
||||
headID: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.headID)
|
||||
12
game_server/resource/configdb/dress_data.py
Normal file
12
game_server/resource/configdb/dress_data.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/DressData.json")
|
||||
class DressData(BaseResource):
|
||||
dressID: int
|
||||
avatarIDList: list
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.dressID)
|
||||
26
game_server/resource/configdb/elf_astra_mate_data.py
Normal file
26
game_server/resource/configdb/elf_astra_mate_data.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.configdb.elf_skill_data import ElfSkillData
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/Elf_AstraMate_Data.json")
|
||||
class ElfAstraMateData(BaseResource):
|
||||
ElfID: int
|
||||
MaxLevel: int
|
||||
MaxRarity: int
|
||||
|
||||
skill_lists: list[ElfSkillData]
|
||||
|
||||
def on_load(self) -> bool:
|
||||
from game_server.resource import ResourceManager
|
||||
|
||||
self.skill_lists = [
|
||||
skill
|
||||
for skill in ResourceManager.instance().values(ElfSkillData)
|
||||
if self.ElfID in skill.ElfIds
|
||||
]
|
||||
return True
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ElfID)
|
||||
13
game_server/resource/configdb/elf_skill_data.py
Normal file
13
game_server/resource/configdb/elf_skill_data.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource, LoadPriority
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/ElfSkillData.json", load_priority=LoadPriority.HIGH)
|
||||
class ElfSkillData(BaseResource):
|
||||
ElfSkillID: int
|
||||
MaxLv: int
|
||||
ElfIds: list
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ElfSkillID)
|
||||
13
game_server/resource/configdb/entry_theme_data.py
Normal file
13
game_server/resource/configdb/entry_theme_data.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/EntryThemeData.json")
|
||||
class EntryThemeData(BaseResource):
|
||||
SpaceShipConfigID: int
|
||||
ThemeBGMConfigList: list
|
||||
ThemeTagList: list
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.SpaceShipConfigID)
|
||||
11
game_server/resource/configdb/entry_theme_item_data.py
Normal file
11
game_server/resource/configdb/entry_theme_item_data.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/EntryThemeItemData.json")
|
||||
class EntryThemeItemData(BaseResource):
|
||||
ThemeItemID: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ThemeItemID)
|
||||
11
game_server/resource/configdb/frame_data.py
Normal file
11
game_server/resource/configdb/frame_data.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/FrameData.json")
|
||||
class Frame_Data(BaseResource):
|
||||
id: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.id)
|
||||
14
game_server/resource/configdb/material_data.py
Normal file
14
game_server/resource/configdb/material_data.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/MaterialData.json")
|
||||
class MaterialData(BaseResource):
|
||||
ID: int
|
||||
rarity: int
|
||||
maxRarity: int
|
||||
quantityLimit: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ID)
|
||||
13
game_server/resource/configdb/mission_data.py
Normal file
13
game_server/resource/configdb/mission_data.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/MissionData.json")
|
||||
class MissionData(BaseResource):
|
||||
id: int
|
||||
Priority: int
|
||||
totalProgress: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.id)
|
||||
11
game_server/resource/configdb/recommend_panel.py
Normal file
11
game_server/resource/configdb/recommend_panel.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/RecommendPanel.json")
|
||||
class RecommendPanelData(BaseResource):
|
||||
PanelID: int
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.PanelID)
|
||||
13
game_server/resource/configdb/stage_data_main.py
Normal file
13
game_server/resource/configdb/stage_data_main.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/StageData_Main.json")
|
||||
class StageDataMain(BaseResource):
|
||||
levelId: int
|
||||
maxProgress: int
|
||||
challengeList: list
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.levelId)
|
||||
15
game_server/resource/configdb/step_mission_compensation.py
Normal file
15
game_server/resource/configdb/step_mission_compensation.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/StepMissionCompensation.json")
|
||||
class StepMissionCompensationData(BaseResource):
|
||||
CompensationID: int
|
||||
UnlockLevel: int
|
||||
MainLineStepIDList: list
|
||||
NewChallengeStepIDList: list
|
||||
OldChallengeStepIDList: list
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.CompensationID)
|
||||
21
game_server/resource/configdb/stigmata_data.py
Normal file
21
game_server/resource/configdb/stigmata_data.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/StigmataData.json")
|
||||
class StigmataData(BaseResource):
|
||||
ID: int
|
||||
maxLv: int
|
||||
rarity: int
|
||||
maxRarity: int
|
||||
evoID: int
|
||||
quality: int
|
||||
isSecurityProtect: bool
|
||||
protect: bool
|
||||
|
||||
def on_load(self) -> bool:
|
||||
return self.evoID == 0
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ID)
|
||||
13
game_server/resource/configdb/theme_data_avatar.py
Normal file
13
game_server/resource/configdb/theme_data_avatar.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/ThemeData_Avatar.json")
|
||||
class ThemeDataAvatar(BaseResource):
|
||||
AvatarData: int
|
||||
BuffList: list[int]
|
||||
avatarIDList: list[int]
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.AvatarData)
|
||||
17
game_server/resource/configdb/weapon_data.py
Normal file
17
game_server/resource/configdb/weapon_data.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from dataclasses import dataclass
|
||||
from game_server.resource.base_resource import BaseResource
|
||||
from game_server.resource.decorators import GameResource
|
||||
|
||||
@dataclass
|
||||
@GameResource("resources/ExcelOutputAsset/WeaponData.json")
|
||||
class WeaponData(BaseResource):
|
||||
ID: int
|
||||
weaponMainID: int
|
||||
maxLv: int
|
||||
rarity: int
|
||||
maxRarity: int
|
||||
evoID: int
|
||||
protect: bool
|
||||
|
||||
def get_index(self) -> str:
|
||||
return str(self.ID)
|
||||
17
game_server/resource/decorators.py
Normal file
17
game_server/resource/decorators.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from typing import Type, Dict
|
||||
|
||||
resource_registry: Dict[Type, Dict[str, any]] = {}
|
||||
|
||||
|
||||
class LoadPriority:
|
||||
HIGH = 1
|
||||
NORMAL = 2
|
||||
LOW = 3
|
||||
|
||||
|
||||
def GameResource(path: str, load_priority=LoadPriority.NORMAL):
|
||||
def decorator(cls):
|
||||
resource_registry[cls] = {"path": path, "load_priority": load_priority}
|
||||
return cls
|
||||
|
||||
return decorator
|
||||
Reference in New Issue
Block a user