Skip to content

feat: 添加特殊字段处理器支持(consumes/requirements等) - #2

Open
ZenthXSin wants to merge 1 commit into
mainfrom
feature/special-field-handlers
Open

feat: 添加特殊字段处理器支持(consumes/requirements等)#2
ZenthXSin wants to merge 1 commit into
mainfrom
feature/special-field-handlers

Conversation

@ZenthXSin

Copy link
Copy Markdown
Owner

变更说明

为 ContentParser 中有专门分支的特殊字段(如 consumesrequirements)添加适配支持。

问题

原版 ContentParser 对以下字段有专门的解析分支:

  • consumes - Block 的消耗器系统
  • requirements - UnitType 的需求配置
  • 其他特殊类型字段

而 MindustryMIT 的 buildClassBuildFromJson 使用 getFieldByName(key) ?: continue,导致这些字段被静默丢弃。

解决方案

  1. 添加 SpecialFieldHandler 接口

    • canHandle(fieldName) - 检查是否能处理该字段
    • handle(element, parser, ownerClassName) - 处理特殊字段
  2. 实现内置处理器

    • ConsumeFieldHandler - 处理 Block 的 consumes 字段
    • RequirementsFieldHandler - 处理 UnitType 的 requirements 字段
  3. 注册表机制

    • SpecialFieldRegistry 管理所有处理器
    • 支持自定义扩展注册新处理器
  4. 集成到 buildClassBuildFromJson

    • 优先检查特殊字段处理器
    • 处理成功则跳过普通字段解析

文件变更

  • JsonWorkFile.kt - 添加特殊字段处理器接口和实现

测试

  • 验证 consumes 字段能正确解析
  • 验证 requirements 字段能正确解析
  • 验证普通字段解析不受影响

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant