local GameUtility = { "Color", "String", "Time", "ErrorCode", "UIRender", "MessageBox", "ItemTips", "Item", "Attr", "Toggle", "Material", "SLG", } -- BootstrapModules:可以理解为Login之前要加载的模块 local BootstrapModules = { "Cheat", "Setting", "Sound", "Tips", "WinLogin", "Login", "Loading", "PreDownloadJP", -- 日服专用 —— 日服下载(HotFix中依赖了该模块 所以需要在HotFix之前) "HotFix", "HeroSelect", --下载分包1需要使用 "Optimize", } -- LaunchModules:可以理解为Login之后要加载的模块 local LaunchModules = { "Level", "Player", "ItemUse", "Bag", "Currency", "Reborn", -- 熔铸(重生、洗练) "Equipment", "Name", "Mail", "LevelSelect", "ChannelChat", "Task", "Dialogue", "SyncTeamPVP", "Reward", "DivineWeapon", "DivineWeaponForgeSoul", "Unlock", "HomeMain", "MiniMap", "RedPoint", "HeroStar", "HeroDetail", "Rank", "Array", "BossChallenge", "Advanced", "ClimbTower", "Interact", "Sweep", "FairPlay", -- 公平竞技 "FairSoloTournament", -- 天下会武 "FightThrone", -- 逐鹿中原 "FirstCharge", -- 首充 "Formation", -- 布阵 "FormationResonance", -- 共鸣 "FrameCmdStatistic", -- 统计工具 "FreeBuy", -- 0元购 "FreeLineUp", -- 自由选将 "Friend", -- 好友 "FriendRecharge", -- 组队充值(金兰之邀) "FunctionNotice", -- 功能预告 "Biography", "Purchase", "WorldBoss", "WarHorse", -- 坐骑 "HorseSoul", -- 坐骑 - 魂珠 "HorseEquip", -- 坐骑 - 战装 "HorseRear", -- 活动玩法 - 养马 "TeamDungeon", "Guide", "PersonalBoss", "Activities", "DrawCard", "Team", "SoloFight", "GemCompose", "Shop", "PlayerGuide", "PlayerInteract", "Broadcast", "MaterialLevel", "TeamMatch", "ItemSources", "DragonArtery", "GuildBoss", "GuildWar", "OfficialPosition", "OfficialPrivilege", "Title", "Guild", "GuildAllies", "GuildParty", "OperationActivity", "PushGift", -- 定向礼包 "SignIn", "Hegemony", "RebelStrike", "Treasure", "OnlineReward", "Cutscene", "Questionnaire", "TestingGift", -- 测试有礼(问卷、FaceBook...) "SyncSolo", "MultilevelRecharge", -- 累冲 --region 福利 --福利子活动 "DailySignin", -- 每日签到 "EnergyGet", -- 领体力 "RewardsRetrieve", -- 奖励找回 "RechargeReturn", -- 充值返利 "DailyGift", -- 每日礼包 "MonthCard", -- 月卡 "GrowthFund", -- 成长基金 "DirectGift", -- 直购礼包 "HeroFund", -- 名将之路 "VersionUpdate", -- 大包更新 "ReservedGift", -- 预约豪礼 "DrawStraws", -- 月累充 "WeekendReward", -- 休沐祭礼(周末祈福) "TestWelfare", -- 内测福利-- 国服公测福利功能(仅公测使用,之后会将整个功能移除掉) "Attention", -- 关注有礼 "FestivalLogin", -- 节日限时签到 "Welfare", -- 要在福利子活动的后面 --endregion 福利 --金将活动 "GoldenHeroMain", -- 金将-主界面 "GoldenHeroBoss", -- 金将-讨伐 "GoldenHeroStory", -- 金将-体验关 "GoldenHeroFame", -- 金将-声明鹊起 "GoldenHeroAnecdote", -- 金将-金将轶事 "GoldHeroReprint", -- 日服——金将复刻抽卡 "GoldHeroPreview", -- 金将活动开服预告 --彩金将活动 "SuperGoldMain", -- 彩金将-主界面 "SuperGoldBoss", -- 彩金将-试炼 "SuperGoldHonorOrder", -- 彩金将-战令 "SuperGoldLottery", -- 彩金将-转盘 "SuperGoldStory", -- 彩金将-体验关 "MultiplayerDungeon", -- 多人副本 "GuildParty", "GuildAuction", "Achievement", -- 成就 "TimerWheel", "GuildCultivation", "Nobility", -- 进爵 "ThumbsUp", "GuildTarget", "DyeAppearance", --图鉴 "HeroLibrary", -- 武将图鉴 "WeaponLibrary", -- 神兵图鉴 "HorseLibrary", -- 坐骑图鉴 "TreasureLibrary", -- 宝物图鉴 "StratagemLibrary", --计略图鉴 "GodBeastLibrary", -- 神兽图鉴 "EffectLibrary", -- 光效图鉴 "AppearanceLibrary",-- 皮肤图鉴 "DyeLibrary", -- 染色图鉴 "AssistanceFight", "PayMall", -- 商城 "Notification", "ActivityGacha", -- 活动抽卡模块 原常住抽卡模块一些通用方法 转移至此 "RedPacket", -- 势力红包 "Appearance", -- 外观系统 "LightEffect", -- 外观_光效 "Rival", -- 仇人系统 "Monopoly", -- 大富翁 "InfoReminder", "Character", -- 头像头像框 "HonorOrder", -- 战令 "HideGolden", -- 屏蔽金品质 "PushInterface", -- 打脸图 "OACommon", -- 运营活动通用 "Translate", -- 翻译 "CommandTheWorld", -- 号令天下 "CrossServer", -- 跨服相关总模块 "WarZone", -- 战区 "CountryWorldBoss", -- 战区boss(乱世争雄) "VIP", -- VIP "DemonGod", -- 魔神(将星临世) "GuildEscort", -- 军团运镖 "NationClimbTower", -- 四国爬塔 "WarZoneAuction", -- 大拍卖 "Stratagem", -- 计略 "Report", -- 举报功能 "NewYear", -- 新年活动 "WebActivity", -- 日服网页版元旦活动 "TestWelfare", -- 内测福利 "WatchBattle", -- 观战 "LuckyLottery", -- 幸运扭蛋 "HeroMatch1v1", -- 天地群雄 "HeroMatch3v3", -- 天地群雄3v3 "SpecialTeam", -- 战队(特殊玩法的队伍) "CustomRoom", -- 自定义房间 "Country", -- 国家 "Replay", -- 公平竞技回放 "CountryWantedTask",-- 国战悬赏任务 "CountryPVP", -- 国战场景对战 "ChannelChatBulletScreen", -- 聊天频道弹幕 "SceneQuiz", -- 场景答题(春节活动) "HeroStrenthen", -- 武将修炼 "VoiceRoom", -- 语音房间模块 "HonorSignet", -- 荣誉印记 "BattleAgent", -- 战斗代理服务器 "CountryNightBoss", -- 国家晚间boss "Storm", -- 暴风 "PlotReviewLibrary",-- 剧情回顾 "TreasureBowl", -- 聚宝盆 "GVGFight", -- 攻城略地 "AnniversaryPrepare", -- 周年预热 "AnniversaryLuckyDraw", --周年抽奖 "RedEnvelopRain", -- 红包雨 "BulletScreen", -- 弹幕 "CycleRecharge", -- 周期累充 "Turntable", -- 转盘运营活动 "GuildMine", -- 矿场 "GodBeast", -- 神兽 "GodBeastActivity", -- 神兽活动 "SyncFourCountryWar", --四国 "ThreeTeamFight", --群雄演武 "FunctionUpdateNotice", --版本更新介绍 "ChangAnSiege", --城池战 "ExpelMonster", --元旦活动恶兽驱役 "Pet", -- 宠物 "KingChallenge", --王者挑战 "FairPlayCard", --公平竞技道具卡 "SlgGvE", -- 汉中风云 "TeamFairChampionship", --天下会武33 "DouYinRechargeReward", --渠道专属充值返利活动(抖音、应用宝等) "PCGameStreamer", --主播PC包玩法(自由演武) "AppPushGift", --召回推送礼包 "Rogue", --肉鸽游戏 "HeroAwaken", --武将觉醒 "AwakenActivity", --觉醒试炼活动 "Decoration", --装饰系统 "LaterEnter", --后起之秀 "SubjectMonth", --主题月活动 "MonthSignIn", --月度签到 "MonthHonorOrder", --月度战令 "MonthBossChallenge", "ViewAssets", --浏览资源 } local EventSystem = require('Event/EventSystem') local MDL = {} local CTL = {} local UTL = {} local function GetPackagePath(target, name) if target == MDL then return string.format("Modules/%s/%s_Model", name, name) elseif target == CTL then return string.format("Modules/%s/%s_Controller", name, name) elseif target == UTL then return string.format("Utility/%s_Utility", name) else error("load module target is not valid") end end local function LoadModule(target, name) local path = GetPackagePath(target, name) local ret, mod = pcall(require, path) if ret then if mod then target[name] = mod else error(string.format("require module %s failed", path)) end else local msg = mod error(string.format("load module %s failed, %s", path, msg)) end end local function OnStartupOrShutdownError(msg) logging.error(LTAG.ERROR, "启动或者关闭lua模块时报错", msg) end local function Bootstrap() rawset(_G, 'MDL', MDL) rawset(_G, 'CTL', CTL) rawset(_G, 'UTL', UTL) for _, name in ipairs(GameUtility) do LoadModule(UTL, name) end for _, name in ipairs(GameUtility) do local utl = UTL[name] if utl and utl.OnStartup then xpcall(utl.OnStartup, OnStartupOrShutdownError) end end for _, name in ipairs(BootstrapModules) do LoadModule(MDL, name) LoadModule(CTL, name) end for _, name in ipairs(BootstrapModules) do local mdl = MDL[name] if mdl and mdl.OnStartup then xpcall(mdl.OnStartup, OnStartupOrShutdownError) end local ctl = CTL[name] if ctl and ctl.OnStartup then xpcall(ctl.OnStartup, OnStartupOrShutdownError) end end end local function Launch() for _, name in ipairs(LaunchModules) do LoadModule(MDL, name) LoadModule(CTL, name) end for _, name in ipairs(LaunchModules) do local mdl = MDL[name] if mdl and mdl.OnStartup then xpcall(mdl.OnStartup, OnStartupOrShutdownError) end local ctl = CTL[name] if ctl and ctl.OnStartup then xpcall(ctl.OnStartup, OnStartupOrShutdownError) end end EventSystem.Dispatch(EventID.ModulesLaunch) end local function Shutdown() --工具类模块不做释放操作 for _, name in ipairs(GameUtility) do local utl = UTL[name] if utl and utl.OnShutdown then xpcall(utl.OnShutdown, OnStartupOrShutdownError) end end for _, name in ipairs(BootstrapModules) do local ctl = CTL[name] if ctl and ctl.OnShutdown then xpcall(ctl.OnShutdown, OnStartupOrShutdownError) end local mdl = MDL[name] if mdl and mdl.OnShutdown then xpcall(mdl.OnShutdown, OnStartupOrShutdownError) end end for _, name in ipairs(LaunchModules) do local ctl = CTL[name] if ctl and ctl.OnShutdown then xpcall(ctl.OnShutdown, OnStartupOrShutdownError) end local mdl = MDL[name] if mdl and mdl.OnShutdown then xpcall(mdl.OnShutdown, OnStartupOrShutdownError) end end --卸载模块及入口 for name, v in pairs(CTL) do local path = GetPackagePath(CTL, name) local packagePath = string.gsub(path, "/", "."); package.loaded[packagePath] = nil CTL[name] = nil end for name, v in pairs(MDL) do local path = GetPackagePath(MDL, name) local packagePath = string.gsub(path, "/", "."); package.loaded[packagePath] = nil MDL[name] = nil end EventSystem.Dispatch(EventID.ModulesShutdown) end return { Bootstrap = Bootstrap, Launch = Launch, Shutdown = Shutdown, }