feat(WeatherControl): 让外部模组能通过 Mod.Call 注册自己的气候控制项#174
Open
hocha113 wants to merge 4 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
把气候控制面板从只支持内置 5 项扩展成一个统一的注册中心,外部模组可以通过
Mod.Call注册自己的控制项,也可以挂自己的 UI 视图自成一栏。原版 5 项的存档、网络协议、公共字段都保留不变。顺手修一处
SandstormLocked存档键名不一致的小 bug。动机
现状是
WeatherAmbientElement把 5 个内置控制项(时间 / 月相 / 降雨 / 沙暴 / 风向)和它们的命中区、网络包、UI 逻辑硬编码在一起,没有给外部模组留入口。如果联动作者想加个自己的天气(比如"火烧日"),既不能在面板上加图标,也不能复用现有的派发与同步机制。这次把控制项抽出来做成接口和注册中心,让所有项走同一条路,本地状态由回调读写,跨客户端同步由统一的派发层负责,UI 由 Registry 列出。内置 5 项也用同一套接口落地,外部读写它们和读写自己注册的项写法一致。
主要改动
新增抽象层
Content/Functions/WeatherControl/IWeatherControl单个控制项的抽象,描述 Id、图标、档位、是否支持锁定、本地读写回调等IWeatherControlGroup一栏内容的抽象,让模组可以挂自己的 UI 视图进面板WeatherControlInfo普通项的具体实现,内置项和Mod.Call注册的项都用这个WeatherControlRegistry注册中心,是ModSystem,提供Register/Unregister/TryGet/DispatchStage/DispatchLocked等WeatherBuiltinControls把内置 5 项注册进 Registry,对接现有的WeatherController静态字段WeatherControlCrossMod把Mod.Call收到的弱引用参数转成WeatherControlInfo走 Registry通用同步包
Packets/Weather/WeatherStageSyncPacket通用档位同步,包内只带id与目标stageWeatherLockSyncPacket通用锁定同步,结构同上UI
UI/WeatherControl/ModdedWeatherItemsView浮在艺术画面左上角,横向排列所有未指定栏目的模组项WeatherControlSlot单个槽位,32x32 半透明小框,左键循环档位,右键切锁定,悬停 tooltip 用 displayName + tooltip + 锁定提示WeatherGUI增加BuildCustomGroupViews()把外部注册的IWeatherControlGroup视图按优先级倒序挂进MainPanelMod.Call API(
Common/ModSystems/ModIntegrationsSystem.cs)新增 8 个分支,命名对齐已有约定:
RegisterWeatherControl/UnregisterWeatherControlRegisterWeatherControlGroup/UnregisterWeatherControlGroupQueryWeatherControlStage/SetWeatherControlStageIsWeatherControlLocked/SetWeatherControlLocked每条都把参数解析交给
WeatherControlCrossMod,返回值约定与项目现有Mod.Call一致(查询类返回结果,操作类返回bool)。实际效果
如图,我编写了一个“火烧日”模组,简单实现了一个烧灼大地风格的天气事件,通过
Mod.Call将这个天气的控制注册进了ImproveGame该模组我已经同步上传至github: hocha113/FireoftheSun
Helper 文件
新增
ImproveGame_WeatherControlCrossModHelper.cs在项目根目录,跟现有的ImproveGame_ModernConfigCrossModHelper.cs同套路:提供强类型封装与内置项 Id 速查常量,建议外部开发者复制到自己模组里直接调用。顺带修的 bug
Content/Functions/WeatherController.cs里SandstormLocked写入键名是sandstorm、读取键名是sandstormLocked,老版本写入的存档读不回锁定状态。统一改成sandstormLocked,同时兼容读取旧的sandstorm键。兼容性
WeatherController.RainLocked/SandstormLocked/MoonPhaseLocked/WindLocked保留不变SetTimePacket/SetMoonPhasePacket/SetRainPacket/SetSandstormPacket/SetWindPacket)未动,原版艺术画面 UI 还是走它们sandstorm键名也能读测试
FireoftheSun("火烧日"),通过 Helper 接入新的Mod.CallAPI,在面板艺术画面里看到自己的图标 + 悬停 tooltip + 左右键交互;该模组还实现了CustomSky+ModSceneEffect+Filters.Scene来演示一个完整的天气效果接入是什么样子Unlocked/RainLocked等键)加载后状态恢复正常sandstorm键存档验证向后兼容读取文档
CrossModSupport.md追加了 8 个新条目 + 内置项 Id 速查表 + 使用例README-en.md的 Cross-mod 区段同步追加了英文版Checklist