feat: 添加特殊字段处理器支持(consumes/requirements等) - #2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2a2d18922
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| private class TempField( | ||
| private val fieldName: String, | ||
| private val fieldType: Class<*> | ||
| ) : Field(null, 0, null, null) { |
There was a problem hiding this comment.
Stop subclassing java.lang.reflect.Field
This TempField class cannot compile because java.lang.reflect.Field is a final JDK class with non-public constructors, so the new special-field path blocks building the Kotlin sources before any JSON import can run. The same : Field(...) pattern appears in the other new temp-field helpers as well, so these synthetic fields need a different representation than a Field subclass.
Useful? React with 👍 / 👎.
| // 创建一个临时字段来存储这个 Consume | ||
| val tempField = createTempField(key, consumeType) | ||
| val fb = FieldBuild(tempField, parser, ownerClassName = ownerClassName) | ||
| applyJsonToFieldBuild(fb, value, tempField) |
There was a problem hiding this comment.
Pass a JsonWorkFile parser helper into handlers
When compiling this file, this call is unresolved because applyJsonToFieldBuild is a private member of JsonWorkFile, while ConsumeFieldHandler and RequirementsFieldHandler are top-level classes with no JsonWorkFile receiver. As a result, any build that includes these handlers fails before the new consumes/requirements support can be used.
Useful? React with 👍 / 👎.
变更说明
为 ContentParser 中有专门分支的特殊字段(如
consumes、requirements)添加适配支持。问题
原版 ContentParser 对以下字段有专门的解析分支:
consumes- Block 的消耗器系统requirements- UnitType 的需求配置而 MindustryMIT 的
buildClassBuildFromJson使用getFieldByName(key) ?: continue,导致这些字段被静默丢弃。解决方案
添加
SpecialFieldHandler接口canHandle(fieldName)- 检查是否能处理该字段handle(element, parser, ownerClassName)- 处理特殊字段实现内置处理器
ConsumeFieldHandler- 处理 Block 的 consumes 字段RequirementsFieldHandler- 处理 UnitType 的 requirements 字段注册表机制
SpecialFieldRegistry管理所有处理器集成到
buildClassBuildFromJson文件变更
JsonWorkFile.kt- 添加特殊字段处理器接口和实现测试